5.2.12. xgt.OidcTokenCache

class xgt.OidcTokenCache(config: OidcClientConfig)

Manages a single JSON token file on disk for a given OidcClientConfig.

Experimental: The API of this class may change in future releases.

Methods

clear()

Delete the cached token file if it exists.

load()

Load the cached token payload, or None if unavailable/unusable.

save(token_payload)

Persist the token payload and annotate it with timing fields.

Attributes

path

The resolved path of the token cache file on disk.

clear() → None

Delete the cached token file if it exists.

load() → dict[str, Any] | None

Load the cached token payload, or None if unavailable/unusable.

Returns the payload in one of two states:

  • Fresh access token: full payload, ready to use directly.

  • Expired access token with a refresh token: payload with access_token stripped, signalling the caller to attempt a refresh.

Returns None (and clears the cache) if the file is missing, corrupt, or contains an expired token with no refresh path.

property path: Path

The resolved path of the token cache file on disk.

save(token_payload: dict[str, Any]) → dict[str, Any]

Persist the token payload and annotate it with timing fields.

Adds ‘obtained_at’ (epoch) and, if ‘expires_in’ is present, ‘expires_at’ so that future loads can evaluate freshness without re-decoding the JWT. Returns the augmented payload.