RFC 6749

The OAuth 2.0 Authorization Framework

๐Ÿ“… published October 2012, from ietf

The OAuth 2.0 Authorization Framework ๐ŸŽ€ (Part 1 of 14)

Internet Engineering Task Force (IETF) ๐ŸŒธ

  • Request for Comments: 6749
  • Author: D. Hardt, Ed. (Microsoft) ๐Ÿ’…
  • Obsoletes: 5849
  • Date: October 2012 ๐Ÿ“…
  • Category: Standards Track โญ
  • ISSN: 2070-1721

Abstract โœจ

okay so OAuth 2.0 is the authorization framework that lets a third-party app get limited access to an HTTP service ๐Ÿฆ‹ It can do this in two ways. Either it works on behalf of a resource owner by setting up an approval interaction between that owner and the HTTP service, or it lets the third-party app get access on its own behalf ๐Ÿซถ

This spec replaces and obsoletes the OAuth 1.0 protocol from RFC 5849. Bye bye, old version ๐Ÿ‘‹

Status of This Memo ๐Ÿ“‹

This is an Internet Standards Track document. ๐Ÿ‘‘

This doc is a product of the Internet Engineering Task Force (IETF). It represents the consensus of the IETF community, it got public review, and the Internet Engineering Steering Group (IESG) approved it for publication ๐Ÿ’– If you want more info on Internet Standards, check out Section 2 of RFC 5741.

Want the current status, any errata, or a way to send feedback? Head to http://www.rfc-editor.org/info/rfc6749 ๐Ÿงš

Copyright (c) 2012 IETF Trust and the persons identified as the document authors. All rights reserved. ๐ŸŽ€

This document is subject to BCP 78 and the IETF Trust's Legal Provisions Relating to IETF Documents (http://trustee.ietf.org/license-info) as they stand on the publication date. Please read these carefully, because they spell out your rights and restrictions for this document ๐Ÿ™ˆ Any Code Components pulled out of this doc must include Simplified BSD License text, as described in Section 4.e of the Trust Legal Provisions. They come without warranty, same as the Simplified BSD License says ๐Ÿ’…

Table of Contents ๐Ÿ—‚๏ธ

   1. Introduction ....................................................4
      1.1. Roles ......................................................6
      1.2. Protocol Flow ..............................................7
      1.3. Authorization Grant ........................................8
           1.3.1. Authorization Code ..................................8
           1.3.2. Implicit ............................................8
           1.3.3. Resource Owner Password Credentials .................9
           1.3.4. Client Credentials ..................................9
      1.4. Access Token ..............................................10
      1.5. Refresh Token .............................................10
      1.6. TLS Version ...............................................12
      1.7. HTTP Redirections .........................................12
      1.8. Interoperability ..........................................12
      1.9. Notational Conventions ....................................13
   2. Client Registration ............................................13
      2.1. Client Types ..............................................14
      2.2. Client Identifier .........................................15
      2.3. Client Authentication .....................................16
           2.3.1. Client Password ....................................16
           2.3.2. Other Authentication Methods .......................17
      2.4. Unregistered Clients ......................................17
   3. Protocol Endpoints .............................................18
      3.1. Authorization Endpoint ....................................18
           3.1.1. Response Type ......................................19
           3.1.2. Redirection Endpoint ...............................19
      3.2. Token Endpoint ............................................21
           3.2.1. Client Authentication ..............................22
      3.3. Access Token Scope ........................................23
   4. Obtaining Authorization ........................................23
      4.1. Authorization Code Grant ..................................24
           4.1.1. Authorization Request ..............................25
           4.1.2. Authorization Response .............................26
           4.1.3. Access Token Request ...............................29
           4.1.4. Access Token Response ..............................30
      4.2. Implicit Grant ............................................31
           4.2.1. Authorization Request ..............................33
           4.2.2. Access Token Response ..............................35
      4.3. Resource Owner Password Credentials Grant .................37
           4.3.1. Authorization Request and Response .................39
           4.3.2. Access Token Request ...............................39
           4.3.3. Access Token Response ..............................40
      4.4. Client Credentials Grant ..................................40
           4.4.1. Authorization Request and Response .................41
           4.4.2. Access Token Request ...............................41
           4.4.3. Access Token Response ..............................42
      4.5. Extension Grants ..........................................42

   5. Issuing an Access Token ........................................43
      5.1. Successful Response .......................................43
      5.2. Error Response ............................................45
   6. Refreshing an Access Token .....................................47
   7. Accessing Protected Resources ..................................48
      7.1. Access Token Types ........................................49
      7.2. Error Response ............................................49
   8. Extensibility ..................................................50
      8.1. Defining Access Token Types ...............................50
      8.2. Defining New Endpoint Parameters ..........................50
      8.3. Defining New Authorization Grant Types ....................51
      8.4. Defining New Authorization Endpoint Response Types ........51
      8.5. Defining Additional Error Codes ...........................51
   9. Native Applications ............................................52
   10. Security Considerations .......................................53
      10.1. Client Authentication ....................................53
      10.2. Client Impersonation .....................................54
      10.3. Access Tokens ............................................55
      10.4. Refresh Tokens ...........................................55
      10.5. Authorization Codes ......................................56
      10.6. Authorization Code Redirection URI Manipulation ..........56
      10.7. Resource Owner Password Credentials ......................57
      10.8. Request Confidentiality ..................................58
      10.9. Ensuring Endpoint Authenticity ...........................58
      10.10. Credentials-Guessing Attacks ............................58
      10.11. Phishing Attacks ........................................58
      10.12. Cross-Site Request Forgery ..............................59
      10.13. Clickjacking ............................................60
      10.14. Code Injection and Input Validation .....................60
      10.15. Open Redirectors ........................................60
      10.16. Misuse of Access Token to Impersonate Resource
             Owner in Implicit Flow ..................................61
   11. IANA Considerations ...........................................62
      11.1. OAuth Access Token Types Registry ........................62
           11.1.1. Registration Template .............................62
      11.2. OAuth Parameters Registry ................................63
           11.2.1. Registration Template .............................63
           11.2.2. Initial Registry Contents .........................64
      11.3. OAuth Authorization Endpoint Response Types Registry .....66
           11.3.1. Registration Template .............................66
           11.3.2. Initial Registry Contents .........................67
      11.4. OAuth Extensions Error Registry ..........................67
           11.4.1. Registration Template .............................68
   12. References ....................................................68
      12.1. Normative References .....................................68
      12.2. Informative References ...................................70

   Appendix A. Augmented Backus-Naur Form (ABNF) Syntax ..............71
     A.1.  "client_id" Syntax ........................................71
     A.2.  "client_secret" Syntax ....................................71
     A.3.  "response_type" Syntax ....................................71
     A.4.  "scope" Syntax ............................................72
     A.5.  "state" Syntax ............................................72
     A.6.  "redirect_uri" Syntax .....................................72
     A.7.  "error" Syntax ............................................72
     A.8.  "error_description" Syntax ................................72
     A.9.  "error_uri" Syntax ........................................72
     A.10. "grant_type" Syntax .......................................73
     A.11. "code" Syntax .............................................73
     A.12. "access_token" Syntax .....................................73
     A.13. "token_type" Syntax .......................................73
     A.14. "expires_in" Syntax .......................................73
     A.15. "username" Syntax .........................................73
     A.16. "password" Syntax .........................................73
     A.17. "refresh_token" Syntax ....................................74
     A.18. Endpoint Parameter Syntax .................................74
   Appendix B. Use of application/x-www-form-urlencoded Media Type ...74
   Appendix C. Acknowledgements ......................................75

Part 1 is a wrap ๐Ÿซถ Part 2 is coming up next with the Introduction and all the roles and flows, so stay tuned ๐Ÿ’œ๐Ÿฆ‹

1. Introduction โœจ

okay so picture this, bestie ๐ŸŽ€ the old-school client-server login model goes like this: the client wants into a locked-down resource (aka the protected resource) on the server, so it logs in with the resource owner's own credentials. and if a third-party app wants access, the owner just hands over their login to that app ๐Ÿ˜ญ which causes SO many problems:

  • Third-party apps have to store the resource owner's credentials for later, usually a password just sitting there in clear-text ๐Ÿ’€
  • Servers have to support password auth, even though passwords are super weak ๐Ÿ™ˆ
  • Third-party apps get way too much access to the owner's protected stuff, and the owner can't limit how long it lasts or which subset of resources it can touch ๐Ÿ˜ค
  • Owners can't revoke access for just ONE third party. they'd have to revoke everybody by changing the third party's password ๐Ÿซ 
  • If any third-party app gets hacked, the end-user's password AND all the data behind it are gone ๐Ÿ’”

OAuth fixes all of this by adding an authorization layer and splitting the client's role apart from the resource owner's. in OAuth, the client asks for access to resources that the resource owner controls and the resource server hosts, and it gets its own set of credentials, totally separate from the owner's ๐Ÿฆ‹

so instead of using the owner's credentials, the client gets an access token -- a string that stands for a specific scope, lifetime, and other access attributes โœจ access tokens are handed out to third-party clients by an authorization server, but only with the resource owner's approval. then the client uses that token to reach the protected resources on the resource server ๐Ÿ’…

for example ๐ŸŒธ an end-user (resource owner) wants a printing service (client) to print her protected photos sitting on a photo-sharing service (resource server). she doesn't have to share her username and password with the printing service at all! she logs in directly with a server that the photo-sharing service trusts (the authorization server), and that server gives the printing service its own delegation-specific credentials (an access token) ๐Ÿ–จ๏ธ๐Ÿ’–

this spec is built for use with HTTP ([RFC2616]). using OAuth over any protocol that isn't HTTP is out of scope, so don't go there ๐Ÿ™…โ€โ™€๏ธ

now, OAuth 1.0 ([RFC5849]) is a thing too! it was published as an informational document and came out of a small, ad hoc community effort ๐Ÿงš this Standards Track spec builds on what people learned from deploying OAuth 1.0, plus extra use cases and extensibility needs gathered from the wider IETF community ๐ŸŒˆ but the big tea is that OAuth 2.0 is NOT backward compatible with OAuth 1.0 โ˜• the two versions can co-exist on the network, and implementations get to choose whether they support both. still, the intention of this spec is that new implementations support OAuth 2.0 as written here, and that OAuth 1.0 only sticks around to support existing deployments ๐Ÿซถ OAuth 2.0 also shares very few implementation details with OAuth 1.0. so if you already know OAuth 1.0, come into this doc with zero assumptions about its structure or details, bestie ๐Ÿง โœจ

1.1. Roles

okay, OAuth has four roles ๐Ÿ‘‘

  • resource owner An entity that can grant access to a protected resource. when the resource owner is a person, they're called an end-user ๐Ÿงโ€โ™€๏ธ
  • resource server The server hosting the protected resources. it can accept and respond to protected resource requests that use access tokens ๐Ÿ 
  • client An application that makes protected resource requests on behalf of the resource owner and with its authorization ๐Ÿ’… the word "client" doesn't imply any particular implementation characteristics (for example, it doesn't matter whether the app runs on a server, a desktop, or other devices). it's whatever app is asking, periodt ๐ŸŽ€
  • authorization server The server that issues access tokens to the client after it successfully authenticates the resource owner and gets authorization ๐Ÿ”

the interaction between the authorization server and the resource server is beyond the scope of this spec ๐Ÿ™ˆ the authorization server can be the same server as the resource server, or it can be a separate entity. and one authorization server can issue access tokens that multiple resource servers accept ๐Ÿค

1.2. Protocol Flow

okay, here's the vibe check on the big picture ๐Ÿฆ‹ Figure 1 shows the four roles talking to each other:

     +--------+                               +---------------+
     |        |--(A)- Authorization Request ->|   Resource    |
     |        |                               |     Owner     |
     |        |<-(B)-- Authorization Grant ---|               |
     |        |                               +---------------+
     |        |
     |        |                               +---------------+
     |        |--(C)-- Authorization Grant -->| Authorization |
     | Client |                               |     Server    |
     |        |<-(D)----- Access Token -------|               |
     |        |                               +---------------+
     |        |
     |        |                               +---------------+
     |        |--(E)----- Access Token ------>|    Resource   |
     |        |                               |     Server    |
     |        |<-(F)--- Protected Resource ---|               |
     +--------+                               +---------------+

                     Figure 1: Abstract Protocol Flow

so the abstract OAuth 2.0 flow in Figure 1 is the interaction between those four roles, and it goes like this ๐Ÿ’–

  • (A) The client asks the resource owner for authorization. this request can go straight to the resource owner (like the diagram shows), or, preferably, indirectly through the authorization server as a middleman โœจ
  • (B) The client gets an authorization grant. that's a credential that represents the resource owner's authorization, and it comes in one of four grant types defined in this spec, or in an extension grant type ๐ŸŽ which grant type it is depends on how the client asked for authorization and which types the authorization server supports ๐Ÿงฉ
  • (C) The client asks for an access token by authenticating with the authorization server and presenting the authorization grant ๐Ÿ”‘
  • (D) The authorization server authenticates the client and validates the authorization grant. if it's valid, it issues an access token ๐Ÿชช
  • (E) The client asks the resource server for the protected resource and authenticates by presenting the access token ๐Ÿš€
  • (F) The resource server validates the access token. if it's valid, it serves the request ๐Ÿฅณ

the preferred way for the client to get an authorization grant from the resource owner (steps (A) and (B)) is to use the authorization server as an intermediary. that's shown in Figure 3 in Section 4.1, so go peek at that when you get the chance ๐Ÿ‘€

1.3. Authorization Grant

okay, an authorization grant is a credential that represents the resource owner's authorization to access their protected resources. the client uses it to get an access token ๐ŸŽŸ๏ธ this spec defines four grant types -- authorization code, implicit, resource owner password credentials, and client credentials -- plus an extensibility mechanism so you can define more types later ๐ŸŒŸ

1.3.1. Authorization Code

the authorization code is obtained by using an authorization server as a middleman between the client and the resource owner ๐Ÿง‘โ€๐Ÿคโ€๐Ÿง‘ instead of asking the resource owner for authorization directly, the client sends the resource owner over to an authorization server (through their user-agent, as defined in [RFC2616]). then that authorization server sends the resource owner back to the client with the authorization code ๐Ÿ”

before it sends the resource owner back to the client with the authorization code, the authorization server authenticates the resource owner and gets authorization ๐Ÿ” and this is the best part: since the resource owner only ever logs in with the authorization server, their credentials are never shared with the client ๐Ÿ™Œ

the authorization code gives a few important security perks ๐Ÿ’ช like the ability to authenticate the client, and the access token gets sent directly to the client without passing through the resource owner's user-agent. that matters because it avoids exposing the token to others, including the resource owner themselves ๐Ÿ›ก๏ธ

1.3.2. Implicit

the implicit grant is a simplified authorization code flow, optimized for clients that run in a browser using a scripting language like JavaScript ๐ŸŒ in the implicit flow, the client doesn't get an authorization code. instead, it gets an access token directly, as the result of the resource owner's authorization โšก it's called "implicit" because no intermediate credentials (like an authorization code) get issued and used later to grab an access token ๐Ÿงฉ

when the authorization server issues an access token during the implicit grant flow, it does NOT authenticate the client ๐Ÿ˜ฌ okay wait, careful, I'm not capitalizing anything here, the original just says it doesn't authenticate the client. in some cases, the client's identity can be verified through the redirection URI used to deliver the access token. but the access token may be exposed to the resource owner or to other applications that can reach the resource owner's user-agent ๐Ÿ‘€

