Internet Engineering Task Force (IETF) D. Hardt, Ed. Request for Comments: 6749 Microsoft Obsoletes: 5849 October 2012 Category: Standards Track ISSN: 2070-1721 The OAuth 2.0 Authorization Framework Abstract The OAuth 2.0 authorization framework enables a third-party application to obtain limited access to an HTTP service, either on behalf of a resource owner by orchestrating an approval interaction between the resource owner and the HTTP service, or by allowing the third-party application to obtain access on its own behalf. This specification replaces and obsoletes the OAuth 1.0 protocol described in RFC 5849. Status of This Memo This is an Internet Standards Track document. This document is a product of the Internet Engineering Task Force (IETF). It represents the consensus of the IETF community. It has received public review and has been approved for publication by the Internet Engineering Steering Group (IESG). Further information on Internet Standards is available in Section 2 of RFC 5741. Information about the current status of this document, any errata, and how to provide feedback on it may be obtained at 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) in effect on the date of publication of this document. Please review these documents carefully, as they describe your rights and restrictions with respect to this document. Code Components extracted from this document must include Simplified BSD License text as described in Section 4.e of the Trust Legal Provisions and are provided without warranty as described in the Simplified BSD License. Hardt Standards Track [Page 1] RFC 6749 OAuth 2.0 October 2012 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 Hardt Standards Track [Page 2] RFC 6749 OAuth 2.0 October 2012 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 Hardt Standards Track [Page 3] RFC 6749 OAuth 2.0 October 2012 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 1. Introduction In the traditional client-server authentication model, the client requests an access-restricted resource (protected resource) on the server by authenticating with the server using the resource owner's credentials. In order to provide third-party applications access to restricted resources, the resource owner shares its credentials with the third party. This creates several problems and limitations: o Third-party applications are required to store the resource owner's credentials for future use, typically a password in clear-text. o Servers are required to support password authentication, despite the security weaknesses inherent in passwords. o Third-party applications gain overly broad access to the resource owner's protected resources, leaving resource owners without any ability to restrict duration or access to a limited subset of resources. o Resource owners cannot revoke access to an individual third party without revoking access to all third parties, and must do so by changing the third party's password. Hardt Standards Track [Page 4] RFC 6749 OAuth 2.0 October 2012 o Compromise of any third-party application results in compromise of the end-user's password and all of the data protected by that password. OAuth addresses these issues by introducing an authorization layer and separating the role of the client from that of the resource owner. In OAuth, the client requests access to resources controlled by the resource owner and hosted by the resource server, and is issued a different set of credentials than those of the resource owner. Instead of using the resource owner's credentials to access protected resources, the client obtains an access token -- a string denoting a specific scope, lifetime, and other access attributes. Access tokens are issued to third-party clients by an authorization server with the approval of the resource owner. The client uses the access token to access the protected resources hosted by the resource server. For example, an end-user (resource owner) can grant a printing service (client) access to her protected photos stored at a photo- sharing service (resource server), without sharing her username and password with the printing service. Instead, she authenticates directly with a server trusted by the photo-sharing service (authorization server), which issues the printing service delegation- specific credentials (access token). This specification is designed for use with HTTP ([RFC2616]). The use of OAuth over any protocol other than HTTP is out of scope. The OAuth 1.0 protocol ([RFC5849]), published as an informational document, was the result of a small ad hoc community effort. This Standards Track specification builds on the OAuth 1.0 deployment experience, as well as additional use cases and extensibility requirements gathered from the wider IETF community. The OAuth 2.0 protocol is not backward compatible with OAuth 1.0. The two versions may co-exist on the network, and implementations may choose to support both. However, it is the intention of this specification that new implementations support OAuth 2.0 as specified in this document and that OAuth 1.0 is used only to support existing deployments. The OAuth 2.0 protocol shares very few implementation details with the OAuth 1.0 protocol. Implementers familiar with OAuth 1.0 should approach this document without any assumptions as to its structure and details. Hardt Standards Track [Page 5] RFC 6749 OAuth 2.0 October 2012 1.1. Roles OAuth defines four roles: resource owner An entity capable of granting access to a protected resource. When the resource owner is a person, it is referred to as an end-user. resource server The server hosting the protected resources, capable of accepting and responding to protected resource requests using access tokens. client An application making protected resource requests on behalf of the resource owner and with its authorization. The term "client" does not imply any particular implementation characteristics (e.g., whether the application executes on a server, a desktop, or other devices). authorization server The server issuing access tokens to the client after successfully authenticating the resource owner and obtaining authorization. The interaction between the authorization server and resource server is beyond the scope of this specification. The authorization server may be the same server as the resource server or a separate entity. A single authorization server may issue access tokens accepted by multiple resource servers. Hardt Standards Track [Page 6] RFC 6749 OAuth 2.0 October 2012 1.2. Protocol Flow +--------+ +---------------+ | |--(A)- Authorization Request ->| Resource | | | | Owner | | || Authorization | | Client | | Server | | || Resource | | | | Server | | || | | | | | | || | | | | | | | | | | || | | | | | | | | | | || | | | | | | || | | User- | | Authorization | | Agent -+----(B)-- User authenticates --->| Server | | | | | | -+----(C)-- Authorization Code ------(D)-- Authorization Code ---------' | | Client | & Redirection URI | | | | | || | | User- | | Authorization | | Agent -|----(B)-- User authenticates -->| Server | | | | | | || Web-Hosted | | | without Fragment | Client | | | | Resource | | (F) |--(B)---- Resource Owner ------->| | | | Password Credentials | Authorization | | Client | | Server | | |--(A)- Client Authentication --->| Authorization | | Client | | Server | | |. [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, . Hardt Standards Track [Page 69] RFC 6749 OAuth 2.0 October 2012 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. Hardt Standards Track [Page 70] RFC 6749 OAuth 2.0 October 2012 Appendix A. Augmented Backus-Naur Form (ABNF) Syntax This section provides Augmented Backus-Naur Form (ABNF) syntax descriptions for the elements defined in this specification using the notation of [RFC5234]. The ABNF below is defined in terms of Unicode code points [W3C.REC-xml-20081126]; these characters are typically encoded in UTF-8. Elements are presented in the order first defined. Some of the definitions that follow use the "URI-reference" definition from [RFC3986]. Some of the definitions that follow 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 definition is based upon the Char definition in Section 2.2 of [W3C.REC-xml-20081126], but omitting the Carriage Return and Linefeed characters.) 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 Hardt Standards Track [Page 71] RFC 6749 OAuth 2.0 October 2012 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 Hardt Standards Track [Page 72] RFC 6749 OAuth 2.0 October 2012 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 Hardt Standards Track [Page 73] RFC 6749 OAuth 2.0 October 2012 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 At the time of publication of this specification, the "application/x-www-form-urlencoded" media type was defined in Section 17.13.4 of [W3C.REC-html401-19991224] but not registered in the IANA MIME Media Types registry (). Furthermore, that definition is incomplete, as it does not consider non-US-ASCII characters. To address this shortcoming when generating payloads using this media type, names and values MUST be encoded using the UTF-8 character encoding scheme [RFC3629] first; the resulting octet sequence then needs to be further encoded using the escaping rules defined in [W3C.REC-html401-19991224]. When parsing data from a payload using this media type, the names and values resulting from reversing the name/value encoding consequently need to be treated as octet sequences, to be decoded using the UTF-8 character encoding scheme. For example, the value consisting of the 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 the octet sequence below (using 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 Hardt Standards Track [Page 74] RFC 6749 OAuth 2.0 October 2012 Appendix C. Acknowledgements The initial OAuth 2.0 protocol specification was edited by David Recordon, based on two previous publications: the OAuth 1.0 community specification [RFC5849], and OAuth WRAP (OAuth Web Resource Authorization Profiles) [OAuth-WRAP]. Eran Hammer then edited many of the intermediate drafts that evolved 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. 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 specification is the work of the OAuth Working Group, which includes dozens of active and dedicated participants. In particular, the following individuals contributed ideas, feedback, and wording that shaped and formed 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. Hardt Standards Track [Page 75] RFC 6749 OAuth 2.0 October 2012 This document was produced under the chairmanship of Blaine Cook, Peter Saint-Andre, Hannes Tschofenig, Barry Leiba, and Derek Atkins. The area directors included Lisa Dusseault, Peter Saint-Andre, and Stephen Farrell. Author's Address Dick Hardt (editor) Microsoft EMail: [email protected] URI: http://dickhardt.org/ Hardt Standards Track [Page 76]