Skip to content

OAuth2 flows

OAuth2 defines several authorization flows (also called “grant types”) for different use cases. Each flow is optimized for a specific type of application and security requirement.

Application TypeRecommended FlowWhy
Web application (server-side)Authorization Code with PKCESecure token exchange, supports refresh tokens
Single-page application (SPA)Authorization Code with PKCEPKCE protects against code interception in public clients
Mobile / Native applicationAuthorization Code with PKCEPKCE is essential for apps that can’t securely store secrets
Backend service / APIClient CredentialsNo user involved, service authenticates with its own credentials
Legacy browser applicationImplicit FlowOnly for legacy apps that cannot be updated to use PKCE
Highly trusted first-party appResource Owner Password CredentialsLegacy flow for apps that need direct username/password authentication
FeatureAuthorization CodeClient CredentialsImplicitROPC
User authenticationYesNoYesYes
Refresh tokensYesNoNoYes (always offline type)
PKCE supportYes (recommended)N/ANoN/A
Client secret requiredOptional (confidential clients)YesNoOptional (confidential clients)
Token endpoint usedYesYesNoYes
Tokens in URLNo (code only)N/AYesNo
2FA supportYesN/AYesNo
OAuth 2.1 compliantYesYesNo (deprecated)No (deprecated)
  1. Always use PKCE with the authorization code flow, even for confidential clients
  2. Use short token lifetimes for implicit flow if you must use it
  3. Rotate client secrets regularly for confidential clients
  4. Validate all tokens on the receiving end (signature, issuer, audience, expiration)
  5. Use HTTPS for all OAuth2 communications