[Django]-Keycloak user Invitation email

5👍

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

👤Salem

Leave a comment