Repository files navigation

CircleCIDocumentation Status

Python Keycloak

For review- see https://github.com/marcospereirampj/python-keycloak

python-keycloak is a Python package providing access to the Keycloak API.

Installation

Via Pypi Package:

$ pip install python-keycloak

Manually

$ python setup.py install

Dependencies

python-keycloak depends on:

Tests Dependencies

Bug reports

Please report bugs and feature requests at https://github.com/marcospereirampj/python-keycloak/issues

Documentation

The documentation for python-keycloak is available on readthedocs.

Contributors

Usage

fromkeycloakimportKeycloakOpenID# Configure clientkeycloak_openid=KeycloakOpenID(server_url="http://localhost:8080/auth/",
client_id="example_client",
realm_name="example_realm",
client_secret_key="secret")
# Get WellKnownconfig_well_known=keycloak_openid.well_known()
# Get Code With Oauth Authorization Requestauth_url=keycloak_openid.auth_url(
redirect_uri="your_call_back_url",
scope="email",
state="your_state_info")
# Get Access Token With Codeaccess_token=keycloak_openid.token(
grant_type='authorization_code',
code='the_code_you_get_from_auth_url_callback',
redirect_uri="your_call_back_url")
# Get Tokentoken=keycloak_openid.token("user", "password")
token=keycloak_openid.token("user", "password", totp="012345")
# Get token using Token Exchangetoken=keycloak_openid.exchange_token(token['access_token'], "my_client", "other_client", "some_user")
# Get Userinfouserinfo=keycloak_openid.userinfo(token['access_token'])
# Refresh tokentoken=keycloak_openid.refresh_token(token['refresh_token'])
# Logoutkeycloak_openid.logout(token['refresh_token'])
# Get Certscerts=keycloak_openid.certs()
# Get RPT (Entitlement)token=keycloak_openid.token("user", "password")
rpt=keycloak_openid.entitlement(token['access_token'], "resource_id")
# Introspect RPTtoken_rpt_info=keycloak_openid.introspect(keycloak_openid.introspect(token['access_token'], rpt=rpt['rpt'],
token_type_hint="requesting_party_token"))
# Introspect Tokentoken_info=keycloak_openid.introspect(token['access_token'])
# Decode TokenKEYCLOAK_PUBLIC_KEY="-----BEGIN PUBLIC KEY-----\n"+keycloak_openid.public_key() +"\n-----END PUBLIC KEY-----"options= {"verify_signature": True, "verify_aud": True, "verify_exp": True}
token_info=keycloak_openid.decode_token(token['access_token'], key=KEYCLOAK_PUBLIC_KEY, options=options)
# Get permissions by tokentoken=keycloak_openid.token("user", "password")
keycloak_openid.load_authorization_config("example-authz-config.json")
policies=keycloak_openid.get_policies(token['access_token'], method_token_info='decode', key=KEYCLOAK_PUBLIC_KEY)
permissions=keycloak_openid.get_permissions(token['access_token'], method_token_info='introspect')
# Get UMA-permissions by tokentoken=keycloak_openid.token("user", "password")
permissions=keycloak_openid.uma_permissions(token['access_token'])
# Get UMA-permissions by token with specific resource and scope requestedtoken=keycloak_openid.token("user", "password")
permissions=keycloak_openid.uma_permissions(token['access_token'], permissions="Resource#Scope")
# Get auth status for a specific resource and scope by tokentoken=keycloak_openid.token("user", "password")
auth_status=keycloak_openid.has_uma_access(token['access_token'], "Resource#Scope")
# KEYCLOAK ADMINfromkeycloakimportKeycloakAdminfromkeycloakimportKeycloakOpenIDConnectionkeycloak_connection=KeycloakOpenIDConnection(
server_url="http://localhost:8080/",
username='example-admin',
password='secret',
realm_name="master",
user_realm_name="only_if_other_realm_than_master",
client_id="my_client",
client_secret_key="client-secret",
verify=True)
keycloak_admin=KeycloakAdmin(connection=keycloak_connection)
# Add usernew_user=keycloak_admin.create_user({"email": "example@example.com",
"username": "example@example.com",
"enabled": True,
"firstName": "Example",
"lastName": "Example"})
# Add user and raise exception if username already exists# exist_ok currently defaults to True for backwards compatibility reasonsnew_user=keycloak_admin.create_user({"email": "example@example.com",
"username": "example@example.com",
"enabled": True,
"firstName": "Example",
"lastName": "Example"},
exist_ok=False)
# Add user and set passwordnew_user=keycloak_admin.create_user({"email": "example@example.com",
"username": "example@example.com",
"enabled": True,
"firstName": "Example",
"lastName": "Example",
"credentials": [{"value": "secret","type": "password",}]})
# Add user and specify a localenew_user=keycloak_admin.create_user({"email": "example@example.fr",
"username": "example@example.fr",
"enabled": True,
"firstName": "Example",
"lastName": "Example",
"attributes": {
"locale": ["fr"]
}})
# User countercount_users=keycloak_admin.users_count()
# Get users Returns a list of users, filtered according to query parametersusers=keycloak_admin.get_users({})
# Get user ID from usernameuser_id_keycloak=keycloak_admin.get_user_id("username-keycloak")
# Get Useruser=keycloak_admin.get_user("user-id-keycloak")
# Update Userresponse=keycloak_admin.update_user(user_id="user-id-keycloak",
payload={'firstName': 'Example Update'})
# Update User Passwordresponse=keycloak_admin.set_user_password(user_id="user-id-keycloak", password="secret", temporary=True)
# Get User Credentialscredentials=keycloak_admin.get_credentials(user_id='user_id')
# Get User Credential by IDcredential=keycloak_admin.get_credential(user_id='user_id', credential_id='credential_id')
# Delete User Credentialresponse=keycloak_admin.delete_credential(user_id='user_id', credential_id='credential_id')
# Delete Userresponse=keycloak_admin.delete_user(user_id="user-id-keycloak")
# Get consents granted by the userconsents=keycloak_admin.consents_user(user_id="user-id-keycloak")
# Send User Actionresponse=keycloak_admin.send_update_account(user_id="user-id-keycloak",
payload=['UPDATE_PASSWORD'])
# Send Verify Emailresponse=keycloak_admin.send_verify_email(user_id="user-id-keycloak")
# Get sessions associated with the usersessions=keycloak_admin.get_sessions(user_id="user-id-keycloak")
# Get themes, social providers, auth providers, and event listeners available on this serverserver_info=keycloak_admin.get_server_info()
# Get clients belonging to the realm Returns a list of clients belonging to the realmclients=keycloak_admin.get_clients()
# Get client - id (not client-id) from client by nameclient_id=keycloak_admin.get_client_id("my-client")
# Get representation of the client - id of client (not client-id)client=keycloak_admin.get_client(client_id="client_id")
# Get all roles for the realm or clientrealm_roles=keycloak_admin.get_realm_roles()
# Get all roles for the clientclient_roles=keycloak_admin.get_client_roles(client_id="client_id")
# Get client rolerole=keycloak_admin.get_client_role(client_id="client_id", role_name="role_name")
# Warning: Deprecated# Get client role id from namerole_id=keycloak_admin.get_client_role_id(client_id="client_id", role_name="test")
# Create client rolekeycloak_admin.create_client_role(client_role_id='client_id', payload={'name': 'roleName', 'clientRole': True})
# 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")
# Retrieve client roles of a user.keycloak_admin.get_client_roles_of_user(user_id="user_id", client_id="client_id")
# Retrieve available client roles of a user.keycloak_admin.get_available_client_roles_of_user(user_id="user_id", client_id="client_id")
# Retrieve composite client roles of a user.keycloak_admin.get_composite_client_roles_of_user(user_id="user_id", client_id="client_id")
# Delete client roles of a user.keycloak_admin.delete_client_roles_of_user(client_id="client_id", user_id="user_id", roles={"id": "role-id"})
keycloak_admin.delete_client_roles_of_user(client_id="client_id", user_id="user_id", roles=[{"id": "role-id_1"}, {"id": "role-id_2"}])
# Get the client authorization settingsclient_authz_settings=get_client_authz_settings(client_id="client_id")
# Get all client authorization resourcesclient_resources=get_client_authz_resources(client_id="client_id")
# Get all client authorization scopesclient_scopes=get_client_authz_scopes(client_id="client_id")
# Get all client authorization permissionsclient_permissions=get_client_authz_permissions(client_id="client_id")
# Get all client authorization policiesclient_policies=get_client_authz_policies(client_id="client_id")
# Create new groupgroup=keycloak_admin.create_group({"name": "Example Group"})
# Get all groupsgroups=keycloak_admin.get_groups()
# Get groupgroup=keycloak_admin.get_group(group_id='group_id')
# Get group by namegroup=keycloak_admin.get_group_by_path(path='/group/subgroup', search_in_subgroups=True)
# Function to trigger user sync from providersync_users(storage_id="storage_di", action="action")
# Get client role id from namerole_id=keycloak_admin.get_client_role_id(client_id=client_id, role_name="test")
# 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")
# Assign realm roles to userkeycloak_admin.assign_realm_roles(user_id=user_id, roles=realm_roles)
# Assign realm roles to client's scopekeycloak_admin.assign_realm_roles_to_client_scope(client_id=client_id, roles=realm_roles)
# Get realm roles assigned to client's scopekeycloak_admin.get_realm_roles_of_client_scope(client_id=client_id)
# Remove realm roles assigned to client's scopekeycloak_admin.delete_realm_roles_of_client_scope(client_id=client_id, roles=realm_roles)
another_client_id=keycloak_admin.get_client_id("my-client-2")
# Assign client roles to client's scopekeycloak_admin.assign_client_roles_to_client_scope(client_id=another_client_id, client_roles_owner_id=client_id, roles=client_roles)
# Get client roles assigned to client's scopekeycloak_admin.get_client_roles_of_client_scope(client_id=another_client_id, client_roles_owner_id=client_id)
# Remove client roles assigned to client's scopekeycloak_admin.delete_client_roles_of_client_scope(client_id=another_client_id, client_roles_owner_id=client_id, roles=client_roles)
# Get all ID Providersidps=keycloak_admin.get_idps()
# Create a new Realmkeycloak_admin.create_realm(payload={"realm": "demo"}, skip_exists=False)
# Changing Realmkeycloak_admin=KeycloakAdmin(realm_name="main", ...)
keycloak_admin.get_users() # Get user in main realmkeycloak_admin.realm_name="demo"# Change realm to 'demo'keycloak_admin.get_users() # Get users in realm 'demo'keycloak_admin.create_user(...) # Creates a new user in 'demo'# KEYCLOAK UMAfromkeycloakimportKeycloakOpenIDConnectionfromkeycloakimportKeycloakUMAkeycloak_connection=KeycloakOpenIDConnection(
server_url="http://localhost:8080/",
realm_name="master",
client_id="my_client",
client_secret_key="client-secret")
keycloak_uma=KeycloakUMA(connection=keycloak_connection)
# Create a resource setresource_set=keycloak_uma.resource_set_create({
"name": "example_resource",
"scopes": ["example:read", "example:write"],
"type": "urn:example"})
# List resource setsresource_sets=uma.resource_set_list()
# get resource setlatest_resource=uma.resource_set_read(resource_set["_id"])
# update resource setlatest_resource["name"] ="New Resource Name"uma.resource_set_update(resource_set["_id"], latest_resource)
# delete resource setuma.resource_set_delete(resource_id=resource_set["_id"])

About

