OidcWebSocketDependency#

class ansys.iam.oidc.OidcWebSocketDependency(oidc_issuer: str | None = None, audience: str | None = None, subprotocol_prefix: str = DEFAULT_SUBPROTOCOL_PREFIX, *, auto_error: bool = True)#

Bases: OidcDependency

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

It’s expected that the token is found, base64-encoded, as a subprotocol of the WebSocket, followed by a given prefix. For example, if the prefix is saf.auth.bearer., the subprotocol should be saf.auth.bearer.. Use ansys.iam.oidc.encode_base64_token to encode the token.

Overview#

__call__

Extract and validate the access token from the WebSocket subprotocol.

Import detail#

from ansys.iam.oidc import OidcWebSocketDependency

Method detail#

async OidcWebSocketDependency.__call__(websocket: fastapi.WebSocket) → str | None#

Extract and validate the access token from the WebSocket subprotocol.

Parameters:
websocketWebSocket

The WebSocket connection object.

Returns:
str | None

If authentication is mandatory, the access token if present and valid. If authentication is optional, the access token if present, otherwise None.

Raises:
WebSocketException

If auto_error is True and authentication fails (missing token, invalid encoding, or token validation fails).