Internet-Draft | The OAuth 2.1 Authorization Framework | March 2023 |
Hardt, et al. | Expires 14 September 2023 | [Page] |
The OAuth 2.1 authorization framework enables an application to obtain limited access to a protected resource, either on behalf of a resource owner by orchestrating an approval interaction between the resource owner and an authorization service, or by allowing the application to obtain access on its own behalf. This specification replaces and obsoletes the OAuth 2.0 Authorization Framework described in RFC 6749 and the Bearer Token Usage in RFC 6750.¶
This note is to be removed before publishing as an RFC.¶
Discussion of this document takes place on the OAuth Working Group mailing list (oauth@ietf.org), which is archived at https://mailarchive.ietf.org/arch/browse/oauth/.¶
Source for this draft and an issue tracker can be found at https://github.com/oauth-wg/oauth-v2-1.¶
This Internet-Draft is submitted in full conformance with the provisions of BCP 78 and BCP 79.¶
Internet-Drafts are working documents of the Internet Engineering Task Force (IETF). Note that other groups may also distribute working documents as Internet-Drafts. The list of current Internet-Drafts is at https://datatracker.ietf.org/drafts/current/.¶
Internet-Drafts are draft documents valid for a maximum of six months and may be updated, replaced, or obsoleted by other documents at any time. It is inappropriate to use Internet-Drafts as reference material or to cite them other than as "work in progress."¶
This Internet-Draft will expire on 14 September 2023.¶
Copyright (c) 2023 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 (https://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 Revised BSD License text as described in Section 4.e of the Trust Legal Provisions and are provided without warranty as described in the Revised BSD License.¶
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 applications access to restricted resources, the resource owner shares their credentials with the application. This creates several problems and limitations:¶
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. Instead of using the resource owner's credentials to access protected resources, the client obtains an access token - a credential representing a specific set of access attributes such as scope and lifetime. Access tokens are issued to 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 their protected photos stored at a photo- sharing service (resource server), without sharing their username and password with the printing service. Instead, they authenticate directly with a server trusted by the photo-sharing service (authorization server), which issues the printing service delegation- specific credentials (access token).¶
This separation of concerns also provides the ability to use more advanced user authentication methods such as multi-factor authentication and even passwordless authentication, without any modification to the applications. With all user authentication logic handled by the authorization server, applications don't need to be concerned with the specifics of implementing any particular authentication mechanism. This provides the ability for the authorization server to manage the user authentication policies and even change them in the future without coordinating the changes with applications.¶
This specification is designed for use with HTTP ([RFC9110]). The use of OAuth over any protocol other than HTTP is out of scope.¶
Since the publication of the OAuth 2.0 Authorization Framework ([RFC6749]) in October 2012, it has been updated by OAuth 2.0 for Native Apps ([RFC8252]), OAuth Security Best Current Practice ([I-D.ietf-oauth-security-topics]), and OAuth 2.0 for Browser-Based Apps ([I-D.ietf-oauth-browser-based-apps]). The OAuth 2.0 Authorization Framework: Bearer Token Usage ([RFC6750]) has also been updated with ([I-D.ietf-oauth-security-topics]). This Standards Track specification consolidates the information in all of these documents and removes features that have been found to be insecure in [I-D.ietf-oauth-security-topics].¶
OAuth defines four roles:¶
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. This is sometimes abbreviated as "RO".¶
The server hosting the protected resources, capable of accepting and responding to protected resource requests using access tokens. The resource server is often accessible via an API. This is sometimes abbreviated as "RS".¶
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).¶
The server issuing access tokens to the client after successfully authenticating the resource owner and obtaining authorization. This is sometimes abbreviated as "AS".¶
The interaction between the authorization server and resource server is beyond the scope of this specification, however several extensions have been defined to provide an option for interoperability between resource servers and authorization servers. 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.¶
The abstract OAuth 2.1 flow illustrated in Figure 1 describes the interaction between the four roles and includes the following steps:¶
The preferred method for the client to obtain an authorization grant from the resource owner (depicted in steps (1) and (2)) is to use the authorization server as an intermediary, which is illustrated in Figure 3 in Section 4.1.¶
Access tokens are credentials used to access protected resources. An access token is a string representing an authorization issued to the client. The string is considered opaque to the client, even if it has a structure. Depending on the authorization server, the access token string may be parseable by the resource server, such as when using the JSON Web Token Profile for Access Tokens ([RFC9068]).¶
Access tokens represent specific scopes and durations of access, granted by the resource owner, and enforced by the resource server and authorization server.¶
The token may be used by the RS to retrieve the authorization information, or the token may self-contain the authorization information in a verifiable manner (i.e., a token string consisting of a signed data payload). One example of a token retrieval mechanism is Token Introspection [RFC7662], in which the RS calls an endpoint on the AS to validate the token presented by the client. One example of a structured token format is [RFC9068], a method of encoding access token data as a JSON Web Token [RFC7519].¶
Additional authentication credentials, which are beyond the scope of this specification, may be required in order for the client to use an access token. This is typically referred to as a sender-constrained access token, such as DPoP [I-D.ietf-oauth-dpop] and Mutual TLS Access Tokens [RFC8705].¶
The access token provides an abstraction layer, replacing different authorization constructs (e.g., username and password) with a single token understood by the resource server. This abstraction enables issuing access tokens more restrictive than the authorization grant used to obtain them, as well as removing the resource server's need to understand a wide range of authentication methods.¶
Access tokens can have different formats, structures, and methods of utilization (e.g., cryptographic properties) based on the resource server security requirements. Access token attributes and the methods used to access protected resources may be extended beyond what is described in this specification.¶
Access tokens (as well as 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 to whom the access token is issued.¶
The authorization server MUST ensure that access tokens cannot be generated, modified, or guessed to produce valid access tokens by unauthorized parties.¶
Implementations MUST use a mechanism to provide communication authentication, integrity and confidentiality such as Transport-Layer Security [RFC8446], to protect the exchange of clear-text credentials and tokens either in the content or in header fields from eavesdropping, tampering, and message forgery (eg. see Section 2.4.1, Section 7.6, Section 3.2, and Section 5.2).¶
OAuth URLs MUST use the https
scheme
except for loopback interface redirect URIs,
which MAY use the http
scheme.
When using https
, TLS certificates MUST be checked
according to [RFC9110].
At the time of this writing,
TLS version 1.3 [RFC8446] is the most recent version.¶
Implementations MAY also support additional transport-layer security mechanisms that meet their security requirements.¶
The identification of the TLS versions and algorithms is outside the scope of this specification. Refer to [BCP195] for up to date recommendations on transport layer security, and to the relevant specifications for certificate validation and other security considerations.¶
This specification makes extensive use of HTTP redirections, in which the client or the authorization server directs the resource owner's user agent to another destination. While the examples in this specification show the use of the HTTP 302 status code, any other method available via the user agent to accomplish this redirection, with the exception of HTTP 307, is allowed and is considered to be an implementation detail. See Section 7.5.2 for details.¶
OAuth 2.1 provides a rich authorization framework with well-defined security properties.¶
This specification leaves a few required components partially or fully undefined (e.g., client registration, authorization server capabilities, endpoint discovery). Some of these behaviors are defined in optional extensions which implementations can choose to use, such as:¶
Please refer to Appendix C for a list of current known extensions at the time of this publication.¶
OAuth 2.1 is compatible with OAuth 2.0 with the extensions and restrictions from known best current practices applied. Specifically, features not specified in OAuth 2.0 core, such as PKCE, are required in OAuth 2.1. Additionally, some features available in OAuth 2.0, such as the Implicit or Resource Owner Credentials grant types, are not specified in OAuth 2.1. Furthermore, some behaviors allowed in OAuth 2.0 are restricted in OAuth 2.1, such as the strict string matching of redirect URIs required by OAuth 2.1.¶
See Section 10 for more details on the differences from OAuth 2.0.¶
The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "NOT RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in BCP 14 [RFC2119] [RFC8174] when, and only when, they appear in all capitals, as shown here.¶
This specification uses the Augmented Backus-Naur Form (ABNF) notation of [RFC5234]. Additionally, 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 are not limited to, "attack", "authentication", "authorization", "certificate", "confidentiality", "credential", "encryption", "identity", "sign", "signature", "trust", "validate", and "verify".¶
The term "content" is to be interpreted as described in Section 6.4 of [RFC9110].¶
The term "user agent" is to be interpreted as described in Section 3.5 of [RFC9110].¶
Unless otherwise noted, all the protocol parameter names and values are case sensitive.¶
Before initiating the protocol, the client must establish its registration with the authorization server. The means through which the client registers with the authorization server are beyond the scope of this specification but typically involve the client developer manually registering the client at the authorization server's website after creating an account and agreeing to the service's Terms of Service, or by using Dynamic Client Registration ([RFC7591]).¶
Client registration does not require a direct interaction between the client and the authorization server. When supported by the authorization server, registration can rely on other means for establishing trust and obtaining the required client properties (e.g., redirect URI, client type). For example, registration can be accomplished using a self-issued or third-party-issued assertion, or by the authorization server performing client discovery using a trusted channel.¶
When registering a client, the client developer SHALL:¶
Dynamic Client Registration ([RFC7591]) defines a common general data model for clients that may be used even with manual client registration.¶
OAuth 2.1 defines two client types based on their ability to authenticate securely with the authorization server.¶
Clients that have credentials with the AS are designated as "confidential clients"¶
Clients without credentials are called "public clients"¶
Any clients with credentials MUST take precautions to prevent leakage and abuse of their credentials.¶
Client authentication allows an Authorization Server to ensure it is interacting with a certain client
(identified by its client_id
) in an OAuth flow. The Authorization Server might make policy decisions
about things such as whether to prompt the user for consent on every authorization or only the first
based on the confidence that the Authorization Server is actually communicating with the legitimate client.¶
Whether and how an Authorization Server validates the identity of a client or the party providing/operating this client is out of scope of this specification. Authorization servers SHOULD consider the level of confidence in a client's identity when deciding whether they allow a client access to more sensitive resources and operations such as the Client Credentials grant type and how often to prompt the user for consent.¶
A single client_id
SHOULD NOT be treated as more than one type of client.¶
This specification has been designed around the following client profiles:¶
A web application is a client running on a web server. Resource owners access the client via an HTML user interface rendered in a user agent on the device used by the resource owner. The client credentials as well as any access tokens issued to the client are stored on the web server and are not exposed to or accessible by the resource owner.¶
A browser-based application is a client in which the client code is downloaded from a web server and executes within a user agent (e.g., web browser) on the device used by the resource owner. Protocol data and credentials are easily accessible (and often visible) to the resource owner. If such applications wish to use client credentials, it is recommended to utilize the backend for frontend pattern. Since such applications reside within the user agent, they can make seamless use of the user agent capabilities when requesting authorization.¶
A native application is a client installed and executed on the device used by the resource owner. Protocol data and credentials are accessible to the resource owner. It is assumed that any client authentication credentials included in the application can be extracted. Dynamically issued access tokens and refresh tokens can receive an acceptable level of protection. On some platforms, these credentials are protected from other applications residing on the same device. If such applications wish to use client credentials, it is recommended to utilize the backend for frontend pattern, or issue the credentials at runtime using Dynamic Client Registration ([RFC7591]).¶
Every client is identified in the context of an authorization server by a client identifier -- a unique string representing the registration information provided by the client. While the Authorization Server typically issues the client identifier itself, it may also serve clients whose client identifier was created by a party other than the Authorization Server. The client identifier is not a secret; it is exposed to the resource owner and MUST NOT be used alone for client authentication. The client identifier is unique in the context of an authorization server.¶
The client identifier string size is left undefined by this specification. The client should avoid making assumptions about the identifier size. The authorization server SHOULD document the size of any identifier it issues.¶
If the authorization server supports clients with client identifiers issued by parties other than the authorization server, the authorization server SHOULD take precautions to avoid clients impersonating resource owners as described in Section 7.4.¶
The client redirection endpoint (also referred to as "redirect endpoint") is the URI of the client that the authorization server redirects the user agent back to after completing its interaction with the resource owner.¶
The authorization server redirects the user agent to one of the client's redirection endpoints previously established with the authorization server during the client registration process.¶
The redirect 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 ([WHATWG.URL]), which MUST be retained when adding additional query parameters. The endpoint URI MUST NOT include a fragment component.¶
Authorization servers MUST require clients to register their complete redirect URI (including the path component). Authorization servers MUST reject authorization requests that specify a redirect URI that doesn't exactly match one that was registered, with an exception for loopback redirects, where an exact match is required except for the port URI component.¶
The authorization server MAY allow the client to register multiple redirect URIs.¶
Registration may happen out of band, such as a manual step of configuring the client information at the authorization server, or may happen at runtime, such as in the initial POST in Pushed Authorization Requests [RFC9126].¶
For private-use URI scheme-based redirect URIs, authorization servers
SHOULD enforce the requirement in Section 8.4.3 that clients use
schemes that are reverse domain name based. At a minimum, any
private-use URI scheme that doesn't contain a period character (.
)
SHOULD be rejected.¶
In addition to the collision-resistant properties,
this can help to prove ownership in the event of a dispute where two apps
claim the same private-use URI scheme (where one app is acting
maliciously). For example, if two apps claimed com.example.app
,
the owner of example.com
could petition the app store operator to
remove the counterfeit app. Such a petition is harder to prove if a
generic URI scheme was used.¶
Clients MUST NOT expose URLs that forward the user's browser to arbitrary URIs obtained from a query parameter ("open redirector"), as described in Section 7.13. Open redirectors can enable exfiltration of authorization codes and access tokens.¶
The client MAY use the state
request parameter to achieve per-request
customization if needed rather than varying the redirect URI per request.¶
Without requiring registration of redirect URIs, attackers can use the authorization endpoint as an open redirector as described in Section 7.13.¶
If multiple redirect URIs have been registered, the client MUST
include a redirect URI with the authorization request using the
redirect_uri
request parameter.¶
Clients MUST prevent Cross-Site Request Forgery (CSRF) attacks. In this
context, CSRF refers to requests to the redirection endpoint that do
not originate at the authorization server, but a malicious third party
(see Section 4.4.1.8. of [RFC6819] for details). Clients that have
ensured that the authorization server supports the code_challenge
parameter MAY
rely on the CSRF protection provided by that mechanism. In OpenID Connect flows,
validating the nonce
parameter provides CSRF protection. Otherwise, one-time
use CSRF tokens carried in the state
parameter that are securely
bound to the user agent MUST be used for CSRF protection (see
Section 7.10).¶
In order to prevent mix-up attacks, clients MUST only process redirect responses of the authorization server they sent the respective request to and from the same user agent this authorization request was initiated with. Clients MUST store the authorization server they sent an authorization request to and bind this information to the user agent and check that the authorization response was received from the correct authorization server. Clients MUST ensure that the subsequent access token request, if applicable, is sent to the same authorization server. Clients SHOULD use distinct redirect URIs for each authorization server as a means to identify the authorization server a particular response came from.¶
If an authorization request fails validation due to a missing, invalid, or mismatching redirect URI, the authorization server SHOULD inform the resource owner of the error and MUST NOT automatically redirect the user agent to the invalid redirect URI.¶
The redirection request to the client's endpoint typically results in an HTML document response, processed by the user agent. If the HTML response is served directly as the result of the redirection request, any script included in the HTML document will execute with full access to the redirect URI and the credentials (e.g. authorization code) it contains. Additionally, the request URL containing the authorization code may be sent in the HTTP Referer header to any embedded images, stylesheets and other elements loaded in the page.¶
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 extract the credentials from the URI and redirect the user agent again to another endpoint without exposing the credentials (in the URI or elsewhere). If third-party scripts are included, the client MUST ensure that its own scripts (used to extract and remove the credentials from the URI) will execute first.¶
The authorization server MUST only rely on client authentication if the process of issuance/registration and distribution of the underlying credentials ensures their confidentiality.¶
If the client is confidential, the authorization server MAY accept any form of client authentication meeting its security requirements (e.g., password, public/private key pair).¶
It is RECOMMENDED to use asymmetric (public-key based) methods for client authentication such as mTLS [RFC8705] or a JWT [RFC7523]. When asymmetric methods for client authentication are used, authorization servers do not need to store sensitive symmetric keys, making these methods more robust against a number of attacks.¶
When client authentication is not possible, the authorization server SHOULD employ other means to validate the client's identity -- for example, by requiring the registration of the client redirect URI or enlisting the resource owner to confirm identity. A valid redirect URI is not sufficient to verify the client's identity when asking for resource owner authorization but can be used to prevent delivering credentials to a counterfeit client after obtaining resource owner authorization.¶
The client MUST NOT use more than one authentication method in each request to prevent a conflict of which authentication mechanism is authoritative for the request.¶
The authorization server MUST consider the security implications of interacting with unauthenticated clients and take measures to limit the potential exposure of tokens issued to such clients, (e.g., limiting the lifetime of refresh tokens).¶
The privileges an authorization server associates with a certain client identity MUST depend on the assessment of the overall process for client identification and client credential lifecycle management. See Section 7.2 for additional details.¶
Clients in possession of a client secret, sometimes known as a client password,
MAY use the HTTP Basic
authentication scheme as defined in Section 11 of [RFC9110] to authenticate with
the authorization server. The client identifier is encoded using the
application/x-www-form-urlencoded
encoding algorithm per
Appendix B, and the encoded value is used as the username; the client
secret is encoded using the 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 secret.¶
For example (with extra line breaks for display purposes only):¶
Authorization: Basic czZCaGRSa3F0Mzo3RmpmcDBaQnIxS3REUmJuZlZkbUl3¶
In addition to that, the authorization server MAY support including the client credentials in the request content using the following parameters:¶
REQUIRED. The client identifier issued to the client during the registration process described by Section 2.2.¶
REQUIRED. The client secret.¶
Including the client credentials in the request content using the two parameters is NOT RECOMMENDED and SHOULD be limited to clients unable to directly utilize the HTTP Basic authentication scheme (or other password-based HTTP authentication schemes). The parameters can only be transmitted in the request content and MUST NOT be included in the request URI.¶
For example, a request to refresh an access token (Section 4.3) using the content parameters (with extra line breaks for display purposes only):¶
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¶
Since this client authentication method involves a password, the authorization server MUST protect any endpoint utilizing it against brute force attacks.¶
The authorization server MAY support any suitable authentication scheme matching its security requirements. When using other authentication methods, the authorization server MUST define a mapping between the client identifier (registration record) and authentication scheme.¶
Some additional authentication methods such as mTLS [RFC8705] and Private Key JWT [RFC7523] are defined in the "OAuth Token Endpoint Authentication Methods" registry, and may be useful as generic client authentication methods beyond the specific use of protecting the token endpoint.¶
This specification does not require that clients be registered with the authorization server. However, the use of unregistered clients is beyond the scope of this specification and requires additional security analysis and review of its interoperability impact.¶
The authorization process utilizes two authorization server endpoints (HTTP resources):¶
As well as one client endpoint:¶
Not every authorization grant type utilizes both endpoints. Extension grant types MAY define additional endpoints as needed.¶
The token endpoint is used by the client to obtain an access token using a grant such as those described in Section 4 and Section 4.3.¶
The means through which the client obtains the location of the token endpoint are beyond the scope of this specification, but the location is typically provided in the service documentation and configured during development of the client, or provided in the authorization server's metadata document ([RFC8414]) and fetched programmatically at runtime.¶
The endpoint URI MAY include an application/x-www-form-urlencoded
formatted query component ([WHATWG.URL])
and MUST NOT include a fragment component.¶
The client MUST use the HTTP POST
method when making access token
requests.¶
The authorization server MUST ignore unrecognized request parameters.¶
Parameters sent without a value MUST be treated as if they were omitted from the request. Request and response parameters defined by this specification MUST NOT be included more than once.¶
Authorization servers that wish to support browser-based applications (applications running exclusively in client-side JavaScript without access to a supporting backend server) will need to ensure the token endpoint supports the necessary Cross-Origin Resource Sharing (CORS) headers. If the authorization server provides additional endpoints to the application, such as metadata URLs, dynamic client registration, revocation, introspection, discovery or user info endpoints, these endpoints may also be accessed by the browser-based application, and will also need to have the CORS headers defined to allow access. See [I-D.ietf-oauth-browser-based-apps] for further details.¶
Confidential clients MUST authenticate with the authorization server as described in Section 2.4 when making requests to the token endpoint.¶
Client authentication is used for:¶
The client makes a request to the token endpoint by sending 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 content:¶
REQUIRED, if the client is not authenticating with the authorization server as described in Section 3.2.1.¶
REQUIRED. Identifier of the grant type the client uses with the particular token request.
This specification defines the values authorization_code
, refresh_token
, and client_credentials
.
The grant type determines the further parameters required or supported by the token request. The
details of those grant types are defined below.¶
Confidential clients MUST authenticate with the authorization server as described in Section 3.2.1.¶
For example, the client makes the following HTTP request (with extra line breaks 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=authorization_code&code=SplxlOBeZQQYbYS6WxSbIA &redirect_uri=https%3A%2F%2Fclient%2Eexample%2Ecom%2Fcb &code_verifier=3641a2d12d66101249cdf7a79c000c1f8c05d2aafcf14bf146497bed¶
The authorization server MUST:¶
Further grant type specific processing rules apply and are specified with the respective grant type.¶
The authorization and token endpoints allow the client to specify the
scope of the access request using the scope
request parameter. In
turn, the authorization server uses the scope
response parameter to
inform the client of the scope of the access token issued.¶
The value of the scope parameter is expressed as a list of space- delimited, case-sensitive strings. The strings are defined by the authorization server. If the value contains multiple space-delimited strings, their order does not matter, and each string adds an additional 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
requested by the client, based on the authorization server policy or
the resource owner's instructions. If the issued access token scope
is different from the one requested by the client, the authorization
server MUST include the scope
response parameter in the token response
(Section 3.2.3) to inform the client of the actual scope granted.¶
If the client omits the scope parameter when requesting authorization, the authorization server MUST either process the request using a pre-defined default value or fail the request indicating an invalid scope. The authorization server SHOULD document its scope requirements and default value (if defined).¶
If the access token request is valid and authorized, the authorization server issues an access token and optional refresh token.¶
If the request client authentication failed or is invalid, the authorization server returns an error response as described in Section 3.2.3.1.¶
The authorization server issues an access token and optional refresh
token by creating an HTTP response content using the application/json
media type as defined by [RFC8259] with the following parameters
and an HTTP 200 (OK) status code:¶
REQUIRED. The access token issued by the authorization server.¶
REQUIRED. The type of the access token issued as described in Section 5.1. Value is case insensitive.¶
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.¶
RECOMMENDED, if identical to the scope requested by the client; otherwise, REQUIRED. The scope of the access token as described by Section 3.2.2.1.¶
OPTIONAL. The refresh token, which can be used to obtain new access tokens based on the grant passed in the corresponding token request.¶
Authorization servers SHOULD determine, based on a risk assessment and their own policies, whether to issue refresh tokens to a certain client. If the authorization server decides not to issue refresh tokens, the client MAY obtain new access tokens by starting the OAuth flow over, for example initiating a new authorization code request. In such a case, the authorization server may utilize cookies and persistent grants to optimize the user experience.¶
If refresh tokens are issued, those refresh tokens MUST be bound to the scope and resource servers as consented by the resource owner. This is to prevent privilege escalation by the legitimate client and reduce the impact of refresh token leakage.¶
The parameters are serialized into a JavaScript Object Notation (JSON) structure by adding each parameter at the highest structure level. Parameter names and string values are included as JSON strings. Numerical values are included as JSON numbers. The order of parameters does not matter and can vary.¶
The authorization server MUST include the HTTP Cache-Control
response header field (see Section 5.2 of [RFC9111]) with a value of no-store
in any
response containing tokens, credentials, or other sensitive
information.¶
For example:¶
HTTP/1.1 200 OK Content-Type: application/json Cache-Control: no-store { "access_token":"2YotnFZFEjr1zCsicMWpAA", "token_type":"Bearer", "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. The client should avoid making assumptions about value sizes. The authorization server SHOULD document the size of any value it issues.¶
The authorization server responds with an HTTP 400 (Bad Request) status code (unless specified otherwise) and includes the following parameters with the response:¶
REQUIRED. A single ASCII [USASCII] error code from the following:¶
The request is missing a required parameter, includes an
unsupported parameter value (other than grant type),
repeats a parameter, includes multiple credentials,
utilizes more than one mechanism for authenticating the
client, contains a code_verifier
although no
code_challenge
was sent in the authorization request,
or is otherwise malformed.¶
Client authentication failed (e.g., unknown client, no
client authentication included, or unsupported
authentication method). The authorization server MAY
return an HTTP 401 (Unauthorized) status code to indicate
which HTTP authentication schemes are supported. If the
client attempted 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 used by the client.¶
The provided authorization grant (e.g., authorization code, resource owner credentials) or refresh token is invalid, expired, revoked, does not match the redirect URI used in the authorization request, or was issued to another client.¶
The authenticated client is not authorized to use this authorization grant type.¶
The authorization grant type is not supported by the authorization server.¶
The requested scope is invalid, unknown, malformed, or exceeds the scope granted by the resource owner.¶
Values for the error
parameter MUST NOT include characters
outside the set %x20-21 / %x23-5B / %x5D-7E.¶
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.¶
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.¶
The parameters are included in the content of the HTTP response
using the application/json
media type as defined by [RFC7159]. The
parameters are serialized into a JSON structure by adding each
parameter at the highest structure level. Parameter names and string
values are included as JSON strings. Numerical values are included
as JSON numbers. The order of parameters does not matter and can
vary.¶
For example:¶
HTTP/1.1 400 Bad Request Content-Type: application/json Cache-Control: no-store { "error":"invalid_request" }¶
The client accesses protected resources by presenting the access token to the resource server. The resource server MUST validate the access token and ensure that it has not expired and that its scope covers the requested resource. The methods used by the resource server to validate the access token (as well as any error responses) are beyond the scope of this specification, but generally involve an interaction or coordination between the resource server and the authorization server. For example, when the resource server and authorization server are colocated or are part of the same system, they may share a database or other storage; when the two components are operated independently, they may use Token Introspection [RFC7662] or a structured access token format such as a JWT [RFC9068].¶
The method in which the client utilizes the access token to
access protected resources at the resource server depends on the type of access
token issued by the authorization server. Typically, it involves
using the HTTP Authorization
request header field [RFC7235] with an
authentication scheme defined by the specification of the access
token type used, such as Bearer
, defined below.¶
The access token type provides the client with the information required to successfully utilize the access token to make a protected resource request (along with type-specific attributes). The client MUST NOT use an access token if it does not understand the token type.¶
For example, the Bearer
token type defined in this specification is utilized
by simply including the access token string in the request:¶
GET /resource/1 HTTP/1.1 Host: example.com Authorization: Bearer mF_9.B5f-4.1JqM¶
The above example is provided for illustration purposes only.¶
Each access token type definition specifies the additional attributes
(if any) sent to the client together with the access_token
response
parameter. It also defines the HTTP authentication method used to
include the access token when making a protected resource request.¶
A Bearer Token is a security token with the property that any party in possession of the token (a "bearer") can use the token in any way that any other party in possession of it can. Using a Bearer Token does not require a bearer to prove possession of cryptographic key material (proof-of-possession).¶
Bearer Tokens may be enhanced with proof-of-possession specifications such as mTLS [RFC8705] to provide proof-of-possession characteristics.¶
To protect against access token disclosure, the communication interaction between the client and the resource server MUST utilize confidentiality and integrity protection as described in Section 1.5.¶
There is no requirement on the particular structure or format of a bearer token, as described in Section 5. If a bearer token is a reference to authorization information, such references MUST be infeasible for an attacker to guess, such as using a sufficiently long cryptographically random string. If a bearer token uses an encoding mechanism to contain the authorization information in the token itself, the access token MUST use integrity protection sufficient to prevent the token from being modified. One example of an encoding and signing mechanism for access tokens is described in JSON Web Token Profile for Access Tokens [RFC9068].¶
This section defines two methods of sending Bearer tokens in resource requests to resource servers. Clients MUST use one of the two methods defined below, and MUST NOT use more than one method to transmit the token in each request.¶
In particular, clients MUST NOT send the access token in a URI query parameter, and resource servers MUST ignore access tokens in a URI query parameter.¶
When sending the access token in the HTTP request content, the
client adds the access token to the request content using the
access_token
parameter. The client MUST NOT use this method unless
all of the following conditions are met:¶
Content-Type
header
field set to application/x-www-form-urlencoded
.¶
application/x-www-form-urlencoded
content-type as defined by
the URL Living Standard [WHATWG.URL].¶
GET
method MUST NOT be used.¶
The content MAY include other request-specific parameters, in
which case the access_token
parameter MUST be properly separated
from the request-specific parameters using &
character(s) (ASCII
code 38).¶
For example, the client makes the following HTTP request using transport-layer security:¶
POST /resource HTTP/1.1 Host: server.example.com Content-Type: application/x-www-form-urlencoded access_token=mF_9.B5f-4.1JqM¶
The application/x-www-form-urlencoded
method SHOULD NOT be used
except in application contexts where participating clients do not
have access to the Authorization
request header field. Resource
servers MAY support this method.¶
After receiving the access token, the resource server MUST check that the access token is not yet expired, is authorized to access the requested resource, was issued with the appropriate scope, and meets other policy requirements of the resource server to access the protected resource.¶
Access tokens generally fall into two categories: reference tokens or self-encoded tokens. Reference tokens can be validated by querying the authorization server or looking up the token in a token database, whereas self-encoded tokens contain the authorization information in an encrypted and/or signed string which can be extracted by the resource server.¶
A standardized method to query the authorization server to check the validity of an access token is defined in Token Introspection ([RFC7662]).¶
A standardized method of encoding information in a token string is defined in JWT Profile for Access Tokens ([RFC9068]).¶
See Section 7.1 for additional considerations around creating and validating access tokens.¶
If the protected resource request does not include authentication
credentials or does not contain an access token that enables access
to the protected resource, the resource server MUST include the HTTP
WWW-Authenticate
response header field; it MAY include it in
response to other conditions as well. The WWW-Authenticate
header
field uses the framework defined by HTTP/1.1 [RFC7235].¶
All challenges for this token type MUST use the auth-scheme
value Bearer
. This scheme MUST be followed by one or more
auth-param values. The auth-param attributes used or defined by this
specification for this token type are as follows. Other auth-param
attributes MAY be used as well.¶
A realm
attribute MAY be included to indicate the scope of
protection in the manner described in HTTP/1.1 [RFC7235]. The
realm
attribute MUST NOT appear more than once.¶
The scope
attribute is defined in Section 3.2.2.1. The
scope
attribute is a space-delimited list of case-sensitive scope
values indicating the required scope of the access token for
accessing the requested resource. scope
values are implementation
defined; there is no centralized registry for them; allowed values
are defined by the authorization server. The order of scope
values
is not significant. In some cases, the scope
value will be used
when requesting a new access token with sufficient scope of access to
utilize the protected resource. Use of the scope
attribute is
OPTIONAL. The scope
attribute MUST NOT appear more than once. The
scope
value is intended for programmatic use and is not meant to be
displayed to end-users.¶
Two example scope values follow; these are taken from the OpenID Connect [OpenID.Messages] and the Open Authentication Technology Committee (OATC) Online Multimedia Authorization Protocol [OMAP] OAuth 2.0 use cases, respectively:¶
scope="openid profile email" scope="urn:example:channel=HBO&urn:example:rating=G,PG-13"¶
If the protected resource request included an access token and failed
authentication, the resource server SHOULD include the error
attribute to provide the client with the reason why the access
request was declined. The parameter value is described in
Section 5.2.4. In addition, the resource server MAY include the
error_description
attribute to provide developers a human-readable
explanation that is not meant to be displayed to end-users. It also
MAY include the error_uri
attribute with an absolute URI
identifying a human-readable web page explaining the error. The
error
, error_description
, and error_uri
attributes MUST NOT
appear more than once.¶
Values for the scope
attribute (specified in Appendix A.4)
MUST NOT include characters outside the set %x21 / %x23-5B
/ %x5D-7E for representing scope values and %x20 for delimiters
between scope values. Values for the error
and error_description
attributes (specified in Appendix A.7 and Appendix A.8) MUST
NOT include characters outside the set %x20-21 / %x23-5B / %x5D-7E.
Values for the error_uri
attribute (specified in Appendix A.9 of)
MUST conform to the URI-reference syntax and thus MUST NOT
include characters outside the set %x21 / %x23-5B / %x5D-7E.¶
For example, in response to a protected resource request without authentication:¶
HTTP/1.1 401 Unauthorized WWW-Authenticate: Bearer realm="example"¶
And in response to a protected resource request with an authentication attempt using an expired access token:¶
HTTP/1.1 401 Unauthorized WWW-Authenticate: Bearer realm="example", error="invalid_token", error_description="The access token expired"¶
When a request fails, the resource server responds using the appropriate HTTP status code (typically, 400, 401, 403, or 405) and includes one of the following error codes in the response:¶
The request is missing a required parameter, includes an unsupported parameter or parameter value, repeats the same parameter, uses more than one method for including an access token, or is otherwise malformed. The resource server SHOULD respond with the HTTP 400 (Bad Request) status code.¶
The access token provided is expired, revoked, malformed, or invalid for other reasons. The resource SHOULD respond with the HTTP 401 (Unauthorized) status code. The client MAY request a new access token and retry the protected resource request.¶
The request requires higher privileges (scopes) than provided by the
scopes granted to the client and represented by the access token.
The resource server SHOULD respond with the HTTP
403 (Forbidden) status code and MAY include the scope
attribute with the scope necessary to access the protected
resource.¶
If the request lacks any authentication information (e.g., the client was unaware that authentication is necessary or attempted using an unsupported authentication method), the resource server SHOULD NOT include an error code or other error information.¶
For example:¶
HTTP/1.1 401 Unauthorized WWW-Authenticate: Bearer realm="example"¶
If a resource access request fails, the resource server SHOULD inform the client of the error. The method by which the resource server does this is determined by the particular token type, such as the description of Bearer tokens in Section 5.2.4.¶
[RFC6750] establishes a common registry in Section 11.4 of [RFC6749] for error values to be shared among OAuth token authentication schemes.¶
New authentication schemes designed primarily for OAuth token authentication SHOULD define a mechanism for providing an error status code to the client, in which the error values allowed are registered in the error registry established by this specification.¶
Such schemes MAY limit the set of valid error codes to a subset of
the registered values. If the error code is returned using a named
parameter, the parameter name SHOULD be error
.¶
Other schemes capable of being used for OAuth token authentication, but not primarily designed for that purpose, MAY bind their error values to the registry in the same manner.¶
New authentication schemes MAY choose to also specify the use of the
error_description
and error_uri
parameters to return error
information in a manner parallel to their usage in this
specification.¶
Access token types can be defined in one of two ways: registered in the Access Token Types registry (following the procedures in Section 11.1 of [RFC6749]), or by using a unique absolute URI as its name.¶
Types utilizing a URI name SHOULD be limited to vendor-specific implementations that are not commonly applicable, and are specific to the implementation details of the resource server where they are 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¶
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 of [RFC6749].¶
Parameter names MUST conform to the param-name ABNF, and parameter values syntax MUST be well-defined (e.g., 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 are not commonly applicable and that are specific to the implementation details of the authorization server where they are used SHOULD utilize a vendor-specific prefix that is not likely to conflict with other registered values (e.g., begin with 'companyname_').¶
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 of [RFC6749]. 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 is compared as a space-delimited list of values in which the order of values does not matter. Only one order of values can be registered, which covers all other arrangements of the same set of values.¶
For example, an extension can define and register the code other_token
response type. Once registered, the same combination cannot be registered
as other_token code
, but both values can be used to
denote the same response type.¶
In cases where protocol extensions (i.e., access token types, extension parameters, or extension grant types) require additional error codes to be used with the authorization code grant error response (Section 4.1.2.1), the token error response (Section 3.2.3.1), or the resource access error response (Section 5.3), such error codes MAY be defined.¶
Extension error codes MUST be registered (following the procedures in Section 11.4 of [RFC6749]) if the extension they are used in conjunction 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¶
As a flexible and extensible framework, OAuth's security considerations depend on many factors. The following sections provide implementers with security guidelines focused on the three client profiles described in Section 2.1: web application, browser-based application, and native application.¶
A comprehensive OAuth security model and analysis, as well as background for the protocol design, is provided by [RFC6819] and [I-D.ietf-oauth-security-topics].¶
The following list presents several common threats against protocols utilizing some form of tokens. This list of threats is based on NIST Special Publication 800-63 [NIST800-63].¶
An attacker may generate a bogus access token or modify the token contents (such as the authentication or attribute statements) of an existing token, causing the resource server to grant inappropriate access to the client. For example, an attacker may modify the token to extend the validity period; a malicious client may modify the assertion to gain access to information that they should not be able to view.¶
Access tokens may contain authentication and attribute statements that include sensitive information.¶
An attacker uses an access token generated for consumption by one resource server to gain access to a different resource server that mistakenly believes the token to be for it.¶
An attacker attempts to use an access token that has already been used with that resource server in the past.¶
A large range of threats can be mitigated by protecting the contents of the access token by using a digital signature.¶
Alternatively, a bearer token can contain a reference to authorization information, rather than encoding the information directly. Using a reference may require an extra interaction between a resource server and authorization server to resolve the reference to the authorization information. The mechanics of such an interaction are not defined by this specification, but one such mechanism is defined in Token Introspection [RFC7662].¶
This document does not specify the encoding or the contents of the access token; hence, detailed recommendations about the means of guaranteeing access token integrity protection are outside the scope of this specification. One example of an encoding and signing mechanism for access tokens is described in JSON Web Token Profile for Access Tokens [RFC9068].¶
To deal with access token redirects, it is important for the authorization server to include the identity of the intended recipients (the audience), typically a single resource server (or a list of resource servers), in the token. Restricting the use of the token to a specific scope is also RECOMMENDED.¶
If cookies are transmitted without TLS protection, any information contained in them is at risk of disclosure. Therefore, Bearer tokens MUST NOT be stored in cookies that can be sent in the clear, as any information in them is at risk of disclosure. See "HTTP State Management Mechanism" [RFC6265] for security considerations about cookies.¶
In some deployments, including those utilizing load balancers, the TLS connection to the resource server terminates prior to the actual server that provides the resource. This could leave the token unprotected between the front-end server where the TLS connection terminates and the back-end server that provides the resource. In such deployments, sufficient measures MUST be employed to ensure confidentiality of the access token between the front-end and back-end servers; encryption of the token is one such possible measure.¶
Client implementations MUST ensure that bearer tokens are not leaked to unintended parties, as they will be able to use them to gain access to protected resources. This is the primary security consideration when using bearer tokens and underlies all the more specific recommendations that follow.¶
The client MUST validate the TLS certificate chain when making requests to protected resources. Failing to do so may enable DNS hijacking attacks to steal the token and gain unintended access.¶
Clients MUST always use TLS (https) or equivalent transport security when making requests with bearer tokens. Failing to do so exposes the token to numerous attacks that could give attackers unintended access.¶
Authorization servers SHOULD issue short-lived bearer tokens, particularly when issuing tokens to clients that run within a web browser or other environments where information leakage may occur. Using short-lived bearer tokens can reduce the impact of them being leaked.¶
Authorization servers SHOULD issue bearer tokens that contain an audience restriction, scoping their use to the intended relying party or set of relying parties.¶
Bearer tokens MUST NOT be passed in page URLs (for example, as query string parameters). Instead, bearer tokens SHOULD be passed in HTTP message headers or message bodies for which confidentiality measures are taken. Browsers, web servers, and other software may not adequately secure URLs in the browser history, web server logs, and other data structures. If bearer tokens are passed in page URLs, attackers might be able to steal them from the history data, logs, or other unsecured locations.¶
A sender-constrained access token scopes the applicability of an access token to a certain sender. This sender is obliged to demonstrate knowledge of a certain secret as prerequisite for the acceptance of that access token at the recipient (e.g., a resource server).¶
Authorization and resource servers SHOULD use mechanisms for sender-constrained access tokens to prevent token replay as described in Section 4.8.1.1.2 of [I-D.ietf-oauth-security-topics]. The use of Mutual TLS for OAuth 2.0 [RFC8705] is RECOMMENDED as the method of sender-constrained access tokens. Another method of achieving sender-constrained tokens is described in [I-D.ietf-oauth-dpop].¶
It is RECOMMENDED to use end-to-end TLS. If TLS traffic needs to be terminated at an intermediary, refer to Section 4.11 of [I-D.ietf-oauth-security-topics] for further security advice.¶
The privileges associated with an access token SHOULD be restricted to the minimum required for the particular application or use case. This prevents clients from exceeding the privileges authorized by the resource owner. It also prevents users from exceeding their privileges authorized by the respective security policy. Privilege restrictions also help to reduce the impact of access token leakage.¶
In particular, access tokens SHOULD be restricted to certain resource
servers (audience restriction), preferably to a single resource
server. To put this into effect, the authorization server associates
the access token with certain resource servers and every resource
server is obliged to verify, for every request, whether the access
token sent with that request was meant to be used for that particular
resource server. If not, the resource server MUST refuse to serve
the respective request. Clients and authorization servers MAY
utilize the parameters scope
or resource
as specified in
this document and [RFC8707], respectively, to
determine the resource server they want to access.¶
Additionally, access tokens SHOULD be restricted to certain resources
and actions on resource servers or resources. To put this into effect,
the authorization server associates the access token with the
respective resource and actions and every resource server is obliged
to verify, for every request, whether the access token sent with that
request was meant to be used for that particular action on the
particular resource. If not, the resource server must refuse to
serve the respective request. Clients and authorization servers MAY
utilize the parameter scope
and
authorization_details
as specified in [I-D.ietf-oauth-rar] to
determine those resources and/or actions.¶
Depending on the overall process of client registration and credential lifecycle management, this may affect the confidence an authorization server has in a particular client.¶
For example, authentication of a dynamically registered client does not prove the identity of the client, it only ensures that repeated requests to the authorization server were made from the same client instance. Such clients may be limited in terms of which scopes they are allowed to request, or may have other limitations such as shorter token lifetimes.¶
In contrast, if there is a registered application whose developer's identity was verified, who signed a contract and is issued a client secret that is only used in a secure backend service, the authorization server might allow this client to request more sensitive scopes or to be issued longer-lasting tokens.¶
If a confidential client has its credentials stolen, a malicious client can impersonate the client and obtain access to protected resources.¶
The authorization server SHOULD enforce explicit resource owner authentication and provide the resource owner with information about the client and the requested authorization scope and lifetime. It is up to the resource owner to review the information in the context of the current client and to authorize 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 ensure that the repeated request comes from the original client and not an impersonator.¶
As stated above, the authorization server SHOULD NOT process authorization requests automatically without user consent or interaction, except when the identity of the client can be assured. This includes the case where the user has previously approved an authorization request for a given client ID -- unless the identity of the client can be proven, the request SHOULD be processed as if no previous request had been approved.¶
Measures such as claimed https
scheme redirects MAY be accepted by
authorization servers as identity proof. Some operating systems may
offer alternative platform-specific identity features that MAY be
accepted, as appropriate.¶
The client SHOULD request access tokens with the minimal scope necessary. The authorization server SHOULD take the client identity into account when choosing how to honor the requested scope and MAY issue an access token with fewer scopes than requested.¶
The privileges associated with an access token SHOULD be restricted to the minimum required for the particular application or use case. This prevents clients from exceeding the privileges authorized by the resource owner. It also prevents users from exceeding their privileges authorized by the respective security policy. Privilege restrictions also help to reduce the impact of access token leakage.¶
In particular, access tokens SHOULD be restricted to certain resource
servers (audience restriction), preferably to a single resource
server. To put this into effect, the authorization server associates
the access token with certain resource servers and every resource
server is obliged to verify, for every request, whether the access
token sent with that request was meant to be used for that particular
resource server. If not, the resource server MUST refuse to serve the
respective request. Clients and authorization servers MAY utilize the
parameters scope
or resource
as specified in
[RFC8707], respectively, to determine the
resource server they want to access.¶
Resource servers may make access control decisions based on the identity of a
resource owner, for which an access token was issued, or based on the identity
of a client in the client credentials grant. If both options are possible,
depending on the details of the implementation, a client's identity may be
mistaken for the identity of a resource owner. For example, if a client is able
to choose its own client_id
during registration with the authorization server,
a malicious client may set it to a value identifying an end-user (e.g., a sub
value if OpenID Connect is used). If the resource server cannot properly
distinguish between access tokens issued to clients and access tokens issued to
end-users, the client may then be able to access resource of the end-user.¶
Authorization servers SHOULD NOT allow clients to influence their client_id
or
any other Claim if that can cause confusion with a genuine resource owner. Where
this cannot be avoided, authorization servers MUST provide other means for the
resource server to distinguish between access tokens authorized by a resource
owner from access tokens authorized by the client itself.¶
The risk related to man-in-the-middle attacks is mitigated by the mandatory use of channel security mechanisms such as [RFC8446] for communicating with the Authorization and Token Endpoints. See Section 1.5 for further details.¶
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 intended for handling by end-users) MUST be less than or equal to 2^(-128) and SHOULD be less than or equal to 2^(-160).¶
The authorization server MUST utilize other means to protect credentials intended for end-user usage.¶
Wide deployment of this and similar protocols may cause end-users to become inured to the practice of being redirected to websites where they are asked to enter their passwords. If end-users are not careful to verify the authenticity of these websites before entering their credentials, it will be possible for attackers to exploit this practice to steal resource owners' passwords.¶
Service providers should attempt to educate end-users about the risks phishing attacks pose and should provide mechanisms that make it easy for end-users to confirm the authenticity of their sites. Client developers should consider the security implications of how they interact with the user agent (e.g., external, embedded), and the ability of the end-user to verify the authenticity of the authorization server.¶
See Section 1.5 for further details on mitigating the risk of phishing attacks.¶
An attacker might attempt to inject a request to the redirect URI of the legitimate client on the victim's device, e.g., to cause the client to access resources under the attacker's control. This is a variant of an attack known as Cross-Site Request Forgery (CSRF).¶
The traditional countermeasure are CSRF tokens that are bound to the
user agent and passed in the state
parameter to the authorization
server as described in [RFC6819]. The same protection is provided by
the code_verifier
parameter or the OpenID Connect nonce
value.¶
When using code_verifier
instead of state
or nonce
for CSRF protection, it is
important to note that:¶
code_challenge_method
intended to be used by the client. If an authorization server does not support the requested method,
state
or nonce
MUST be used for CSRF protection instead.¶
state
is used for carrying application state, and integrity of
its contents is a concern, clients MUST protect state
against
tampering and swapping. This can be achieved by binding the
contents of state to the browser session and/or signed/encrypted
state values [I-D.bradley-oauth-jwt-encoded-state].¶
AS therefore MUST provide a way to detect their supported code challenge methods either via AS metadata according to [RFC8414] or provide a deployment-specific way to ensure or determine support.¶
As described in Section 4.4.1.9 of [RFC6819], the authorization request is susceptible to clickjacking attacks, also called user interface redressing. In such an attack, an attacker embeds the authorization endpoint user interface in an innocuous context. A user believing to interact with that context, for example, clicking on buttons, inadvertently interacts with the authorization endpoint user interface instead. The opposite can be achieved as well: A user believing to interact with the authorization endpoint might inadvertently type a password into an attacker-provided input field overlaid over the original user interface. Clickjacking attacks can be designed such that users can hardly notice the attack, for example using almost invisible iframes overlaid on top of other elements.¶
An attacker can use this vector to obtain the user's authentication credentials, change the scope of access granted to the client, and potentially access the user's resources.¶
Authorization servers MUST prevent clickjacking attacks. Multiple
countermeasures are described in [RFC6819], including the use of the
X-Frame-Options
HTTP response header field and frame-busting
JavaScript. In addition to those, authorization servers SHOULD also
use Content Security Policy (CSP) level 2 [CSP-2] or greater.¶
To be effective, CSP must be used on the authorization endpoint and, if applicable, other endpoints used to authenticate the user and authorize the client (e.g., the device authorization endpoint, login pages, error pages, etc.). This prevents framing by unauthorized origins in user agents that support CSP. The client MAY permit being framed by some other origin than the one used in its redirection endpoint. For this reason, authorization servers SHOULD allow administrators to configure allowed origins for particular clients and/or for clients to register these dynamically.¶
Using CSP allows authorization servers to specify multiple origins in
a single response header field and to constrain these using flexible
patterns (see [CSP-2] for details). Level 2 of this standard provides
a robust mechanism for protecting against clickjacking by using
policies that restrict the origin of frames (using frame-ancestors
)
together with those that restrict the sources of scripts allowed to
execute on an HTML page (by using script-src
). A non-normative
example of such a policy is shown in the following listing:¶
HTTP/1.1 200 OK
Content-Security-Policy: frame-ancestors https://ext.example.org:8000
Content-Security-Policy: script-src 'self'
X-Frame-Options: ALLOW-FROM https://ext.example.org:8000
...
¶
Because some user agents do not support [CSP-2], this technique SHOULD be combined with others, including those described in [RFC6819], unless such legacy user agents are explicitly unsupported by the authorization server. Even in such cases, additional countermeasures SHOULD still be employed.¶
A code injection attack occurs when an input or otherwise external variable is used by an application unsanitized and causes modification to the application logic. This may allow an attacker to gain access to the application device or its data, cause denial of service, or introduce a wide range of malicious side-effects.¶
The authorization server and client MUST sanitize (and validate when
possible) any value received -- in particular, the value of the
state
and redirect_uri
parameters.¶
The following attacks can occur when an AS or client has an open redirector. An open redirector is an endpoint that forwards a user's browser to an arbitrary URI obtained from a query parameter. Such endpoints are sometimes implemented, for example, to show a message before a user is then redirected to an external website, or to redirect users back to a URL they were intending to visit before being interrupted, e.g., by a login prompt.¶
Clients MUST NOT expose open redirectors. Attackers may use open redirectors to produce URLs pointing to the client and utilize them to exfiltrate authorization codes, as described in Section 4.1.1 of [I-D.ietf-oauth-security-topics]. Another abuse case is to produce URLs that appear to point to the client. This might trick users into trusting the URL and follow it in their browser. This can be abused for phishing.¶
In order to prevent open redirection, clients should only redirect if the target URLs are whitelisted or if the origin and integrity of a request can be authenticated. Countermeasures against open redirection are described by OWASP [owasp_redir].¶
Native applications are clients installed and executed on the device used by the resource owner (i.e., desktop application, native mobile application). Native applications require special consideration related to security, platform capabilities, and overall end-user experience.¶
The authorization endpoint requires interaction between the client and the resource owner's user agent. The best current practice is to perform the OAuth authorization request in an external user agent (typically the browser) rather than an embedded user agent (such as one implemented with web-views).¶
The native application can capture the response from the authorization server using a redirect URI with a scheme registered with the operating system to invoke the client as the handler, manual copy-and-paste of the credentials, running a local web server, installing a user agent extension, or by providing a redirect URI identifying a server-hosted resource under the client's control, which in turn makes the response available to the native application.¶
Previously, it was common for native apps to use embedded user agents (commonly implemented with web-views) for OAuth authorization requests. That approach has many drawbacks, including the host app being able to copy user credentials and cookies as well as the user needing to authenticate from scratch in each app. See Section 8.5.1 for a deeper analysis of the drawbacks of using embedded user agents for OAuth.¶
Native app authorization requests that use the system browser are more secure and can take advantage of the user's authentication state on the device. Being able to use the existing authentication session in the browser enables single sign-on, as users don't need to authenticate to the authorization server each time they use a new app (unless required by the authorization server policy).¶
Supporting authorization flows between a native app and the browser is possible without changing the OAuth protocol itself, as the OAuth authorization request and response are already defined in terms of URIs. This encompasses URIs that can be used for inter-app communication. Some OAuth server implementations that assume all clients are confidential web clients will need to add an understanding of public native app clients and the types of redirect URIs they use to support this best practice.¶
Except when using a mechanism like Dynamic Client Registration [RFC7591] to provision per-instance secrets, native apps are classified as public clients, as defined in Section 2.1; they MUST be registered with the authorization server as such. Authorization servers MUST record the client type in the client registration details in order to identify and process requests accordingly.¶
Secrets that are statically included as part of an app distributed to
multiple users should not be treated as confidential secrets, as one
user may inspect their copy and learn the shared secret. For this
reason, it is NOT
RECOMMENDED for authorization servers to require client
authentication of public native apps clients using a shared secret,
as this serves little value beyond client identification which is
already provided by the client_id
request parameter.¶
Authorization servers that still require a statically included shared secret for native app clients MUST treat the client as a public client (as defined in Section 2.1), and not accept the secret as proof of the client's identity. Without additional measures, such clients are subject to client impersonation (see Section 7.3.1).¶
Just as URIs are used for OAuth on the web to initiate the authorization request and return the authorization response to the requesting website, URIs can be used by native apps to initiate the authorization request in the device's browser and return the response to the requesting native app.¶
By adopting the same methods used on the web for OAuth, benefits seen in the web context like the usability of a single sign-on session and the security of a separate authentication context are likewise gained in the native app context. Reusing the same approach also reduces the implementation complexity and increases interoperability by relying on standards-based web flows that are not specific to a particular platform.¶
Native apps MUST use an external user agent to perform OAuth authorization requests. This is achieved by opening the authorization request in the browser (detailed in Section 8.3) and using a redirect URI that will return the authorization response back to the native app (defined in Section 8.4).¶
Embedded user agents are a technically possible method for authorizing native apps. These embedded user agents are unsafe for use by third parties to the authorization server by definition, as the app that hosts the embedded user agent can access the user's full authentication credentials, not just the OAuth authorization grant that was intended for the app.¶
In typical web-view-based implementations of embedded user agents, the host application can record every keystroke entered in the login form to capture usernames and passwords, automatically submit forms to bypass user consent, and copy session cookies and use them to perform authenticated actions as the user.¶
Even when used by trusted apps belonging to the same party as the authorization server, embedded user agents violate the principle of least privilege by having access to more powerful credentials than they need, potentially increasing the attack surface.¶
Encouraging users to enter credentials in an embedded user agent without the usual address bar and visible certificate validation features that browsers have makes it impossible for the user to know if they are signing in to the legitimate site; even when they are, it trains them that it's OK to enter credentials without validating the site first.¶
Aside from the security concerns, embedded user agents do not share the authentication state with other apps or the browser, requiring the user to log in for every authorization request, which is often considered an inferior user experience.¶
The native app that is initiating the authorization request has a large degree of control over the user interface and can potentially present a fake external user agent, that is, an embedded user agent made to appear as an external user agent.¶
When all good actors are using external user agents, the advantage is that it is possible for security experts to detect bad actors, as anyone faking an external user agent is provably bad. On the other hand, if good and bad actors alike are using embedded user agents, bad actors don't need to fake anything, making them harder to detect. Once a malicious app is detected, it may be possible to use this knowledge to blacklist the app's signature in malware scanning software, take removal action (in the case of apps distributed by app stores) and other steps to reduce the impact and spread of the malicious app.¶
Authorization servers can also directly protect against fake external user agents by requiring an authentication factor only available to true external user agents.¶
Users who are particularly concerned about their security when using in-app browser tabs may also take the additional step of opening the request in the full browser from the in-app browser tab and complete the authorization there, as most implementations of the in-app browser tab pattern offer such functionality.¶
If a malicious app is able to configure itself as the default handler
for https
scheme URIs in the operating system, it will be able to
intercept authorization requests that use the default browser and
abuse this position of trust for malicious ends such as phishing the
user.¶
This attack is not confined to OAuth; a malicious app configured in
this way would present a general and ongoing risk to the user beyond
OAuth usage by native apps. Many operating systems mitigate this
issue by requiring an explicit user action to change the default
handler for http
and https
scheme URIs.¶
Browser-based apps are are clients that run in a web browser, typically written in JavaScript, also known as "single-page apps". These types of apps have particular security considerations similar to native apps.¶
TODO: Bring in the normative text of the browser-based apps BCP when it is finalized.¶
This draft consolidates the functionality in OAuth 2.0 [RFC6749], OAuth 2.0 for Native Apps ([RFC8252]), Proof Key for Code Exchange ([RFC7636]), OAuth 2.0 for Browser-Based Apps ([I-D.ietf-oauth-browser-based-apps]), OAuth Security Best Current Practice ([I-D.ietf-oauth-security-topics]), and Bearer Token Usage ([RFC6750]).¶
Where a later draft updates or obsoletes functionality found in the original [RFC6749], that functionality in this draft is updated with the normative changes described in a later draft, or removed entirely.¶
A non-normative list of changes from OAuth 2.0 is listed below:¶
response_type=token
) is omitted from this specification
as per Section 2.1.2 of [I-D.ietf-oauth-security-topics]¶
The OAuth 2.0 Implicit grant is omitted from OAuth 2.1 as it was deprecated in [I-D.ietf-oauth-security-topics].¶
The intent of removing the Implicit grant is to no longer issue access tokens
in the authorization response, as such tokens are vulnerable to leakage
and injection, and are unable to be sender-constrained to a client.
This behavior was indicated by clients using the response_type=token
parameter.
This value for the response_type
parameter is no longer defined in OAuth 2.1.¶
Removal of response_type=token
does not have an effect on other extension
response types returning other artifacts from the authorization endpoint,
for example, response_type=id_token
defined by [OpenID].¶
This document does not require any IANA actions.¶
All referenced registries are defined by [RFC6749] and related documents that this work is based upon. No changes to those registries are required by this specification.¶
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.)¶
The client_id
element is defined in Section 2.4.1:¶
client-id = *VSCHAR¶
The client_secret
element is defined in Section 2.4.1:¶
client-secret = *VSCHAR¶
The response_type
element is defined in Section 4.1.1 and Section 6.4:¶
response-type = response-name *( SP response-name ) response-name = 1*response-char response-char = "_" / DIGIT / ALPHA¶
The scope
element is defined in Section 3.2.2.1:¶
scope = scope-token *( SP scope-token ) scope-token = 1*NQCHAR¶
The state
element is defined in Section 4.1.1, Section 4.1.2, and Section 4.1.2.1:¶
state = 1*VSCHAR¶
The redirect_uri
element is defined in Section 4.1.1, and Section 4.1.3:¶
redirect-uri = URI-reference¶
The error
element is defined in Sections Section 4.1.2.1, Section 3.2.3.1,
7.2, and 8.5:¶
error = 1*NQSCHAR¶
The error_description
element is defined in Sections Section 4.1.2.1,
Section 3.2.3.1, and Section 5.3:¶
error-description = 1*NQSCHAR¶
The error_uri
element is defined in Sections Section 4.1.2.1, Section 3.2.3.1,
and 7.2:¶
error-uri = URI-reference¶
The grant_type
element is defined in Section Section 3.2.2:¶
grant-type = grant-name / URI-reference grant-name = 1*name-char name-char = "-" / "." / "_" / DIGIT / ALPHA¶
The code
element is defined in Section 4.1.3:¶
code = 1*VSCHAR¶
The access_token
element is defined in Section 3.2.3:¶
access-token = 1*VSCHAR¶
The token_type
element is defined in Section 3.2.3, and Section 6.1:¶
token-type = type-name / URI-reference type-name = 1*name-char name-char = "-" / "." / "_" / DIGIT / ALPHA¶
The expires_in
element is defined in Section 3.2.3:¶
expires-in = 1*DIGIT¶
The refresh_token
element is defined in Section 3.2.3 and Section 4.3:¶
refresh-token = 1*VSCHAR¶
The syntax for new endpoint parameters is defined in Section 6.2:¶
param-name = 1*name-char name-char = "-" / "." / "_" / DIGIT / ALPHA¶
ABNF for code_verifier
is as follows.¶
code-verifier = 43*128unreserved unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~" ALPHA = %x41-5A / %x61-7A DIGIT = %x30-39¶
ABNF for code_challenge
is as follows.¶
code-challenge = 43*128unreserved unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~" ALPHA = %x41-5A / %x61-7A DIGIT = %x30-39¶
TBD: Describe OAuth's use of application/x-www-form-urlencoded
encoding, both for URL parameters as well as for the client_id and secret encoding.¶
GitHub discussion: https://github.com/oauth-wg/oauth-v2-1/issues/128¶
Below is a list of well-established extensions at the time of publication:¶
[RFC8628]: OAuth 2.0 Device Authorization Grant¶
[RFC8414]: Authorization Server Metadata¶
[RFC8707]: Resource Indicators¶
[RFC7591]: Dynamic Client Registration¶
[RFC7592]: Dynamic Client Management¶
[RFC9068]: JSON Web Token (JWT) Profile for OAuth 2.0 Access Tokens¶
[RFC7662]: Token Introspection¶
[RFC9126]: Pushed Authorization Requests¶
[RFC9207]: Authorization Server Issuer Identification¶
iss
parameter in the authorization response indicates the identity of the authorization server to prevent mix-up attacks in the client.¶
[I-D.ietf-oauth-rar]: Rich Authorization Requests¶
authorization_details
that is used to carry fine-grained authorization data in the OAuth authorization request.¶
This specification is the work of the OAuth Working Group, and its starting point was based on the contents of the following specifications: OAuth 2.0 Authorization Framework (RFC 6749), OAuth 2.0 for Native Apps (RFC 8252), OAuth Security Best Current Practice, and OAuth 2.0 for Browser-Based Apps. The editors would like to thank everyone involved in the creation of those specifications upon which this is built.¶
The editors would also like to thank the following individuals for their ideas, feedback, corrections, and wording that helped shape this version of the specification: Vittorio Bertocci, Michael Jones, Justin Richer, Daniel Fett, Brian Campbell, Joseph Heenan, Roberto Polli, Andrii Deinega, Falko, Michael Peck, and Bob Hamburg.¶
Discussions around this specification have also occurred at the OAuth Security Workshop in 2021 and 2022. The authors thank the organizers of the workshop (Guido Schmitz, Steinar Noem, and Daniel Fett) for hosting an event that's conducive to collaboration and community input.¶
[[ To be removed from the final specification ]]¶
-08¶
-07¶
-06¶
iss
response parameter referencing RFC9207¶
-05¶
-04¶
-03¶
-02¶
-01¶
-00¶