No description, website, or topics provided.

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Add copy buttons to all
 blocks\n(function() {\n function addCopyButtons() {\n document.querySelectorAll('pre code').forEach(function(codeBlock) {\n if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;\n codeBlock.parentElement.setAttribute('data-copy-added', 'true');\n \n var btn = document.createElement('button');\n btn.textContent = 'Copy';\n btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';\n btn.onmouseover = function() { this.style.opacity = '1'; };\n btn.onmouseout = function() { this.style.opacity = '0.7'; };\n btn.onclick = function() {\n navigator.clipboard.writeText(codeBlock.textContent).then(function() {\n btn.textContent = 'Copied!';\n setTimeout(function() { btn.textContent = 'Copy'; }, 1500);\n });\n };\n codeBlock.parentElement.style.position = 'relative';\n codeBlock.parentElement.appendChild(btn);\n });\n }\n \n addCopyButtons();\n \n // Re-run on dynamic content\n var observer = new MutationObserver(addCopyButtons);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Add Copy Buttons to Code Blocks");
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
Skip to content

Repository files navigation

CircleCIDocumentation Status

Python Keycloak

For review- see https://github.com/marcospereirampj/python-keycloak

python-keycloak is a Python package providing access to the Keycloak API.

Installation

Via Pypi Package:

$ pip install python-keycloak

Manually

$ python setup.py install

Dependencies

python-keycloak depends on:

Tests Dependencies

Bug reports

Please report bugs and feature requests at https://github.com/marcospereirampj/python-keycloak/issues

Documentation

The documentation for python-keycloak is available on readthedocs.

Contributors

Usage

fromkeycloakimportKeycloakOpenID# Configure clientkeycloak_openid=KeycloakOpenID(server_url="http://localhost:8080/auth/",
client_id="example_client",
realm_name="example_realm",
client_secret_key="secret")
# Get WellKnownconfig_well_known=keycloak_openid.well_known()
# Get Code With Oauth Authorization Requestauth_url=keycloak_openid.auth_url(
redirect_uri="your_call_back_url",
scope="email",
state="your_state_info")
# Get Access Token With Codeaccess_token=keycloak_openid.token(
grant_type='authorization_code',
code='the_code_you_get_from_auth_url_callback',
redirect_uri="your_call_back_url")
# Get Tokentoken=keycloak_openid.token("user", "password")
token=keycloak_openid.token("user", "password", totp="012345")
# Get token using Token Exchangetoken=keycloak_openid.exchange_token(token['access_token'], "my_client", "other_client", "some_user")
# Get Userinfouserinfo=keycloak_openid.userinfo(token['access_token'])
# Refresh tokentoken=keycloak_openid.refresh_token(token['refresh_token'])
# Logoutkeycloak_openid.logout(token['refresh_token'])
# Get Certscerts=keycloak_openid.certs()
# Get RPT (Entitlement)token=keycloak_openid.token("user", "password")
rpt=keycloak_openid.entitlement(token['access_token'], "resource_id")
# Introspect RPTtoken_rpt_info=keycloak_openid.introspect(keycloak_openid.introspect(token['access_token'], rpt=rpt['rpt'],
token_type_hint="requesting_party_token"))
# Introspect Tokentoken_info=keycloak_openid.introspect(token['access_token'])
# Decode TokenKEYCLOAK_PUBLIC_KEY="-----BEGIN PUBLIC KEY-----\n"+keycloak_openid.public_key() +"\n-----END PUBLIC KEY-----"options= {"verify_signature": True, "verify_aud": True, "verify_exp": True}
token_info=keycloak_openid.decode_token(token['access_token'], key=KEYCLOAK_PUBLIC_KEY, options=options)
# Get permissions by tokentoken=keycloak_openid.token("user", "password")
keycloak_openid.load_authorization_config("example-authz-config.json")
policies=keycloak_openid.get_policies(token['access_token'], method_token_info='decode', key=KEYCLOAK_PUBLIC_KEY)
permissions=keycloak_openid.get_permissions(token['access_token'], method_token_info='introspect')
# Get UMA-permissions by tokentoken=keycloak_openid.token("user", "password")
permissions=keycloak_openid.uma_permissions(token['access_token'])
# Get UMA-permissions by token with specific resource and scope requestedtoken=keycloak_openid.token("user", "password")
permissions=keycloak_openid.uma_permissions(token['access_token'], permissions="Resource#Scope")
# Get auth status for a specific resource and scope by tokentoken=keycloak_openid.token("user", "password")
auth_status=keycloak_openid.has_uma_access(token['access_token'], "Resource#Scope")
# KEYCLOAK ADMINfromkeycloakimportKeycloakAdminfromkeycloakimportKeycloakOpenIDConnectionkeycloak_connection=KeycloakOpenIDConnection(
server_url="http://localhost:8080/",
username='example-admin',
password='secret',
realm_name="master",
user_realm_name="only_if_other_realm_than_master",
client_id="my_client",
client_secret_key="client-secret",
verify=True)
keycloak_admin=KeycloakAdmin(connection=keycloak_connection)
# Add usernew_user=keycloak_admin.create_user({"email": "example@example.com",
"username": "example@example.com",
"enabled": True,
"firstName": "Example",
"lastName": "Example"})
# Add user and raise exception if username already exists# exist_ok currently defaults to True for backwards compatibility reasonsnew_user=keycloak_admin.create_user({"email": "example@example.com",
"username": "example@example.com",
"enabled": True,
"firstName": "Example",
"lastName": "Example"},
exist_ok=False)
# Add user and set passwordnew_user=keycloak_admin.create_user({"email": "example@example.com",
"username": "example@example.com",
"enabled": True,
"firstName": "Example",
"lastName": "Example",
"credentials": [{"value": "secret","type": "password",}]})
# Add user and specify a localenew_user=keycloak_admin.create_user({"email": "example@example.fr",
"username": "example@example.fr",
"enabled": True,
"firstName": "Example",
"lastName": "Example",
"attributes": {
"locale": ["fr"]
}})
# User countercount_users=keycloak_admin.users_count()
# Get users Returns a list of users, filtered according to query parametersusers=keycloak_admin.get_users({})
# Get user ID from usernameuser_id_keycloak=keycloak_admin.get_user_id("username-keycloak")
# Get Useruser=keycloak_admin.get_user("user-id-keycloak")
# Update Userresponse=keycloak_admin.update_user(user_id="user-id-keycloak",
payload={'firstName': 'Example Update'})
# Update User Passwordresponse=keycloak_admin.set_user_password(user_id="user-id-keycloak", password="secret", temporary=True)
# Get User Credentialscredentials=keycloak_admin.get_credentials(user_id='user_id')
# Get User Credential by IDcredential=keycloak_admin.get_credential(user_id='user_id', credential_id='credential_id')
# Delete User Credentialresponse=keycloak_admin.delete_credential(user_id='user_id', credential_id='credential_id')
# Delete Userresponse=keycloak_admin.delete_user(user_id="user-id-keycloak")
# Get consents granted by the userconsents=keycloak_admin.consents_user(user_id="user-id-keycloak")
# Send User Actionresponse=keycloak_admin.send_update_account(user_id="user-id-keycloak",
payload=['UPDATE_PASSWORD'])
# Send Verify Emailresponse=keycloak_admin.send_verify_email(user_id="user-id-keycloak")
# Get sessions associated with the usersessions=keycloak_admin.get_sessions(user_id="user-id-keycloak")
# Get themes, social providers, auth providers, and event listeners available on this serverserver_info=keycloak_admin.get_server_info()
# Get clients belonging to the realm Returns a list of clients belonging to the realmclients=keycloak_admin.get_clients()
# Get client - id (not client-id) from client by nameclient_id=keycloak_admin.get_client_id("my-client")
# Get representation of the client - id of client (not client-id)client=keycloak_admin.get_client(client_id="client_id")
# Get all roles for the realm or clientrealm_roles=keycloak_admin.get_realm_roles()
# Get all roles for the clientclient_roles=keycloak_admin.get_client_roles(client_id="client_id")
# Get client rolerole=keycloak_admin.get_client_role(client_id="client_id", role_name="role_name")
# Warning: Deprecated# Get client role id from namerole_id=keycloak_admin.get_client_role_id(client_id="client_id", role_name="test")
# Create client rolekeycloak_admin.create_client_role(client_role_id='client_id', payload={'name': 'roleName', 'clientRole': True})
# 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")
# Retrieve client roles of a user.keycloak_admin.get_client_roles_of_user(user_id="user_id", client_id="client_id")
# Retrieve available client roles of a user.keycloak_admin.get_available_client_roles_of_user(user_id="user_id", client_id="client_id")
# Retrieve composite client roles of a user.keycloak_admin.get_composite_client_roles_of_user(user_id="user_id", client_id="client_id")
# Delete client roles of a user.keycloak_admin.delete_client_roles_of_user(client_id="client_id", user_id="user_id", roles={"id": "role-id"})
keycloak_admin.delete_client_roles_of_user(client_id="client_id", user_id="user_id", roles=[{"id": "role-id_1"}, {"id": "role-id_2"}])
# Get the client authorization settingsclient_authz_settings=get_client_authz_settings(client_id="client_id")
# Get all client authorization resourcesclient_resources=get_client_authz_resources(client_id="client_id")
# Get all client authorization scopesclient_scopes=get_client_authz_scopes(client_id="client_id")
# Get all client authorization permissionsclient_permissions=get_client_authz_permissions(client_id="client_id")
# Get all client authorization policiesclient_policies=get_client_authz_policies(client_id="client_id")
# Create new groupgroup=keycloak_admin.create_group({"name": "Example Group"})
# Get all groupsgroups=keycloak_admin.get_groups()
# Get groupgroup=keycloak_admin.get_group(group_id='group_id')
# Get group by namegroup=keycloak_admin.get_group_by_path(path='/group/subgroup', search_in_subgroups=True)
# Function to trigger user sync from providersync_users(storage_id="storage_di", action="action")
# Get client role id from namerole_id=keycloak_admin.get_client_role_id(client_id=client_id, role_name="test")
# 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")
# Assign realm roles to userkeycloak_admin.assign_realm_roles(user_id=user_id, roles=realm_roles)
# Assign realm roles to client's scopekeycloak_admin.assign_realm_roles_to_client_scope(client_id=client_id, roles=realm_roles)
# Get realm roles assigned to client's scopekeycloak_admin.get_realm_roles_of_client_scope(client_id=client_id)
# Remove realm roles assigned to client's scopekeycloak_admin.delete_realm_roles_of_client_scope(client_id=client_id, roles=realm_roles)
another_client_id=keycloak_admin.get_client_id("my-client-2")
# Assign client roles to client's scopekeycloak_admin.assign_client_roles_to_client_scope(client_id=another_client_id, client_roles_owner_id=client_id, roles=client_roles)
# Get client roles assigned to client's scopekeycloak_admin.get_client_roles_of_client_scope(client_id=another_client_id, client_roles_owner_id=client_id)
# Remove client roles assigned to client's scopekeycloak_admin.delete_client_roles_of_client_scope(client_id=another_client_id, client_roles_owner_id=client_id, roles=client_roles)
# Get all ID Providersidps=keycloak_admin.get_idps()
# Create a new Realmkeycloak_admin.create_realm(payload={"realm": "demo"}, skip_exists=False)
# Changing Realmkeycloak_admin=KeycloakAdmin(realm_name="main", ...)
keycloak_admin.get_users() # Get user in main realmkeycloak_admin.realm_name="demo"# Change realm to 'demo'keycloak_admin.get_users() # Get users in realm 'demo'keycloak_admin.create_user(...) # Creates a new user in 'demo'# KEYCLOAK UMAfromkeycloakimportKeycloakOpenIDConnectionfromkeycloakimportKeycloakUMAkeycloak_connection=KeycloakOpenIDConnection(
server_url="http://localhost:8080/",
realm_name="master",
client_id="my_client",
client_secret_key="client-secret")
keycloak_uma=KeycloakUMA(connection=keycloak_connection)
# Create a resource setresource_set=keycloak_uma.resource_set_create({
"name": "example_resource",
"scopes": ["example:read", "example:write"],
"type": "urn:example"})
# List resource setsresource_sets=uma.resource_set_list()
# get resource setlatest_resource=uma.resource_set_read(resource_set["_id"])
# update resource setlatest_resource["name"] ="New Resource Name"uma.resource_set_update(resource_set["_id"], latest_resource)
# delete resource setuma.resource_set_delete(resource_id=resource_set["_id"])

About

No description, website, or topics provided.

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Force GitHub README to respect dark mode\n(function() {\n var style = document.createElement('style');\n style.textContent = '\n .markdown-body {\n color-scheme: dark light;\n }\n .markdown-body pre { background: #161b22 !important; }\n .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; }\n .markdown-body table th, .markdown-body table td { border-color: #30363d !important; }\n .markdown-body img { background: #0d1117; }\n .markdown-body blockquote { border-left-color: #8b949e; }\n .markdown-body hr { border-color: #30363d; }\n ';\n document.head.appendChild(style);\n})();", "GitHub Dark Mode README Fix"); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Repository files navigation

CircleCIDocumentation Status

Python Keycloak

For review- see https://github.com/marcospereirampj/python-keycloak

python-keycloak is a Python package providing access to the Keycloak API.

Installation

Via Pypi Package:

$ pip install python-keycloak

Manually

$ python setup.py install

Dependencies

python-keycloak depends on:

Tests Dependencies

