satorbis_kit.auth package¶
- class satorbis_kit.auth.Environment(value)[source]¶
Bases:
str,EnumNamed deployment environments supported by the auth layer.
- DEV = 'dev'¶
- PROD = 'prod'¶
- class satorbis_kit.auth.OIDCAuth(environment: Environment | str | None = None, application: str | None = None, redirect_port: int = 4200, scopes: str = 'openid profile email offline_access', callback_timeout: int = 300, authorization_url: str | None = None, token_url: str | None = None, verify_jwt: bool = True)[source]¶
Bases:
BaseAuthManages the full OIDC Authorization Code + PKCE flow against an OIDC provider, designed for use inside a Jupyter notebook.
- Parameters:
environment – Target deployment environment. Accepts an
Environmentmember, a plain string ("prod"or"dev"), orNone. WhenNonethe value of theSATORBIS_ENVenvironment variable is used; if that is also absent,prodis the default. Example:OIDCAuth(environment="dev").application – Application name used to look up a Zitadel project ID from the environment’s
project_idsmapping. When a project ID is found,urn:zitadel:iam:org:project:id:{project_id}:audis appended to the requested scopes so the token carries the project audience claim. Example:OIDCAuth(application="spatial_engine").redirect_port – Local port for the OAuth callback server. Must match the redirect URI registered with the provider. Default:
4200.scopes – Space-separated OIDC scopes. Include
offline_accessto receive a refresh token.callback_timeout – Seconds to wait for the browser callback before raising
TimeoutError. Default: 300 (5 minutes).authorization_url – Optional. The authorization endpoint URL. If not provided, it will be discovered from the OIDC discovery document.
token_url – Optional. The token endpoint URL. If not provided, it will be discovered from the OIDC discovery document.
verify_jwt – If
True, JWT signature verification is performed using the provider’s JWKS when enforcing email identity. Default:True.
- authenticate() TokenStore[source]¶
For interactive OIDC flows, use
start_login()followed byawait_callback(). This method is not directly applicable to interactive browser-based flows.- Raises:
NotImplementedError – Always. Use
start_login()+await_callback()instead.
- await_callback() TokenStore[source]¶
Block until the browser callback is received, exchange the authorization code for tokens, then verify that the authenticated email matches the
login_hintfromstart_login().- Raises:
RuntimeError – If
start_login()has not been called first.TimeoutError – If no callback is received within
callback_timeoutseconds.IdentityMismatchError – If the authenticated user’s email does not match the expected
login_hint. Tokens are not stored in this case.
- refresh_token() TokenStore[source]¶
Exchange the refresh token for a new access token (and possibly a new refresh token). Updates
tokensin-place.Providers with refresh token rotation return a new refresh token with each call, which is saved automatically.
- Returns:
The updated token store.
- Return type:
- Raises:
ValueError – If no refresh token is available (e.g.
offline_accessscope was not requested).
- start_login(login_hint: str = '') str[source]¶
Generate the PKCE authorization URL and start the local callback server in a background thread.
The
login_hintemail is remembered and enforced inawait_callback()— if the user authenticates as a different identity,IdentityMismatchErroris raised and no tokens are stored.- Parameters:
login_hint – Email address to pre-fill on the provider login page. When provided, the authenticated token must match this email.
- Returns:
The authorization URL. The user must open it in a browser.
- Return type:
str
- class satorbis_kit.auth.ServiceAuth(client_id: str, client_secret: str, environment: Environment | str | None = None, scopes: str = 'openid profile email', token_url: str | None = None)[source]¶
Bases:
BaseAuthManages the service-account (client-credentials) login flow against an OIDC provider, designed for use inside a Jupyter notebook.
- Parameters:
client_id – The client ID of the OIDC application.
client_secret – The client secret of the OIDC application.
environment – Target deployment environment. Accepts an
Environmentmember, a plain string ("prod"or"dev"), orNone. WhenNonethe value of theSATORBIS_ENVenvironment variable is used; if that is also absent,prodis the default. Example:ServiceAuth(..., environment="dev").scopes – Space-separated OIDC scopes.
token_url – Optional. The token endpoint URL. If not provided, it will be discovered from the OIDC discovery document.
- authenticate()[source]¶
Authenticate using service account (client credentials flow).
- Returns:
Token store containing the access token.
- Return type:
- class satorbis_kit.auth.TokenStore(access_token: str | None = None, refresh_token: str | None = None, id_token: str | None = None, token_type: str = 'Bearer', expires_at: float | None = None)[source]¶
Bases:
object- access_token: str | None = None¶
- decode_jwt_payload() dict[source]¶
Decode the access token’s JWT payload without signature verification.
- static decode_jwt_payload_str(token_str: str) dict[source]¶
Base64-decode a JWT payload without verifying the signature.
- expires_at: float | None = None¶
- id_token: str | None = None¶
- property is_empty¶
- property is_expired¶
- refresh_token: str | None = None¶
- token_type: str = 'Bearer'¶