implicit grants make some clients (like in-browser apps) more responsive and efficient, because they cut down the number of round trips needed to get an access token ๐ŸŽ๏ธ๐Ÿ’จ but you should weigh that convenience against the security implications of implicit grants, such as the ones described in Sections 10.3 and 10.16 ๐Ÿšจ especially when the authorization code grant type is available!! ๐Ÿ™…โ€โ™€๏ธ

1.3.3. Resource Owner Password Credentials

the resource owner password credentials (that's the username and password) can be used directly as an authorization grant to get an access token ๐Ÿ”‘ but they should only be used when there's a high degree of trust between the resource owner and the client (for example, the client is part of the device's operating system, or it's a highly privileged app) AND when other grant types, like an authorization code, aren't available ๐Ÿซฃ

even though this grant type means the client directly accesses the resource owner's credentials, those credentials are used for a single request and then exchanged for an access token ๐ŸŽ€ this grant type can also get rid of the need for the client to store the resource owner's credentials for later, because the credentials get swapped for a long-lived access token or a refresh token ๐Ÿ”„

1.3.4. Client Credentials

the client credentials (or other forms of client authentication) can be used as an authorization grant when the authorization scope is limited to the protected resources under the control of the client, or to protected resources that were previously arranged with the authorization server ๐Ÿงธ client credentials are typically used as an authorization grant when the client is acting on its own behalf (the client is also the resource owner), or when it's requesting access to protected resources based on an authorization that was previously arranged with the authorization server ๐Ÿ’œ

1.4. Access Token ๐Ÿ”‘

okay so access tokens are the credentials that unlock protected resources ๐Ÿ”“ An access token is a string that represents an authorization given to the client. It's usually opaque to the client, so the client isn't meant to read what's inside ๐Ÿ™ˆ Tokens represent specific scopes and durations of access, granted by the resource owner and enforced by the resource server and the authorization server ๐Ÿ‘‘

The token might be an identifier that's used to look up the authorization information. Or it might carry the authorization information inside itself in a way that can be verified, like a string with some data plus a signature ๐Ÿงš Additional authentication credentials, which are beyond the scope of this specification, may be required before the client can use a token.

The access token is an abstraction layer, and it's honestly so iconic ๐Ÿ’… It swaps out different authorization constructs (like a username and password) for one single token that the resource server understands. This means you can issue access tokens that are more restrictive than the authorization grant used to get them, and the resource server doesn't need to understand a bunch of different authentication methods ๐ŸŽ€

Access tokens can have different formats, structures, and methods of use (for example, cryptographic properties) depending on the security requirements of the resource server โœจ The attributes of access tokens and the methods used to access protected resources are beyond the scope of this specification. They're defined by companion specifications such as [RFC6750] ๐Ÿ“š

1.5. Refresh Token ๐Ÿ”„

Refresh tokens are the credentials used to get access tokens ๐Ÿ’– The authorization server issues them to the client, and the client uses them to get a new access token when the current one becomes invalid or expires. They can also be used to get additional access tokens with the same or narrower scope, since access tokens may have a shorter lifetime and fewer permissions than the resource owner authorized ๐ŸŒธ Issuing a refresh token is optional and up to the authorization server. If the authorization server does issue one, it's included when the access token is issued (that's step (D) in Figure 1) ๐Ÿซถ

A refresh token is a string that represents the authorization the resource owner granted to the client. It's usually opaque to the client, and it denotes an identifier that's used to retrieve the authorization information. Unlike access tokens, refresh tokens are meant only for authorization servers. They are never sent to resource servers ๐Ÿšซ

  +--------+                                           +---------------+
  |        |--(A)------- Authorization Grant --------->|               |
  |        |                                           |               |
  |        |<-(B)----------- Access Token -------------|               |
  |        |               & Refresh Token             |               |
  |        |                                           |               |
  |        |                            +----------+   |               |
  |        |--(C)---- Access Token ---->|          |   |               |
  |        |                            |          |   |               |
  |        |<-(D)- Protected Resource --| Resource |   | Authorization |
  | Client |                            |  Server  |   |     Server    |
  |        |--(E)---- Access Token ---->|          |   |               |
  |        |                            |          |   |               |
  |        |<-(F)- Invalid Token Error -|          |   |               |
  |        |                            +----------+   |               |
  |        |                                           |               |
  |        |--(G)----------- Refresh Token ----------->|               |
  |        |                                           |               |
  |        |<-(H)----------- Access Token -------------|               |
  +--------+           & Optional Refresh Token        +---------------+

               Figure 2: Refreshing an Expired Access Token

Here's how the flow in Figure 2 goes, step by step ๐Ÿ‘€

  • (A) The client asks for an access token by authenticating with the authorization server and presenting an authorization grant.
  • (B) The authorization server authenticates the client and validates the authorization grant. If it's valid, the server issues an access token and a refresh token.
  • (C) The client makes a protected resource request to the resource server by presenting the access token.
  • (D) The resource server validates the access token. If it's valid, the server serves the request.
  • (E) Steps (C) and (D) repeat until the access token expires. If the client knows the access token has expired, it skips to step (G). Otherwise, it makes another protected resource request.
  • (F) Since the access token is invalid, the resource server returns an invalid token error.
  • (G) The client asks for a new access token by authenticating with the authorization server and presenting the refresh token. The client authentication requirements depend on the client type and on the authorization server's policies.
  • (H) The authorization server authenticates the client and validates the refresh token. If it's valid, the server issues a new access token and, optionally, a new refresh token.

Steps (C), (D), (E), and (F) are outside the scope of this specification, as described in Section 7 ๐ŸŽ€

1.6. TLS Version ๐Ÿ”

Whenever Transport Layer Security (TLS) is used by this specification, the right version (or versions) of TLS will change over time. That depends on how widely it's deployed and on known security vulnerabilities ๐Ÿ˜ฌ At the time of writing, TLS version 1.2 [RFC5246] is the most recent version, but it has a very limited deployment base and might not be easy to get for implementation. TLS version 1.0 [RFC2246] is the most widely deployed version and gives the broadest interoperability ๐ŸŒˆ

Implementations MAY also support additional transport-layer security mechanisms that meet their security requirements ๐Ÿ’œ

1.7. HTTP Redirections โ†ช๏ธ

This specification makes heavy use of HTTP redirections, where the client or the authorization server sends the resource owner's user-agent to another destination ๐Ÿฆ‹ The examples in this specification show the HTTP 302 status code, but any other method the user-agent has available to do the redirect is allowed too. It's considered an implementation detail ๐Ÿ“

1.8. Interoperability ๐Ÿค

OAuth 2.0 gives you a rich authorization framework with well-defined security properties ๐Ÿ”ฅ But it's a rich and highly extensible framework with lots of optional components. On its own, this specification is likely to produce a wide range of implementations that don't interoperate ๐Ÿ˜ญ

Also, this specification leaves a few required components partly or fully undefined (like client registration, authorization server capabilities, and endpoint discovery). Without those components, clients have to be manually and specifically configured against a particular authorization server and resource server in order to interoperate ๐Ÿ™ƒ

This framework was designed with the clear expectation that future work will define prescriptive profiles and extensions needed to reach full web-scale interoperability โœจ

1.9. Notational Conventions ๐Ÿ“

The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this specification are to be interpreted as described in [RFC2119] ๐Ÿซถ

This specification uses the Augmented Backus-Naur Form (ABNF) notation of [RFC5234]. On top of that, the rule URI-reference is included from "Uniform Resource Identifier (URI): Generic Syntax" [RFC3986] ๐Ÿง 

Certain security-related terms are to be understood in the sense defined in [RFC4949]. These terms include, but aren't limited to, "attack", "authentication", "authorization", "certificate", "confidentiality", "credential", "encryption", "identity", "sign", "signature", "trust", "validate", and "verify" ๐Ÿ›ก๏ธ

Unless otherwise noted, all the protocol parameter names and values are case sensitive ๐Ÿ” 

2. Client Registration ๐ŸŽ€

Before starting the protocol, the client registers with the authorization server ๐Ÿ“‹ The means through which the client registers are beyond the scope of this specification, but they typically involve end-user interaction with an HTML registration form ๐Ÿ’ป

Client registration doesn't require direct interaction between the client and the authorization server. When the authorization server supports it, registration can rely on other ways of establishing trust and getting the required client properties (like the redirection URI and client type). For example, registration can be done with a self-issued or third-party-issued assertion, or by the authorization server doing client discovery over a trusted channel ๐Ÿ•ต๏ธโ€โ™€๏ธ

When registering a client, the client developer SHALL:

  • specify the client type as described in Section 2.1,
  • provide its client redirection URIs as described in Section 3.1.2, and
  • include any other information required by the authorization server (for example, application name, website, description, logo image, and the acceptance of legal terms) ๐Ÿ’…

2.1. Client Types โœจ

okay so OAuth has two client types ๐Ÿซถ, and the difference is all about whether the client can keep its credentials secret from the wider world. bestie this is the main character decision of the whole spec ๐Ÿ’…

  • confidential: clients that can keep their credentials confidential (like a client running on a secure server where nobody can poke around in the client credentials ๐Ÿ”), or that can do secure client authentication some other way โœจ
  • public: clients that can't keep their credentials confidential (like code running on the resource owner's own device, such as an installed native app or a browser-based app ๐Ÿ“ฑ), and can't do secure client authentication any other way ๐Ÿ˜ญ

The client type is decided by the authorization server's own idea of what counts as secure authentication, and how much exposure of client credentials it's okay with ๐ŸŽ€. The authorization server SHOULD NOT make assumptions about the client type ๐Ÿ™ˆ

A client can also be a distributed set of components, each with its own client type and security context ๐Ÿงฉ (think a client with a confidential server-side part AND a public browser-based part). If the authorization server doesn't support clients like that, or doesn't give any guidance on registering them, the client SHOULD register each component as a separate client ๐ŸŒธ

This spec was designed around these client profiles ๐Ÿ‘‘:

  • web application: a confidential client running on a web server ๐Ÿ–ฅ๏ธ. Resource owners reach the client through an HTML user interface rendered in a user-agent on their device. The client credentials and any access token issued to the client are stored on the web server, and they're NOT exposed to or accessible by the resource owner ๐Ÿ”’
  • user-agent-based application: a public client where the client code is downloaded from a web server and runs inside a user-agent (like a web browser) on the resource owner's device ๐ŸŒ. Protocol data and credentials are easily accessible, and often visible, to the resource owner ๐Ÿ‘€. Since these apps live inside the user-agent, they can make seamless use of the user-agent's capabilities when requesting authorization โœจ
  • native application: a public client installed and run on the resource owner's device ๐Ÿ“ฒ. Protocol data and credentials are accessible to the resource owner. It's assumed that any client authentication credentials baked into the app can be extracted ๐Ÿ˜ฌ. On the other hand, dynamically issued credentials like access tokens or refresh tokens can get an acceptable level of protection ๐Ÿ›ก๏ธ. At a minimum, these credentials are protected from hostile servers the app may interact with. On some platforms, they might also be protected from other apps on the same device ๐Ÿ’œ

2.2. Client Identifier โœจ

the authorization server gives the registered client a client identifier, which is a unique string representing the registration info the client provided ๐Ÿชช. The client identifier is NOT a secret, since it's exposed to the resource owner, and it MUST NOT be used alone for client authentication ๐Ÿšซ. It's unique to the authorization server ๐Ÿ’–

The size of the client identifier string is left undefined by this spec, so the client should avoid making assumptions about how big it is ๐Ÿ“. The authorization server SHOULD document the size of any identifier it issues ๐Ÿ“

2.3. Client Authentication โœจ

if the client is confidential, the client and the authorization server set up a client authentication method that fits the authorization server's security requirements ๐Ÿ”. The authorization server MAY accept any form of client authentication that meets its security requirements ๐ŸŽ€

Confidential clients usually get issued (or set up) a set of client credentials for authenticating with the authorization server, like a password or a public/private key pair ๐Ÿ—๏ธ

The authorization server MAY set up a client authentication method with public clients too. But the authorization server MUST NOT rely on public client authentication for identifying the client ๐Ÿ™…โ€โ™€๏ธ

The client MUST NOT use more than one authentication method in each request โ˜๏ธ

2.3.1. Client Password ๐Ÿ”‘

clients holding a client password MAY use the HTTP Basic authentication scheme defined in [RFC2617] to authenticate with the authorization server ๐Ÿฆ‹. The client identifier gets encoded using the "application/x-www-form-urlencoded" encoding algorithm from Appendix B, and the encoded value is used as the username. The client password gets encoded with that same algorithm and used as the password ๐Ÿง. The authorization server MUST support the HTTP Basic authentication scheme for authenticating clients that were issued a client password ๐Ÿ’…

for example (with extra line breaks just for display):

Authorization: Basic czZCaGRSa3F0Mzo3RmpmcDBaQnIxS3REUmJuZlZkbUl3

alternatively, the authorization server MAY support including the client credentials in the request body using these parameters ๐Ÿ“:

  • client_id: REQUIRED. The client identifier issued to the client during the registration process described by Section 2.2 ๐Ÿชช
  • client_secret: REQUIRED. The client secret. The client MAY omit the parameter if the client secret is an empty string ๐Ÿคซ

including the client credentials in the request body using those two parameters is NOT RECOMMENDED ๐Ÿ˜ญ, and it SHOULD be limited to clients that can't directly use the HTTP Basic authentication scheme (or other password-based HTTP authentication schemes) ๐Ÿ™ˆ. The parameters can ONLY be sent in the request body, and they MUST NOT be included in the request URI ๐Ÿšซ๐Ÿ”—

for example, here's a request to refresh an access token (Section 6) using the body parameters (with extra line breaks just for display) ๐Ÿ”„:

POST /token HTTP/1.1
Host: server.example.com
Content-Type: application/x-www-form-urlencoded

grant_type=refresh_token&refresh_token=tGzv3JOkF0XG5Qx2TlKWIA
&client_id=s6BhdRkqt3&client_secret=7Fjfp0ZBr1KtDRbnfVdmIw

the authorization server MUST require the use of TLS as described in Section 1.6 when sending requests using password authentication ๐Ÿ”’. And since this client authentication method involves a password, the authorization server MUST protect any endpoint using it against brute force attacks ๐Ÿ›ก๏ธ๐Ÿ’€

2.3.2. Other Authentication Methods โœจ

the authorization server MAY support any suitable HTTP authentication scheme that matches its security requirements ๐ŸŒˆ. When using other authentication methods, the authorization server MUST define a mapping between the client identifier (registration record) and the authentication scheme ๐Ÿ—บ๏ธ

2.4. Unregistered Clients โœจ

this spec doesn't rule out unregistered clients ๐Ÿคทโ€โ™€๏ธ. BUT using them is beyond the scope of this spec, and it requires extra security analysis and a review of its interoperability impact ๐Ÿง


3. Protocol Endpoints โœจ

the authorization process uses two authorization server endpoints (HTTP resources) ๐Ÿฐ:

  • Authorization endpoint: used by the client to get authorization from the resource owner via user-agent redirection ๐Ÿฆ‹
  • Token endpoint: used by the client to swap an authorization grant for an access token, typically with client authentication ๐ŸŽŸ๏ธ

plus one client endpoint ๐Ÿ’Œ:

  • Redirection endpoint: used by the authorization server to send responses containing authorization credentials back to the client via the resource owner's user-agent ๐Ÿ’–

not every authorization grant type uses both endpoints ๐Ÿ™ƒ. Extension grant types MAY define additional endpoints as needed ๐Ÿงš

3.1. Authorization Endpoint โœจ

the authorization endpoint is how the client talks to the resource owner and gets an authorization grant ๐Ÿ’ฌ. The authorization server MUST first verify the identity of the resource owner ๐Ÿชช. How the authorization server authenticates the resource owner (like a username and password login, or session cookies) is beyond the scope of this spec ๐Ÿช

