marcospereirampj / python-keycloak

MIT License
728 stars 303 forks source link

How to add a user with the IDP details to the realm using the API #609

Open althaf004 opened 1 month ago

althaf004 commented 1 month ago

I needed to create a user to the realm with its IDP details.

is it some parameters i needed to have along with https://github.com/marcospereirampj/python-keycloak/blob/7cfad72a68346ca4cbcba69f9e8808091ae47daa/src/keycloak/keycloak_admin.py#L551 API?

      import json
      from keycloak import KeycloakOpenID
      from keycloak import KeycloakAdmin
      try:         
        keycloak_admin = KeycloakAdmin(server_url=api_base_url,
                                          username=admin_username,
                                          password=admin_password,
                                          realm_name=master_realm,                                     
                                          verify=True)    
        keycloak_admin.realm_name = user_realm_name                                
        new_user = keycloak_admin.create_user({"email":email,
                              "username": username,
                              "enabled": True,
                              "firstName":firstname,
                              "lastName": lastname,
                              "credentials": [{"value": value_password,"type":  "password",}]})

Thanks Althaf

carbonleakage commented 1 week ago

If I understand correctly you have an admin user in the master realm, you would like to create a user in another realm? If so this should work.

When initiating the KeycloakAdmin set the user_realm_name= 'master' or the appropriate realm where the admin user is defined, and set the realm_name to the realm where you want new user to be created.