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
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.
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>
Usage of the library
from KCAuth import KCAuth
kcAuth = KCAuth("keycloak.json")
kcAuth.getAccessToken()
#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