Bug reports

Please report bugs and feature requests at https://github.com/marcospereirampj/python-keycloak/issues

Documentation

The documentation for python-keycloak is available on readthedocs.

Contributors

Usage

fromkeycloakimportKeycloakOpenID# Configure clientkeycloak_openid=KeycloakOpenID(server_url="http://localhost:8080/auth/",
client_id="example_client",
realm_name="example_realm",
client_secret_key="secret")
# Get WellKnownconfig_well_known=keycloak_openid.well_known()
# Get Code With Oauth Authorization Requestauth_url=keycloak_openid.auth_url(
redirect_uri="your_call_back_url",
scope="email",
state="your_state_info")
# Get Access Token With Codeaccess_token=keycloak_openid.token(
grant_type='authorization_code',
code='the_code_you_get_from_auth_url_callback',
redirect_uri="your_call_back_url")
# Get Tokentoken=keycloak_openid.token("user", "password")
token=keycloak_openid.token("user", "password", totp="012345")
# Get token using Token Exchangetoken=keycloak_openid.exchange_token(token['access_token'], "my_client", "other_client", "some_user")
# Get Userinfouserinfo=keycloak_openid.userinfo(token['access_token'])
# Refresh tokentoken=keycloak_openid.refresh_token(token['refresh_token'])
# Logoutkeycloak_openid.logout(token['refresh_token'])
# Get Certscerts=keycloak_openid.certs()
# Get RPT (Entitlement)token=keycloak_openid.token("user", "password")
rpt=keycloak_openid.entitlement(token['access_token'], "resource_id")
# Introspect RPTtoken_rpt_info=keycloak_openid.introspect(keycloak_openid.introspect(token['access_token'], rpt=rpt['rpt'],
token_type_hint="requesting_party_token"))
# Introspect Tokentoken_info=keycloak_openid.introspect(token['access_token'])
# Decode TokenKEYCLOAK_PUBLIC_KEY="-----BEGIN PUBLIC KEY-----\n"+keycloak_openid.public_key() +"\n-----END PUBLIC KEY-----"options= {"verify_signature": True, "verify_aud": True, "verify_exp": True}
token_info=keycloak_openid.decode_token(token['access_token'], key=KEYCLOAK_PUBLIC_KEY, options=options)
# Get permissions by tokentoken=keycloak_openid.token("user", "password")
keycloak_openid.load_authorization_config("example-authz-config.json")
policies=keycloak_openid.get_policies(token['access_token'], method_token_info='decode', key=KEYCLOAK_PUBLIC_KEY)
permissions=keycloak_openid.get_permissions(token['access_token'], method_token_info='introspect')
# Get UMA-permissions by tokentoken=keycloak_openid.token("user", "password")
permissions=keycloak_openid.uma_permissions(token['access_token'])
# Get UMA-permissions by token with specific resource and scope requestedtoken=keycloak_openid.token("user", "password")
permissions=keycloak_openid.uma_permissions(token['access_token'], permissions="Resource#Scope")
# Get auth status for a specific resource and scope by tokentoken=keycloak_openid.token("user", "password")
auth_status=keycloak_openid.has_uma_access(token['access_token'], "Resource#Scope")
# KEYCLOAK ADMINfromkeycloakimportKeycloakAdminfromkeycloakimportKeycloakOpenIDConnectionkeycloak_connection=KeycloakOpenIDConnection(
server_url="http://localhost:8080/",
username='example-admin',
password='secret',
realm_name="master",
user_realm_name="only_if_other_realm_than_master",
client_id="my_client",
client_secret_key="client-secret",
verify=True)
keycloak_admin=KeycloakAdmin(connection=keycloak_connection)
# Add usernew_user=keycloak_admin.create_user({"email": "example@example.com",
"username": "example@example.com",
"enabled": True,
"firstName": "Example",
"lastName": "Example"})
# Add user and raise exception if username already exists# exist_ok currently defaults to True for backwards compatibility reasonsnew_user=keycloak_admin.create_user({"email": "example@example.com",
"username": "example@example.com",
"enabled": True,
"firstName": "Example",
"lastName": "Example"},
exist_ok=False)
# Add user and set passwordnew_user=keycloak_admin.create_user({"email": "example@example.com",
"username": "example@example.com",
"enabled": True,
"firstName": "Example",
"lastName": "Example",
"credentials": [{"value": "secret","type": "password",}]})
# Add user and specify a localenew_user=keycloak_admin.create_user({"email": "example@example.fr",
"username": "example@example.fr",
"enabled": True,
"firstName": "Example",
"lastName": "Example",
"attributes": {
"locale": ["fr"]
}})
# User countercount_users=keycloak_admin.users_count()
# Get users Returns a list of users, filtered according to query parametersusers=keycloak_admin.get_users({})
# Get user ID from usernameuser_id_keycloak=keycloak_admin.get_user_id("username-keycloak")
# Get Useruser=keycloak_admin.get_user("user-id-keycloak")
# Update Userresponse=keycloak_admin.update_user(user_id="user-id-keycloak",
payload={'firstName': 'Example Update'})
# Update User Passwordresponse=keycloak_admin.set_user_password(user_id="user-id-keycloak", password="secret", temporary=True)
# Get User Credentialscredentials=keycloak_admin.get_credentials(user_id='user_id')
# Get User Credential by IDcredential=keycloak_admin.get_credential(user_id='user_id', credential_id='credential_id')
# Delete User Credentialresponse=keycloak_admin.delete_credential(user_id='user_id', credential_id='credential_id')
# Delete Userresponse=keycloak_admin.delete_user(user_id="user-id-keycloak")
# Get consents granted by the userconsents=keycloak_admin.consents_user(user_id="user-id-keycloak")
# Send User Actionresponse=keycloak_admin.send_update_account(user_id="user-id-keycloak",
payload=['UPDATE_PASSWORD'])
# Send Verify Emailresponse=keycloak_admin.send_verify_email(user_id="user-id-keycloak")
# Get sessions associated with the usersessions=keycloak_admin.get_sessions(user_id="user-id-keycloak")
# Get themes, social providers, auth providers, and event listeners available on this serverserver_info=keycloak_admin.get_server_info()
# Get clients belonging to the realm Returns a list of clients belonging to the realmclients=keycloak_admin.get_clients()
# Get client - id (not client-id) from client by nameclient_id=keycloak_admin.get_client_id("my-client")
# Get representation of the client - id of client (not client-id)client=keycloak_admin.get_client(client_id="client_id")
# Get all roles for the realm or clientrealm_roles=keycloak_admin.get_realm_roles()
# Get all roles for the clientclient_roles=keycloak_admin.get_client_roles(client_id="client_id")
# Get client rolerole=keycloak_admin.get_client_role(client_id="client_id", role_name="role_name")
# Warning: Deprecated# Get client role id from namerole_id=keycloak_admin.get_client_role_id(client_id="client_id", role_name="test")
# Create client rolekeycloak_admin.create_client_role(client_role_id='client_id', payload={'name': 'roleName', 'clientRole': True})
# 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")
# Retrieve client roles of a user.keycloak_admin.get_client_roles_of_user(user_id="user_id", client_id="client_id")
# Retrieve available client roles of a user.keycloak_admin.get_available_client_roles_of_user(user_id="user_id", client_id="client_id")
# Retrieve composite client roles of a user.keycloak_admin.get_composite_client_roles_of_user(user_id="user_id", client_id="client_id")
# Delete client roles of a user.keycloak_admin.delete_client_roles_of_user(client_id="client_id", user_id="user_id", roles={"id": "role-id"})
keycloak_admin.delete_client_roles_of_user(client_id="client_id", user_id="user_id", roles=[{"id": "role-id_1"}, {"id": "role-id_2"}])
# Get the client authorization settingsclient_authz_settings=get_client_authz_settings(client_id="client_id")
# Get all client authorization resourcesclient_resources=get_client_authz_resources(client_id="client_id")
# Get all client authorization scopesclient_scopes=get_client_authz_scopes(client_id="client_id")
# Get all client authorization permissionsclient_permissions=get_client_authz_permissions(client_id="client_id")
# Get all client authorization policiesclient_policies=get_client_authz_policies(client_id="client_id")
# Create new groupgroup=keycloak_admin.create_group({"name": "Example Group"})
# Get all groupsgroups=keycloak_admin.get_groups()
# Get groupgroup=keycloak_admin.get_group(group_id='group_id')
# Get group by namegroup=keycloak_admin.get_group_by_path(path='/group/subgroup', search_in_subgroups=True)
# Function to trigger user sync from providersync_users(storage_id="storage_di", action="action")
# Get client role id from namerole_id=keycloak_admin.get_client_role_id(client_id=client_id, role_name="test")
# 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")
# Assign realm roles to userkeycloak_admin.assign_realm_roles(user_id=user_id, roles=realm_roles)
# Assign realm roles to client's scopekeycloak_admin.assign_realm_roles_to_client_scope(client_id=client_id, roles=realm_roles)
# Get realm roles assigned to client's scopekeycloak_admin.get_realm_roles_of_client_scope(client_id=client_id)
# Remove realm roles assigned to client's scopekeycloak_admin.delete_realm_roles_of_client_scope(client_id=client_id, roles=realm_roles)
another_client_id=keycloak_admin.get_client_id("my-client-2")
# Assign client roles to client's scopekeycloak_admin.assign_client_roles_to_client_scope(client_id=another_client_id, client_roles_owner_id=client_id, roles=client_roles)
# Get client roles assigned to client's scopekeycloak_admin.get_client_roles_of_client_scope(client_id=another_client_id, client_roles_owner_id=client_id)
# Remove client roles assigned to client's scopekeycloak_admin.delete_client_roles_of_client_scope(client_id=another_client_id, client_roles_owner_id=client_id, roles=client_roles)
# Get all ID Providersidps=keycloak_admin.get_idps()
# Create a new Realmkeycloak_admin.create_realm(payload={"realm": "demo"}, skip_exists=False)
# Changing Realmkeycloak_admin=KeycloakAdmin(realm_name="main", ...)
keycloak_admin.get_users() # Get user in main realmkeycloak_admin.realm_name="demo"# Change realm to 'demo'keycloak_admin.get_users() # Get users in realm 'demo'keycloak_admin.create_user(...) # Creates a new user in 'demo'# KEYCLOAK UMAfromkeycloakimportKeycloakOpenIDConnectionfromkeycloakimportKeycloakUMAkeycloak_connection=KeycloakOpenIDConnection(
server_url="http://localhost:8080/",
realm_name="master",
client_id="my_client",
client_secret_key="client-secret")
keycloak_uma=KeycloakUMA(connection=keycloak_connection)
# Create a resource setresource_set=keycloak_uma.resource_set_create({
"name": "example_resource",
"scopes": ["example:read", "example:write"],
"type": "urn:example"})
# List resource setsresource_sets=uma.resource_set_list()
# get resource setlatest_resource=uma.resource_set_read(resource_set["_id"])
# update resource setlatest_resource["name"] ="New Resource Name"uma.resource_set_update(resource_set["_id"], latest_resource)
# delete resource setuma.resource_set_delete(resource_id=resource_set["_id"])

About

No description, website, or topics provided.

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Highlight search terms from Google/DuckDuckGo/Bing referrer\n(function() {\n var ref = document.referrer;\n var terms = [];\n \n if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) {\n var url = new URL(ref);\n var q = url.searchParams.get('q') || url.searchParams.get('p');\n if (q) {\n terms = q.split(/\\s+/).filter(function(t) { return t.length > 2; });\n }\n }\n \n if (terms.length === 0) return;\n \n var style = document.createElement('style');\n style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }';\n document.head.appendChild(style);\n \n function highlight(node) {\n if (node.nodeType === 3) { // text node\n var text = node.textContent;\n var found = false;\n terms.forEach(function(term) {\n var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\') + ')', 'gi');\n if (regex.test(text)) {\n found = true;\n var frag = document.createDocumentFragment();\n var parts = text.split(regex);\n parts.forEach(function(part, i) {\n if (i % 2 === 0) {\n frag.appendChild(document.createTextNode(part));\n } else {\n var span = document.createElement('span');\n span.className = 'userscript-highlight';\n span.textContent = part;\n frag.appendChild(span);\n }\n });\n node.parentNode.replaceChild(frag, node);\n }\n });\n } else if (node.nodeType === 1 && node.childNodes) { // element\n var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT'];\n if (!skipTags.includes(node.tagName)) {\n Array.from(node.childNodes).forEach(highlight);\n }\n }\n }\n \n highlight(document.body);\n \n // Re-highlight on dynamic content\n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1 || node.nodeType === 3) highlight(node);\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Highlight Search Terms"); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Repository files navigation

