API reference#

Summary#

AsyncOidcClient

OIDC Async client.

OidcClient

OIDC client.

OidcDependency

FastAPI dependency class for OpenID Connect (OIDC) access token validation.

OidcWebSocketDependency

FastAPI dependency class for OpenID Connect (OIDC) access token validation for WebSocket connections.

UserInfo

OpenID Connect set of standard claims about the profile information of the end-user.

NoIssuerError

Raised when no issuer is provided but is required for the operation.

NoIssuerOrAudienceError

Raised when no issuer or audience is provided but is required for the operation.

get_websocket_subprotocol

Extract the first subprotocol that matches the specified prefix from the WebSocket’s subprotocols list.

decode_base64_token

Decode a base64-encoded token.

encode_base64_token

Encode a token using base64 encoding.

Description#

IAM OIDC package.

This package provides OAuth2 and OpenID Connect (OIDC) capabilities, enabling seamless integration of authentication and authorization features.

The package is built on top of Authlib and provides both synchronous and asynchronous OIDC clients, FastAPI dependencies for token validation, and utility functions for token handling.

Module detail#

oidc.get_websocket_subprotocol(websocket: fastapi.WebSocket, subprotocol_prefix: str = DEFAULT_SUBPROTOCOL_PREFIX) → str | None#

Extract the first subprotocol that matches the specified prefix from the WebSocket’s subprotocols list.

Parameters:
websocket: WebSocket

The WebSocket connection object containing the headers.

subprotocol_prefix: str, optional

The prefix to match against WebSocket subprotocols. Defaults to DEFAULT_SUBPROTOCOL_PREFIX.

Returns:
str | None

The first matching subprotocol string if found, otherwise None.

oidc.decode_base64_token(encoded_token: str) → str#

Decode a base64-encoded token.

Parameters:
encoded_token: str

The base64-encoded token to decode.

Returns:
str

The decoded token.

Raises:
ValueError

If the token cannot be decoded.

oidc.encode_base64_token(token: str) → str#

Encode a token using base64 encoding.

Parameters:
token: str

The token to encode.

Returns:
str

The base64-encoded token.

oidc.DEFAULT_SUBPROTOCOL_PREFIX = 'saf.auth.bearer.'#