ovok_sdk.auth.user_session

The signed-in user's session and its token refresh.

  • Stable unknown
  • Release candidate since 0.1.0-rc.4
  • Development since 0.1.0-dev.25+2ba84b0

The signed-in user's session and its token refresh.

UserSession

UserSession(
    store: SessionStore,
    endpoint: TokenEndpoint,
    settings: OvokSettings,
    clock: Clock = epoch_ms,
)

The signed-in user's tokens, kept in storage and refreshed a minute before they expire.

Parameters

NameTypeDefaultDescription
storeSessionStoreWhere the session is kept.
endpointTokenEndpointThe OAuth token endpoint used to refresh.
settingsOvokSettingsThe client's settings.
clockClockepoch_msCurrent time in epoch milliseconds.

current()

current() -> Session | None

Return the stored session, or None when no one is signed in.

begin()

begin(tokens: Mapping[str, Any]) -> Session

Start a session from a sign-in response and notify listeners.

Parameters

NameTypeDefaultDescription
tokensMapping[str, Any]The camelCase body of an Ovok sign-in route.

Returns

  • Session: The new session.

end()

end() -> None

Delete the session and notify listeners.

on_change()

on_change(listener: Callable[[], None]) -> None

Call listener whenever the session starts, refreshes or ends.

access_token()

access_token() -> str | None

Return the access token, refreshing it first when it is stale; None when signed out.

refresh()

refresh() -> bool

Exchange the refresh token for new tokens.

A refused refresh signs the user out and calls on_unauthenticated.

Returns

  • bool: True when the session was refreshed; False when there is nothing to refresh
  • bool: or the refresh was refused.

Raises

  • OvokError: The refresh failed for another reason, such as an outage.

Last updated on

On this page