|
@ -73,14 +73,15 @@ Usage |
|
|
|
|
|
|
|
|
Main methods:: |
|
|
Main methods:: |
|
|
|
|
|
|
|
|
|
|
|
# KEYCLOAK OPENID |
|
|
|
|
|
|
|
|
from keycloak import KeycloakOpenID |
|
|
from keycloak import KeycloakOpenID |
|
|
|
|
|
|
|
|
# Configure client |
|
|
# Configure client |
|
|
keycloak_openid = KeycloakOpenID(server_url="http://localhost:8080/auth/", |
|
|
keycloak_openid = KeycloakOpenID(server_url="http://localhost:8080/auth/", |
|
|
client_id="example_client", |
|
|
client_id="example_client", |
|
|
realm_name="example_realm", |
|
|
realm_name="example_realm", |
|
|
client_secret_key="secret", |
|
|
|
|
|
verify=True) |
|
|
|
|
|
|
|
|
client_secret_key="secret") |
|
|
|
|
|
|
|
|
# Get WellKnow |
|
|
# Get WellKnow |
|
|
config_well_know = keycloak_openid.well_know() |
|
|
config_well_know = keycloak_openid.well_know() |
|
@ -91,6 +92,9 @@ Main methods:: |
|
|
# Get Userinfo |
|
|
# Get Userinfo |
|
|
userinfo = keycloak_openid.userinfo(token['access_token']) |
|
|
userinfo = keycloak_openid.userinfo(token['access_token']) |
|
|
|
|
|
|
|
|
|
|
|
# Refresh token |
|
|
|
|
|
token = keycloak_openid.refresh_token(token['refresh_token']) |
|
|
|
|
|
|
|
|
# Logout |
|
|
# Logout |
|
|
keycloak_openid.logout(token['refresh_token']) |
|
|
keycloak_openid.logout(token['refresh_token']) |
|
|
|
|
|
|
|
@ -138,12 +142,26 @@ Main methods:: |
|
|
"realmRoles": ["user_default", ], |
|
|
"realmRoles": ["user_default", ], |
|
|
"attributes": {"example": "1,2,3,3,"}}) |
|
|
"attributes": {"example": "1,2,3,3,"}}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Add user and set password |
|
|
|
|
|
new_user = keycloak_admin.create_user({"email": "example@example.com", |
|
|
|
|
|
"username": "example@example.com", |
|
|
|
|
|
"enabled": True, |
|
|
|
|
|
"firstName": "Example", |
|
|
|
|
|
"lastName": "Example", |
|
|
|
|
|
"credentials": [{"value": "secret","type": "password",}], |
|
|
|
|
|
"realmRoles": ["user_default", ], |
|
|
|
|
|
"attributes": {"example": "1,2,3,3,"}}) |
|
|
|
|
|
|
|
|
# User counter |
|
|
# User counter |
|
|
count_users = keycloak_admin.users_count() |
|
|
count_users = keycloak_admin.users_count() |
|
|
|
|
|
|
|
|
# Get users Returns a list of users, filtered according to query parameters |
|
|
# Get users Returns a list of users, filtered according to query parameters |
|
|
users = keycloak_admin.get_users({}) |
|
|
users = keycloak_admin.get_users({}) |
|
|
|
|
|
|
|
|
|
|
|
# Get user ID from name |
|
|
|
|
|
user-id-keycloak = keycloak_admin.get_user_id("example@example.com") |
|
|
|
|
|
|
|
|
# Get User |
|
|
# Get User |
|
|
user = keycloak_admin.get_user("user-id-keycloak") |
|
|
user = keycloak_admin.get_user("user-id-keycloak") |
|
|
|
|
|
|
|
@ -151,6 +169,9 @@ Main methods:: |
|
|
response = keycloak_admin.update_user(user_id="user-id-keycloak", |
|
|
response = keycloak_admin.update_user(user_id="user-id-keycloak", |
|
|
payload={'firstName': 'Example Update'}) |
|
|
payload={'firstName': 'Example Update'}) |
|
|
|
|
|
|
|
|
|
|
|
# Update User Password |
|
|
|
|
|
response = set_user_password(user_id="user-id-keycloak", password="secret", temporary=True) |
|
|
|
|
|
|
|
|
# Delete User |
|
|
# Delete User |
|
|
response = keycloak_admin.delete_user(user_id="user-id-keycloak") |
|
|
response = keycloak_admin.delete_user(user_id="user-id-keycloak") |
|
|
|
|
|
|
|
@ -177,19 +198,38 @@ Main methods:: |
|
|
client_id=keycloak_admin.get_client_id("my-client") |
|
|
client_id=keycloak_admin.get_client_id("my-client") |
|
|
|
|
|
|
|
|
# Get representation of the client - id of client (not client-id) |
|
|
# Get representation of the client - id of client (not client-id) |
|
|
client_roles = keycloak_admin.get_client_role(client_id=client_id) |
|
|
|
|
|
|
|
|
client = keycloak_admin.get_client(client_id="client_id") |
|
|
|
|
|
|
|
|
|
|
|
# Get all roles for the realm or client |
|
|
|
|
|
realm_roles = keycloak_admin.get_realm_roles() |
|
|
|
|
|
|
|
|
# Get all roles for the client |
|
|
# Get all roles for the client |
|
|
client_roles = keycloak_admin.get_client_role(client_id=client_id) |
|
|
|
|
|
|
|
|
client_roles = keycloak_admin.get_client_roles(client_id="client_id") |
|
|
|
|
|
|
|
|
# Create client role |
|
|
|
|
|
keycloak_admin.create_client_role(client_id, "test") |
|
|
|
|
|
|
|
|
# Get client role |
|
|
|
|
|
role = keycloak_admin.get_client_role(client_id="client_id", role_name="role_name") |
|
|
|
|
|
|
|
|
|
|
|
# Warning: Deprecated |
|
|
# Get client role id from name |
|
|
# Get client role id from name |
|
|
role_id = keycloak_admin.get_client_role_id(client_id=client_id, role_name="test") |
|
|
|
|
|
|
|
|
role_id = keycloak_admin.get_client_role_id(client_id="client_id", role_name="test") |
|
|
|
|
|
|
|
|
# Get all roles for the realm or client |
|
|
|
|
|
realm_roles = keycloak_admin.get_roles() |
|
|
|
|
|
|
|
|
# Create client role |
|
|
|
|
|
keycloak_admin.create_client_role(client_id, "test") |
|
|
|
|
|
|
|
|
# Assign client role to user. Note that BOTH role_name and role_id appear to be required. |
|
|
# Assign client role to user. Note that BOTH role_name and role_id appear to be required. |
|
|
keycloak_admin.assign_client_role(client_id=client_id, user_id=user_id, role_id=role_id, role_name="test") |
|
|
|
|
|
|
|
|
keycloak_admin.assign_client_role(client_id="client_id", user_id="user_id", role_id="role_id", role_name="test") |
|
|
|
|
|
|
|
|
|
|
|
# Create new group |
|
|
|
|
|
group = keycloak_admin.create_group(name="Example Group") |
|
|
|
|
|
|
|
|
|
|
|
# Get all groups |
|
|
|
|
|
groups = keycloak_admin.get_groups() |
|
|
|
|
|
|
|
|
|
|
|
# Get group |
|
|
|
|
|
group = keycloak_admin.get_group(group_id='group_id') |
|
|
|
|
|
|
|
|
|
|
|
# Get group by name |
|
|
|
|
|
group = keycloak_admin.get_group_by_name(name_or_path='group_id', search_in_subgroups=True) |
|
|
|
|
|
|
|
|
|
|
|
# Function to trigger user sync from provider |
|
|
|
|
|
sync_users(storage_id="storage_di", action="action") |