- Notifications
You must be signed in to change notification settings - Fork325
License
marcospereirampj/python-keycloak
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
python-keycloak is a Python package providing access to the Keycloak API.
Install via PyPI:
$ pip install python-keycloak
Please report bugs and feature requests athttps://github.com/marcospereirampj/python-keycloak/issues
The documentation for python-keycloak is available onreadthedocs.
The library strives to always support Keycloak's latest version. Additionally to that, we also support 5 latest major versions of Keycloak,in order to give our user base more time for smoother upgrades.
Current list of supported Keycloak versions:
- 26.X
- 25.X
- 24.X
- 23.X
- 22.X
We only support Python versions that have active or security support by the Python Software Foundation. You can find the list of active Python versionshere.
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'])
fromkeycloakimportKeycloakAdminfromkeycloakimportKeycloakOpenIDConnectionkeycloak_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",}]})
For more details, see the documentation available onreadthedocs.
About
Topics
Resources
License
Contributing
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.