Skip to main content

Keycloak Authenticator

Project description


All the libraries I found for Keycloak are outdated and not nearly generic enough, so here's a new one.



python -m pip install keycloak-basic


from keycloak import Keycloak, Token, UserInfo

keycloak: Keycloak = Keycloak(
    "http(s)://<host>:<port>", # Keycloak server URL with no trailing path
    "<realm name>", # Name of realm to authenticate in
    "<client id>", # Client ID
    client_secret = "<client secret" # Client secret, if present

token: Token = keycloak.auth(
    "<username>", # User username
    "<password>" # User password
) -> Token

token.authenticated # Boolean, true if logged in
token.isScoped("scope") -> bool # True if current token has scope

info: UserInfo = -> UserInfo object

token.refresh() # Refreshes connection
token.logout() # Logs out

keycloak.load_token(token.content) -> Token # Loads token from dict

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

keycloak-basic-1.2.1.tar.gz (4.8 kB view hashes)

Uploaded Source

Built Distribution

keycloak_basic-1.2.1-py3-none-any.whl (6.0 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page