module documentation
Federation bearer authentication utilities.
This module provides functions to perform OAuth 2.0 authorization code flow with PKCE for federation bearer token authentication. It handles browser-based authentication, callback server management, and token exchange.
| Class | |
Result of token retrieval. |
| Async Function | authorize |
Perform full OAuth authorization flow and return access token. |
| Async Function | get |
Obtain authorization code via OAuth callback. |
| Async Function | get |
Exchange authorization code for access token. |
| Function | https |
Ensure the URL uses HTTPS scheme. |
| Async Function | open |
Open the given URL in the default web browser. |
| Variable | log |
Undocumented |
async def authorize(client_id:
str, federation_endpoint: str, federation_id: str, writer: TextIO | None = None, no_browser_open: bool = False, timeout: float | None = 300, ssl_ctx: ssl.SSLContext | None = None) -> GetTokenResult:
(source)
¶
Perform full OAuth authorization flow and return access token.
Combines getting the authorization code and exchanging it for a token.
| Parameters | |
| client | The OAuth client ID. |
| federation | The base federation endpoint URL. |
| federation | The federation identifier. |
writer:TextIO or None | Optional text stream to write messages to. |
| no | If True, do not open browser automatically. |
| timeout:float or None | Timeout in seconds for the entire flow. |
sslssl.SSLContext or None | Optional SSL context for token request. |
| Returns | |
GetTokenResult | The token result containing access token and expiration. |
async def get_code(client_id:
str, auth_endpoint: str, federation_id: str, pkce_code: PKCE, writer: TextIO | None = None, no_browser_open: bool = False, timeout: float | None = 300) -> tuple[ str, str]:
(source)
¶
Obtain authorization code via OAuth callback.
Starts a local callback server, constructs the authorization URL with PKCE, opens the browser (or prints the URL), and waits for the callback.
| Parameters | |
| client | The OAuth client ID. |
| auth | The authorization endpoint URL. |
| federation | The federation identifier. |
pkcePKCE | The PKCE code challenge and method. |
writer:TextIO or None | Optional text stream to write messages to. |
| no | If True, do not open browser automatically. |
| timeout:float or None | Timeout in seconds for waiting for the code. |
| Returns | |
| tuple[str, str] | A tuple of (authorization_code, redirect_uri). |
| Raises | |
RuntimeError | If browser fails to open or no code received. |
TimeoutError | If timeout waiting for code. |
async def get_token(client_id:
str, token_url: str, code: str, redirect_uri: str, verifier: str, ssl_ctx: ssl.SSLContext | None = None) -> GetTokenResult:
(source)
¶
Exchange authorization code for access token.
Sends a POST request to the token endpoint with the code and PKCE verifier.
| Parameters | |
| client | The OAuth client ID. |
| token | The token endpoint URL. |
| code:str | The authorization code received from callback. |
| redirect | The redirect URI used in the request. |
| verifier:str | The PKCE code verifier. |
sslssl.SSLContext or None | Optional SSL context for the request. |
| Returns | |
GetTokenResult | The token result containing access token and expiration. |
| Raises | |
RuntimeError | If token request fails or response is invalid. |
Ensure the URL uses HTTPS scheme.
| Parameters | |
| raw | The input URL string. |
| Returns | |
| str | The URL with HTTPS scheme. |