marcospereirampj / python-keycloak

MIT License
724 stars 301 forks source link

API to send a verification email after creating a user #391

Open althaf004 opened 1 year ago

althaf004 commented 1 year ago

Below is my requirement,

1) API to create a user and send a verify email to confirm their account. 2) API to send password reset link.

With my current understanding we can edit only executeaction.ftl to make the api work. But the subject line cant be made dynamic.

Any help on my above requirement is much appreciated.

Althaf

ryshoooo commented 1 year ago

To create a new user you can use the KeycloakAdmin class

new_user = keycloak_admin.create_user({"email": "example@example.com",
                                       "username": "example@example.com",
                                       "enabled": True,
                                       "firstName": "Example",
                                       "lastName": "Example"})

To send a verification email, you can again use the KeycloakAdmin class

response = keycloak_admin.send_verify_email(user_id="user-id-keycloak")

To send a reset password link, you can again use the KeycloakAdmin class

keycloak_admin.send_update_account(user_id="user-id-keycloak", payload=["UPDATE_PASSWORD"], lifespan=43200)

If you wish to have a dynamic subject on the email, this is something that we can't support as this library is just a python client library for Keycloak's API. For dynamic subjects on the emails you should make a request on the Keycloak repository.