Skip to content

A simple python console application showing how to obtain access grants with OIDC Keycloak console clients

License

Notifications You must be signed in to change notification settings

ddtxra/python-console-keycloak-example

Repository files navigation

python-console-keycloak-example

A client application, configured as an OIDC client in Keycloak that shows how to obtain access grants, using the OAuth's Resource Owner Password Credentials

Keycloak configuration (if not done already)

Create a new OIDC client in keycloak, with "Access Type" set to "confidential" and optionally disable the option "Standard Flow Enabled" and save it. Click again on the client and go under Credentials tab, you will see the secret.

Usage

Copy keycloak.json.template to keycloak.json or to any filename of your choice and change the values according to your environment. If the filename is different than keycloak.json, pass the filename as argument.

python KCAuth.py <filename>

Developers

Usage of the library

from KCAuth import KCAuth

kcAuth = KCAuth("keycloak.json")
kcAuth.getAccessToken()

Curl usage

#Use the access token as follows
ACCESS_TOKEN=<copy-your-access-token-from-the-python-script>
RESOURCE_URL=http://localhost:8080/my-protected-resource
curl -H "Authorization: Bearer $ACCESS_TOKEN" $RESOURCE_URL

About

A simple python console application showing how to obtain access grants with OIDC Keycloak console clients

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published