Keycloak user Invitation email

Viewed 2223

I am using Keycloak-9.0.2 as SSO in my Django project. I want to get send an invitation link in the e-mail by one user to another user. Is there any inbuilt functionality in Keycloak for the same? If not then what should be the better way to do this in Django.

1 Answers

You can use python-keycloak library like this:

from keycloak import KeycloakAdmin

keycloak_admin = KeycloakAdmin(server_url="http://localhost:8080/auth/",
                           username='example-admin',
                           password='secret',
                           realm_name="master",
                           user_realm_name="only_if_other_realm_than_master",
                           client_secret_key="client-secret",
                           verify=True)
# Add user                       
new_user = keycloak_admin.create_user({"email": "example@example.com",
                "username": "example@example.com",
                "enabled": True,
                "requiredActions": ["UPDATE_PASSWORD", "UPDATE_PROFILE", "VERIFY_EMAIL"]})


# Get user ID from name
user_id_keycloak = keycloak_admin.get_user_id("example@example.com")

# Send User Action
response = keycloak_admin.send_update_account(user_id=user_id_keycloak, 
                                          payload=json.dumps(["UPDATE_PASSWORD", "UPDATE_PROFILE", "VERIFY_EMAIL"]))

Then you will get invite email like this:

Email invite example

Related