how the client finds the location of the authorization endpoint is also beyond the scope of this spec, but the location is usually given in the service documentation ๐Ÿ“š

The endpoint URI MAY include an "application/x-www-form-urlencoded" formatted query component (per Appendix B) ([RFC3986] Section 3.4), and that component MUST be retained when adding additional query parameters ๐Ÿงฉ. The endpoint URI MUST NOT include a fragment component ๐Ÿšซ

since requests to the authorization endpoint result in user authentication and the transmission of clear-text credentials (in the HTTP response) ๐Ÿ˜ฑ, the authorization server MUST require the use of TLS as described in Section 1.6 when sending requests to the authorization endpoint ๐Ÿ”

The authorization server MUST support the use of the HTTP "GET" method [RFC2616] for the authorization endpoint, and it MAY support the "POST" method as well ๐Ÿ“ฎ

parameters sent without a value MUST be treated as if they were omitted from the request ๐Ÿซฅ. The authorization server MUST ignore unrecognized request parameters ๐Ÿ™ˆ. Request and response parameters MUST NOT be included more than once ๐ŸšซโœŒ๏ธ

3.1.1. Response Type โœจ

the authorization endpoint is used by the authorization code grant type and implicit grant type flows ๐ŸŒธ. The client tells the authorization server which grant type it wants using this parameter:

  • response_type: REQUIRED. The value MUST be one of "code" for requesting an authorization code as described by Section 4.1.1, "token" for requesting an access token (implicit grant) as described by Section 4.2.1, or a registered extension value as described by Section 8.4 ๐Ÿ‘‘

extension response types MAY contain a space-delimited (%x20) list of values, where the order of values does not matter (e.g., response type "a b" is the same as "b a") ๐Ÿงƒ. The meaning of such composite response types is defined by their respective specifications ๐Ÿ“œ

if an authorization request is missing the "response_type" parameter, or if the response type isn't understood, the authorization server MUST return an error response as described in Section 4.1.2.1 ๐Ÿšจ

3.1.2. Redirection Endpoint โœจ

after finishing its interaction with the resource owner, the authorization server sends the resource owner's user-agent back to the client ๐Ÿ”™โœจ. It redirects the user-agent to the client's redirection endpoint, which was set up with the authorization server during client registration or when making the authorization request ๐ŸŽฏ

The redirection endpoint URI MUST be an absolute URI as defined by [RFC3986] Section 4.3 ๐ŸŒ. The endpoint URI MAY include an "application/x-www-form-urlencoded" formatted query component (per Appendix B) ([RFC3986] Section 3.4), and that component MUST be retained when adding additional query parameters ๐ŸŽ€. The endpoint URI MUST NOT include a fragment component ๐Ÿ™…โ€โ™€๏ธ

3.1.2.1. Endpoint Request Confidentiality ๐Ÿ”

okay bestie, the redirection endpoint SHOULD require TLS (see Section 1.6) when the requested response type is "code" or "token", or when the redirection request is gonna send sensitive credentials over an open network ๐Ÿ’…. This spec doesn't make TLS mandatory, bc at the time of writing, making clients deploy TLS is a seriously big hurdle for a lot of client devs ๐Ÿฅบ. If TLS isn't available, the authorization server SHOULD warn the resource owner about the insecure endpoint before redirecting (e.g., show a message during the authorization request) โš ๏ธ.

๐Ÿšจ Lack of transport-layer security can have a severe impact on the security of the client and the protected resources it is authorized to access. It's especially critical when the authorization process is used as a form of delegated end-user authentication by the client (e.g., third-party sign-in service). Not playing with this one, fr fr ๐Ÿ’€

3.1.2.2. Registration Requirements ๐Ÿ“

the authorization server MUST require these clients to register their redirection endpoint:

  • Public clients. ๐ŸŒธ
  • Confidential clients utilizing the implicit grant type. ๐Ÿ”ฎ

the authorization server SHOULD require all clients to register their redirection endpoint before they touch the authorization endpoint ๐Ÿ™ˆ.

the authorization server SHOULD require the client to give the complete redirection URI (the client MAY use the "state" request parameter to do per-request customization โœจ). If requiring the complete URI isn't possible, the authorization server SHOULD require the registration of the URI scheme, authority, and path, which lets the client dynamically change only the query component of the redirection URI when it asks for authorization ๐Ÿงš.

the authorization server MAY let the client register multiple redirection endpoints ๐ŸŒˆ.

ngl, if there's no redirection URI registration requirement, an attacker can use the authorization endpoint as an open redirector, as described in Section 10.15. Big red flag ๐Ÿšฉ.

3.1.2.3. Dynamic Configuration ๐ŸŽ€

if multiple redirection URIs have been registered, if only part of the redirection URI has been registered, or if no redirection URI has been registered, the client MUST include a redirection URI with the authorization request using the "redirect_uri" request parameter ๐Ÿซถ.

when a redirection URI is included in an authorization request, the authorization server MUST compare and match the value received against at least one of the registered redirection URIs (or URI components) as defined in [RFC3986] Section 6, if any redirection URIs were registered. If the client registration included the full redirection URI, the authorization server MUST compare the two URIs using simple string comparison as defined in [RFC3986] Section 6.2.1 ๐Ÿ”.

3.1.2.4. Invalid Endpoint ๐Ÿ™…โ€โ™€๏ธ

if an authorization request fails validation because of a missing, invalid, or mismatching redirection URI, the authorization server SHOULD tell the resource owner about the error, and it MUST NOT automatically redirect the user-agent to the invalid redirection URI. no auto-redirecting to sketchy places, periodt ๐Ÿ’…โœจ.

3.1.2.5. Endpoint Content ๐Ÿง

the redirection request to the client's endpoint usually results in an HTML document response, which the user-agent processes ๐ŸŒ. If that HTML response is served directly as the result of the redirection request, any script in the HTML document runs with full access to the redirection URI and the credentials it contains ๐Ÿ˜ญ.

so the client SHOULD NOT include any third-party scripts (e.g., third-party analytics, social plug-ins, ad networks) in the redirection endpoint response ๐Ÿšซ. Instead, it SHOULD pull the credentials out of the URI and redirect the user-agent again to another endpoint without exposing the credentials (in the URI or anywhere else) ๐Ÿฆ‹. If third-party scripts are included, the client MUST make sure its own scripts (the ones that extract and remove the credentials from the URI) run first. Main character energy is making your code go first ๐Ÿ‘‘.

3.2. Token Endpoint ๐ŸŽŸ๏ธ

the token endpoint is how the client gets an access token by presenting its authorization grant or refresh token ๐Ÿ’–. It's used with every authorization grant except the implicit grant type, since an access token is issued directly in that case ๐Ÿ™ƒ.

how the client finds out where the token endpoint lives is out of scope for this spec, but it's usually listed in the service documentation ๐Ÿ“š.

the endpoint URI MAY include an "application/x-www-form-urlencoded" formatted (per Appendix B) query component ([RFC3986] Section 3.4), and that query component MUST be kept when you add more query parameters ๐Ÿ“. The endpoint URI MUST NOT include a fragment component. no fragments here, bestie ๐Ÿ™…โ€โ™€๏ธ.

requests to the token endpoint send clear-text credentials (in the HTTP request and response), so the authorization server MUST require TLS as described in Section 1.6 when it's sending requests to the token endpoint ๐Ÿ”’๐Ÿ”ฅ.

the client MUST use the HTTP "POST" method when making access token requests ๐Ÿ“ฎ.

parameters sent without a value MUST be treated as if they were omitted from the request. The authorization server MUST ignore unrecognized request parameters. Request and response parameters MUST NOT be included more than once. no duplicates, no drama ๐Ÿ’….

3.2.1. Client Authentication ๐Ÿชช

confidential clients (or other clients that were issued client credentials) MUST authenticate with the authorization server as described in Section 2.3 when they make requests to the token endpoint ๐Ÿ›ก๏ธ. Client authentication is used for:

  • Enforcing the binding of refresh tokens and authorization codes to the client they were issued to. Client authentication is critical when an authorization code is sent to the redirection endpoint over an insecure channel, or when the redirection URI hasn't been registered in full ๐Ÿงท.
  • Recovering from a compromised client by disabling the client or changing its credentials, which stops an attacker from abusing stolen refresh tokens. Changing one set of client credentials is way faster than revoking a whole set of refresh tokens โšก.
  • Implementing authentication management best practices, which require periodic credential rotation. Rotating a whole set of refresh tokens can be a lot, but rotating a single set of client credentials is significantly easier ๐Ÿ”„.

a client MAY use the "client_id" request parameter to identify itself when it sends requests to the token endpoint ๐Ÿช„. In the "authorization_code" "grant_type" request to the token endpoint, an unauthenticated client MUST send its "client_id", so it doesn't accidentally accept a code meant for a client with a different "client_id" ๐Ÿ‘€. This protects the client from substitution of the authentication code. (It gives the protected resource no extra security, though ๐Ÿคทโ€โ™€๏ธ.)

3.3. Access Token Scope ๐Ÿ—๏ธ

the authorization and token endpoints let the client say what scope it wants for the access request, using the "scope" request parameter โœจ. Then the authorization server uses the "scope" response parameter to tell the client what scope the issued access token actually has ๐Ÿ’Œ.

the value of the scope parameter is a list of space-delimited, case-sensitive strings. The authorization server defines those strings ๐Ÿง . If there are multiple space-delimited strings, their order doesn't matter, and each string adds another access range to the requested scope ๐ŸŒˆ.

     scope       = scope-token *( SP scope-token )
     scope-token = 1*( %x21 / %x23-5B / %x5D-7E )

the authorization server MAY fully or partially ignore the scope the client asked for, based on its policy or the resource owner's instructions ๐Ÿ™ƒ. If the issued access token scope is different from what the client requested, the authorization server MUST include the "scope" response parameter so the client knows the actual scope granted ๐Ÿ“ฃ.

if the client leaves out the scope parameter when it requests authorization, the authorization server MUST either process the request with a pre-defined default value, or fail the request and say the scope is invalid ๐Ÿšฆ. The authorization server SHOULD document its scope requirements and default value (if one is defined) ๐Ÿ“–๐Ÿ’•.


4. Obtaining Authorization ๐ŸŒท

to request an access token, the client first has to get authorization from the resource owner ๐Ÿฅฐ. That authorization comes in the form of an authorization grant, which the client then uses to ask for the access token ๐ŸŽซ.

OAuth defines four grant types: authorization code, implicit, resource owner password credentials, and client credentials ๐Ÿฐ. It also has an extension mechanism for defining additional grant types, so the grant menu can keep growing ๐Ÿงšโ€โ™€๏ธโœจ.

4.1. Authorization Code Grant โœจ

okay bestie, the authorization code grant is the big-brain flow ๐Ÿง  it's how you get access tokens and refresh tokens, and it's basically built for confidential clients ๐Ÿ’… since it's a redirect-based flow, the client needs to be able to chat with the resource owner's user-agent (usually a web browser) AND be able to receive incoming requests via redirection from the authorization server ๐Ÿฆ‹

  +----------+
  | Resource |
  |   Owner  |
  |          |
  +----------+
       ^
       |
      (B)
  +----|-----+          Client Identifier      +---------------+
  |         -+----(A)-- & Redirection URI ---->|               |
  |  User-   |                                 | Authorization |
  |  Agent  -+----(B)-- User authenticates --->|     Server    |
  |          |                                 |               |
  |         -+----(C)-- Authorization Code ---<|               |
  +-|----|---+                                 +---------------+
    |    |                                         ^      v
   (A)  (C)                                        |      |
    |    |                                         |      |
    ^    v                                         |      |
  +---------+                                      |      |
  |         |>---(D)-- Authorization Code ---------'      |
  |  Client |          & Redirection URI                  |
  |         |                                             |
  |         |<---(E)----- Access Token -------------------'
  +---------+       (w/ Optional Refresh Token)

Note: The lines illustrating steps (A), (B), and (C) are broken into
two parts as they pass through the user-agent.

                  Figure 3: Authorization Code Flow

the flow in Figure 3 goes like this ๐Ÿ‘€

(A) The client kicks things off by sending the resource owner's user-agent over to the authorization endpoint ๐Ÿš€ It brings its client identifier, requested scope, local state, and a redirection URI, which is where the authorization server will send the user-agent back once access is granted (or denied).

(B) The authorization server authenticates the resource owner (through the user-agent) and figures out whether they grant or deny the client's access request ๐Ÿ”

(C) If the resource owner grants access, the authorization server redirects the user-agent back to the client using the redirection URI from earlier (either in the request or during client registration) ๐ŸŽ€ That redirection URI carries an authorization code plus any local state the client gave earlier.

(D) The client asks the authorization server's token endpoint for an access token, handing over the authorization code from the last step. While it's doing that, it authenticates with the authorization server ๐Ÿซถ It also includes the redirection URI it used to get the code, so that can be verified.

(E) The authorization server authenticates the client, validates the authorization code, and checks that the redirection URI it received matches the one used to redirect the client in step (C) ๐Ÿ‘‘ If everything checks out, it responds with an access token and, optionally, a refresh token ๐Ÿ’–


4.1.1. Authorization Request ๐ŸŒธ

the client builds the request URI by adding these parameters to the query component of the authorization endpoint URI, using the "application/x-www-form-urlencoded" format, per Appendix B:

  • response_type: REQUIRED. Value MUST be set to "code".
  • client_id: REQUIRED. The client identifier as described in Section 2.2.
  • redirect_uri: OPTIONAL. As described in Section 3.1.2.
  • scope: OPTIONAL. The scope of the access request as described by Section 3.3.
  • state: RECOMMENDED. An opaque value the client uses to keep track of state between the request and the callback. The authorization server includes this value when it redirects the user-agent back to the client. The parameter SHOULD be used for preventing cross-site request forgery as described in Section 10.12.

the client sends the resource owner to the constructed URI using an HTTP redirection response, or by any other means it has available through the user-agent.

for example, the client points the user-agent at this HTTP request over TLS (with extra line breaks just for display purposes):

GET /authorize?response_type=code&client_id=s6BhdRkqt3&state=xyz
    &redirect_uri=https%3A%2F%2Fclient%2Eexample%2Ecom%2Fcb HTTP/1.1
Host: server.example.com

the authorization server checks the request to make sure all required parameters are present and valid ๐Ÿ” If the request is valid, the server authenticates the resource owner and gets an authorization decision (by asking the resource owner or by establishing approval some other way) โœจ

once a decision is established, the authorization server directs the user-agent to the provided client redirection URI using an HTTP redirection response, or by other means it has available through the user-agent ๐Ÿฆ‹


4.1.2. Authorization Response ๐ŸŽ€

if the resource owner grants the access request, the authorization server issues an authorization code and delivers it to the client by adding these parameters to the query component of the redirection URI, using the "application/x-www-form-urlencoded" format, per Appendix B:

  • code: REQUIRED. The authorization code generated by the authorization server. The authorization code MUST expire shortly after it is issued to mitigate the risk of leaks. A maximum authorization code lifetime of 10 minutes is RECOMMENDED. The client MUST NOT use the authorization code more than once. If an authorization code is used more than once, the authorization server MUST deny the request and SHOULD revoke (when possible) all tokens previously issued based on that authorization code. The authorization code is bound to the client identifier and redirection URI.
  • state: REQUIRED if the "state" parameter was present in the client authorization request. The exact value received from the client.

for example, the authorization server redirects the user-agent by sending this HTTP response:

HTTP/1.1 302 Found
Location: https://client.example.com/cb?code=SplxlOBeZQQYbYS6WxSbIA
          &state=xyz

