Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
althaf004 opened this issue Oct 22, 2024 · 2 comments
Open

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

althaf004 opened this issue Oct 22, 2024 · 2 comments

Comments

@althaf004
Copy link

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

is it some parameters i needed to have along with

def create_user(self, payload, exist_ok=False):
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
Copy link

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.

@althaf004
Copy link
Author

@carbonleakage

You’re correct that adding a user from the master realm to another realm is the case here. However, along with the user details, I also need to add the IDP (Identity Provider) details of the user.

This is where I’m stuck.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants