Namespaces

Session

Learn how to read the current session, react when it changes and switch between the accounts signed in on this client.

  • Stable unknown
  • Release candidate not available
  • Development since 0.2.0-dev.34+53a6a64

ovok.session holds the signed-in user's session and every account signed in to on this client. Each sign-in saves its account under ovok:<tenant_code>:saved-accounts in storage, next to the session.

React to sign-in and sign-out

stop = ovok.session.on_change(lambda session: print(session.profile if session else "signed out"))

stop()
  • The listener gets the new session on sign-in and account switch, and None on sign-out.
  • current returns the stored session, or None.

Switch accounts

for account in ovok.session.saved_accounts.list():
    print(account.id, account.active, account.expired)

ovok.session.saved_accounts.switch("Patient/123")
  • switch raises OvokAccountError with code account_not_found or account_expired. An account expires when its refresh token is refused; signing in again renews it.
  • remove ends the account's session on the server with that account's own token, then forgets it. Removing the active account switches to the next live one, or signs out.
  • A machine client has no session: current returns None and saved_accounts raises OvokConfigError.

See also

Last updated on

On this page