CircleCIDocumentation Status

Python Keycloak

For review- see https://github.com/marcospereirampj/python-keycloak

python-keycloak is a Python package providing access to the Keycloak API.

Installation

Via Pypi Package:

$ pip install python-keycloak

Manually

$ python setup.py install

Dependencies

python-keycloak depends on:

Tests Dependencies

Bug reports

Please report bugs and feature requests at https://github.com/marcospereirampj/python-keycloak/issues

Documentation

The documentation for python-keycloak is available on readthedocs.

Contributors

Usage

fromkeycloakimportKeycloakOpenID# Configure clientkeycloak_openid=KeycloakOpenID(server_url="http://localhost:8080/auth/",
client_id="example_client",
realm_name="example_realm",
client_secret_key="secret")
# Get WellKnownconfig_well_known=keycloak_openid.well_known()
# Get Code With Oauth Authorization Requestauth_url=keycloak_openid.auth_url(
redirect_uri="your_call_back_url",
scope="email",
state="your_state_info")
# Get Access Token With Codeaccess_token=keycloak_openid.token(
grant_type='authorization_code',
code='the_code_you_get_from_auth_url_callback',
redirect_uri="your_call_back_url")
# Get Tokentoken=keycloak_openid.token("user", "password")
token=keycloak_openid.token("user", "password", totp="012345")
# Get token using Token Exchangetoken=keycloak_openid.exchange_token(token['access_token'], "my_client", "other_client", "some_user")
# Get Userinfouserinfo=keycloak_openid.userinfo(token['access_token'])
# Refresh tokentoken=keycloak_openid.refresh_token(token['refresh_token'])
# Logoutkeycloak_openid.logout(token['refresh_token'])
# Get Certscerts=keycloak_openid.certs()
# Get RPT (Entitlement)token=keycloak_openid.token("user", "password")
rpt=keycloak_openid.entitlement(token['access_token'], "resource_id")
# Introspect RPTtoken_rpt_info=keycloak_openid.introspect(keycloak_openid.introspect(token['access_token'], rpt=rpt['rpt'],
token_type_hint="requesting_party_token"))
# Introspect Tokentoken_info=keycloak_openid.introspect(token['access_token'])
# Decode TokenKEYCLOAK_PUBLIC_KEY="-----BEGIN PUBLIC KEY-----\n"+keycloak_openid.public_key() +"\n-----END PUBLIC KEY-----"options= {"verify_signature": True, "verify_aud": True, "verify_exp": True}
token_info=keycloak_openid.decode_token(token['access_token'], key=KEYCLOAK_PUBLIC_KEY, options=options)
# Get permissions by tokentoken=keycloak_openid.token("user", "password")
keycloak_openid.load_authorization_config("example-authz-config.json")
policies=keycloak_openid.get_policies(token['access_token'], method_token_info='decode', key=KEYCLOAK_PUBLIC_KEY)
permissions=keycloak_openid.get_permissions(token['access_token'], method_token_info='introspect')
# Get UMA-permissions by tokentoken=keycloak_openid.token("user", "password")
permissions=keycloak_openid.uma_permissions(token['access_token'])
# Get UMA-permissions by token with specific resource and scope requestedtoken=keycloak_openid.token("user", "password")
permissions=keycloak_openid.uma_permissions(token['access_token'], permissions="Resource#Scope")
# Get auth status for a specific resource and scope by tokentoken=keycloak_openid.token("user", "password")
auth_status=keycloak_openid.has_uma_access(token['access_token'], "Resource#Scope")
# KEYCLOAK ADMINfromkeycloakimportKeycloakAdminfromkeycloakimportKeycloakOpenIDConnectionkeycloak_connection=KeycloakOpenIDConnection(
server_url="http://localhost:8080/",
username='example-admin',
password='secret',
realm_name="master",
user_realm_name="only_if_other_realm_than_master",
client_id="my_client",
client_secret_key="client-secret",
verify=True)
keycloak_admin=KeycloakAdmin(connection=keycloak_connection)
# Add usernew_user=keycloak_admin.create_user({"email": "example@example.com",
"username": "example@example.com",
"enabled": True,
"firstName": "Example",
"lastName": "Example"})
# Add user and raise exception if username already exists# exist_ok currently defaults to True for backwards compatibility reasonsnew_user=keycloak_admin.create_user({"email": "example@example.com",
"username": "example@example.com",
"enabled": True,
"firstName": "Example",
"lastName": "Example"},
exist_ok=False)
# Add user and set passwordnew_user=keycloak_admin.create_user({"email": "example@example.com",
"username": "example@example.com",
"enabled": True,
"firstName": "Example",
"lastName": "Example",
"credentials": [{"value": "secret","type": "password",}]})
# Add user and specify a localenew_user=keycloak_admin.create_user({"email": "example@example.fr",
"username": "example@example.fr",
"enabled": True,
"firstName": "Example",
"lastName": "Example",
"attributes": {
"locale": ["fr"]
}})
# User countercount_users=keycloak_admin.users_count()
# Get users Returns a list of users, filtered according to query parametersusers=keycloak_admin.get_users({})
# Get user ID from usernameuser_id_keycloak=keycloak_admin.get_user_id("username-keycloak")
# Get Useruser=keycloak_admin.get_user("user-id-keycloak")
# Update Userresponse=keycloak_admin.update_user(user_id="user-id-keycloak",
payload={'firstName': 'Example Update'})
# Update User Passwordresponse=keycloak_admin.set_user_password(user_id="user-id-keycloak", password="secret", temporary=True)
# Get User Credentialscredentials=keycloak_admin.get_credentials(user_id='user_id')
# Get User Credential by IDcredential=keycloak_admin.get_credential(user_id='user_id', credential_id='credential_id')
# Delete User Credentialresponse=keycloak_admin.delete_credential(user_id='user_id', credential_id='credential_id')
# Delete Userresponse=keycloak_admin.delete_user(user_id="user-id-keycloak")
# Get consents granted by the userconsents=keycloak_admin.consents_user(user_id="user-id-keycloak")
# Send User Actionresponse=keycloak_admin.send_update_account(user_id="user-id-keycloak",
payload=['UPDATE_PASSWORD'])
# Send Verify Emailresponse=keycloak_admin.send_verify_email(user_id="user-id-keycloak")
# Get sessions associated with the usersessions=keycloak_admin.get_sessions(user_id="user-id-keycloak")
# Get themes, social providers, auth providers, and event listeners available on this serverserver_info=keycloak_admin.get_server_info()
# Get clients belonging to the realm Returns a list of clients belonging to the realmclients=keycloak_admin.get_clients()
# Get client - id (not client-id) from client by nameclient_id=keycloak_admin.get_client_id("my-client")
# Get representation of the client - id of client (not client-id)client=keycloak_admin.get_client(client_id="client_id")
# Get all roles for the realm or clientrealm_roles=keycloak_admin.get_realm_roles()
# Get all roles for the clientclient_roles=keycloak_admin.get_client_roles(client_id="client_id")
# Get client rolerole=keycloak_admin.get_client_role(client_id="client_id", role_name="role_name")
# Warning: Deprecated# Get client role id from namerole_id=keycloak_admin.get_client_role_id(client_id="client_id", role_name="test")
# Create client rolekeycloak_admin.create_client_role(client_role_id='client_id', payload={'name': 'roleName', 'clientRole': True})
# 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")
# Retrieve client roles of a user.keycloak_admin.get_client_roles_of_user(user_id="user_id", client_id="client_id")
# Retrieve available client roles of a user.keycloak_admin.get_available_client_roles_of_user(user_id="user_id", client_id="client_id")
# Retrieve composite client roles of a user.keycloak_admin.get_composite_client_roles_of_user(user_id="user_id", client_id="client_id")
# Delete client roles of a user.keycloak_admin.delete_client_roles_of_user(client_id="client_id", user_id="user_id", roles={"id": "role-id"})
keycloak_admin.delete_client_roles_of_user(client_id="client_id", user_id="user_id", roles=[{"id": "role-id_1"}, {"id": "role-id_2"}])
# Get the client authorization settingsclient_authz_settings=get_client_authz_settings(client_id="client_id")
# Get all client authorization resourcesclient_resources=get_client_authz_resources(client_id="client_id")
# Get all client authorization scopesclient_scopes=get_client_authz_scopes(client_id="client_id")
# Get all client authorization permissionsclient_permissions=get_client_authz_permissions(client_id="client_id")
# Get all client authorization policiesclient_policies=get_client_authz_policies(client_id="client_id")
# Create new groupgroup=keycloak_admin.create_group({"name": "Example Group"})
# Get all groupsgroups=keycloak_admin.get_groups()
# Get groupgroup=keycloak_admin.get_group(group_id='group_id')
# Get group by namegroup=keycloak_admin.get_group_by_path(path='/group/subgroup', search_in_subgroups=True)
# Function to trigger user sync from providersync_users(storage_id="storage_di", action="action")
# Get client role id from namerole_id=keycloak_admin.get_client_role_id(client_id=client_id, role_name="test")
# 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")
# Assign realm roles to userkeycloak_admin.assign_realm_roles(user_id=user_id, roles=realm_roles)
# Assign realm roles to client's scopekeycloak_admin.assign_realm_roles_to_client_scope(client_id=client_id, roles=realm_roles)
# Get realm roles assigned to client's scopekeycloak_admin.get_realm_roles_of_client_scope(client_id=client_id)
# Remove realm roles assigned to client's scopekeycloak_admin.delete_realm_roles_of_client_scope(client_id=client_id, roles=realm_roles)
another_client_id=keycloak_admin.get_client_id("my-client-2")
# Assign client roles to client's scopekeycloak_admin.assign_client_roles_to_client_scope(client_id=another_client_id, client_roles_owner_id=client_id, roles=client_roles)
# Get client roles assigned to client's scopekeycloak_admin.get_client_roles_of_client_scope(client_id=another_client_id, client_roles_owner_id=client_id)
# Remove client roles assigned to client's scopekeycloak_admin.delete_client_roles_of_client_scope(client_id=another_client_id, client_roles_owner_id=client_id, roles=client_roles)
# Get all ID Providersidps=keycloak_admin.get_idps()
# Create a new Realmkeycloak_admin.create_realm(payload={"realm": "demo"}, skip_exists=False)
# Changing Realmkeycloak_admin=KeycloakAdmin(realm_name="main", ...)
keycloak_admin.get_users() # Get user in main realmkeycloak_admin.realm_name="demo"# Change realm to 'demo'keycloak_admin.get_users() # Get users in realm 'demo'keycloak_admin.create_user(...) # Creates a new user in 'demo'# KEYCLOAK UMAfromkeycloakimportKeycloakOpenIDConnectionfromkeycloakimportKeycloakUMAkeycloak_connection=KeycloakOpenIDConnection(
server_url="http://localhost:8080/",
realm_name="master",
client_id="my_client",
client_secret_key="client-secret")
keycloak_uma=KeycloakUMA(connection=keycloak_connection)
# Create a resource setresource_set=keycloak_uma.resource_set_create({
"name": "example_resource",
"scopes": ["example:read", "example:write"],
"type": "urn:example"})
# List resource setsresource_sets=uma.resource_set_list()
# get resource setlatest_resource=uma.resource_set_read(resource_set["_id"])
# update resource setlatest_resource["name"] ="New Resource Name"uma.resource_set_update(resource_set["_id"], latest_resource)
# delete resource setuma.resource_set_delete(resource_id=resource_set["_id"])

About

