The OAuth 2.0 Protocol: Bearer TokensMicrosoftmbj@microsoft.comhttp://self-issued.info/independentdick.hardt@gmail.comhttp://dickhardt.org/Facebookdr@fb.comhttp://www.davidrecordon.com/
This specification describes how to use bearer tokens when accessing OAuth 2.0
protected resources.
OAuth enables clients to access protected resources by
obtaining an access token, which is defined in as "a string representing an access
authorization issued to the client", rather than using the
resource owner's credentials.
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. This specification describes how to make protected resource
requests when the OAuth access token is a bearer token.
This specification defines the use of bearer tokens with OAuth
over HTTP using TLS. Other specifications may extend
it for use with other transport protocols.
The key words 'MUST', 'MUST NOT', 'REQUIRED', 'SHALL', 'SHALL NOT', 'SHOULD', 'SHOULD
NOT', 'RECOMMENDED', 'MAY', and 'OPTIONAL' in this document are to be interpreted as
described in .
This document uses the Augmented Backus-Naur Form (ABNF)
notation of ,
which is based upon the Augmented Backus-Naur Form (ABNF)
notation of . Additionally, the
following rules are included from
: auth-param and realm; from
: URI-Reference; and from
: RWS
and quoted-string.
Unless otherwise noted, all the protocol parameter names and values are case sensitive.
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).
All other terms are as defined in .
OAuth provides a method for clients to access a protected resource on behalf of a
resource owner. Before a client can access a protected resource, it must first obtain
authorization (access grant) from the resource owner and then exchange the access grant for
an access token (representing the grant's scope, duration, and other attributes). The
client accesses the protected resource by presenting the access token to the resource
server.
The access token provides an abstraction layer, replacing different authorization
constructs (e.g. username and password, assertion) for a single token understood by the
resource server. This abstraction enables issuing access tokens valid for a short time
period, as well as removing the resource server's need to understand a wide range of
authentication schemes.
The abstract flow illustrated in describes the overall
OAuth 2.0 protocol architecture. The following steps are specified within this
document:
E) The client makes a protected resource request to the resource server by presenting
the access token.
F) The resource server validates the access token, and if valid, serves the request.
Clients SHOULD make authenticated requests with a bearer token
using the Authorization request
header field defined by .
Resource servers MUST accept authenticated
requests using the Bearer HTTP
authorization scheme as described in , and MAY support additional methods.
Alternatively, clients MAY transmit the access token in the
HTTP body when using the application/x-www-form-urlencoded content
type as described in ; or clients
MAY transmit the access token in the HTTP request URI in the
query component as described in . Resource servers MAY support these alternative methods.
Clients SHOULD NOT use the request body or URI unless the
Authorization request header field
is not available, and MUST NOT use more than one method to
transmit the token in each request. Because of the Security Considerations associated
with the URI method, it SHOULD NOT be used unless no other
method is feasible.
The Authorization request header
field is used by clients to make authenticated requests with
bearer tokens. The client uses the Bearer authentication scheme to transmit
the access token in the request.
The Authorization header field uses the framework defined by
as follows:
When including the access token in the HTTP request
entity-body, the client adds the access token to the request
body using the access_token
parameter. The client MUST NOT use this method unless the
following conditions are met:
The HTTP request entity-body is single-part.
The entity-body follows the encoding requirements of the
application/x-www-form-urlencoded content-type as
defined by .
The HTTP request entity-header includes the Content-Type
header field set to application/x-www-form-urlencoded.
The HTTP request method is one for which a body is
permitted to be present in the request. In particular,
this means that the GET
method MUST NOT be used.
The entity-body can include other request-specific
parameters, in which case, the access_token parameter MUST be properly
separated from the request-specific parameters by an & character (ASCII code 38).
The application/x-www-form-urlencoded
method SHOULD NOT be used except in application contexts
where participating browsers do not have access to the
Authorization request header
field.
When including the access token in the HTTP request URI, the client adds the access
token to the request URI query component as defined by using
the access_token parameter.
The HTTP request URI query can include other
request-specific parameters, in which case, the access_token parameter MUST be properly
separated from the request-specific parameters by an & character (ASCII code 38).
Because of the Security
Considerations associated with the URI method, it
SHOULD NOT be used unless no other method is feasible.
If the protected resource request does not include
authentication credentials or contains an invalid access
token, 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 as follows:
The scope attribute is a space-delimited list of scope values
indicating the required scope of the access token for accessing the requested resource.
The scope attribute MUST NOT appear more than once.
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 . In addition, the resource server MAY
include the error_description attribute to provide a
human-readable explanation, and the error_uri attribute with
an absolute URI identifying a human-readable web page explaining the error.
The error, error_description, and
error_uri attribute MUST NOT appear more than once.
[[ add language and encoding information to error_description if the core specification does ]]
When a request fails, the resource server responds using the appropriate HTTP status
code (typically, 400, 401, or 403), 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 than provided 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 (i.e. the client was unaware
authentication is necessary or attempted using an unsupported authentication method),
the resource server SHOULD NOT include an error code or other error information.
This section describes the relevant security threats regarding
token handling when using bearer tokens and describes how to
mitigate these threats.
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 . Since this document builds on the
OAuth 2.0 specification, we exclude a discussion of threats
that are described there or in related documents.
An attacker may generate a bogus 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.
Tokens may contain authentication and attribute
statements that include sensitive information.
An attacker uses the token generated for consumption by
resource server to obtain access to another resource
server.
An attacker attempts to use a 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 token by using a digital signature or a
Message Authentication Code (MAC).
Alternatively, a bearer token can contain a reference to
authorization information, rather than encoding the
information directly. Such references MUST be infeasible for
an attacker to guess; using a reference may require an extra
interaction between a server and the token issuer to resolve
the reference to the authorization information.
This document does not specify the encoding or the contents
of the token; hence detailed recommendations for token
integrity protection are outside the scope of this document.
We assume that the token integrity protection is sufficient
to prevent the token from being modified.
To deal with token redirect, 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.
To provide protection against token disclosure,
confidentiality protection is applied via TLS with a
ciphersuite that offers confidentiality protection. This
requires that the communication interaction between the
client and the authorization server, as well as the
interaction between the client and the resource server,
utilize confidentiality protection.
Since TLS is mandatory to
implement and to use with this specification, it is the
preferred approach for preventing token disclosure via the
communication channel. For those cases where the client
is prevented from observing the contents of the token, token
encryption has to be applied in addition to the usage of TLS
protection.
To deal with token capture and replay,
the following recommendations are
made: First, the lifetime of the token has to be limited by
putting a validity time field inside the protected part of
the token. Note that using short-lived (one hour or less)
tokens significantly reduces the impact of one of them being
leaked. Second, confidentiality protection of the exchanges
between the client and the authorization server and between
the client and the resource server MUST be applied, for instance,
through the use of TLS. As a
consequence, no eavesdropper along the communication path is
able to observe the token exchange. Consequently, such an
on-path adversary cannot replay the token.
Furthermore, when
presenting the token to a resource server, the client MUST
verify the identity of that resource server, as per .
Note that the
client MUST validate the TLS certificate chain when making
these requests to protected resources. Presenting the token
to an unauthenticated and unauthorized resource server or
failing to validate the certificate chain will allow
adversaries to steal the token and gain unauthorized access
to protected resources.
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) when making requests
with bearer tokens. Failing to do so exposes the token
to numerous attacks that could give attackers unintended
access.
Implementations MUST NOT store bearer tokens within
cookies that can be sent in the clear (which is the
default transmission mode for cookies).
Using short-lived (one hour or less) bearer tokens can
reduce the impact of one of them being leaked. In
particular, only short-lived bearer tokens should be
issued to clients that run within a web browser or other
environments where information leakage may occur.
Issue bearer tokens that contain an audience
restriction, scoping their use to the intended relying
party or set of relying parties.
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 (typically as query
string parameters), attackers might be able to steal
them from the history data, logs, or other unsecured
locations. Instead, pass bearer tokens in HTTP message
headers or message bodies for which confidentiality
measures are taken.
This specification registers the following access token type in the OAuth Access Token
Type Registry.
Bearer
(none)
Bearer
IETF
[[ this document ]]
NIST Special Publication 800-63-1, INFORMATION SECURITYNISTNISTNISTNISTNISTNIST
The following people contributed to preliminary versions of this document:
Blaine Cook (BT), Brian Eaton (Google), Yaron Goland (Microsoft), Brent Goldman (Facebook),
Raffi Krikorian (Twitter), Luke Shepard (Facebook), and Allen Tom (Yahoo!). The content and
concepts within are a product of the OAuth community, the WRAP community, and the OAuth Working
Group.
The OAuth Working Group has dozens of very active contributors who proposed ideas and
wording for this document, including:
Michael Adams, Andrew Arnott, Dirk Balfanz, Brian Campbell, Leah Culver, Bill de hÓra,
Brian Ellin, Igor Faynberg, George Fletcher, Tim Freeman, Evan Gilbert, Justin Hart,
John Kemp, Eran Hammer-Lahav, Chasen Le Hara, Michael B. Jones, Torsten Lodderstedt,
Eve Maler, James Manger, Laurence Miao,
Chuck Mortimore, Anthony Nadalin, Justin Richer, Peter Saint-Andre, Nat Sakimura, Rob Sayre,
Marius Scurtescu, Naitik Shah, Justin Smith, Jeremy Suriel, Christian Stübner, Paul Tarjan,
and Franklin Tse.
[[ to be removed by the RFC editor before publication as an RFC ]]
-07
Added missing comma in error response example.
-06
Changed parameter name bearer_token to access_token, per working group
consensus.
Changed HTTP status code for invalid_request error code from HTTP
401 (Unauthorized) back to HTTP 400 (Bad Request), per
input from HTTP working group experts.
-05
Removed OAuth Errors Registry, per design team input.
Changed HTTP status code for invalid_request error code from HTTP
400 (Bad Request) to HTTP 401 (Unauthorized) to match HTTP
usage [[ change pending working group consensus ]].
Added missing quotation marks in error-uri definition.
Added note to add language and encoding information to
error_description if the core specification does.
Explicitly reference the Augmented Backus-Naur Form (ABNF)
defined in .
Use auth-param instead of repeating its definition, which
is ( token "=" ( token / quoted-string ) ).
Clarify security considerations about including an
audience restriction in the token and include a
recommendation to issue scoped bearer tokens in the
summary of recommendations.
-04
Edits responding to working group last call feedback on
-03. Specific edits enumerated below.
Added Bearer Token definition in Terminology section.
Changed parameter name oauth_token to bearer_token.
Added realm parameter to WWW-Authenticate response to comply
with .
Removed "[ RWS 1#auth-param ]" from credentials definition since it did
not comply with the ABNF in .
Removed restriction that the bearer_token (formerly oauth_token) parameter be the last
parameter in the entity-body and the HTTP request URI
query.
Do not require WWW-Authenticate Response in a reply to a
malformed request, as an HTTP 400 Bad Request response
without a WWW-Authenticate header is likely the right
response in some cases of malformed requests.
Removed OAuth Parameters registry extension.
Numerous editorial improvements suggested by working group
members.
-03
Restored the WWW-Authenticate response header
functionality deleted from the framework specification in
draft 12 based upon the specification text from draft 11.
Augmented the OAuth Parameters registry by adding two
additional parameter usage locations: "resource request"
and "resource response".
Registered the "oauth_token" OAuth parameter with usage
location "resource request".
Registered the "error" OAuth parameter.
Created the OAuth Error registry and registered errors.
Changed the "OAuth2" OAuth access token type name to
"Bearer".
-02
Incorporated feedback received on draft 01. Most changes
were to the security considerations section. No normative
changes were made. Specific changes included:
Changed terminology from "token reuse" to "token capture
and replay".
Removed sentence "Encrypting the token contents is another
alternative" from the security considerations since it was
redundant and potentially confusing.
Corrected some references to "resource server" to be
"authorization server" in the security considerations.
Generalized security considerations language about
obtaining consent of the resource owner.
Broadened scope of security considerations description for
recommendation "Don't pass bearer tokens in page URLs".
Removed unused reference to OAuth 1.0.
Updated reference to framework specification and updated
David Recordon's e-mail address.
Removed security considerations text on authenticating
clients.
Registered the "OAuth2" OAuth access token type and
"oauth_token" parameter.
-01
First public draft, which incorporates feedback received
on -00 including enhanced Security Considerations content.
This version is intended to accompany OAuth 2.0 draft 11.
-00
Initial draft based on preliminary version of OAuth 2.0 draft 11.