OAuth 2.0 and OpenID Connect
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
| Field | Default | Notes |
|---|---|---|
authorizationEndpoint, tokenEndpoint | required | From the server's /.well-known/openid-configuration. |
clientId | required | A public client: no secret. A mobile or web app cannot keep one; PKCE protects the exchange instead. |
redirectUri | required | A custom scheme, for example com.example.app:/oauth-callback. Register it on the server. |
scopes | openid profile email offline_access | Keep offline_access to get a refresh token and openid to get an ID token. |
userInfoEndpoint | null | When set, the user is read from it; otherwise from the ID token. |
revocationEndpoint | null | RFC 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. |
userFromClaims | userFromOidcClaims | Maps claims to an AuthUser. |
What it checks
- A fresh
stateper sign-in, compared on return: a redirect crafted elsewhere cannot complete your sign-in. - PKCE with S256.
- With
openid, anoncethat must match the ID token, and anaudclaim 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.