No description, website, or topics provided.

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Strip utm_, fbclid, gclid, etc. from all links on page\n(function() {\n var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content',\n 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid',\n 'ref', 'ref_src', 'source', 'medium', 'campaign'];\n \n function cleanUrl(url) {\n try {\n var u = new URL(url, window.location.origin);\n var changed = false;\n trackingParams.forEach(function(p) {\n if (u.searchParams.has(p)) {\n u.searchParams.delete(p);\n changed = true;\n }\n });\n return changed ? u.toString() : url;\n } catch (e) {\n return url;\n }\n }\n \n function cleanLinks() {\n document.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n \n cleanLinks();\n \n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1) {\n if (node.tagName === 'A') cleanLinks();\n node.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Remove Tracking Parameters from Links"); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + '
Skip to content

Repository files navigation

CircleCIDocumentation Status

Python Keycloak

For review- see https://github.com/marcospereirampj/python-keycloak

python-keycloak is a Python package providing access to the Keycloak API.

Installation

Via Pypi Package:

$ pip install python-keycloak

Manually

$ python setup.py install

Dependencies

python-keycloak depends on:

Tests Dependencies

Bug reports

Please report bugs and feature requests at https://github.com/marcospereirampj/python-keycloak/issues

Documentation

The documentation for python-keycloak is available on readthedocs.

Contributors

Usage

fromkeycloakimportKeycloakOpenID# Configure clientkeycloak_openid=KeycloakOpenID(server_url="http://localhost:8080/auth/",
client_id="example_client",
realm_name="example_realm",
client_secret_key="secret")
# Get WellKnownconfig_well_known=keycloak_openid.well_known()
# Get Code With Oauth Authorization Requestauth_url=keycloak_openid.auth_url(
redirect_uri="your_call_back_url",
scope="email",
state="your_state_info")
# Get Access Token With Codeaccess_token=keycloak_openid.token(
grant_type='authorization_code',
code='the_code_you_get_from_auth_url_callback',
redirect_uri="your_call_back_url")
# Get Tokentoken=keycloak_openid.token("user", "password")
token=keycloak_openid.token("user", "password", totp="012345")
# Get token using Token Exchangetoken=keycloak_openid.exchange_token(token['access_token'], "my_client", "other_client", "some_user")
# Get Userinfouserinfo=keycloak_openid.userinfo(token['access_token'])
# Refresh tokentoken=keycloak_openid.refresh_token(token['refresh_token'])
# Logoutkeycloak_openid.logout(token['refresh_token'])
# Get Certscerts=keycloak_openid.certs()
# Get RPT (Entitlement)token=keycloak_openid.token("user", "password")
rpt=keycloak_openid.entitlement(token['access_token'], "resource_id")
# Introspect RPTtoken_rpt_info=keycloak_openid.introspect(keycloak_openid.introspect(token['access_token'], rpt=rpt['rpt'],
token_type_hint="requesting_party_token"))
# Introspect Tokentoken_info=keycloak_openid.introspect(token['access_token'])
# Decode TokenKEYCLOAK_PUBLIC_KEY="-----BEGIN PUBLIC KEY-----\n"+keycloak_openid.public_key() +"\n-----END PUBLIC KEY-----"options= {"verify_signature": True, "verify_aud": True, "verify_exp": True}
token_info=keycloak_openid.decode_token(token['access_token'], key=KEYCLOAK_PUBLIC_KEY, options=options)
# Get permissions by tokentoken=keycloak_openid.token("user", "password")
keycloak_openid.load_authorization_config("example-authz-config.json")
policies=keycloak_openid.get_policies(token['access_token'], method_token_info='decode', key=KEYCLOAK_PUBLIC_KEY)
permissions=keycloak_openid.get_permissions(token['access_token'], method_token_info='introspect')
# Get UMA-permissions by tokentoken=keycloak_openid.token("user", "password")
permissions=keycloak_openid.uma_permissions(token['access_token'])
# Get UMA-permissions by token with specific resource and scope requestedtoken=keycloak_openid.token("user", "password")
permissions=keycloak_openid.uma_permissions(token['access_token'], permissions="Resource#Scope")
# Get auth status for a specific resource and scope by tokentoken=keycloak_openid.token("user", "password")
auth_status=keycloak_openid.has_uma_access(token['access_token'], "Resource#Scope")
# KEYCLOAK ADMINfromkeycloakimportKeycloakAdminfromkeycloakimportKeycloakOpenIDConnectionkeycloak_connection=KeycloakOpenIDConnection(
server_url="http://localhost:8080/",
username='example-admin',
password='secret',
realm_name="master",
user_realm_name="only_if_other_realm_than_master",
client_id="my_client",
client_secret_key="client-secret",
verify=True)
keycloak_admin=KeycloakAdmin(connection=keycloak_connection)
# Add usernew_user=keycloak_admin.create_user({"email": "example@example.com",
"username": "example@example.com",
"enabled": True,
"firstName": "Example",
"lastName": "Example"})
# Add user and raise exception if username already exists# exist_ok currently defaults to True for backwards compatibility reasonsnew_user=keycloak_admin.create_user({"email": "example@example.com",
"username": "example@example.com",
"enabled": True,
"firstName": "Example",
"lastName": "Example"},
exist_ok=False)
# Add user and set passwordnew_user=keycloak_admin.create_user({"email": "example@example.com",
"username": "example@example.com",
"enabled": True,
"firstName": "Example",
"lastName": "Example",
"credentials": [{"value": "secret","type": "password",}]})
# Add user and specify a localenew_user=keycloak_admin.create_user({"email": "example@example.fr",
"username": "example@example.fr",
"enabled": True,
"firstName": "Example",
"lastName": "Example",
"attributes": {
"locale": ["fr"]
}})
# User countercount_users=keycloak_admin.users_count()
# Get users Returns a list of users, filtered according to query parametersusers=keycloak_admin.get_users({})
# Get user ID from usernameuser_id_keycloak=keycloak_admin.get_user_id("username-keycloak")
# Get Useruser=keycloak_admin.get_user("user-id-keycloak")
# Update Userresponse=keycloak_admin.update_user(user_id="user-id-keycloak",
payload={'firstName': 'Example Update'})
# Update User Passwordresponse=keycloak_admin.set_user_password(user_id="user-id-keycloak", password="secret", temporary=True)
# Get User Credentialscredentials=keycloak_admin.get_credentials(user_id='user_id')
# Get User Credential by IDcredential=keycloak_admin.get_credential(user_id='user_id', credential_id='credential_id')
# Delete User Credentialresponse=keycloak_admin.delete_credential(user_id='user_id', credential_id='credential_id')
# Delete Userresponse=keycloak_admin.delete_user(user_id="user-id-keycloak")
# Get consents granted by the userconsents=keycloak_admin.consents_user(user_id="user-id-keycloak")
# Send User Actionresponse=keycloak_admin.send_update_account(user_id="user-id-keycloak",
payload=['UPDATE_PASSWORD'])
# Send Verify Emailresponse=keycloak_admin.send_verify_email(user_id="user-id-keycloak")
# Get sessions associated with the usersessions=keycloak_admin.get_sessions(user_id="user-id-keycloak")
# Get themes, social providers, auth providers, and event listeners available on this serverserver_info=keycloak_admin.get_server_info()
# Get clients belonging to the realm Returns a list of clients belonging to the realmclients=keycloak_admin.get_clients()
# Get client - id (not client-id) from client by nameclient_id=keycloak_admin.get_client_id("my-client")
# Get representation of the client - id of client (not client-id)client=keycloak_admin.get_client(client_id="client_id")
# Get all roles for the realm or clientrealm_roles=keycloak_admin.get_realm_roles()
# Get all roles for the clientclient_roles=keycloak_admin.get_client_roles(client_id="client_id")
# Get client rolerole=keycloak_admin.get_client_role(client_id="client_id", role_name="role_name")
# Warning: Deprecated# Get client role id from namerole_id=keycloak_admin.get_client_role_id(client_id="client_id", role_name="test")
# Create client rolekeycloak_admin.create_client_role(client_role_id='client_id', payload={'name': 'roleName', 'clientRole': True})
# 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")
# Retrieve client roles of a user.keycloak_admin.get_client_roles_of_user(user_id="user_id", client_id="client_id")
# Retrieve available client roles of a user.keycloak_admin.get_available_client_roles_of_user(user_id="user_id", client_id="client_id")
# Retrieve composite client roles of a user.keycloak_admin.get_composite_client_roles_of_user(user_id="user_id", client_id="client_id")
# Delete client roles of a user.keycloak_admin.delete_client_roles_of_user(client_id="client_id", user_id="user_id", roles={"id": "role-id"})
keycloak_admin.delete_client_roles_of_user(client_id="client_id", user_id="user_id", roles=[{"id": "role-id_1"}, {"id": "role-id_2"}])
# Get the client authorization settingsclient_authz_settings=get_client_authz_settings(client_id="client_id")
# Get all client authorization resourcesclient_resources=get_client_authz_resources(client_id="client_id")
# Get all client authorization scopesclient_scopes=get_client_authz_scopes(client_id="client_id")
# Get all client authorization permissionsclient_permissions=get_client_authz_permissions(client_id="client_id")
# Get all client authorization policiesclient_policies=get_client_authz_policies(client_id="client_id")
# Create new groupgroup=keycloak_admin.create_group({"name": "Example Group"})
# Get all groupsgroups=keycloak_admin.get_groups()
# Get groupgroup=keycloak_admin.get_group(group_id='group_id')
# Get group by namegroup=keycloak_admin.get_group_by_path(path='/group/subgroup', search_in_subgroups=True)
# Function to trigger user sync from providersync_users(storage_id="storage_di", action="action")
# Get client role id from namerole_id=keycloak_admin.get_client_role_id(client_id=client_id, role_name="test")
# 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")
# Assign realm roles to userkeycloak_admin.assign_realm_roles(user_id=user_id, roles=realm_roles)
# Assign realm roles to client's scopekeycloak_admin.assign_realm_roles_to_client_scope(client_id=client_id, roles=realm_roles)
# Get realm roles assigned to client's scopekeycloak_admin.get_realm_roles_of_client_scope(client_id=client_id)
# Remove realm roles assigned to client's scopekeycloak_admin.delete_realm_roles_of_client_scope(client_id=client_id, roles=realm_roles)
another_client_id=keycloak_admin.get_client_id("my-client-2")
# Assign client roles to client's scopekeycloak_admin.assign_client_roles_to_client_scope(client_id=another_client_id, client_roles_owner_id=client_id, roles=client_roles)
# Get client roles assigned to client's scopekeycloak_admin.get_client_roles_of_client_scope(client_id=another_client_id, client_roles_owner_id=client_id)
# Remove client roles assigned to client's scopekeycloak_admin.delete_client_roles_of_client_scope(client_id=another_client_id, client_roles_owner_id=client_id, roles=client_roles)
# Get all ID Providersidps=keycloak_admin.get_idps()
# Create a new Realmkeycloak_admin.create_realm(payload={"realm": "demo"}, skip_exists=False)
# Changing Realmkeycloak_admin=KeycloakAdmin(realm_name="main", ...)
keycloak_admin.get_users() # Get user in main realmkeycloak_admin.realm_name="demo"# Change realm to 'demo'keycloak_admin.get_users() # Get users in realm 'demo'keycloak_admin.create_user(...) # Creates a new user in 'demo'# KEYCLOAK UMAfromkeycloakimportKeycloakOpenIDConnectionfromkeycloakimportKeycloakUMAkeycloak_connection=KeycloakOpenIDConnection(
server_url="http://localhost:8080/",
realm_name="master",
client_id="my_client",
client_secret_key="client-secret")
keycloak_uma=KeycloakUMA(connection=keycloak_connection)
# Create a resource setresource_set=keycloak_uma.resource_set_create({
"name": "example_resource",
"scopes": ["example:read", "example:write"],
"type": "urn:example"})
# List resource setsresource_sets=uma.resource_set_list()
# get resource setlatest_resource=uma.resource_set_read(resource_set["_id"])
# update resource setlatest_resource["name"] ="New Resource Name"uma.resource_set_update(resource_set["_id"], latest_resource)
# delete resource setuma.resource_set_delete(resource_id=resource_set["_id"])

About

