Providers

Credentials

Sign in against your own API with an identifier and a password.

CredentialsProvider is for the most common setup: your API has a login endpoint and a refresh endpoint. You write the two HTTP calls; Authyra does the rest.

CredentialsProvider(
  id: 'api',
  signIn: (credentials) async {
    // Call your login endpoint with credentials.identifier and
    // credentials.password. Return null when they are wrong.
  },
  refresh: (refreshToken) async {
    // Call your refresh endpoint. Throw RefreshRevokedException when the
    // server rejects the token.
  },
  signOut: (session) async {
    // Optional: revoke session.tokens?.refreshToken on the server.
  },
)

A complete version with Dio is in the quick start.

The three callbacks

CallbackReturnThrow
signIn(CredentialsSignInParams)An AuthSignInResult, or null for wrong credentials (Authyra then throws SignInFailedException).Anything else fails the sign-in, wrapped in SignInFailedException.
refresh(String refreshToken)New AuthTokens. Omit refreshToken in them if your backend does not rotate it.RefreshRevokedException when the token is rejected (401, invalid_grant). Anything else is treated as temporary.
signOut(AuthSession)Nothing.Errors are logged; the local sign-out happens anyway.

Without refresh, a session ends when its access token expires or when your API rejects it with a 401 seen by AuthyraInterceptor.

Signing in

await authyra.signIn(
  'api',
  params: CredentialsSignInParams(identifier: email, password: password),
);

identifier is whatever your backend accepts: an email, a username, a phone number. The password is never logged.

Two-step sign-in

If your login returns a challenge (a one-time code, a second factor), keep the first step out of Authyra and sign in once you have tokens. A custom provider with its own params class is the cleanest way:

await authyra.signIn('api-otp', params: OtpParams(challengeId: id, code: code));
Copyright © 2026