You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
Richard Nemeth af3d596166
test: fix match
1 week ago
.github/workflows ci: upgrade actions (#548) 1 week ago
bin pure, not universal. 2 years ago
docs feat: new docs. 2 months ago
src/keycloak feat: allows retrieval of realm and client level roles for a user (#512) 1 week ago
tests test: fix match 1 week ago
.gitignore chore: no envrc 2 months ago
.pre-commit-config.yaml fix: tests and upgraded deps (#419) 1 year ago
.readthedocs.yaml ci: fix docs pipeline 2 weeks ago
.releaserc.json feat: initial setup of CICD and linting 2 years ago
CHANGELOG.md docs: changelog update 1 week ago
CODEOWNERS feat: initial setup of CICD and linting 2 years ago
CONTRIBUTING.md chore: tox test install without hashes 2 years ago
LICENSE style: removed manifest, applied pre-commit hooks 2 years ago
README.md feat: new docs. 2 months ago
poetry.lock test: Test/keycloak versions (#543) 2 weeks ago
pyproject.toml fix: replace python-jose with jwcrypto 2 months ago
test_keycloak_init.sh test: Test with multiple Keycloak versions (#418) 1 year ago
tox.env fix: Ci/fix tests (#506) 5 months ago
tox.ini feat: Adding additional methods to support roles-by-id api calls 2 months ago

README.md

CircleCI Documentation Status

Python Keycloak

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

Installation

Install via PyPI:

$ pip install python-keycloak

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.

Example of Using Keycloak OpenID

from keycloak import KeycloakOpenID

# Configure client
keycloak_openid = KeycloakOpenID(server_url="http://localhost:8080/auth/",
                                 client_id="example_client",
                                 realm_name="example_realm",
                                 client_secret_key="secret")

# Get WellKnown
config_well_known = keycloak_openid.well_known()

# Get Code With Oauth Authorization Request
auth_url = keycloak_openid.auth_url(
    redirect_uri="your_call_back_url",
    scope="email",
    state="your_state_info")

# Get Access Token With Code
access_token = keycloak_openid.token(
    grant_type='authorization_code',
    code='the_code_you_get_from_auth_url_callback',
    redirect_uri="your_call_back_url")


# Get Token
token = keycloak_openid.token("user", "password")
token = keycloak_openid.token("user", "password", totp="012345")

# Get token using Token Exchange
token = keycloak_openid.exchange_token(token['access_token'], "my_client", "other_client", "some_user")

# Get Userinfo
userinfo = keycloak_openid.userinfo(token['access_token'])

# Refresh token
token = keycloak_openid.refresh_token(token['refresh_token'])

# Logout
keycloak_openid.logout(token['refresh_token'])

Example of Using Keycloak Admin API

from keycloak import KeycloakAdmin
from keycloak import KeycloakOpenIDConnection

keycloak_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 user
new_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 reasons
new_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 password
new_user = keycloak_admin.create_user({"email": "example@example.com",
                                       "username": "example@example.com",
                                       "enabled": True,
                                       "firstName": "Example",
                                       "lastName": "Example",
                    "credentials": [{"value": "secret","type": "password",}]})

For more details, see the documentation available on readthedocs.