OAuth 2.0 focuses on client developer simplicity while providing specific Grant Types which have associated OAuth 2.0 Protocol Flows.
OAuth 2.0 is a very flexible standard and can be adapted to work in many different scenarios. The core specification describes four Grant Types:[2]
The OAuth 2.0 specification details a fifth grant, the Refresh Token Grant, which can be used to "refresh" (i.e. get an "new" Access Token which has the same Authorization as the original.
There are other Grant Types that are NOT defined in The OAuth 2.0 Authorization Framework, that have gone through, or are currently in, the IETF ratification process:
The OpenID Connect spec provides a nice comparison of the three flows supported, reproduced here in a simplified form.
Flow property | Code | Implicit | Hybrid |
---|---|---|---|
All tokens returned from Authorization_endpoint | ✕ | ✔ | ✕ |
All tokens returned from Token_endpoint | ✔ | ✕ | ✕ |
Tokens NOT revealed to user-agent | ✔ | ✕ | ✕ |
Client can be authenticated | ✔ | ✕ | ✔ |
Refresh Token possible | ✔ | ✕ | ✔ |
Communication in one round trip | ✕ | ✔ | ✕ |
Most communication server-to-server | ✔ | ✕ | varies |
The flow used is determined by the response_type value contained in the Authorization Request. These response_type values select the following flows
response_type value | Flow |
---|---|
code | Authorization Code Flow |
id_token | Implicit Flow |
id_token token | {Implicit Flow} |
code id_token | Hybrid Flow |
code token | Hybrid Flow |
code id_token token | Hybrid Flow |
Application Type | OAuth Client | OAuth 2.0 | OpenID Connect |
---|---|---|---|
Web Application (with dedicated server-side component) | Confidential | Authorization Code Grant | Authorization Code Flow |
Desktop Native Application | Confidential | Authorization Code Grant | Authorization Code Flow |
Desktop Native Application | Public | Authorization Code Grant with PKCE | Authorization Code Flow with PKCE |
Native application | Public | Authorization Code Grant with PKCE | Authorization Code Flow with PKCE |
SPA App | Public | Authorization Code Grant | Authorization Code Flow See Notes OAuth Public Clients |
JavaScript application | either | Implicit Grant | Implicit Flow |
Previously, it was recommended that browser-based apps use the Implicit Grant, which returns an access token immediately and does not have a token exchange step. In the time since the spec was originally written, the industry Best Practice has changed to recommend that the authorization code flow be used without the client secret. This provides more opportunities to create a secure flow, such as using the state parameter.