Providers

OAuth 2.0 and OpenID Connect

Authorization Code with PKCE against an authorization server whose tokens your API accepts.

OAuth2Provider (in authyra_flutter) signs users in with the Authorization Code flow and PKCE, in a secure browser session. Use it when your API accepts the tokens this server issues: Keycloak, Auth0, Zitadel, Okta, Amazon Cognito, Microsoft Entra ID, or your own OAuth server.

For a social login whose tokens your API cannot use (GitHub, Google), see OAuth through your backend or the native providers.

OAuth2Provider(
  id: 'sso',
  config: OAuth2Config(
    authorizationEndpoint: Uri.parse('https://sso.example.com/realms/app/protocol/openid-connect/auth'),
    tokenEndpoint: Uri.parse('https://sso.example.com/realms/app/protocol/openid-connect/token'),
    revocationEndpoint: Uri.parse('https://sso.example.com/realms/app/protocol/openid-connect/revoke'),
    clientId: 'mobile-app',
    redirectUri: Uri.parse('com.example.app:/oauth-callback'),
  ),
)
await authyra.signIn('sso');

Configuration

FieldDefaultNotes
authorizationEndpoint, tokenEndpointrequiredFrom the server's /.well-known/openid-configuration.
clientIdrequiredA public client: no secret. A mobile or web app cannot keep one; PKCE protects the exchange instead.
redirectUrirequiredA custom scheme, for example com.example.app:/oauth-callback. Register it on the server.
scopesopenid profile email offline_accessKeep offline_access to get a refresh token and openid to get an ID token.
userInfoEndpointnullWhen set, the user is read from it; otherwise from the ID token.
revocationEndpointnullRFC 7009 endpoint, called with the refresh token on sign-out.
authorizationParameters{}Extra parameters such as audience, prompt or login_hint. They cannot override the security parameters.
userFromClaimsuserFromOidcClaimsMaps claims to an AuthUser.

What it checks

  • A fresh state per sign-in, compared on return: a redirect crafted elsewhere cannot complete your sign-in.
  • PKCE with S256.
  • With openid, a nonce that must match the ID token, and an aud claim that must contain your client id.

The ID token signature is not verified on the device. Your API must verify the access tokens it receives, as it would for any client.

Refresh and sign-out

Refresh uses the refresh_token grant. invalid_grant or a 401 ends the session; any other error, including a 403, is treated as temporary. Sign-out revokes the refresh token when revocationEndpoint is set.

Platform setup

Redirects are captured by flutter_web_auth_2; see Installation.

Copyright © 2026