lib/users.js
function find (client) {
  return function find (realm, options) {
    return new Promise((resolve, reject) => {
      options = options || {};
      const req = {
        auth: {
          bearer: privates.get(client).accessToken
        },
        json: true
      };

      if (options.userId) {
        req.url = `${client.baseUrl}/admin/realms/${realm}/users/${options.userId}`;
      } else {
        req.url = `${client.baseUrl}/admin/realms/${realm}/users`;
        req.qs = options;
      }

      request(req, (err, resp, body) => {
        if (err) {
          return reject(err);
        }

        if (resp.statusCode !== 200) {
          return reject(body);
        }

        return resolve(body);
      });
    });
  };
}
function find (client) {
  return function find (realm, options) {
    return new Promise((resolve, reject) => {
      options = options || {};
      const req = {
        auth: {
          bearer: privates.get(client).accessToken
        },
        json: true
      };

      if (options.userId) {
        req.url = `${client.baseUrl}/admin/realms/${realm}/users/${options.userId}`;
      } else {
        req.url = `${client.baseUrl}/admin/realms/${realm}/users`;
        req.qs = options;
      }

      request(req, (err, resp, body) => {
        if (err) {
          return reject(err);
        }

        if (resp.statusCode !== 200) {
          return reject(body);
        }

        return resolve(body);
      });
    });
  };
}
function find ( client ) { return function find ( realm , options ) { return new Promise ( ( resolve , reject ) => { options = options || { } ; const req = { auth : { bearer : privates . get ( client ) . accessToken } , json : true } ; if ( options . userId ) { req . url = ` ${ client . baseUrl } ${ realm } ${ options . userId } ` ; } else { req . url = ` ${ client . baseUrl } ${ realm } ` ; req . qs = options ; } request ( req , ( err , resp , body ) => { if ( err ) { return reject ( err ) ; } if ( resp . statusCode !== 200 ) { return reject ( body ) ; } return resolve ( body ) ; } ) ; } ) ; } ; }
A function to get the list of users or a user for a realm.
@param {string} realmName - The name of the realm(not the realmID) - ex: master
@param {object} [options] - The options object
@param {string} [options.userId] - use this options to get a user by an id. If this value is populated, it overrides the querystring param options
@param {string} [options.username] - the querystring param to search based on username
@param {string} [options.firstName] - the querystring param to search based on firstName
@param {string} [options.lastName] - the querystring param to search based on lastName
@param {string} [options.email] - the querystring param to search based on email
@returns {Promise} A promise that will resolve with an Array of user objects or just the 1 user object if userId is used
@example
keycloakAdminClient(settings)
.then((client) => {
client.users.find(realmName)
.then((userList) => {
console.log(userList) // [{...},{...}, ...]
})
})
A function to get the list of users or a user for a realm .