Getting started

Introduction

What Authyra does, what it does not do, and how its packages fit together.

Authyra is the session layer of a Dart or Flutter app that talks to its own backend. A provider proves who the user is and returns tokens; Authyra takes it from there.

The problem it solves

Most apps start with a login call that stores two tokens and an interceptor that refreshes on 401. That code works in the demo and fails in production, in ways that are hard to reproduce:

  • Concurrent refreshes. Ten requests fail with a 401 at the same time and each one starts a refresh. With rotating refresh tokens, every call after the first presents a token that was already used. A server that detects reuse, as OAuth 2.1 recommends for public clients, treats it as theft and revokes the whole session: the user is signed out for no visible reason. Some servers tolerate reuse for a few seconds; relying on that grace period only hides the race.
  • Transient errors taken as revocations. A timeout or a 503 during a refresh is handled like an invalid token, and a user on a train loses their session.
  • Lost writes. The app is killed between receiving a rotated refresh token and saving it. At the next launch, the stored token was already consumed.
  • Suspended timers. A proactive refresh timer does not run while a mobile app is in the background; the app resumes with an expired token.
  • Accounts that bleed into each other. A 401 received after switching accounts is retried with the other account's token.

Authyra handles each of these, and its test suite reproduces each of them.

What it does

ResponsibilityHow
PersistenceSessions live in an AuthStorage: the platform keystore with SecureAuthStorage. They are restored at launch.
RefreshBefore expiry, on demand, and after a 401. One refresh at a time per session, always with the latest refresh token.
Failure handlingNetwork and server errors never end a session; they are retried with exponential backoff. A rejected refresh token does.
Multi-accountAny number of sessions on the device, one active. Switch, add or remove without signing the others out.
StateA sealed AuthState (AuthUnknown, AuthSignedIn, AuthSignedOut), a stream of it, and a stream of session events.
PolicyAn optional AuthPolicy can refuse a sign-in or a switch, for example to restrict an app to company accounts.

What it does not do

  • It has no server. Your backend issues and verifies tokens. Authyra never invents a token or a lifetime.
  • It is not an identity provider. If your app only talks to Firebase, Supabase or Auth0, their SDKs already manage the session; use them.
  • It does not refresh identity-provider tokens. A Google ID token or an Apple identity token proves an identity once. Your backend exchanges it for its own session, which Authyra then manages.

Packages

All packages share the same version and depend only on the core.

PackageUse it for
authyraThe core, pure Dart: sessions, refresh, state, credentials provider. Works in Dart CLIs and servers too.
authyra_flutterFlutter apps: keystore storage, widgets, OAuth 2.0 / OIDC with PKCE, OAuth through your backend. Re-exports the core.
authyra_dioAttaches tokens to Dio requests and recovers from 401 with a single shared refresh.
authyra_googleNative Google Sign-In.
authyra_appleNative Sign in with Apple.

Native sign-in lives in its own package so an app that does not use it never pulls the native SDK.

Next steps

Quick start

Sign in against your API and send authenticated requests in five minutes.

Session Lab

Break a fake backend in your browser and watch the session hold.
Copyright © 2026