nolito.oauth module¶
- class nolito.oauth.OAuthManager(settings, token_store, session=None)[source]¶
Bases:
objectHandles authorization code flow and refresh token rotation.
- Parameters:
settings (
NolitoSettings) – Settings for this instance of the API.token_store (
KeyringTokenStore) – The token store used for authentication info.session (
Session|None) – requests.Session object to attach to the client. Plain session is created from scratch ifNone. Defaults toNone.
- authorization_url(state)[source]¶
Create an authorization URL for the API
- Parameters:
state (
str) – The secret state to use the authorization- Return type:
str- Returns:
URL
- authorize_with_local_callback(timeout_seconds=180)[source]¶
Authorize through a browser and capture the callback on localhost.
- Parameters:
timeout_seconds (
int) – Maximum time to wait for the browser callback (in sec).- Return type:
- Returns:
The exchanged access and refresh tokens.
- exchange_code(code)[source]¶
Exchange an OAuth authorization code for tokens and persist them.
- Parameters:
code (
str) – The authorization code returned by Nolio’s authorization endpoint. Codes expire after 10 minutes and may be used once.- Return type:
- Returns:
The exchanged access and refresh tokens.
- Raises:
OAuthFlowError – If Nolio rejects the exchange.
- load_or_authorize()[source]¶
Load the token from the store and authorize or refresh if required
- Return type:
- Returns:
The loaded token set
- refresh(refresh_token)[source]¶
Refresh the authentication token, or re-authorize after token revocation.
- Parameters:
refresh_token (
str) – The refresh token for the API- Return type:
- Returns:
The updated token set.
Nolio rotates refresh tokens. A consumed or revoked token produces
invalid_grantand cannot be retried, so its local copy is removed before restarting the authorization flow.