the client MUST ignore unrecognized response parameters ๐Ÿ™ˆ This spec leaves the authorization code string size undefined, so the client should avoid making assumptions about code value sizes. The authorization server SHOULD document the size of any value it issues ๐Ÿ“


4.1.2.1. Error Response ๐Ÿ’…

if the request fails because of a missing, invalid, or mismatching redirection URI, or because the client identifier is missing or invalid, the authorization server SHOULD inform the resource owner of the error and MUST NOT automatically redirect the user-agent to the invalid redirection URI ๐Ÿšซ

if the resource owner denies the access request, or if the request fails for reasons other than a missing or invalid redirection URI, the authorization server informs the client by adding these parameters to the query component of the redirection URI, using the "application/x-www-form-urlencoded" format, per Appendix B:

  • error: REQUIRED. A single ASCII [USASCII] error code from the following:
    • invalid_request: The request is missing a required parameter, includes an invalid parameter value, includes a parameter more than once, or is otherwise malformed.
    • unauthorized_client: The client is not authorized to request an authorization code using this method.
    • access_denied: The resource owner or authorization server denied the request.
    • unsupported_response_type: The authorization server does not support obtaining an authorization code using this method.
    • invalid_scope: The requested scope is invalid, unknown, or malformed.
    • server_error: The authorization server encountered an unexpected condition that prevented it from fulfilling the request. (This error code is needed because a 500 Internal Server Error HTTP status code cannot be returned to the client via an HTTP redirect.)
    • temporarily_unavailable: The authorization server is currently unable to handle the request due to a temporary overloading or maintenance of the server. (This error code is needed because a 503 Service Unavailable HTTP status code cannot be returned to the client via an HTTP redirect.)
    • Values for the "error" parameter MUST NOT include characters outside the set %x20-21 / %x23-5B / %x5D-7E.
  • error_description: OPTIONAL. Human-readable ASCII [USASCII] text providing additional information, used to assist the client developer in understanding the error that occurred. Values for the "error_description" parameter MUST NOT include characters outside the set %x20-21 / %x23-5B / %x5D-7E.
  • error_uri: OPTIONAL. A URI identifying a human-readable web page with information about the error, used to provide the client developer with additional information about the error. Values for the "error_uri" parameter MUST conform to the URI-reference syntax and thus MUST NOT include characters outside the set %x21 / %x23-5B / %x5D-7E.
  • state: REQUIRED if a "state" parameter was present in the client authorization request. The exact value received from the client.

for example, the authorization server redirects the user-agent by sending this HTTP response:

HTTP/1.1 302 Found
Location: https://client.example.com/cb?error=access_denied&state=xyz

and that's the authorization code grant, periodt ๐ŸŒˆ๐Ÿ‘‘

4.1.3. Access Token Request โœจ

okay bestie, this is where the client finally goes to the token endpoint and asks for the goods ๐ŸŽ€ It sends these parameters using the "application/x-www-form-urlencoded" format per Appendix B, with a character encoding of UTF-8, in the HTTP request entity-body:

  • grant_type: REQUIRED. Value MUST be set to "authorization_code".
  • code: REQUIRED. The authorization code received from the authorization server.
  • redirect_uri: REQUIRED, if the "redirect_uri" parameter was included in the authorization request as described in Section 4.1.1, and their values MUST be identical.
  • client_id: REQUIRED, if the client is not authenticating with the authorization server as described in Section 3.2.1.

If the client type is confidential or the client was issued client credentials (or assigned other authentication requirements), the client MUST authenticate with the authorization server as described in Section 3.2.1. no skipping this part, periodt ๐Ÿ’…

Here's an example of the client making the HTTP request over TLS (with extra line breaks just for display purposes ๐ŸŒธ):

POST /token HTTP/1.1
Host: server.example.com
Authorization: Basic czZCaGRSa3F0MzpnWDFmQmF0M2JW
Content-Type: application/x-www-form-urlencoded

grant_type=authorization_code&code=SplxlOBeZQQYbYS6WxSbIA
&redirect_uri=https%3A%2F%2Fclient%2Eexample%2Ecom%2Fcb

The authorization server MUST:

  • require client authentication for confidential clients or for any client that was issued client credentials (or with other authentication requirements),
  • authenticate the client if client authentication is included,
  • ensure that the authorization code was issued to the authenticated confidential client, or if the client is public, ensure that the code was issued to "client_id" in the request,
  • verify that the authorization code is valid, and
  • ensure that the "redirect_uri" parameter is present if the "redirect_uri" parameter was included in the initial authorization request as described in Section 4.1.1, and if included ensure that their values are identical.

4.1.4. Access Token Response โœจ

so if the access token request is valid and authorized, the authorization server issues an access token and an optional refresh token, as described in Section 5.1 ๐ŸŽ If the client authentication failed or is invalid, the authorization server returns an error response as described in Section 5.2. no cap, that's the whole vibe ๐Ÿ’€

Here's an example successful response:

HTTP/1.1 200 OK
Content-Type: application/json;charset=UTF-8
Cache-Control: no-store
Pragma: no-cache

{
  "access_token":"2YotnFZFEjr1zCsicMWpAA",
  "token_type":"example",
  "expires_in":3600,
  "refresh_token":"tGzv3JOkF0XG5Qx2TlKWIA",
  "example_parameter":"example_value"
}

4.2. Implicit Grant ๐Ÿฆ‹

okay so the implicit grant type is used to get access tokens, and it does NOT support refresh tokens ๐Ÿ™ˆ It's optimized for public clients that are known to operate a particular redirection URI. These clients are usually built in a browser with a scripting language like JavaScript, so it's giving front-end ๐Ÿงš

This is a redirection-based flow, so the client has to be able to interact with the resource owner's user-agent (usually a web browser) AND be able to receive incoming requests (via redirection) from the authorization server. lowkey a lot of requirements, but it makes sense ๐Ÿ’œ

Unlike the authorization code grant type, where the client makes separate requests for authorization and for an access token, here the client gets the access token as the result of the authorization request. one trip, no cap โœจ

The implicit grant type doesn't include client authentication. It relies on the presence of the resource owner and on the registration of the redirection URI. Since the access token is encoded into the redirection URI, it may be exposed to the resource owner and other applications residing on the same device. that's a big deal, so keep it in mind ๐Ÿ‘€

  +----------+
  | Resource |
  |  Owner   |
  |          |
  +----------+
       ^
       |
      (B)
  +----|-----+          Client Identifier     +---------------+
  |         -+----(A)-- & Redirection URI --->|               |
  |  User-   |                                | Authorization |
  |  Agent  -|----(B)-- User authenticates -->|     Server    |
  |          |                                |               |
  |          |<---(C)--- Redirection URI ----<|               |
  |          |          with Access Token     +---------------+
  |          |            in Fragment
  |          |                                +---------------+
  |          |----(D)--- Redirection URI ---->|   Web-Hosted  |
  |          |          without Fragment      |     Client    |
  |          |                                |    Resource   |
  |     (F)  |<---(E)------- Script ---------<|               |
  |          |                                +---------------+
  +-|--------+
    |    |
   (A)  (G) Access Token
    |    |
    ^    v
  +---------+
  |         |
  |  Client |
  |         |
  +---------+

Note: The lines illustrating steps (A) and (B) are broken into two parts as they pass through the user-agent.

Figure 4: Implicit Grant Flow ๐ŸŽ€

The flow in Figure 4 goes like this:

  • (A) The client starts the flow by directing the resource owner's user-agent to the authorization endpoint. The client includes its client identifier, requested scope, local state, and a redirection URI to which the authorization server will send the user-agent back once access is granted (or denied).
  • (B) The authorization server authenticates the resource owner (via the user-agent) and establishes whether the resource owner grants or denies the client's access request.
  • (C) Assuming the resource owner grants access, the authorization server redirects the user-agent back to the client using the redirection URI provided earlier. The redirection URI includes the access token in the URI fragment.
  • (D) The user-agent follows the redirection instructions by making a request to the web-hosted client resource (which does not include the fragment per [RFC2616]). The user-agent keeps the fragment information locally.
  • (E) The web-hosted client resource returns a web page (usually an HTML document with an embedded script) that can access the full redirection URI, including the fragment the user-agent kept, and extract the access token (and other parameters) from the fragment.
  • (F) The user-agent runs the script provided by the web-hosted client resource locally, which extracts the access token.
  • (G) The user-agent passes the access token to the client.

For background on the implicit grant, check Sections 1.3.2 and 9 ๐Ÿ“š For the important security stuff when using the implicit grant, see Sections 10.3 and 10.16. pls read these, they're serious ๐Ÿ”ฅ


4.2.1. Authorization Request โœจ

The client builds the request URI by adding the following parameters to the query component of the authorization endpoint URI, using the "application/x-www-form-urlencoded" format per Appendix B:

  • response_type: REQUIRED. Value MUST be set to "token".
  • client_id: REQUIRED. The client identifier as described in Section 2.2.
  • redirect_uri: OPTIONAL. As described in Section 3.1.2.
  • scope: OPTIONAL. The scope of the access request as described by Section 3.3.
  • state: RECOMMENDED. An opaque value used by the client to maintain state between the request and callback. The authorization server includes this value when redirecting the user-agent back to the client. The parameter SHOULD be used for preventing cross-site request forgery as described in Section 10.12. ๐Ÿ›ก๏ธ

The client directs the resource owner to the constructed URI using an HTTP redirection response, or by other means available to it via the user-agent.

Here's an example where the client directs the user-agent to make this HTTP request over TLS (with extra line breaks just for display ๐ŸŒธ):

GET /authorize?response_type=token&client_id=s6BhdRkqt3&state=xyz
    &redirect_uri=https%3A%2F%2Fclient%2Eexample%2Ecom%2Fcb HTTP/1.1
Host: server.example.com

The authorization server validates the request to make sure all required parameters are present and valid. It MUST verify that the redirection URI it will use to redirect the access token matches a redirection URI registered by the client as described in Section 3.1.2. this check is non-negotiable, bestie ๐Ÿ™…โ€โ™€๏ธ

If the request is valid, the authorization server authenticates the resource owner and gets an authorization decision (by asking the resource owner or by establishing approval via other means).

Once a decision is established, the authorization server directs the user-agent to the provided client redirection URI using an HTTP redirection response, or by other means available to it via the user-agent. ๐Ÿฆ‹


4.2.2. Access Token Response โœจ

If the resource owner grants the access request, the authorization server issues an access token and delivers it to the client by adding the following parameters to the fragment component of the redirection URI, using the "application/x-www-form-urlencoded" format per Appendix B:

  • access_token: REQUIRED. The access token issued by the authorization server.
  • token_type: REQUIRED. The type of the token issued as described in Section 7.1. Value is case insensitive.
  • expires_in: RECOMMENDED. The lifetime in seconds of the access token. For example, the value "3600" denotes that the access token will expire in one hour from the time the response was generated. If omitted, the authorization server SHOULD provide the expiration time via other means or document the default value.
  • scope: OPTIONAL, if identical to the scope requested by the client; otherwise, REQUIRED. The scope of the access token as described by Section 3.3.
  • state: REQUIRED if the "state" parameter was present in the client authorization request. The exact value received from the client.

The authorization server MUST NOT issue a refresh token. ๐Ÿšซ no refresh tokens for the implicit grant, that's the rule

Here's an example where the authorization server redirects the user-agent by sending this HTTP response (with extra line breaks for display purposes only ๐Ÿงš):

HTTP/1.1 302 Found
Location: http://example.com/cb#access_token=2YotnFZFEjr1zCsicMWpAA
          &state=xyz&token_type=example&expires_in=3600

Developers should note that some user-agents don't support including a fragment component in the HTTP "Location" response header field. Those clients will need other methods for redirecting, instead of a 3xx redirection response. For example, they could return an HTML page with a 'continue' button linked to the redirection URI. โš ๏ธ

The client MUST ignore unrecognized response parameters. The access token string size is left undefined by this specification, so the client should avoid making assumptions about value sizes. The authorization server SHOULD document the size of any value it issues. ๐Ÿ’–

4.2.2.1. Error Response ๐Ÿšจ

okay so bestie, if the redirection URI is missing, invalid, or doesn't match, or the client identifier is missing or invalid, the authorization server SHOULD inform the resource owner of the error and MUST NOT automatically redirect the user-agent to the invalid redirection URI. no sending people to sketchy places ๐Ÿ™…โ€โ™€๏ธ

if the resource owner says no to the access request, or the request fails for any reason other than a missing or invalid redirection URI, the authorization server tells the client by adding these parameters to the fragment component of the redirection URI. they go in the application/x-www-form-urlencoded format, per Appendix B ๐Ÿ’Œ

  • error โ€” REQUIRED. This is a single ASCII [USASCII] error code from this list:
    • invalid_request: the request is missing a required parameter, includes an invalid parameter value, includes a parameter more than once, or is otherwise malformed. ๐Ÿ™ƒ
    • unauthorized_client: the client isn't allowed to ask for an access token using this method.
    • access_denied: the resource owner or the authorization server said no to the request. ๐Ÿ’€
    • unsupported_response_type: the authorization server can't get an access token using this method.
    • invalid_scope: the requested scope is invalid, unknown, or malformed.
    • server_error: the authorization server hit an unexpected condition that stopped it from fulfilling the request. (this one exists because a 500 Internal Server Error HTTP status code can't be sent back to the client through an HTTP redirect ๐Ÿ˜ญ)
    • temporarily_unavailable: the authorization server can't handle the request right now because of temporary overloading or maintenance. (this one exists because a 503 Service Unavailable HTTP status code can't be sent back through an HTTP redirect either ๐Ÿฅบ)

Values for the error parameter MUST NOT include characters outside the set %x20-21 / %x23-5B / %x5D-7E.

  • error_description โ€” OPTIONAL. This is human-readable ASCII [USASCII] text that gives extra info to help the client developer understand what went wrong ๐Ÿง 

Values for the error_description parameter MUST NOT include characters outside the set %x20-21 / %x23-5B / %x5D-7E.

  • error_uri โ€” OPTIONAL. This is a URI pointing to a human-readable web page with more info about the error, so the client developer can dig deeper ๐Ÿ”

Values for the error_uri parameter MUST conform to the URI-reference syntax, and thus MUST NOT include characters outside the set %x21 / %x23-5B / %x5D-7E.

  • state โ€” REQUIRED if a state parameter was present in the client authorization request. This is the exact value received from the client, no changes ๐Ÿซถ

For example, the authorization server redirects the user-agent by sending this HTTP response:

HTTP/1.1 302 Found
Location: https://client.example.com/cb#error=access_denied&state=xyz

4.3. Resource Owner Password Credentials Grant ๐Ÿ”‘

okay this grant type is giving trusted friend energy โœจ it fits when the resource owner has a trust relationship with the client, like the device operating system or a super privileged app. the authorization server should take special care when turning this grant type on, and should only allow it when other flows aren't viable. don't just hand out the keys to everyone ๐Ÿ—๏ธ

this grant type works for clients that can get the resource owner's credentials (a username and password, usually through an interactive form). it's also a glow-up path for existing clients using direct authentication schemes like HTTP Basic or Digest authentication. they move over to OAuth by swapping the stored credentials for an access token ๐Ÿ’…

     +----------+
     | Resource |
     |  Owner   |
     |          |
     +----------+
          v
          |    Resource Owner
         (A) Password Credentials
          |
          v
     +---------+                                  +---------------+
     |         |>--(B)---- Resource Owner ------->|               |
     |         |         Password Credentials     | Authorization |
     | Client  |                                  |     Server    |
     |         |<--(C)---- Access Token ---------<|               |
     |         |    (w/ Optional Refresh Token)   |               |
     +---------+                                  +---------------+

            Figure 5: Resource Owner Password Credentials Flow

