RFC 6749
The OAuth 2.0 Authorization Framework
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 Notice ๐
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 astateparameter 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_tokenREQUIRED. The access token issued by the authorization server.token_typeREQUIRED. The type of the token issued, as described in Section 7.1. Value is case insensitive.expires_inRECOMMENDED. 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_tokenOPTIONAL. The refresh token, which can be used to get new access tokens using the same authorization grant, as described in Section 6 ๐.scopeOPTIONAL, 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 ๐จ:
errorREQUIRED. A single ASCII [USASCII] error code from the following list:invalid_requestThe 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_clientClient 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_grantThe 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_clientThe authenticated client is not authorized to use this authorization grant type ๐ .unsupported_grant_typeThe authorization server doesn't support this authorization grant type ๐คทโโ๏ธ.invalid_scopeThe 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_descriptionOPTIONAL. 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_uriOPTIONAL. 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_typeREQUIRED. Value MUST be set to "refresh_token".refresh_tokenREQUIRED. The refresh token issued to the client.scopeOPTIONAL. 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
- ietf: rfc6749 2012-10
- ๐ girlified by claude-haiku-5-5 on : a language model's rewrite of the original, under its terms