No description, website, or topics provided.

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Auto-enable theater mode on YouTube\n(function() {\n function tryTheater() {\n var btn = document.querySelector('button[aria-label=\"Theater mode\"], ytd-player #player button[title=\"Theater mode\"]');\n if (btn && !btn.classList.contains('activated')) {\n btn.click();\n }\n }\n \n // Try immediately\n tryTheater();\n \n // Try after navigation (SPA)\n var lastUrl = location.href;\n setInterval(function() {\n if (location.href !== lastUrl) {\n lastUrl = location.href;\n setTimeout(tryTheater, 500);\n }\n }, 1000);\n \n // Also try on player load\n var observer = new MutationObserver(tryTheater);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "YouTube Theater Mode Default"); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Repository files navigation

CircleCIDocumentation Status

Python Keycloak

For review- see https://github.com/marcospereirampj/python-keycloak

python-keycloak is a Python package providing access to the Keycloak API.

Installation

Via Pypi Package:

$ pip install python-keycloak

Manually

$ python setup.py install

Dependencies

python-keycloak depends on:

Tests Dependencies

Bug reports

Please report bugs and feature requests at https://github.com/marcospereirampj/python-keycloak/issues

Documentation

The documentation for python-keycloak is available on readthedocs.

Contributors

Usage

fromkeycloakimportKeycloakOpenID# Configure clientkeycloak_openid=KeycloakOpenID(server_url="http://localhost:8080/auth/",
client_id="example_client",
realm_name="example_realm",
client_secret_key="secret")
# Get WellKnownconfig_well_known=keycloak_openid.well_known()
# Get Code With Oauth Authorization Requestauth_url=keycloak_openid.auth_url(
redirect_uri="your_call_back_url",
scope="email",
state="your_state_info")
# Get Access Token With Codeaccess_token=keycloak_openid.token(
grant_type='authorization_code',
code='the_code_you_get_from_auth_url_callback',
redirect_uri="your_call_back_url")
# Get Tokentoken=keycloak_openid.token("user", "password")
token=keycloak_openid.token("user", "password", totp="012345")
# Get token using Token Exchangetoken=keycloak_openid.exchange_token(token['access_token'], "my_client", "other_client", "some_user")
# Get Userinfouserinfo=keycloak_openid.userinfo(token['access_token'])
# Refresh tokentoken=keycloak_openid.refresh_token(token['refresh_token'])
# Logoutkeycloak_openid.logout(token['refresh_token'])
# Get Certscerts=keycloak_openid.certs()
# Get RPT (Entitlement)token=keycloak_openid.token("user", "password")
rpt=keycloak_openid.entitlement(token['access_token'], "resource_id")
# Introspect RPTtoken_rpt_info=keycloak_openid.introspect(keycloak_openid.introspect(token['access_token'], rpt=rpt['rpt'],
token_type_hint="requesting_party_token"))
# Introspect Tokentoken_info=keycloak_openid.introspect(token['access_token'])
# Decode TokenKEYCLOAK_PUBLIC_KEY="-----BEGIN PUBLIC KEY-----\n"+keycloak_openid.public_key() +"\n-----END PUBLIC KEY-----"options= {"verify_signature": True, "verify_aud": True, "verify_exp": True}
token_info=keycloak_openid.decode_token(token['access_token'], key=KEYCLOAK_PUBLIC_KEY, options=options)
# Get permissions by tokentoken=keycloak_openid.token("user", "password")
keycloak_openid.load_authorization_config("example-authz-config.json")
policies=keycloak_openid.get_policies(token['access_token'], method_token_info='decode', key=KEYCLOAK_PUBLIC_KEY)
permissions=keycloak_openid.get_permissions(token['access_token'], method_token_info='introspect')
# Get UMA-permissions by tokentoken=keycloak_openid.token("user", "password")
permissions=keycloak_openid.uma_permissions(token['access_token'])
# Get UMA-permissions by token with specific resource and scope requestedtoken=keycloak_openid.token("user", "password")
permissions=keycloak_openid.uma_permissions(token['access_token'], permissions="Resource#Scope")
# Get auth status for a specific resource and scope by tokentoken=keycloak_openid.token("user", "password")
auth_status=keycloak_openid.has_uma_access(token['access_token'], "Resource#Scope")
# KEYCLOAK ADMINfromkeycloakimportKeycloakAdminfromkeycloakimportKeycloakOpenIDConnectionkeycloak_connection=KeycloakOpenIDConnection(
server_url="http://localhost:8080/",
username='example-admin',
password='secret',
realm_name="master",
user_realm_name="only_if_other_realm_than_master",
client_id="my_client",
client_secret_key="client-secret",
verify=True)
keycloak_admin=KeycloakAdmin(connection=keycloak_connection)
# Add usernew_user=keycloak_admin.create_user({"email": "example@example.com",
"username": "example@example.com",
"enabled": True,
"firstName": "Example",
"lastName": "Example"})
# Add user and raise exception if username already exists# exist_ok currently defaults to True for backwards compatibility reasonsnew_user=keycloak_admin.create_user({"email": "example@example.com",
"username": "example@example.com",
"enabled": True,
"firstName": "Example",
"lastName": "Example"},
exist_ok=False)
# Add user and set passwordnew_user=keycloak_admin.create_user({"email": "example@example.com",
"username": "example@example.com",
"enabled": True,
"firstName": "Example",
"lastName": "Example",
"credentials": [{"value": "secret","type": "password",}]})
# Add user and specify a localenew_user=keycloak_admin.create_user({"email": "example@example.fr",
"username": "example@example.fr",
"enabled": True,
"firstName": "Example",
"lastName": "Example",
"attributes": {
"locale": ["fr"]
}})
# User countercount_users=keycloak_admin.users_count()
# Get users Returns a list of users, filtered according to query parametersusers=keycloak_admin.get_users({})
# Get user ID from usernameuser_id_keycloak=keycloak_admin.get_user_id("username-keycloak")
# Get Useruser=keycloak_admin.get_user("user-id-keycloak")
# Update Userresponse=keycloak_admin.update_user(user_id="user-id-keycloak",
payload={'firstName': 'Example Update'})
# Update User Passwordresponse=keycloak_admin.set_user_password(user_id="user-id-keycloak", password="secret", temporary=True)
# Get User Credentialscredentials=keycloak_admin.get_credentials(user_id='user_id')
# Get User Credential by IDcredential=keycloak_admin.get_credential(user_id='user_id', credential_id='credential_id')
# Delete User Credentialresponse=keycloak_admin.delete_credential(user_id='user_id', credential_id='credential_id')
# Delete Userresponse=keycloak_admin.delete_user(user_id="user-id-keycloak")
# Get consents granted by the userconsents=keycloak_admin.consents_user(user_id="user-id-keycloak")
# Send User Actionresponse=keycloak_admin.send_update_account(user_id="user-id-keycloak",
payload=['UPDATE_PASSWORD'])
# Send Verify Emailresponse=keycloak_admin.send_verify_email(user_id="user-id-keycloak")
# Get sessions associated with the usersessions=keycloak_admin.get_sessions(user_id="user-id-keycloak")
# Get themes, social providers, auth providers, and event listeners available on this serverserver_info=keycloak_admin.get_server_info()
# Get clients belonging to the realm Returns a list of clients belonging to the realmclients=keycloak_admin.get_clients()
# Get client - id (not client-id) from client by nameclient_id=keycloak_admin.get_client_id("my-client")
# Get representation of the client - id of client (not client-id)client=keycloak_admin.get_client(client_id="client_id")
# Get all roles for the realm or clientrealm_roles=keycloak_admin.get_realm_roles()
# Get all roles for the clientclient_roles=keycloak_admin.get_client_roles(client_id="client_id")
# Get client rolerole=keycloak_admin.get_client_role(client_id="client_id", role_name="role_name")
# Warning: Deprecated# Get client role id from namerole_id=keycloak_admin.get_client_role_id(client_id="client_id", role_name="test")
# Create client rolekeycloak_admin.create_client_role(client_role_id='client_id', payload={'name': 'roleName', 'clientRole': True})
# 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")
# Retrieve client roles of a user.keycloak_admin.get_client_roles_of_user(user_id="user_id", client_id="client_id")
# Retrieve available client roles of a user.keycloak_admin.get_available_client_roles_of_user(user_id="user_id", client_id="client_id")
# Retrieve composite client roles of a user.keycloak_admin.get_composite_client_roles_of_user(user_id="user_id", client_id="client_id")
# Delete client roles of a user.keycloak_admin.delete_client_roles_of_user(client_id="client_id", user_id="user_id", roles={"id": "role-id"})
keycloak_admin.delete_client_roles_of_user(client_id="client_id", user_id="user_id", roles=[{"id": "role-id_1"}, {"id": "role-id_2"}])
# Get the client authorization settingsclient_authz_settings=get_client_authz_settings(client_id="client_id")
# Get all client authorization resourcesclient_resources=get_client_authz_resources(client_id="client_id")
# Get all client authorization scopesclient_scopes=get_client_authz_scopes(client_id="client_id")
# Get all client authorization permissionsclient_permissions=get_client_authz_permissions(client_id="client_id")
# Get all client authorization policiesclient_policies=get_client_authz_policies(client_id="client_id")
# Create new groupgroup=keycloak_admin.create_group({"name": "Example Group"})
# Get all groupsgroups=keycloak_admin.get_groups()
# Get groupgroup=keycloak_admin.get_group(group_id='group_id')
# Get group by namegroup=keycloak_admin.get_group_by_path(path='/group/subgroup', search_in_subgroups=True)
# Function to trigger user sync from providersync_users(storage_id="storage_di", action="action")
# Get client role id from namerole_id=keycloak_admin.get_client_role_id(client_id=client_id, role_name="test")
# 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")
# Assign realm roles to userkeycloak_admin.assign_realm_roles(user_id=user_id, roles=realm_roles)
# Assign realm roles to client's scopekeycloak_admin.assign_realm_roles_to_client_scope(client_id=client_id, roles=realm_roles)
# Get realm roles assigned to client's scopekeycloak_admin.get_realm_roles_of_client_scope(client_id=client_id)
# Remove realm roles assigned to client's scopekeycloak_admin.delete_realm_roles_of_client_scope(client_id=client_id, roles=realm_roles)
another_client_id=keycloak_admin.get_client_id("my-client-2")
# Assign client roles to client's scopekeycloak_admin.assign_client_roles_to_client_scope(client_id=another_client_id, client_roles_owner_id=client_id, roles=client_roles)
# Get client roles assigned to client's scopekeycloak_admin.get_client_roles_of_client_scope(client_id=another_client_id, client_roles_owner_id=client_id)
# Remove client roles assigned to client's scopekeycloak_admin.delete_client_roles_of_client_scope(client_id=another_client_id, client_roles_owner_id=client_id, roles=client_roles)
# Get all ID Providersidps=keycloak_admin.get_idps()
# Create a new Realmkeycloak_admin.create_realm(payload={"realm": "demo"}, skip_exists=False)
# Changing Realmkeycloak_admin=KeycloakAdmin(realm_name="main", ...)
keycloak_admin.get_users() # Get user in main realmkeycloak_admin.realm_name="demo"# Change realm to 'demo'keycloak_admin.get_users() # Get users in realm 'demo'keycloak_admin.create_user(...) # Creates a new user in 'demo'# KEYCLOAK UMAfromkeycloakimportKeycloakOpenIDConnectionfromkeycloakimportKeycloakUMAkeycloak_connection=KeycloakOpenIDConnection(
server_url="http://localhost:8080/",
realm_name="master",
client_id="my_client",
client_secret_key="client-secret")
keycloak_uma=KeycloakUMA(connection=keycloak_connection)
# Create a resource setresource_set=keycloak_uma.resource_set_create({
"name": "example_resource",
"scopes": ["example:read", "example:write"],
"type": "urn:example"})
# List resource setsresource_sets=uma.resource_set_list()
# get resource setlatest_resource=uma.resource_set_read(resource_set["_id"])
# update resource setlatest_resource["name"] ="New Resource Name"uma.resource_set_update(resource_set["_id"], latest_resource)
# delete resource setuma.resource_set_delete(resource_id=resource_set["_id"])

About

