services/src/main/java/org/keycloak/services/resources/admin/UsersResource.java
/**
     * Send an email to the user with a link they can click to reset their password.
     * The redirectUri and clientId parameters are optional. The default for the
     * redirect is the account client.
     *
     * @param id
     * @param redirectUri redirect uri
     * @param clientId client id
     * @return
     */
Send an email to the user with a link they can click to reset their password.
The redirectUri and clientId parameters are optional. The default for the
redirect is the account client.

@param id
@param redirectUri redirect uri
@param clientId client id
@return
Send an email to the user with a link they can click to reset their password . The redirectUri and clientId parameters are optional . The default for the redirect is the account client . @param id @param redirectUri redirect uri @param clientId client id @return
@Path("{id}/reset-password-email")
    @PUT
    @Consumes(MediaType.APPLICATION_JSON)
    public Response resetPasswordEmail(@PathParam("id") String id, @QueryParam(OIDCLoginProtocol.REDIRECT_URI_PARAM) String redirectUri, @QueryParam(OIDCLoginProtocol.CLIENT_ID_PARAM) String clientId) {
        auth.requireManage();
        UserModel user = session.users().getUserById(id, realm);
        if (user == null) {
            return ErrorResponse.error("User not found", Response.Status.NOT_FOUND);
        }
        if (user.getEmail() == null) {
            return ErrorResponse.error("User email missing", Response.Status.BAD_REQUEST);
        }
        ClientSessionModel clientSession = createClientSession(user, redirectUri, clientId);
        ClientSessionCode accessCode = new ClientSessionCode(realm, clientSession);
        accessCode.setAction(ClientSessionModel.Action.RECOVER_PASSWORD);
        try {
            UriBuilder builder = Urls.loginPasswordResetBuilder(uriInfo.getBaseUri());
            builder.queryParam("key", accessCode.getCode());
            String link = builder.build(realm.getName()).toString();
            long expiration = TimeUnit.SECONDS.toMinutes(realm.getAccessCodeLifespanUserAction());
            this.session.getProvider(EmailProvider.class).setRealm(realm).setUser(user).sendPasswordReset(link, expiration);
            adminEvent.operation(OperationType.ACTION).resourcePath(uriInfo).success();
            return Response.ok().build();
        } catch (EmailException e) {
            logger.error("Failed to send password reset email", e);
            return ErrorResponse.error("Failed to send email", Response.Status.INTERNAL_SERVER_ERROR);
        }
    }
@ Path ( "{id}/reset-password-email" ) @ PUT @ Consumes ( MediaType . APPLICATION_JSON ) public Response resetPasswordEmail ( @ PathParam ( "id" ) String id , @ QueryParam ( OIDCLoginProtocol . REDIRECT_URI_PARAM ) String redirectUri , @ QueryParam ( OIDCLoginProtocol . CLIENT_ID_PARAM ) String clientId ) { auth . requireManage ( ) ; UserModel user = session . users ( ) . getUserById ( id , realm ) ; if ( user == null ) { return ErrorResponse . error ( "User not found" , Response . Status . NOT_FOUND ) ; } if ( user . getEmail ( ) == null ) { return ErrorResponse . error ( "User email missing" , Response . Status . BAD_REQUEST ) ; } ClientSessionModel clientSession = createClientSession ( user , redirectUri , clientId ) ; ClientSessionCode accessCode = new ClientSessionCode ( realm , clientSession ) ; accessCode . setAction ( ClientSessionModel . Action . RECOVER_PASSWORD ) ; try { UriBuilder builder = Urls . loginPasswordResetBuilder ( uriInfo . getBaseUri ( ) ) ; builder . queryParam ( "key" , accessCode . getCode ( ) ) ; String link = builder . build ( realm . getName ( ) ) . toString ( ) ; long expiration = TimeUnit . SECONDS . toMinutes ( realm . getAccessCodeLifespanUserAction ( ) ) ; this . session . getProvider ( EmailProvider . class ) . setRealm ( realm ) . setUser ( user ) . sendPasswordReset ( link , expiration ) ; adminEvent . operation ( OperationType . ACTION ) . resourcePath ( uriInfo ) . success ( ) ; return Response . ok ( ) . build ( ) ; } catch ( EmailException e ) { logger . error ( "Failed to send password reset email" , e ) ; return ErrorResponse . error ( "Failed to send email" , Response . Status . INTERNAL_SERVER_ERROR ) ; } }
Send an email to the user with a link they can click to reset their password.
Send an email to the user with a link they can click to reset their password .
//audit.user(user).detail(Details.EMAIL, user.getEmail()).detail(Details.CODE_ID, accessCode.getCodeId()).success();
