lib/users.js
function resetPassword (c) {
  return function resetPassword (realmName, userId, payload) {
    return new Promise((resolve, reject) => {
      payload = payload || {};
      payload.type = 'password';

      if (!userId) {
        return reject(new Error('userId is missing'));
      }

      if (!payload.value) {
        return reject(new Error('value for the new password is missing'));
      }

      const req = {
        url: `${c.baseUrl}/admin/realms/${realmName}/users/${userId}/reset-password`,
        auth: {
          bearer: privates.get(c).accessToken
        },
        json: true,
        method: 'PUT',
        body: payload
      };

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

        // Check that the status cod
        if (resp.statusCode !== 204) {
          return reject(body);
        }

        return resolve(body);
      });
    });
  };
}
function resetPassword (c) {
  return function resetPassword (realmName, userId, payload) {
    return new Promise((resolve, reject) => {
      payload = payload || {};
      payload.type = 'password';

      if (!userId) {
        return reject(new Error('userId is missing'));
      }

      if (!payload.value) {
        return reject(new Error('value for the new password is missing'));
      }

      const req = {
        url: `${c.baseUrl}/admin/realms/${realmName}/users/${userId}/reset-password`,
        auth: {
          bearer: privates.get(c).accessToken
        },
        json: true,
        method: 'PUT',
        body: payload
      };

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

        // Check that the status cod
        if (resp.statusCode !== 204) {
          return reject(body);
        }

        return resolve(body);
      });
    });
  };
}
function resetPassword ( c ) { return function resetPassword ( realmName , userId , payload ) { return new Promise ( ( resolve , reject ) => { payload = payload || { } ; payload . type = 'password' ; if ( ! userId ) { return reject ( new Error ( 'userId is missing' ) ) ; } if ( ! payload . value ) { return reject ( new Error ( 'value for the new password is missing' ) ) ; } const req = { url : ` ${ c . baseUrl } ${ realmName } ${ userId } ` , auth : { bearer : privates . get ( c ) . accessToken } , json : true , method : 'PUT' , body : payload } ; request ( req , ( err , resp , body ) => { if ( err ) { return reject ( err ) ; } // Check that the status cod if ( resp . statusCode !== 204 ) { return reject ( body ) ; } return resolve ( body ) ; } ) ; } ) ; } ; }
A function to reset a user password for a realm
@param {string} realmName - The name of the realm(not the realmID) - ex: master,
@param {string} userId - The id of user
@param {object} payload { temporary: boolean , value : string } - The JSON representation of the fields to update for the password
@returns {Promise} A promise that resolves.
@example
keycloakAdminClient(settings)
.then((client) => {
client.users.resetPassword(realmName, userId, { temporary: boolean , value : string})
.then(() => {
console.log('success')
})
})
A function to reset a user password for a realm