Skip to content

cmem_client.models.token¤

Authentication token models for OAuth 2.0 flows.

This module provides models for handling OAuth 2.0 tokens, particularly Keycloak tokens used in Corporate Memory authentication. It includes automatic JWT parsing and expiration checking functionality.

The KeycloakToken model handles token lifecycle management, including automatically parsing JWT contents and providing expiration checking to support token refresh logic in authentication providers.

Classes:

Functions:

KeycloakToken¤

Bases: Model

A Keycloak token

Attributes:

  • access_token (str) – The encoded bearer token, as sent in the Authorization header.
  • expires_in (int) – Lifetime of the token in seconds, counted from when Keycloak issued it.
  • expires (datetime) – When the token expires. Taken from the exp claim of the decoded token on creation, so the default is never what a caller sees.
  • jwt (dict) – Claims of the decoded token. The signature is not verified here, because the token comes straight from the token endpoint over TLS.

Functions:

access_token¤

access_token: str

expires¤

expires: datetime = Field(default_factory=default_factory_now)

expires_in¤

expires_in: int

is_expired¤

is_expired()

Check if token is expired

jwt¤

jwt: dict = Field(default_factory=dict)

model_config¤

model_config = ConfigDict(extra='allow', populate_by_name=True)

model_post_init¤

model_post_init(context)

Do the post init

default_factory_now¤

default_factory_now()

Get the current UTC datetime

Comments