here's the play-by-play from Figure 5:

  • (A) The resource owner gives the client its username and password. ๐Ÿซ 
  • (B) The client asks the authorization server's token endpoint for an access token, and includes the credentials it got from the resource owner. when it makes this request, the client authenticates with the authorization server.
  • (C) The authorization server authenticates the client and checks the resource owner credentials. if they're valid, it issues an access token. โœ…

4.3.1. Authorization Request and Response

how the client gets the resource owner credentials is out of scope for this spec, so we're skipping it ๐Ÿ™ˆ the client MUST discard the credentials once an access token has been obtained. no hoarding passwords, periodt ๐Ÿงน

4.3.2. Access Token Request

the client sends a request to the token endpoint by adding these parameters in the application/x-www-form-urlencoded format per Appendix B, using UTF-8 as the character encoding, in the HTTP request entity-body:

  • grant_type โ€” REQUIRED. The value MUST be set to "password".
  • username โ€” REQUIRED. The resource owner username.
  • password โ€” REQUIRED. The resource owner password.
  • scope โ€” OPTIONAL. The scope of the access request, as described in Section 3.3.

if the client type is confidential, or the client was issued client credentials (or was assigned other authentication requirements), the client MUST authenticate with the authorization server, as described in Section 3.2.1 ๐Ÿ”

here's an example HTTP request using transport-layer security (I added extra line breaks just so it's easier to read ๐ŸŽ€):

POST /token HTTP/1.1
Host: server.example.com
Authorization: Basic czZCaGRSa3F0MzpnWDFmQmF0M2JW
Content-Type: application/x-www-form-urlencoded

grant_type=password&username=johndoe&password=A3ddj3w

the authorization server MUST:

  • require client authentication for confidential clients, or for any client that was issued client credentials (or has other authentication requirements),
  • authenticate the client if client authentication is included, and
  • validate the resource owner password credentials using its existing password validation algorithm.

since this request uses the resource owner's password, the authorization server MUST protect the endpoint against brute force attacks (for example, with rate-limiting or by generating alerts). this is serious, bestie ๐Ÿšจ

4.3.3. Access Token Response

if the access token request is valid and authorized, the authorization server issues an access token and an optional refresh token, as described in Section 5.1. if the request fails client authentication or is invalid, the authorization server returns an error response, as described in Section 5.2. ๐Ÿ’ซ

an example successful response looks like this:

HTTP/1.1 200 OK
Content-Type: application/json;charset=UTF-8
Cache-Control: no-store
Pragma: no-cache

{
  "access_token":"2YotnFZFEjr1zCsicMWpAA",
  "token_type":"example",
  "expires_in":3600,
  "refresh_token":"tGzv3JOkF0XG5Qx2TlKWIA",
  "example_parameter":"example_value"
}

4.4. Client Credentials Grant โšก

the client can ask for an access token using only its client credentials (or another supported form of authentication). this works when the client is requesting access to protected resources under its control, or to resources of another resource owner that were arranged ahead of time with the authorization server. how that arrangement happens is out of scope for this spec ๐Ÿคทโ€โ™€๏ธ

the client credentials grant type MUST only be used by confidential clients. main character energy for the confidential crew only ๐Ÿ‘‘

     +---------+                                  +---------------+
     |         |                                  |               |
     |         |>--(A)- Client Authentication --->| Authorization |
     | Client  |                                  |     Server    |
     |         |<--(B)---- Access Token ---------<|               |
     |         |                                  |               |
     +---------+                                  +---------------+

                     Figure 6: Client Credentials Flow

here's the Figure 6 breakdown:

  • (A) The client authenticates with the authorization server and asks the token endpoint for an access token.
  • (B) The authorization server authenticates the client, and if that checks out, issues an access token. ๐ŸŽ‰

4.4.1. Authorization Request and Response

since client authentication is used as the authorization grant, no extra authorization request is needed. we skip straight to the good part ๐Ÿงš

4.4.2. Access Token Request

the client sends a request to the token endpoint by adding these parameters in the application/x-www-form-urlencoded format per Appendix B, with UTF-8 as the character encoding, in the HTTP request entity-body:

  • grant_type โ€” REQUIRED. The value MUST be set to "client_credentials".
  • scope โ€” OPTIONAL. The scope of the access request, as described in Section 3.3.

the client MUST authenticate with the authorization server, as described in Section 3.2.1 ๐Ÿ”

here's an example HTTP request using transport-layer security (extra line breaks added for display purposes only ๐ŸŒธ):

POST /token HTTP/1.1
Host: server.example.com
Authorization: Basic czZCaGRSa3F0MzpnWDFmQmF0M2JW
Content-Type: application/x-www-form-urlencoded

grant_type=client_credentials

the authorization server MUST authenticate the client. no exceptions, no vibes-based access ๐Ÿ’…

4.4.3. Access Token Response

if the access token request is valid and authorized, the authorization server issues an access token, as described in Section 5.1. a refresh token SHOULD NOT be included. if the request fails client authentication or is invalid, the authorization server returns an error response, as described in Section 5.2. ๐Ÿซถ

an example successful response:

HTTP/1.1 200 OK
Content-Type: application/json;charset=UTF-8
Cache-Control: no-store
Pragma: no-cache

{
  "access_token":"2YotnFZFEjr1zCsicMWpAA",
  "token_type":"example",
  "expires_in":3600,
  "example_parameter":"example_value"
}

4.5. Extension Grants โœจ

okay so bestie, this is where the spec gets extra customizable ๐Ÿ’…. A client can use an extension grant type by putting an absolute URI (one the authorization server defines) into the grant_type parameter at the token endpoint, and then adding any extra parameters it needs ๐Ÿงš.

