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
Feature Authorization Code Client Credentials Implicit ROPC
User authentication Yes No Yes Yes
Refresh tokens Yes No No Yes (always offline type)
PKCE support Yes (recommended) N/A No N/A
Client secret required Optional (confidential clients) Yes No Optional (confidential clients)
Token endpoint used Yes Yes No Yes
Tokens in URL No (code only) N/A Yes No
2FA support Yes N/A Yes No
OAuth 2.1 compliant Yes Yes No (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