No description, website, or topics provided.

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Remove or un-stick sticky/fixed headers that block content\n(function() {\n function unstick() {\n document.querySelectorAll('header, nav, [role=\"banner\"], .header, .navbar, .sticky, .fixed-top, [style*=\"position: fixed\"], [style*=\"position:sticky\"]').forEach(function(el) {\n if (el.style.position === 'fixed' || el.style.position === 'sticky' || \n getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') {\n el.style.position = 'static';\n el.style.top = 'auto';\n el.style.zIndex = 'auto';\n }\n });\n }\n \n unstick();\n \n var observer = new MutationObserver(unstick);\n observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] });\n})();", "Kill Sticky Headers"); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Repository files navigation

CircleCIDocumentation Status

Python Keycloak

For review- see https://github.com/marcospereirampj/python-keycloak

python-keycloak is a Python package providing access to the Keycloak API.

Installation

Via Pypi Package:

$ pip install python-keycloak

Manually

$ python setup.py install

Dependencies

python-keycloak depends on:

Tests Dependencies

Bug reports

Please report bugs and feature requests at https://github.com/marcospereirampj/python-keycloak/issues

Documentation

The documentation for python-keycloak is available on readthedocs.

Contributors

Usage

fromkeycloakimportKeycloakOpenID# Configure clientkeycloak_openid=KeycloakOpenID(server_url="http://localhost:8080/auth/",
client_id="example_client",
realm_name="example_realm",
client_secret_key="secret")
# Get WellKnownconfig_well_known=keycloak_openid.well_known()
# Get Code With Oauth Authorization Requestauth_url=keycloak_openid.auth_url(
redirect_uri="your_call_back_url",
scope="email",
state="your_state_info")
# Get Access Token With Codeaccess_token=keycloak_openid.token(
grant_type='authorization_code',
code='the_code_you_get_from_auth_url_callback',
redirect_uri="your_call_back_url")
# Get Tokentoken=keycloak_openid.token("user", "password")
token=keycloak_openid.token("user", "password", totp="012345")
# Get token using Token Exchangetoken=keycloak_openid.exchange_token(token['access_token'], "my_client", "other_client", "some_user")
# Get Userinfouserinfo=keycloak_openid.userinfo(token['access_token'])
# Refresh tokentoken=keycloak_openid.refresh_token(token['refresh_token'])
# Logoutkeycloak_openid.logout(token['refresh_token'])
# Get Certscerts=keycloak_openid.certs()
# Get RPT (Entitlement)token=keycloak_openid.token("user", "password")
rpt=keycloak_openid.entitlement(token['access_token'], "resource_id")
# Introspect RPTtoken_rpt_info=keycloak_openid.introspect(keycloak_openid.introspect(token['access_token'], rpt=rpt['rpt'],
token_type_hint="requesting_party_token"))
# Introspect Tokentoken_info=keycloak_openid.introspect(token['access_token'])
# Decode TokenKEYCLOAK_PUBLIC_KEY="-----BEGIN PUBLIC KEY-----\n"+keycloak_openid.public_key() +"\n-----END PUBLIC KEY-----"options= {"verify_signature": True, "verify_aud": True, "verify_exp": True}
token_info=keycloak_openid.decode_token(token['access_token'], key=KEYCLOAK_PUBLIC_KEY, options=options)
# Get permissions by tokentoken=keycloak_openid.token("user", "password")
keycloak_openid.load_authorization_config("example-authz-config.json")
policies=keycloak_openid.get_policies(token['access_token'], method_token_info='decode', key=KEYCLOAK_PUBLIC_KEY)
permissions=keycloak_openid.get_permissions(token['access_token'], method_token_info='introspect')
# Get UMA-permissions by tokentoken=keycloak_openid.token("user", "password")
permissions=keycloak_openid.uma_permissions(token['access_token'])
# Get UMA-permissions by token with specific resource and scope requestedtoken=keycloak_openid.token("user", "password")
permissions=keycloak_openid.uma_permissions(token['access_token'], permissions="Resource#Scope")
# Get auth status for a specific resource and scope by tokentoken=keycloak_openid.token("user", "password")
auth_status=keycloak_openid.has_uma_access(token['access_token'], "Resource#Scope")
# KEYCLOAK ADMINfromkeycloakimportKeycloakAdminfromkeycloakimportKeycloakOpenIDConnectionkeycloak_connection=KeycloakOpenIDConnection(
server_url="http://localhost:8080/",
username='example-admin',
password='secret',
realm_name="master",
user_realm_name="only_if_other_realm_than_master",
client_id="my_client",
client_secret_key="client-secret",
verify=True)
keycloak_admin=KeycloakAdmin(connection=keycloak_connection)
# Add usernew_user=keycloak_admin.create_user({"email": "example@example.com",
"username": "example@example.com",
"enabled": True,
"firstName": "Example",
"lastName": "Example"})
# Add user and raise exception if username already exists# exist_ok currently defaults to True for backwards compatibility reasonsnew_user=keycloak_admin.create_user({"email": "example@example.com",
"username": "example@example.com",
"enabled": True,
"firstName": "Example",
"lastName": "Example"},
exist_ok=False)
# Add user and set passwordnew_user=keycloak_admin.create_user({"email": "example@example.com",
"username": "example@example.com",
"enabled": True,
"firstName": "Example",
"lastName": "Example",
"credentials": [{"value": "secret","type": "password",}]})
# Add user and specify a localenew_user=keycloak_admin.create_user({"email": "example@example.fr",
"username": "example@example.fr",
"enabled": True,
"firstName": "Example",
"lastName": "Example",
"attributes": {
"locale": ["fr"]
}})
# User countercount_users=keycloak_admin.users_count()
# Get users Returns a list of users, filtered according to query parametersusers=keycloak_admin.get_users({})
# Get user ID from usernameuser_id_keycloak=keycloak_admin.get_user_id("username-keycloak")
# Get Useruser=keycloak_admin.get_user("user-id-keycloak")
# Update Userresponse=keycloak_admin.update_user(user_id="user-id-keycloak",
payload={'firstName': 'Example Update'})
# Update User Passwordresponse=keycloak_admin.set_user_password(user_id="user-id-keycloak", password="secret", temporary=True)
# Get User Credentialscredentials=keycloak_admin.get_credentials(user_id='user_id')
# Get User Credential by IDcredential=keycloak_admin.get_credential(user_id='user_id', credential_id='credential_id')
# Delete User Credentialresponse=keycloak_admin.delete_credential(user_id='user_id', credential_id='credential_id')
# Delete Userresponse=keycloak_admin.delete_user(user_id="user-id-keycloak")
# Get consents granted by the userconsents=keycloak_admin.consents_user(user_id="user-id-keycloak")
# Send User Actionresponse=keycloak_admin.send_update_account(user_id="user-id-keycloak",
payload=['UPDATE_PASSWORD'])
# Send Verify Emailresponse=keycloak_admin.send_verify_email(user_id="user-id-keycloak")
# Get sessions associated with the usersessions=keycloak_admin.get_sessions(user_id="user-id-keycloak")
# Get themes, social providers, auth providers, and event listeners available on this serverserver_info=keycloak_admin.get_server_info()
# Get clients belonging to the realm Returns a list of clients belonging to the realmclients=keycloak_admin.get_clients()
# Get client - id (not client-id) from client by nameclient_id=keycloak_admin.get_client_id("my-client")
# Get representation of the client - id of client (not client-id)client=keycloak_admin.get_client(client_id="client_id")
# Get all roles for the realm or clientrealm_roles=keycloak_admin.get_realm_roles()
# Get all roles for the clientclient_roles=keycloak_admin.get_client_roles(client_id="client_id")
# Get client rolerole=keycloak_admin.get_client_role(client_id="client_id", role_name="role_name")
# Warning: Deprecated# Get client role id from namerole_id=keycloak_admin.get_client_role_id(client_id="client_id", role_name="test")
# Create client rolekeycloak_admin.create_client_role(client_role_id='client_id', payload={'name': 'roleName', 'clientRole': True})
# 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")
# Retrieve client roles of a user.keycloak_admin.get_client_roles_of_user(user_id="user_id", client_id="client_id")
# Retrieve available client roles of a user.keycloak_admin.get_available_client_roles_of_user(user_id="user_id", client_id="client_id")
# Retrieve composite client roles of a user.keycloak_admin.get_composite_client_roles_of_user(user_id="user_id", client_id="client_id")
# Delete client roles of a user.keycloak_admin.delete_client_roles_of_user(client_id="client_id", user_id="user_id", roles={"id": "role-id"})
keycloak_admin.delete_client_roles_of_user(client_id="client_id", user_id="user_id", roles=[{"id": "role-id_1"}, {"id": "role-id_2"}])
# Get the client authorization settingsclient_authz_settings=get_client_authz_settings(client_id="client_id")
# Get all client authorization resourcesclient_resources=get_client_authz_resources(client_id="client_id")
# Get all client authorization scopesclient_scopes=get_client_authz_scopes(client_id="client_id")
# Get all client authorization permissionsclient_permissions=get_client_authz_permissions(client_id="client_id")
# Get all client authorization policiesclient_policies=get_client_authz_policies(client_id="client_id")
# Create new groupgroup=keycloak_admin.create_group({"name": "Example Group"})
# Get all groupsgroups=keycloak_admin.get_groups()
# Get groupgroup=keycloak_admin.get_group(group_id='group_id')
# Get group by namegroup=keycloak_admin.get_group_by_path(path='/group/subgroup', search_in_subgroups=True)
# Function to trigger user sync from providersync_users(storage_id="storage_di", action="action")
# Get client role id from namerole_id=keycloak_admin.get_client_role_id(client_id=client_id, role_name="test")
# 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")
# Assign realm roles to userkeycloak_admin.assign_realm_roles(user_id=user_id, roles=realm_roles)
# Assign realm roles to client's scopekeycloak_admin.assign_realm_roles_to_client_scope(client_id=client_id, roles=realm_roles)
# Get realm roles assigned to client's scopekeycloak_admin.get_realm_roles_of_client_scope(client_id=client_id)
# Remove realm roles assigned to client's scopekeycloak_admin.delete_realm_roles_of_client_scope(client_id=client_id, roles=realm_roles)
another_client_id=keycloak_admin.get_client_id("my-client-2")
# Assign client roles to client's scopekeycloak_admin.assign_client_roles_to_client_scope(client_id=another_client_id, client_roles_owner_id=client_id, roles=client_roles)
# Get client roles assigned to client's scopekeycloak_admin.get_client_roles_of_client_scope(client_id=another_client_id, client_roles_owner_id=client_id)
# Remove client roles assigned to client's scopekeycloak_admin.delete_client_roles_of_client_scope(client_id=another_client_id, client_roles_owner_id=client_id, roles=client_roles)
# Get all ID Providersidps=keycloak_admin.get_idps()
# Create a new Realmkeycloak_admin.create_realm(payload={"realm": "demo"}, skip_exists=False)
# Changing Realmkeycloak_admin=KeycloakAdmin(realm_name="main", ...)
keycloak_admin.get_users() # Get user in main realmkeycloak_admin.realm_name="demo"# Change realm to 'demo'keycloak_admin.get_users() # Get users in realm 'demo'keycloak_admin.create_user(...) # Creates a new user in 'demo'# KEYCLOAK UMAfromkeycloakimportKeycloakOpenIDConnectionfromkeycloakimportKeycloakUMAkeycloak_connection=KeycloakOpenIDConnection(
server_url="http://localhost:8080/",
realm_name="master",
client_id="my_client",
client_secret_key="client-secret")
keycloak_uma=KeycloakUMA(connection=keycloak_connection)
# Create a resource setresource_set=keycloak_uma.resource_set_create({
"name": "example_resource",
"scopes": ["example:read", "example:write"],
"type": "urn:example"})
# List resource setsresource_sets=uma.resource_set_list()
# get resource setlatest_resource=uma.resource_set_read(resource_set["_id"])
# update resource setlatest_resource["name"] ="New Resource Name"uma.resource_set_update(resource_set["_id"], latest_resource)
# delete resource setuma.resource_set_delete(resource_id=resource_set["_id"])

About