For example, say you want an access token with a Security Assertion Markup Language (SAML) 2.0 assertion grant type as defined by [OAuth-SAML2]. The client could send this HTTP request over TLS (the extra line breaks are just there so it's easier to read ๐ŸŽ€):

  POST /token HTTP/1.1
  Host: server.example.com
  Content-Type: application/x-www-form-urlencoded

  grant_type=urn%3Aietf%3Aparams%3Aoauth%3Agrant-type%3Asaml2-
  bearer&assertion=PEFzc2VydGlvbiBJc3N1ZUluc3RhbnQ9IjIwMTEtMDU
  [...omitted for brevity...]aG5TdGF0ZW1lbnQ-PC9Bc3NlcnRpb24-

If the access token request is valid and authorized, the authorization server issues an access token and an optional refresh token, as described in Section 5.1 ๐Ÿฆ‹. If the request fails client authentication or is invalid, the authorization server sends back an error response, as described in Section 5.2 ๐Ÿ’€.

5. Issuing an Access Token ๐Ÿ‘‘

Honestly this is the same little story as the end of 4.5 ๐Ÿ™ˆ. If the access token request is valid and authorized, the authorization server issues an access token and an optional refresh token, as described in Section 5.1. If the request fails client authentication or is invalid, the authorization server returns an error response, as described in Section 5.2.

5.1. Successful Response ๐ŸŒธ

The authorization server issues an access token and an optional refresh token. Then it builds the response by adding the following parameters to the entity-body of the HTTP response, with a 200 (OK) status code ๐Ÿ’–:

  • access_token REQUIRED. The access token issued by the authorization server.
  • token_type REQUIRED. The type of the token issued, as described in Section 7.1. Value is case insensitive.
  • expires_in RECOMMENDED. The lifetime in seconds of the access token. For example, the value "3600" means the access token will expire one hour after the response was generated โฐ. If it's omitted, the authorization server SHOULD provide the expiration time some other way or document the default value.
  • refresh_token OPTIONAL. The refresh token, which can be used to get new access tokens using the same authorization grant, as described in Section 6 ๐Ÿ”.
  • scope OPTIONAL, if identical to the scope requested by the client; otherwise, REQUIRED. The scope of the access token, as described by Section 3.3 ๐ŸŽฏ.

The parameters go in the entity-body of the HTTP response using the "application/json" media type, as defined by [RFC4627] ๐Ÿ“. They get serialized into a JavaScript Object Notation (JSON) structure, with each parameter added at the highest structure level. Parameter names and string values are included as JSON strings, and numerical values are included as JSON numbers. The order of the parameters doesn't matter and can change โœจ.

The authorization server MUST include the HTTP "Cache-Control" response header field [RFC2616] with a value of "no-store" in any response that contains tokens, credentials, or other sensitive information. It MUST also include the "Pragma" response header field [RFC2616] with a value of "no-cache" ๐Ÿ”’.

For example:

  HTTP/1.1 200 OK
  Content-Type: application/json;charset=UTF-8
  Cache-Control: no-store
  Pragma: no-cache

  {
    "access_token":"2YotnFZFEjr1zCsicMWpAA",
    "token_type":"example",
    "expires_in":3600,
    "refresh_token":"tGzv3JOkF0XG5Qx2TlKWIA",
    "example_parameter":"example_value"
  }

The client MUST ignore unrecognized value names in the response ๐Ÿ™…โ€โ™€๏ธ. The sizes of tokens and other values received from the authorization server are left undefined, so the client should avoid making assumptions about value sizes. The authorization server SHOULD document the size of any value it issues ๐Ÿ“.

5.2. Error Response ๐Ÿ’€

The authorization server responds with an HTTP 400 (Bad Request) status code (unless something else is specified) and includes the following parameters with the response ๐Ÿšจ:

  • error REQUIRED. A single ASCII [USASCII] error code from the following list:
    • invalid_request The request is missing a required parameter, includes an unsupported parameter value (other than grant type), repeats a parameter, includes multiple credentials, uses more than one mechanism for authenticating the client, or is otherwise malformed.
    • invalid_client Client authentication failed (for example, unknown client, no client authentication included, or unsupported authentication method). The authorization server MAY return an HTTP 401 (Unauthorized) status code to show which HTTP authentication schemes are supported. If the client tried to authenticate via the "Authorization" request header field, the authorization server MUST respond with an HTTP 401 (Unauthorized) status code and include the "WWW-Authenticate" response header field matching the authentication scheme the client used ๐Ÿฅฒ.
    • invalid_grant The provided authorization grant (for example, an authorization code or resource owner credentials) or refresh token is invalid, expired, revoked, doesn't match the redirection URI used in the authorization request, or was issued to another client ๐Ÿšซ.
    • unauthorized_client The authenticated client is not authorized to use this authorization grant type ๐Ÿ™….
    • unsupported_grant_type The authorization server doesn't support this authorization grant type ๐Ÿคทโ€โ™€๏ธ.
    • invalid_scope The requested scope is invalid, unknown, malformed, or goes beyond the scope the resource owner granted ๐Ÿงพ.

Values for the "error" parameter MUST NOT include characters outside the set %x20-21 / %x23-5B / %x5D-7E.

  • error_description OPTIONAL. Human-readable ASCII [USASCII] text that gives extra info to help the client developer understand what went wrong ๐Ÿ“. Values for the "error_description" parameter MUST NOT include characters outside the set %x20-21 / %x23-5B / %x5D-7E.
  • error_uri OPTIONAL. A URI that points to a human-readable web page with info about the error, giving the client developer more context ๐Ÿ”—. Values for the "error_uri" parameter MUST conform to the URI-reference syntax, and thus MUST NOT include characters outside the set %x21 / %x23-5B / %x5D-7E.

The parameters go in the entity-body of the HTTP response using the "application/json" media type, as defined by [RFC4627]. They get serialized into a JSON structure, with each parameter added at the highest structure level. Parameter names and string values are included as JSON strings, and numerical values are included as JSON numbers. The order of the parameters doesn't matter and can vary ๐ŸŒˆ.

For example:

  HTTP/1.1 400 Bad Request
  Content-Type: application/json;charset=UTF-8
  Cache-Control: no-store
  Pragma: no-cache

  {
    "error":"invalid_request"
  }

6. Refreshing an Access Token ๐Ÿ”

If the authorization server issued a refresh token to the client, the client makes a refresh request to the token endpoint. It does this by adding the following parameters, using the "application/x-www-form-urlencoded" format per Appendix B with a character encoding of UTF-8, in the HTTP request entity-body ๐Ÿง:

  • grant_type REQUIRED. Value MUST be set to "refresh_token".
  • refresh_token REQUIRED. The refresh token issued to the client.
  • scope OPTIONAL. The scope of the access request, as described by Section 3.3. The requested scope MUST NOT include any scope that the resource owner didn't originally grant, and if it's omitted, it is treated as equal to the scope originally granted by the resource owner ๐ŸŽ€.

Refresh tokens are usually long-lasting credentials used to request additional access tokens, so the refresh token is bound to the client it was issued to ๐Ÿ”. If the client type is confidential, or the client was issued client credentials (or has other authentication requirements), the client MUST authenticate with the authorization server, as described in Section 3.2.1.

For example, the client makes the following HTTP request using transport-layer security (the extra line breaks are for display only) ๐Ÿ’ป:

  POST /token HTTP/1.1
  Host: server.example.com
  Authorization: Basic czZCaGRSa3F0MzpnWDFmQmF0M2JW
  Content-Type: application/x-www-form-urlencoded

  grant_type=refresh_token&refresh_token=tGzv3JOkF0XG5Qx2TlKWIA

The authorization server MUST:

  • require client authentication for confidential clients, or for any client that was issued client credentials (or has other authentication requirements),
  • authenticate the client if client authentication is included, and ensure that the refresh token was issued to the authenticated client, and
  • validate the refresh token.

If it's valid and authorized, the authorization server issues an access token, as described in Section 5.1. If the request fails verification or is invalid, the authorization server returns an error response, as described in Section 5.2 ๐Ÿ™ˆ.

The authorization server MAY issue a new refresh token. If it does, the client MUST discard the old refresh token and replace it with the new one ๐Ÿ”„. The authorization server MAY revoke the old refresh token after issuing a new one to the client. If a new refresh token is issued, the refresh token scope MUST be identical to that of the refresh token the client included in the request ๐Ÿ’….


7. Accessing Protected Resources ๐Ÿ›ก๏ธ

The client accesses protected resources by presenting the access token to the resource server. The resource server MUST validate the access token and make sure it hasn't expired and that its scope covers the requested resource ๐Ÿ‘€. The methods the resource server uses to validate the access token (as well as any error responses) are beyond the scope of this specification, but they generally involve some interaction or coordination between the resource server and the authorization server ๐Ÿค.

How the client uses the access token to authenticate with the resource server depends on the type of access token the authorization server issued. Typically, this means using the HTTP "Authorization" request header field [RFC2617] with an authentication scheme defined by the specification of the access token type used, such as [RFC6750] ๐Ÿฆ‹.

7.1. Access Token Types ๐Ÿ’–

Okay so the access token type is basically the instruction manual that tells the client how to actually use the token when it asks a protected resource for something, plus any type-specific extras. The client MUST NOT use an access token if it does not understand the token type ๐Ÿ™…โ€โ™€๏ธ no guessing allowed!

For example, the "bearer" token type defined in [RFC6750] is used by simply popping the access token string right into the request:

GET /resource/1 HTTP/1.1
Host: example.com
Authorization: Bearer mF_9.B5f-4.1JqM

Then there's the "mac" token type defined in [OAuth-HTTP-MAC], which is a whole vibe โœจ. Here the client gets a Message Authentication Code (MAC) key along with the access token, and that key is used to sign certain parts of the HTTP requests:

GET /resource/1 HTTP/1.1
Host: example.com
Authorization: MAC id="h480djs93hd8",
                   nonce="274312:dj83hs9s",
                   mac="kDZvddkndxvhGRXZhvuDjEWhGeE="

The examples above are just for illustration ๐Ÿฆ‹ Developers are advised to check out [RFC6750] and [OAuth-HTTP-MAC] before they actually use any of this, bestie ๐Ÿ“š

Every access token type definition spells out the extra attributes (if there are any) that get sent to the client alongside the "access_token" response parameter. It also defines the HTTP authentication method used to include the access token when the client makes a protected resource request. Main character definitions only ๐Ÿ‘‘

7.2. Error Response ๐Ÿšจ

So if a resource access request fails, the resource server SHOULD let the client know what went wrong. The nitty-gritty of those error responses is out of scope for this spec, but this document does set up a shared registry in Section 11.4 for error values that OAuth token authentication schemes can all use together ๐Ÿซถ

New authentication schemes that are designed mainly for OAuth token authentication SHOULD define a way to hand the client an error status code, and the error values they allow MUST be ones registered in the error registry this specification establishes. Wait, let me correct that vibe: the registry requirement is what keeps everyone speaking the same language ๐Ÿ’…

Such schemes MAY limit the set of valid error codes to a subset of the registered values. If the error code comes back in a named parameter, the parameter name SHOULD be "error" ๐ŸŽ€

Other schemes that can be used for OAuth token authentication, but weren't primarily designed for it, MAY bind their error values to the registry in the same way ๐ŸŒธ

New authentication schemes MAY also choose to specify the use of the "error_description" and "error_uri" parameters, so they can return error information in a way that matches how this specification uses them ๐Ÿงš

8. Extensibility โœจ

8.1. Defining Access Token Types ๐Ÿฆ‹

Access token types can be defined in one of two ways: either registered in the Access Token Types registry (following the procedures in Section 11.1), or by using a unique absolute URI as its name ๐Ÿ’œ

Types that use a URI name SHOULD be limited to vendor-specific implementations that aren't commonly applicable, and that are specific to the implementation details of the resource server where they're used ๐Ÿ™ˆ

All other types MUST be registered. Type names MUST conform to the type-name ABNF. If the type definition includes a new HTTP authentication scheme, the type name SHOULD be identical to the HTTP authentication scheme name (as defined by [RFC2617]). The token type "example" is reserved for use in examples ๐Ÿ“

type-name  = 1*name-char
name-char  = "-" / "." / "_" / DIGIT / ALPHA

8.2. Defining New Endpoint Parameters ๐ŸŒˆ

New request or response parameters for use with the authorization endpoint or the token endpoint are defined and registered in the OAuth Parameters registry, following the procedure in Section 11.2 ๐Ÿ“

Parameter names MUST conform to the param-name ABNF, and parameter values syntax MUST be well-defined (for example, using ABNF, or a reference to the syntax of an existing parameter) โœจ

param-name  = 1*name-char
name-char   = "-" / "." / "_" / DIGIT / ALPHA

Unregistered vendor-specific parameter extensions that aren't commonly applicable, and that are specific to the implementation details of the authorization server where they're used, SHOULD use a vendor-specific prefix that's unlikely to clash with other registered values (for example, starting with 'companyname_') ๐Ÿ’…

8.3. Defining New Authorization Grant Types ๐ŸŽ€

New authorization grant types can be defined by giving them a unique absolute URI to use with the "grant_type" parameter. If the extension grant type needs additional token endpoint parameters, they MUST be registered in the OAuth Parameters registry as described by Section 11.2 ๐Ÿซถ

8.4. Defining New Authorization Endpoint Response Types ๐ŸŒธ

New response types for use with the authorization endpoint are defined and registered in the Authorization Endpoint Response Types registry, following the procedure in Section 11.3 ๐Ÿ’– Response type names MUST conform to the response-type ABNF.

response-type  = response-name *( SP response-name )
response-name  = 1*response-char
response-char  = "_" / DIGIT / ALPHA

If a response type contains one or more space characters (%x20), it gets compared as a space-delimited list of values where the order doesn't matter. Only one order of values can be registered, and that one covers every other arrangement of the same set of values ๐Ÿ”ฅ

For example, the response type "token code" is left undefined by this specification. However, an extension can define and register the "token code" response type. Once it's registered, the same combo can't be registered again as "code token", but both values can still be used to denote the same response type ๐Ÿงš

8.5. Defining Additional Error Codes ๐Ÿšจ

In cases where protocol extensions (that is, access token types, extension parameters, or extension grant types) need extra error codes to be used with the authorization code grant error response (Section 4.1.2.1), the implicit grant error response (Section 4.2.2.1), the token error response (Section 5.2), or the resource access error response (Section 7.2), such error codes MAY be defined ๐Ÿ’œ

Extension error codes MUST be registered (following the procedures in Section 11.4) if the extension they're used with is a registered access token type, a registered endpoint parameter, or an extension grant type. Error codes used with unregistered extensions MAY be registered ๐ŸŒˆ

Error codes MUST conform to the error ABNF, and SHOULD be prefixed by an identifying name when possible. For example, an error identifying an invalid value set to the extension parameter "example" SHOULD be named "example_invalid" ๐Ÿ“

error      = 1*error-char
error-char = %x20-21 / %x23-5B / %x5D-7E

9. Native Applications ๐Ÿ“ฑ

Native applications are clients that are installed and run on the device used by the resource owner (think desktop apps or native mobile apps). They need special consideration when it comes to security, platform capabilities, and the overall end-user experience ๐ŸŒธ

The authorization endpoint needs interaction between the client and the resource owner's user-agent. Native applications can invoke an external user-agent or embed a user-agent within the application. For example:

  • External user-agent: the native application can capture the response from the authorization server using a redirection URI with a scheme registered with the operating system so the client gets invoked as the handler, manual copy-and-paste of the credentials, running a local web server, installing a user-agent extension, or providing a redirection URI that identifies a server-hosted resource under the client's control, which then makes the response available to the native application ๐Ÿฆ‹
  • Embedded user-agent: the native application gets the response by talking directly to the embedded user-agent, either by monitoring state changes emitted during the resource load or by accessing the user-agent's cookie storage ๐Ÿงš

When choosing between an external or embedded user-agent, developers should consider the following:

  • An external user-agent may improve completion rate, since the resource owner may already have an active session with the authorization server, which means no need to re-authenticate. It also gives a familiar end-user experience and functionality. The resource owner may rely on user-agent features or extensions to help with authentication (for example, a password manager or a 2-factor device reader) ๐Ÿ’…
  • An embedded user-agent may offer improved usability, because it removes the need to switch context and open new windows โœจ
  • An embedded user-agent poses a security challenge because resource owners are authenticating in an unidentified window without the visual protections found in most external user-agents. An embedded user-agent teaches end-users to trust unidentified requests for authentication, which makes phishing attacks easier to pull off ๐Ÿšจ

When choosing between the implicit grant type and the authorization code grant type, the following should be considered:

  • Native applications that use the authorization code grant type SHOULD do so without using client credentials, because a native application can't keep client credentials confidential ๐Ÿ”
  • When using the implicit grant type flow, a refresh token is not returned, which means the authorization process has to be repeated once the access token expires ๐ŸŒ€

10. Security Considerations ๐Ÿ›ก๏ธ

OAuth is a flexible and extensible framework, so its security considerations depend on lots of different factors ๐Ÿซง The following sections give implementers security guidelines focused on the three client profiles described in Section 2.1: web application, user-agent-based application, and native application. This is serious business, bestie, so pay attention ๐Ÿ‘‘

A comprehensive OAuth security model and analysis, along with background on the protocol design, is provided by [OAuth-THREATMODEL] ๐Ÿ“–

10.1. Client Authentication ๐Ÿ”‘

The authorization server establishes client credentials with web application clients for the purpose of client authentication. The authorization server is encouraged to consider stronger client authentication means than a client password. Web application clients MUST ensure confidentiality of client passwords and other client credentials ๐Ÿ”’

The authorization server MUST NOT issue client passwords or other client credentials to native application or user-agent-based application clients for the purpose of client authentication. The authorization server MAY issue a client password or other credentials for a specific installation of a native application client on a specific device ๐Ÿ“ฑ

When client authentication isn't possible, the authorization server SHOULD use other means to validate the client's identity. For example, it can require registration of the client redirection URI or ask the resource owner to confirm identity ๐Ÿ•ต๏ธโ€โ™€๏ธ A valid redirection URI is not enough to verify the client's identity when asking for resource owner authorization, but it can be used to prevent delivering credentials to a counterfeit client after resource owner authorization has been obtained ๐Ÿ™…โ€โ™€๏ธ

The authorization server must consider the security implications of interacting with unauthenticated clients, and take measures to limit the potential exposure of other credentials (e.g., refresh tokens) issued to such clients. Seriously, this one's a big deal ๐Ÿ˜ญ๐Ÿ’€

10.2. Client Impersonation ๐ŸŽญ

Okay so a sneaky client can totally pretend to be another client and grab protected resources ๐Ÿ˜ค if the impersonated client can't keep its client credentials secret (fails to, or just is unable to, lol).

The authorization server MUST authenticate the client whenever possible ๐Ÿ”. If it can't authenticate the client because of what kind of client it is, then it MUST require every redirection URI used for receiving authorization responses to be registered ๐Ÿ“, and it SHOULD use other means to protect resource owners from those potentially shady clients. For example, the authorization server can bring the resource owner in to help figure out who the client is and where it's from ๐Ÿ•ต๏ธโ€โ™€๏ธ

The authorization server SHOULD enforce explicit resource owner authentication ๐Ÿ’… and show the resource owner info about the client, plus the requested authorization scope and lifetime โœจ. It's up to the resource owner to look at that info in the context of the current client and then decide to approve or deny the request ๐Ÿซถ

The authorization server SHOULD NOT process repeated authorization requests automatically (without active resource owner interaction) ๐Ÿ™…โ€โ™€๏ธ without authenticating the client or relying on other measures to make sure the repeated request is coming from the original client and not an impersonator ๐Ÿ‘€


10.3. Access Tokens ๐ŸŽŸ๏ธ

Access token credentials (plus any confidential access token attributes) MUST be kept confidential in transit and storage ๐Ÿคซ, and only shared among the authorization server, the resource servers the access token is valid for, and the client the access token was issued to. Access token credentials MUST only be transmitted using TLS as described in Section 1.6, with server authentication as defined by [RFC2818] ๐Ÿ”’

When using the implicit grant type, the access token gets sent in the URI fragment ๐Ÿ˜ฌ, which can expose it to unauthorized parties. Not ideal, bestie ๐Ÿ’€

The authorization server MUST ensure that access tokens cannot be generated, modified, or guessed to produce valid access tokens by unauthorized parties ๐Ÿ›ก๏ธ

The client SHOULD request access tokens with the minimal scope necessary ๐ŸŒธ. The authorization server SHOULD take the client identity into account when deciding how to honor the requested scope, and MAY issue an access token with fewer rights than requested ๐Ÿงš

This specification does not provide any methods for the resource server to make sure an access token presented to it by a given client was actually issued to that client by the authorization server. So that one's on you, resource server ๐Ÿ™ˆ


10.4. Refresh Tokens ๐Ÿ”„

Authorization servers MAY issue refresh tokens to web application clients and native application clients ๐Ÿฆ‹

Refresh tokens MUST be kept confidential in transit and storage ๐Ÿค, and shared only among the authorization server and the client the refresh tokens were issued to. The authorization server MUST maintain the binding between a refresh token and the client it was issued to ๐Ÿ”—. Refresh tokens MUST only be transmitted using TLS as described in Section 1.6, with server authentication as defined by [RFC2818] ๐Ÿ”’

The authorization server MUST verify the binding between the refresh token and the client identity whenever the client identity can be authenticated โœ…. When client authentication isn't possible, the authorization server SHOULD deploy other means to detect refresh token abuse ๐Ÿšจ

For example, the authorization server could use refresh token rotation, where a new refresh token is issued with every access token refresh response ๐Ÿ“. The previous refresh token gets invalidated but is kept around by the authorization server. If a refresh token is compromised and then used by both the attacker and the legit client, one of them will present an invalidated refresh token, and that will tip the authorization server off to the breach ๐Ÿ•ต๏ธโ€โ™€๏ธโœจ iconic detective work

The authorization server MUST ensure that refresh tokens cannot be generated, modified, or guessed to produce valid refresh tokens by unauthorized parties ๐Ÿ›ก๏ธ


10.5. Authorization Codes ๐Ÿงพ

The transmission of authorization codes SHOULD be made over a secure channel ๐Ÿ”, and the client SHOULD require the use of TLS with its redirection URI if the URI identifies a network resource. Since authorization codes get sent through user-agent redirections, they could potentially be exposed through user-agent history and HTTP referrer headers ๐Ÿ‘€ that's giving leaky

Authorization codes operate as plaintext bearer credentials ๐ŸŽ€. They're used to verify that the resource owner who granted authorization at the authorization server is the same resource owner coming back to the client to finish the process. So if the client relies on the authorization code for its own resource owner authentication, the client redirection endpoint MUST require the use of TLS ๐Ÿ”’

Authorization codes MUST be short lived and single-use โณ. If the authorization server sees multiple attempts to exchange an authorization code for an access token, the authorization server SHOULD attempt to revoke all access tokens already granted based on the compromised authorization code ๐Ÿšซ

If the client can be authenticated, the authorization servers MUST authenticate the client and make sure the authorization code was issued to the same client ๐Ÿซถ


10.6. Authorization Code Redirection URI Manipulation ๐Ÿ•ธ๏ธ

When requesting authorization using the authorization code grant type, the client can specify a redirection URI via the redirect_uri parameter ๐Ÿงต. If an attacker can manipulate the value of the redirection URI, they can make the authorization server redirect the resource owner user-agent to a URI under the attacker's control, with the authorization code attached ๐Ÿ˜ˆ

Here's how the sneaky plan goes ๐ŸŽฌ. An attacker creates an account at a legit client and starts the authorization flow. When the attacker's user-agent is sent to the authorization server to grant access, the attacker grabs the authorization URI the legit client provided and swaps the client's redirection URI for one under their own control. Then they trick the victim into following the manipulated link to authorize access to the legit client ๐Ÿชค

Once the victim lands at the authorization server, they see a normal, valid request on behalf of a legit and trusted client, and they approve it โœ…. The victim then gets redirected to an endpoint under the attacker's control, carrying the authorization code. The attacker finishes the flow by sending the authorization code to the client using the original redirection URI the client provided ๐Ÿƒโ€โ™€๏ธ๐Ÿ’จ. The client swaps the authorization code for an access token and links it to the attacker's client account, and now the attacker can access the protected resources the victim authorized (through the client) ๐Ÿ’€ yikes

To prevent this attack, the authorization server MUST ensure that the redirection URI used to obtain the authorization code is identical to the redirection URI provided when exchanging the authorization code for an access token ๐Ÿ”. The authorization server MUST require public clients, and SHOULD require confidential clients, to register their redirection URIs ๐Ÿ“. If a redirection URI is provided in the request, the authorization server MUST validate it against the registered value โœ…


10.7. Resource Owner Password Credentials ๐Ÿ”‘

The resource owner password credentials grant type is often used for legacy or migration reasons ๐Ÿ•ฐ๏ธ. It lowers the overall risk of the client storing usernames and passwords, but it doesn't get rid of the need to expose highly privileged credentials to the client ๐Ÿ˜ต

This grant type carries a higher risk than other grant types ๐Ÿšฉ because it keeps the password anti-pattern this protocol is trying to avoid. The client could abuse the password, or the password could accidentally be disclosed to an attacker (for example, through log files or other records the client keeps) ๐Ÿ“œ

On top of that, the resource owner doesn't control the authorization process (their involvement ends once they hand their credentials over to the client). So the client can obtain access tokens with a broader scope than the resource owner wanted ๐Ÿ˜ณ. The authorization server should consider the scope and lifetime of access tokens issued via this grant type ๐Ÿง

The authorization server and client SHOULD minimize use of this grant type and use other grant types whenever possible ๐ŸŒˆ


10.8. Request Confidentiality ๐Ÿคซ

Access tokens, refresh tokens, resource owner passwords, and client credentials MUST NOT be transmitted in the clear ๐Ÿšซ. Authorization codes SHOULD NOT be transmitted in the clear either ๐Ÿ™…โ€โ™€๏ธ

The "state" and "scope" parameters SHOULD NOT include sensitive client or resource owner information in plain text ๐Ÿซฃ, since they can be transmitted over insecure channels or stored insecurely. Not the vibe ๐Ÿ’…


10.9. Ensuring Endpoint Authenticity ๐Ÿ›ก๏ธ

To stop man-in-the-middle attacks ๐Ÿฅท, the authorization server MUST require the use of TLS with server authentication as defined by [RFC2818] for any request sent to the authorization and token endpoints ๐Ÿ”’. The client MUST validate the authorization server's TLS certificate as defined by [RFC6125] and in accordance with its requirements for server identity authentication ๐Ÿชช


10.10. Credentials-Guessing Attacks ๐ŸŽฒ

The authorization server MUST prevent attackers from guessing access tokens, authorization codes, refresh tokens, resource owner passwords, and client credentials ๐Ÿ™…โ€โ™€๏ธ

The probability of an attacker guessing generated tokens (and other credentials not meant for handling by end-users) MUST be less than or equal to 2^(-128) and SHOULD be less than or equal to 2^(-160) ๐Ÿ”ขโœจ those odds are tiny, bestie

The authorization server MUST utilize other means to protect credentials intended for end-user usage ๐Ÿง


10.11. Phishing Attacks ๐ŸŽฃ

Wide deployment of this and similar protocols may get end-users used to being redirected to websites where they're asked to type in their passwords ๐Ÿ˜ฉ. If end-users don't carefully verify that these websites are legit before entering their credentials, attackers can exploit that habit to steal resource owners' passwords ๐Ÿ’”

Service providers should try to teach end-users about the risks phishing attacks pose, and should provide mechanisms that make it easy for end-users to confirm their sites are authentic ๐ŸŽ“. Client developers should think hard about the security implications of how they interact with the user-agent (for example, external or embedded), and about whether the end-user can verify the authenticity of the authorization server ๐Ÿง 

To reduce the risk of phishing attacks, the authorization servers MUST require the use of TLS on every endpoint used for end-user interaction. ๐Ÿšจ๐Ÿ’–

10.12. Cross-Site Request Forgery ๐Ÿ’Œ

Okay bestie, so cross-site request forgery (CSRF) is when an attacker tricks a victim's browser (the user-agent) into following a sketchy URI. It might be hidden in a misleading link, an image, or a redirect, and it lands on a server that trusts the user because of a valid session cookie ๐Ÿ™ˆ. Not me falling for a cute meme ๐Ÿ’€

A CSRF attack on the client's redirection URI lets the attacker sneak in their own authorization code or access token ๐Ÿ˜ฑ. Then the client ends up using a token tied to the attacker's protected resources instead of the victim's. Imagine your bank account info getting saved into a resource the attacker controls. Absolutely not ๐Ÿ™…

The client MUST implement CSRF protection for its redirection URI. Usually this means every request hitting the redirection URI endpoint has to include a value that ties it to the user-agent's logged-in state, like a hash of the session cookie ๐ŸŽ€. The client SHOULD use the state request parameter to send that value to the authorization server when it makes the authorization request โœจ.

Once the end-user has given authorization, the authorization server sends the user-agent back to the client with that binding value in the state parameter. The client checks it by matching the value against the user-agent's authenticated state, so it can tell whether the request is legit ๐Ÿ”. That binding value used for CSRF protection MUST contain a non-guessable value (as described in Section 10.10), and the user-agent's authenticated state (e.g., session cookie, HTML5 local storage) MUST be kept somewhere only the client and the user-agent can reach (i.e., protected by same-origin policy) ๐Ÿ”.

A CSRF attack on the authorization server's authorization endpoint can let an attacker get end-user authorization for a malicious client, and the end-user never even notices ๐Ÿ˜ญ.

The authorization server MUST implement CSRF protection for its authorization endpoint. It also has to make sure a malicious client can't get authorization without the resource owner's awareness and explicit consent ๐Ÿ‘‘.

10.13. Clickjacking ๐Ÿ–ฑ๏ธ

In a clickjacking attack, the attacker registers a legit client, then builds a malicious site that loads the authorization server's authorization page inside a see-through iframe. That iframe sits on top of fake buttons, carefully placed right under the important buttons on the real page ๐Ÿ˜ค. When the end-user clicks a visible fake button, they're actually clicking an invisible one, like an "Authorize" button. That's how an attacker tricks a resource owner into granting access without knowing it.

To prevent this, native applications SHOULD use external browsers instead of embedding browsers inside the app when they ask for end-user authorization ๐Ÿฆ‹. For most newer browsers, the authorization server can block framing using the (non-standard) x-frame-options header. That header has two values, "deny" and "sameorigin". One blocks all framing, and the other blocks framing by sites with a different origin. For older browsers, JavaScript frame-busting techniques can work, but they might not be effective in every browser ๐Ÿฅฒ.

10.14. Code Injection and Input Validation ๐Ÿ’‰

A code injection attack happens when an input, or some other external variable, gets used by an app without being sanitized, and that changes the app's logic ๐Ÿ’€. This can give an attacker access to the app's device or its data, cause denial of service, or lead to a whole mess of other malicious side effects.

The authorization server and client MUST sanitize (and validate when possible) any value they receive, especially the state and redirect_uri parameters ๐Ÿงผ.

10.15. Open Redirectors ๐Ÿšช

The authorization server, the authorization endpoint, and the client's redirection endpoint can all be misconfigured and end up acting as open redirectors ๐Ÿ™ƒ. An open redirector is an endpoint that uses a parameter to automatically send a user-agent to whatever location that parameter says, with no validation at all.

Open redirectors can be used in phishing attacks, or by an attacker to get end-users to visit malicious sites by borrowing the URI authority component of a familiar, trusted destination ๐ŸŽฃ. Also, if the authorization server only lets the client register part of its redirection URI, an attacker can use an open redirector operated by the client to build a redirection URI that passes validation. Then it sends the authorization code or access token to an endpoint the attacker controls ๐Ÿ˜ˆ.

10.16. Misuse of Access Token to Impersonate Resource Owner in Implicit Flow ๐ŸŽญ

For public clients using implicit flows, this specification doesn't give the client any method to figure out which client an access token was issued to ๐Ÿคท.

A resource owner might willingly delegate access by granting an access token to an attacker's malicious client, maybe because of phishing or some other pretext ๐Ÿชค. An attacker can also steal a token through some other mechanism. Then the attacker can try to impersonate the resource owner by handing that access token to a legitimate public client.

In the implicit flow (response_type=token), the attacker can easily swap the token in the response from the authorization server, replacing the real access token with the one that was previously issued to the attacker ๐Ÿ˜ฌ.

Servers talking to native applications that rely on being passed an access token over the back channel to identify the user of the client can be compromised in a similar way. An attacker just builds a compromised application that can inject arbitrary stolen access tokens ๐Ÿ’”.

Any public client that assumes only the resource owner can present it with a valid access token for the resource is vulnerable to this kind of attack ๐Ÿซ .

This type of attack may expose information about the resource owner at the legitimate client to the attacker (the malicious client). It also lets the attacker do things at the legitimate client with the same permissions as the resource owner who originally granted the access token or authorization code ๐Ÿ‘€.

Authenticating resource owners to clients is out of scope for this specification. Any specification that uses the authorization process as a form of delegated end-user authentication to the client (e.g., third-party sign-in service) MUST NOT use the implicit flow without additional security mechanisms. Those mechanisms would let the client check that the access token was issued for its use (e.g., audience-restricting the access token) ๐Ÿ”’.


11. IANA Considerations ๐Ÿ“‹

11.1. OAuth Access Token Types Registry ๐Ÿ—‚๏ธ

This specification establishes the OAuth Access Token Types registry.

Access token types are registered with a Specification Required ([RFC5226]) after a two-week review period on the oauth-ext-review@ietf.org mailing list, on the advice of one or more Designated Experts. To allow values to be allocated before publication, though, the Designated Expert(s) may approve a registration once they're satisfied that such a specification will be published โœจ.

Registration requests must be sent to the oauth-ext-review@ietf.org mailing list for review and comment, with an appropriate subject (e.g., "Request for access token type: example") ๐Ÿ“ฌ.

Within the review period, the Designated Expert(s) will either approve or deny the request, and they'll communicate that decision to the review list and IANA. Denials should include an explanation and, if applicable, suggestions for how to make the request successful ๐Ÿ’….

IANA must only accept registry updates from the Designated Expert(s) and should direct all requests for registration to the review mailing list ๐Ÿซถ.

11.1.1. Registration Template

Type name:
   The name requested (e.g., "example").

Additional Token Endpoint Response Parameters:
   Additional response parameters returned together with the
   "access_token" parameter.  New parameters MUST be separately
   registered in the OAuth Parameters registry as described by
   Section 11.2.

HTTP Authentication Scheme(s):
   The HTTP authentication scheme name(s), if any, used to
   authenticate protected resource requests using access tokens of
   this type.

Change controller:
   For Standards Track RFCs, state "IETF".  For others, give the name
   of the responsible party.  Other details (e.g., postal address,
   email address, home page URI) may also be included.

Specification document(s):
   Reference to the document(s) that specify the parameter,
   preferably including a URI that can be used to retrieve a copy of
   the document(s).  An indication of the relevant sections may also
   be included but is not required.

11.2. OAuth Parameters Registry ๐Ÿงพ

This specification establishes the OAuth Parameters registry.

Additional parameters for inclusion in the authorization endpoint request, the authorization endpoint response, the token endpoint request, or the token endpoint response get registered with a Specification Required ([RFC5226]) after a two-week review period on the oauth-ext-review@ietf.org mailing list, on the advice of one or more Designated Experts. Again, so values can be allocated before publication, the Designated Expert(s) may approve registration once they're satisfied such a specification will be published ๐ŸŒธ.

Registration requests must be sent to the oauth-ext-review@ietf.org mailing list for review and comment, with an appropriate subject (e.g., "Request for parameter: example") ๐Ÿ’Œ.

Within the review period, the Designated Expert(s) will either approve or deny the request and communicate that decision to the review list and IANA. Denials should include an explanation and, if applicable, suggestions for making the request successful ๐Ÿฆ‹.

IANA must only accept registry updates from the Designated Expert(s) and should direct all requests for registration to the review mailing list โญ.

11.2.1. Registration Template

Parameter name:
   The name requested (e.g., "example").

Parameter usage location:
   The location(s) where parameter can be used.  The possible
   locations are authorization request, authorization response, token
   request, or token response.

Change controller:
   For Standards Track RFCs, state "IETF".  For others, give the name
   of the responsible party.  Other details (e.g., postal address,
   email address, home page URI) may also be included.

Specification document(s):
   Reference to the document(s) that specify the parameter,
   preferably including a URI that can be used to retrieve a copy of
   the document(s).  An indication of the relevant sections may also
   be included but is not required.

11.2.2. Initial Registry Contents โœจ

Okay bestie, here's the starter pack for the OAuth Parameters registry ๐Ÿ’– Every entry is IETF-controlled and points back to RFC 6749, so it's giving consistency ๐Ÿ’…

Parameter name: client_id
Parameter usage location: authorization request, token request
Change controller: IETF
Specification document(s): RFC 6749

Parameter name: client_secret
Parameter usage location: token request
Change controller: IETF
Specification document(s): RFC 6749

Parameter name: response_type
Parameter usage location: authorization request
Change controller: IETF
Specification document(s): RFC 6749

Parameter name: redirect_uri
Parameter usage location: authorization request, token request
Change controller: IETF
Specification document(s): RFC 6749

Parameter name: scope
Parameter usage location: authorization request, authorization response, token request, token response
Change controller: IETF
Specification document(s): RFC 6749

Parameter name: state
Parameter usage location: authorization request, authorization response
Change controller: IETF
Specification document(s): RFC 6749

Parameter name: code
Parameter usage location: authorization response, token request
Change controller: IETF
Specification document(s): RFC 6749

Parameter name: error_description
Parameter usage location: authorization response, token response
Change controller: IETF
Specification document(s): RFC 6749

Parameter name: error_uri
Parameter usage location: authorization response, token response
Change controller: IETF
Specification document(s): RFC 6749

Parameter name: grant_type
Parameter usage location: token request
Change controller: IETF
Specification document(s): RFC 6749

Parameter name: access_token
Parameter usage location: authorization response, token response
Change controller: IETF
Specification document(s): RFC 6749

Parameter name: token_type
Parameter usage location: authorization response, token response
Change controller: IETF
Specification document(s): RFC 6749

Parameter name: expires_in
Parameter usage location: authorization response, token response
Change controller: IETF
Specification document(s): RFC 6749

Parameter name: username
Parameter usage location: token request
Change controller: IETF
Specification document(s): RFC 6749

Parameter name: password
Parameter usage location: token request
Change controller: IETF
Specification document(s): RFC 6749

Parameter name: refresh_token
Parameter usage location: token request, token response
Change controller: IETF
Specification document(s): RFC 6749

11.3. OAuth Authorization Endpoint Response Types Registry ๐Ÿฆ‹

This spec sets up the OAuth Authorization Endpoint Response Types registry, which is the official list of response types you can use at the authorization endpoint ๐ŸŒธ

New response types get added with a Specification Required ([RFC5226]) policy. That means a two-week review period on the oauth-ext-review@ietf.org mailing list, with advice from one or more Designated Experts. Real talk, the Designated Experts can also approve a registration before the spec is actually published, but only once they're satisfied that the spec will get published ๐Ÿ”ฅ

Registration requests go to the oauth-ext-review@ietf.org list for review and comment. Use a clear subject line like "Request for response type: example" so everyone knows what's up โœจ

During the review period, the Designated Experts will either approve or deny the request, and they'll tell both the review list and IANA what they decided. If they deny it, they should explain why and, where it makes sense, suggest how to get it approved next time ๐Ÿ’œ

IANA must only accept registry updates from the Designated Experts, and it should send all registration requests over to the review mailing list ๐Ÿ™ˆ

11.3.1. Registration Template ๐ŸŽ€

  • Response type name: This is the name you're requesting (e.g., "example"). Pick something that slaps ๐Ÿ’…
  • Change controller: For Standards Track RFCs, write "IETF". For everything else, put down the name of the responsible party. You can also add extra details like a postal address, email address, or home page URI ๐ŸŒˆ
  • Specification document(s): Point to the document(s) that define the type. A URI where people can grab a copy is preferred. Pointing at the relevant sections is optional, and it's not required ๐Ÿซถ

11.3.2. Initial Registry Contents ๐Ÿ’–

Here are the starter response types, both IETF-controlled and both defined in RFC 6749:

Response type name: code
Change controller: IETF
Specification document(s): RFC 6749

Response type name: token
Change controller: IETF
Specification document(s): RFC 6749

11.4. OAuth Extensions Error Registry ๐ŸŒธ

This spec sets up the OAuth Extensions Error registry for error codes that show up alongside protocol extensions ๐Ÿงš

If an extension grant type, access token type, or extension parameter needs its own error codes, they get registered with a Specification Required ([RFC5226]) policy. Same deal as before: a two-week review period on the oauth-ext-review@ietf.org mailing list, with advice from one or more Designated Experts. The Designated Experts can approve a registration before publication too, once they're satisfied the spec will be published ๐Ÿ’…

Registration requests go to the oauth-ext-review@ietf.org list for review and comment. Use a subject line like "Request for error code: example" ๐Ÿฆ‹

Within the review period, the Designated Experts will approve or deny the request and communicate the decision to the review list and IANA. Denials should include an explanation and, if it applies, suggestions for making the request successful โœจ

IANA must only accept registry updates from the Designated Experts, and should direct all registration requests to the review mailing list ๐Ÿ’œ

11.4.1. Registration Template ๐ŸŽ€

  • Error name: This is the name you're requesting (e.g., "example"). Error name values MUST NOT include characters outside the set %x20-21 / %x23-5B / %x5D-7E ๐Ÿ™ˆ
  • Error usage location: The location(s) where the error can be used. The possible locations are authorization code grant error response (Section 4.1.2.1), implicit grant error response (Section 4.2.2.1), token error response (Section 5.2), or resource access error response (Section 7.2) ๐ŸŒˆ
  • Related protocol extension: The name of the extension grant type, access token type, or extension parameter that the error code is used with ๐Ÿ“
  • Change controller: For Standards Track RFCs, write "IETF". For others, give the name of the responsible party. Other details (e.g., postal address, email address, home page URI) may also be included ๐Ÿ’–
  • Specification document(s): Point to the document(s) that define the error code. A URI where people can grab a copy is preferred. Pointing at the relevant sections is optional, and it's not required ๐Ÿซถ

12. References ๐ŸŒˆ

12.1. Normative References ๐Ÿ’œ

[RFC2119]  Bradner, S., "Key words for use in RFCs to Indicate
           Requirement Levels", BCP 14, RFC 2119, March 1997.

[RFC2246]  Dierks, T. and C. Allen, "The TLS Protocol Version 1.0",
           RFC 2246, January 1999.

[RFC2616]  Fielding, R., Gettys, J., Mogul, J., Frystyk, H.,
           Masinter, L., Leach, P., and T. Berners-Lee, "Hypertext
           Transfer Protocol -- HTTP/1.1", RFC 2616, June 1999.

[RFC2617]  Franks, J., Hallam-Baker, P., Hostetler, J., Lawrence, S.,
           Leach, P., Luotonen, A., and L. Stewart, "HTTP
           Authentication: Basic and Digest Access Authentication",
           RFC 2617, June 1999.

[RFC2818]  Rescorla, E., "HTTP Over TLS", RFC 2818, May 2000.

[RFC3629]  Yergeau, F., "UTF-8, a transformation format of
           ISO 10646", STD 63, RFC 3629, November 2003.

[RFC3986]  Berners-Lee, T., Fielding, R., and L. Masinter, "Uniform
           Resource Identifier (URI): Generic Syntax", STD 66,
           RFC 3986, January 2005.

[RFC4627]  Crockford, D., "The application/json Media Type for
           JavaScript Object Notation (JSON)", RFC 4627, July 2006.

[RFC4949]  Shirey, R., "Internet Security Glossary, Version 2",
           RFC 4949, August 2007.

[RFC5226]  Narten, T. and H. Alvestrand, "Guidelines for Writing an
           IANA Considerations Section in RFCs", BCP 26, RFC 5226,
           May 2008.

[RFC5234]  Crocker, D. and P. Overell, "Augmented BNF for Syntax
           Specifications: ABNF", STD 68, RFC 5234, January 2008.

[RFC5246]  Dierks, T. and E. Rescorla, "The Transport Layer Security
           (TLS) Protocol Version 1.2", RFC 5246, August 2008.

[RFC6125]  Saint-Andre, P. and J. Hodges, "Representation and
           Verification of Domain-Based Application Service Identity
           within Internet Public Key Infrastructure Using X.509
           (PKIX) Certificates in the Context of Transport Layer
           Security (TLS)", RFC 6125, March 2011.

[USASCII]  American National Standards Institute, "Coded Character
           Set -- 7-bit American Standard Code for Information
           Interchange", ANSI X3.4, 1986.

[W3C.REC-html401-19991224]
           Raggett, D., Le Hors, A., and I. Jacobs, "HTML 4.01
           Specification", World Wide Web Consortium
           Recommendation REC-html401-19991224, December 1999,
           <http://www.w3.org/TR/1999/REC-html401-19991224>.

[W3C.REC-xml-20081126]
           Bray, T., Paoli, J., Sperberg-McQueen, C., Maler, E.,
           and F. Yergeau, "Extensible Markup Language (XML) 1.0
           (Fifth Edition)", World Wide Web Consortium
            Recommendation REC-xml-20081126, November 2008,
           <http://www.w3.org/TR/2008/REC-xml-20081126>.

12.2. Informative References ๐Ÿฆ‹

[OAuth-HTTP-MAC]
           Hammer-Lahav, E., Ed., "HTTP Authentication: MAC Access
           Authentication", Work in Progress, February 2012.

[OAuth-SAML2]
           Campbell, B. and C. Mortimore, "SAML 2.0 Bearer Assertion
           Profiles for OAuth 2.0", Work in Progress, September 2012.

[OAuth-THREATMODEL]
           Lodderstedt, T., Ed., McGloin, M., and P. Hunt, "OAuth 2.0
           Threat Model and Security Considerations", Work
           in Progress, October 2012.

[OAuth-WRAP]
           Hardt, D., Ed., Tom, A., Eaton, B., and Y. Goland, "OAuth
           Web Resource Authorization Profiles", Work in Progress,
           January 2010.

[RFC5849]  Hammer-Lahav, E., "The OAuth 1.0 Protocol", RFC 5849,
           April 2010.

[RFC6750]  Jones, M. and D. Hardt, "The OAuth 2.0 Authorization
           Framework: Bearer Token Usage", RFC 6750, October 2012.

Appendix A. Augmented Backus-Naur Form (ABNF) Syntax โœจ

okay bestie, this is the grammar appendix ๐Ÿค“๐Ÿ’… it's where all the ABNF syntax for the stuff defined earlier in the spec lives, so you can check every single rule. the ABNF uses the notation from [RFC5234] ๐ŸŽ€ and it's defined in terms of Unicode code points [W3C.REC-xml-20081126], which are typically encoded in UTF-8 ๐ŸŒˆ. the elements are listed in the order they were first defined, so it reads like a little tour ๐Ÿฆ‹

some of the definitions use the "URI-reference" definition from [RFC3986] ๐Ÿ”—

some of the definitions below also use these common definitions ๐Ÿ’–

VSCHAR     = %x20-7E
NQCHAR     = %x21 / %x23-5B / %x5D-7E
NQSCHAR    = %x20-21 / %x23-5B / %x5D-7E
UNICODECHARNOCRLF = %x09 /%x20-7E / %x80-D7FF /
                    %xE000-FFFD / %x10000-10FFFF

(the UNICODECHARNOCRLF one is based on the Char definition in Section 2.2 of [W3C.REC-xml-20081126], but with Carriage Return and Linefeed left out ๐Ÿ™ˆโœจ)

A.1. "client_id" Syntax

the "client_id" element is defined in Section 2.3.1 ๐Ÿชช

client-id     = *VSCHAR

A.2. "client_secret" Syntax

the "client_secret" element is defined in Section 2.3.1 ๐Ÿ”

client-secret = *VSCHAR

A.3. "response_type" Syntax

the "response_type" element is defined in Sections 3.1.1 and 8.4 ๐ŸŽฏ

response-type = response-name *( SP response-name )
response-name = 1*response-char
response-char = "_" / DIGIT / ALPHA

A.4. "scope" Syntax

the "scope" element is defined in Section 3.3 ๐Ÿง

scope       = scope-token *( SP scope-token )
scope-token = 1*NQCHAR

A.5. "state" Syntax

the "state" element is defined in Sections 4.1.1, 4.1.2, 4.1.2.1, 4.2.1, 4.2.2, and 4.2.2.1 ๐ŸŒธ

state      = 1*VSCHAR

A.6. "redirect_uri" Syntax

the "redirect_uri" element is defined in Sections 4.1.1, 4.1.3, and 4.2.1 ๐Ÿฆ‹

redirect-uri      = URI-reference

A.7. "error" Syntax

the "error" element is defined in Sections 4.1.2.1, 4.2.2.1, 5.2, 7.2, and 8.5 ๐Ÿšจ

error             = 1*NQSCHAR

A.8. "error_description" Syntax

the "error_description" element is defined in Sections 4.1.2.1, 4.2.2.1, 5.2, and 7.2 ๐Ÿ“

error-description = 1*NQSCHAR

A.9. "error_uri" Syntax

the "error_uri" element is defined in Sections 4.1.2.1, 4.2.2.1, 5.2, and 7.2 ๐Ÿ”—

error-uri         = URI-reference

A.10. "grant_type" Syntax

the "grant_type" element is defined in Sections 4.1.3, 4.3.2, 4.4.2, 4.5, and 6 ๐ŸŽŸ๏ธ

grant-type = grant-name / URI-reference
grant-name = 1*name-char
name-char  = "-" / "." / "_" / DIGIT / ALPHA

A.11. "code" Syntax

the "code" element is defined in Section 4.1.3 ๐Ÿงพ

code       = 1*VSCHAR

A.12. "access_token" Syntax

the "access_token" element is defined in Sections 4.2.2 and 5.1 ๐Ÿ—๏ธ

access-token = 1*VSCHAR

A.13. "token_type" Syntax

the "token_type" element is defined in Sections 4.2.2, 5.1, and 8.1 ๐Ÿท๏ธ

token-type = type-name / URI-reference
type-name  = 1*name-char
name-char  = "-" / "." / "_" / DIGIT / ALPHA

A.14. "expires_in" Syntax

the "expires_in" element is defined in Sections 4.2.2 and 5.1 โฐ

expires-in = 1*DIGIT

A.15. "username" Syntax

the "username" element is defined in Section 4.3.2 ๐Ÿ‘ค

username = *UNICODECHARNOCRLF

A.16. "password" Syntax

the "password" element is defined in Section 4.3.2 ๐Ÿ™Š

password = *UNICODECHARNOCRLF

A.17. "refresh_token" Syntax

the "refresh_token" element is defined in Sections 5.1 and 6 ๐Ÿ”„

refresh-token = 1*VSCHAR

A.18. Endpoint Parameter Syntax

the syntax for new endpoint parameters is defined in Section 8.2 ๐Ÿงฉ

param-name = 1*name-char
name-char  = "-" / "." / "_" / DIGIT / ALPHA

Appendix B. Use of application/x-www-form-urlencoded Media Type

okay so, story time ๐Ÿ“– at the time this spec was published, the "application/x-www-form-urlencoded" media type was defined in Section 17.13.4 of [W3C.REC-html401-19991224] but it was NOT registered in the IANA MIME Media Types registry (http://www.iana.org/assignments/media-types) ๐Ÿ˜ฌ and the definition was incomplete too, because it didn't cover non-US-ASCII characters. messy ๐Ÿ’€

so to fix that gap, when you're generating payloads with this media type, names and values MUST be encoded using the UTF-8 character encoding scheme [RFC3629] first ๐Ÿซถ then the resulting octet sequence gets further encoded using the escaping rules from [W3C.REC-html401-19991224] ๐ŸŒˆ

when you're parsing a payload using this media type, the names and values you get after reversing the name/value encoding need to be treated as octet sequences and decoded with UTF-8 ๐Ÿงš

for example ๐Ÿ“ the value made of these six Unicode code points: (1) U+0020 (SPACE), (2) U+0025 (PERCENT SIGN), (3) U+0026 (AMPERSAND), (4) U+002B (PLUS SIGN), (5) U+00A3 (POUND SIGN), and (6) U+20AC (EURO SIGN) would be encoded into this octet sequence (hexadecimal notation) ๐Ÿ‘‡

20 25 26 2B C2 A3 E2 82 AC

and then represented in the payload as ๐Ÿ‘‡

+%25%26%2B%C2%A3%E2%82%AC

Appendix C. Acknowledgements

the big thank-you section ๐Ÿซถ๐Ÿ’– the initial OAuth 2.0 protocol spec was edited by David Recordon, based on two earlier publications: the OAuth 1.0 community specification [RFC5849] and OAuth WRAP (OAuth Web Resource Authorization Profiles) [OAuth-WRAP] ๐ŸŒŸ Eran Hammer then edited a lot of the intermediate drafts that turned into this RFC ๐Ÿ™Œ the Security Considerations section was drafted by Torsten Lodderstedt, Mark McGloin, Phil Hunt, Anthony Nadalin, and John Bradley ๐Ÿ” the section on use of the "application/x-www-form-urlencoded" media type was drafted by Julian Reschke ๐ŸŽ€ and the ABNF section was drafted by Michael B. Jones ๐Ÿง 

the OAuth 1.0 community specification was edited by Eran Hammer and authored by Mark Atwood, Dirk Balfanz, Darren Bounds, Richard M. Conlan, Blaine Cook, Leah Culver, Breno de Medeiros, Brian Eaton, Kellan Elliott-McCrea, Larry Halff, Eran Hammer, Ben Laurie, Chris Messina, John Panzer, Sam Quigley, David Recordon, Eran Sandler, Jonathan Sergent, Todd Sieling, Brian Slesinsky, and Andy Smith ๐Ÿ™

the OAuth WRAP specification was edited by Dick Hardt and authored by Brian Eaton, Yaron Y. Goland, Dick Hardt, and Allen Tom ๐ŸŽ‰

this spec is the work of the OAuth Working Group, which has dozens of active and dedicated people in it ๐Ÿ the following individuals contributed ideas, feedback, and wording that shaped the final specification โœจ:

Michael Adams, Amanda Anganes, Andrew Arnott, Dirk Balfanz, Aiden Bell, John Bradley, Marcos Caceres, Brian Campbell, Scott Cantor, Blaine Cook, Roger Crew, Leah Culver, Bill de hOra, Andre DeMarre, Brian Eaton, Wesley Eddy, Wolter Eldering, Brian Ellin, Igor Faynberg, George Fletcher, Tim Freeman, Luca Frosini, Evan Gilbert, Yaron Y. Goland, Brent Goldman, Kristoffer Gronowski, Eran Hammer, Dick Hardt, Justin Hart, Craig Heath, Phil Hunt, Michael B. Jones, Terry Jones, John Kemp, Mark Kent, Raffi Krikorian, Chasen Le Hara, Rasmus Lerdorf, Torsten Lodderstedt, Hui-Lan Lu, Casey Lucas, Paul Madsen, Alastair Mair, Eve Maler, James Manger, Mark McGloin, Laurence Miao, William Mills, Chuck Mortimore, Anthony Nadalin, Julian Reschke, Justin Richer, Peter Saint-Andre, Nat Sakimura, Rob Sayre, Marius Scurtescu, Naitik Shah, Luke Shepard, Vlad Skvortsov, Justin Smith, Haibin Song, Niv Steingarten, Christian Stuebner, Jeremy Suriel, Paul Tarjan, Christopher Thomas, Henry S. Thompson, Allen Tom, Franklin Tse, Nick Walker, Shane Weeden, and Skylar Woodward ๐Ÿ’…๐ŸŒธ

this document was produced under the chairmanship of Blaine Cook, Peter Saint-Andre, Hannes Tschofenig, Barry Leiba, and Derek Atkins ๐Ÿ‘‘ the area directors were Lisa Dusseault, Peter Saint-Andre, and Stephen Farrell ๐Ÿฆ‹

Author's Address โœจ

Dick Hardt (editor) ๐ŸŽ€ Microsoft

EMail: dick.hardt@gmail.com URI: http://dickhardt.org/

๐Ÿ“ฆ where this page comes from