No description, website, or topics provided.

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Universal Dark Mode - works on any site\n(function() {\n var enabled = true;\n \n function applyDarkMode() {\n if (!enabled) return;\n \n // Create style element if it doesn't exist\n var style = document.getElementById('universal-dark-mode-style');\n if (!style) {\n style = document.createElement('style');\n style.id = 'universal-dark-mode-style';\n document.head.appendChild(style);\n }\n \n // Dark mode CSS - inverts colors but preserves images/video\n style.textContent = '\n /* Invert everything except media */\n html {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #1a1a2e !important;\n }\n \n /* Restore images, videos, iframes, canvas */\n img, video, iframe, canvas, svg, picture, [style*=\"background-image\"] {\n filter: invert(1) hue-rotate(180deg) !important;\n }\n \n /* Preserve specific elements that should not be inverted */\n .no-dark-mode, .no-dark-mode *,\n [data-theme=\"light\"], [data-theme=\"light\"],\n .ace_editor, .ace_editor *,\n .CodeMirror, .CodeMirror *,\n .monaco-editor, .monaco-editor *,\n .markdown-body pre, .markdown-body pre *,\n .highlight, .highlight *,\n pre code, pre code * {\n filter: none !important;\n }\n \n /* Fix common UI elements */\n .modal, .popup, .dropdown-menu, .tooltip, .popover {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #2d2d44 !important;\n border-color: #444 !important;\n }\n \n /* Scrollbars */\n ::-webkit-scrollbar { background: #1a1a2e !important; }\n ::-webkit-scrollbar-thumb { background: #444 !important; }\n ::-webkit-scrollbar-thumb:hover { background: #555 !important; }\n \n /* Selection */\n ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ';\n }\n \n function removeDarkMode() {\n var style = document.getElementById('universal-dark-mode-style');\n if (style) style.remove();\n }\n \n // Toggle with Alt+Shift+D\n document.addEventListener('keydown', function(e) {\n if (e.altKey && e.shiftKey && e.key === 'D') {\n e.preventDefault();\n enabled = !enabled;\n if (enabled) {\n applyDarkMode();\n console.log('[Universal Dark Mode] Enabled');\n } else {\n removeDarkMode();\n console.log('[Universal Dark Mode] Disabled');\n }\n }\n });\n \n // Apply on load\n applyDarkMode();\n \n // Re-apply on dynamic content\n var observer = new MutationObserver(function(mutations) {\n if (enabled && !document.getElementById('universal-dark-mode-style')) {\n applyDarkMode();\n }\n });\n observer.observe(document.head, { childList: true });\n \n console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle');\n})();", "Universal Dark Mode"); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })();
Skip to content

Repository files navigation

CircleCIDocumentation Status

Python Keycloak

For review- see https://github.com/marcospereirampj/python-keycloak

python-keycloak is a Python package providing access to the Keycloak API.

Installation

Via Pypi Package:

$ pip install python-keycloak

Manually

$ python setup.py install

Dependencies

python-keycloak depends on:

Tests Dependencies

Bug reports

Please report bugs and feature requests at https://github.com/marcospereirampj/python-keycloak/issues

Documentation

The documentation for python-keycloak is available on readthedocs.

Contributors

Usage

fromkeycloakimportKeycloakOpenID# Configure clientkeycloak_openid=KeycloakOpenID(server_url="http://localhost:8080/auth/",
client_id="example_client",
realm_name="example_realm",
client_secret_key="secret")
# Get WellKnownconfig_well_known=keycloak_openid.well_known()
# Get Code With Oauth Authorization Requestauth_url=keycloak_openid.auth_url(
redirect_uri="your_call_back_url",
scope="email",
state="your_state_info")
# Get Access Token With Codeaccess_token=keycloak_openid.token(
grant_type='authorization_code',
code='the_code_you_get_from_auth_url_callback',
redirect_uri="your_call_back_url")
# Get Tokentoken=keycloak_openid.token("user", "password")
token=keycloak_openid.token("user", "password", totp="012345")
# Get token using Token Exchangetoken=keycloak_openid.exchange_token(token['access_token'], "my_client", "other_client", "some_user")
# Get Userinfouserinfo=keycloak_openid.userinfo(token['access_token'])
# Refresh tokentoken=keycloak_openid.refresh_token(token['refresh_token'])
# Logoutkeycloak_openid.logout(token['refresh_token'])
# Get Certscerts=keycloak_openid.certs()
# Get RPT (Entitlement)token=keycloak_openid.token("user", "password")
rpt=keycloak_openid.entitlement(token['access_token'], "resource_id")
# Introspect RPTtoken_rpt_info=keycloak_openid.introspect(keycloak_openid.introspect(token['access_token'], rpt=rpt['rpt'],
token_type_hint="requesting_party_token"))
# Introspect Tokentoken_info=keycloak_openid.introspect(token['access_token'])
# Decode TokenKEYCLOAK_PUBLIC_KEY="-----BEGIN PUBLIC KEY-----\n"+keycloak_openid.public_key() +"\n-----END PUBLIC KEY-----"options= {"verify_signature": True, "verify_aud": True, "verify_exp": True}
token_info=keycloak_openid.decode_token(token['access_token'], key=KEYCLOAK_PUBLIC_KEY, options=options)
# Get permissions by tokentoken=keycloak_openid.token("user", "password")
keycloak_openid.load_authorization_config("example-authz-config.json")
policies=keycloak_openid.get_policies(token['access_token'], method_token_info='decode', key=KEYCLOAK_PUBLIC_KEY)
permissions=keycloak_openid.get_permissions(token['access_token'], method_token_info='introspect')
# Get UMA-permissions by tokentoken=keycloak_openid.token("user", "password")
permissions=keycloak_openid.uma_permissions(token['access_token'])
# Get UMA-permissions by token with specific resource and scope requestedtoken=keycloak_openid.token("user", "password")
permissions=keycloak_openid.uma_permissions(token['access_token'], permissions="Resource#Scope")
# Get auth status for a specific resource and scope by tokentoken=keycloak_openid.token("user", "password")
auth_status=keycloak_openid.has_uma_access(token['access_token'], "Resource#Scope")
# KEYCLOAK ADMINfromkeycloakimportKeycloakAdminfromkeycloakimportKeycloakOpenIDConnectionkeycloak_connection=KeycloakOpenIDConnection(
server_url="http://localhost:8080/",
username='example-admin',
password='secret',
realm_name="master",
user_realm_name="only_if_other_realm_than_master",
client_id="my_client",
client_secret_key="client-secret",
verify=True)
keycloak_admin=KeycloakAdmin(connection=keycloak_connection)
# Add usernew_user=keycloak_admin.create_user({"email": "example@example.com",
"username": "example@example.com",
"enabled": True,
"firstName": "Example",
"lastName": "Example"})
# Add user and raise exception if username already exists# exist_ok currently defaults to True for backwards compatibility reasonsnew_user=keycloak_admin.create_user({"email": "example@example.com",
"username": "example@example.com",
"enabled": True,
"firstName": "Example",
"lastName": "Example"},
exist_ok=False)
# Add user and set passwordnew_user=keycloak_admin.create_user({"email": "example@example.com",
"username": "example@example.com",
"enabled": True,
"firstName": "Example",
"lastName": "Example",
"credentials": [{"value": "secret","type": "password",}]})
# Add user and specify a localenew_user=keycloak_admin.create_user({"email": "example@example.fr",
"username": "example@example.fr",
"enabled": True,
"firstName": "Example",
"lastName": "Example",
"attributes": {
"locale": ["fr"]
}})
# User countercount_users=keycloak_admin.users_count()
# Get users Returns a list of users, filtered according to query parametersusers=keycloak_admin.get_users({})
# Get user ID from usernameuser_id_keycloak=keycloak_admin.get_user_id("username-keycloak")
# Get Useruser=keycloak_admin.get_user("user-id-keycloak")
# Update Userresponse=keycloak_admin.update_user(user_id="user-id-keycloak",
payload={'firstName': 'Example Update'})
# Update User Passwordresponse=keycloak_admin.set_user_password(user_id="user-id-keycloak", password="secret", temporary=True)
# Get User Credentialscredentials=keycloak_admin.get_credentials(user_id='user_id')
# Get User Credential by IDcredential=keycloak_admin.get_credential(user_id='user_id', credential_id='credential_id')
# Delete User Credentialresponse=keycloak_admin.delete_credential(user_id='user_id', credential_id='credential_id')
# Delete Userresponse=keycloak_admin.delete_user(user_id="user-id-keycloak")
# Get consents granted by the userconsents=keycloak_admin.consents_user(user_id="user-id-keycloak")
# Send User Actionresponse=keycloak_admin.send_update_account(user_id="user-id-keycloak",
payload=['UPDATE_PASSWORD'])
# Send Verify Emailresponse=keycloak_admin.send_verify_email(user_id="user-id-keycloak")
# Get sessions associated with the usersessions=keycloak_admin.get_sessions(user_id="user-id-keycloak")
# Get themes, social providers, auth providers, and event listeners available on this serverserver_info=keycloak_admin.get_server_info()
# Get clients belonging to the realm Returns a list of clients belonging to the realmclients=keycloak_admin.get_clients()
# Get client - id (not client-id) from client by nameclient_id=keycloak_admin.get_client_id("my-client")
# Get representation of the client - id of client (not client-id)client=keycloak_admin.get_client(client_id="client_id")
# Get all roles for the realm or clientrealm_roles=keycloak_admin.get_realm_roles()
# Get all roles for the clientclient_roles=keycloak_admin.get_client_roles(client_id="client_id")
# Get client rolerole=keycloak_admin.get_client_role(client_id="client_id", role_name="role_name")
# Warning: Deprecated# Get client role id from namerole_id=keycloak_admin.get_client_role_id(client_id="client_id", role_name="test")
# Create client rolekeycloak_admin.create_client_role(client_role_id='client_id', payload={'name': 'roleName', 'clientRole': True})
# 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")
# Retrieve client roles of a user.keycloak_admin.get_client_roles_of_user(user_id="user_id", client_id="client_id")
# Retrieve available client roles of a user.keycloak_admin.get_available_client_roles_of_user(user_id="user_id", client_id="client_id")
# Retrieve composite client roles of a user.keycloak_admin.get_composite_client_roles_of_user(user_id="user_id", client_id="client_id")
# Delete client roles of a user.keycloak_admin.delete_client_roles_of_user(client_id="client_id", user_id="user_id", roles={"id": "role-id"})
keycloak_admin.delete_client_roles_of_user(client_id="client_id", user_id="user_id", roles=[{"id": "role-id_1"}, {"id": "role-id_2"}])
# Get the client authorization settingsclient_authz_settings=get_client_authz_settings(client_id="client_id")
# Get all client authorization resourcesclient_resources=get_client_authz_resources(client_id="client_id")
# Get all client authorization scopesclient_scopes=get_client_authz_scopes(client_id="client_id")
# Get all client authorization permissionsclient_permissions=get_client_authz_permissions(client_id="client_id")
# Get all client authorization policiesclient_policies=get_client_authz_policies(client_id="client_id")
# Create new groupgroup=keycloak_admin.create_group({"name": "Example Group"})
# Get all groupsgroups=keycloak_admin.get_groups()
# Get groupgroup=keycloak_admin.get_group(group_id='group_id')
# Get group by namegroup=keycloak_admin.get_group_by_path(path='/group/subgroup', search_in_subgroups=True)
# Function to trigger user sync from providersync_users(storage_id="storage_di", action="action")
# Get client role id from namerole_id=keycloak_admin.get_client_role_id(client_id=client_id, role_name="test")
# 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")
# Assign realm roles to userkeycloak_admin.assign_realm_roles(user_id=user_id, roles=realm_roles)
# Assign realm roles to client's scopekeycloak_admin.assign_realm_roles_to_client_scope(client_id=client_id, roles=realm_roles)
# Get realm roles assigned to client's scopekeycloak_admin.get_realm_roles_of_client_scope(client_id=client_id)
# Remove realm roles assigned to client's scopekeycloak_admin.delete_realm_roles_of_client_scope(client_id=client_id, roles=realm_roles)
another_client_id=keycloak_admin.get_client_id("my-client-2")
# Assign client roles to client's scopekeycloak_admin.assign_client_roles_to_client_scope(client_id=another_client_id, client_roles_owner_id=client_id, roles=client_roles)
# Get client roles assigned to client's scopekeycloak_admin.get_client_roles_of_client_scope(client_id=another_client_id, client_roles_owner_id=client_id)
# Remove client roles assigned to client's scopekeycloak_admin.delete_client_roles_of_client_scope(client_id=another_client_id, client_roles_owner_id=client_id, roles=client_roles)
# Get all ID Providersidps=keycloak_admin.get_idps()
# Create a new Realmkeycloak_admin.create_realm(payload={"realm": "demo"}, skip_exists=False)
# Changing Realmkeycloak_admin=KeycloakAdmin(realm_name="main", ...)
keycloak_admin.get_users() # Get user in main realmkeycloak_admin.realm_name="demo"# Change realm to 'demo'keycloak_admin.get_users() # Get users in realm 'demo'keycloak_admin.create_user(...) # Creates a new user in 'demo'# KEYCLOAK UMAfromkeycloakimportKeycloakOpenIDConnectionfromkeycloakimportKeycloakUMAkeycloak_connection=KeycloakOpenIDConnection(
server_url="http://localhost:8080/",
realm_name="master",
client_id="my_client",
client_secret_key="client-secret")
keycloak_uma=KeycloakUMA(connection=keycloak_connection)
# Create a resource setresource_set=keycloak_uma.resource_set_create({
"name": "example_resource",
"scopes": ["example:read", "example:write"],
"type": "urn:example"})
# List resource setsresource_sets=uma.resource_set_list()
# get resource setlatest_resource=uma.resource_set_read(resource_set["_id"])
# update resource setlatest_resource["name"] ="New Resource Name"uma.resource_set_update(resource_set["_id"], latest_resource)
# delete resource setuma.resource_set_delete(resource_id=resource_set["_id"])

About

No description, website, or topics provided.

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages