summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--doc/specs/draft-ietf-oauth-v2-bearer-05.txt952
-rw-r--r--projecttemplates/RelyingPartyLogic/OAuthAuthorizationServer.cs2
-rw-r--r--samples/OAuthAuthorizationServer/Code/OAuth2AuthorizationServer.cs2
-rw-r--r--src/DotNetOpenAuth.Test/OAuth2/MessageFactoryTests.cs12
-rw-r--r--src/DotNetOpenAuth/DotNetOpenAuth.csproj4
-rw-r--r--src/DotNetOpenAuth/Messaging/MessagingUtilities.cs4
-rw-r--r--src/DotNetOpenAuth/OAuth2/AuthorizationServer.cs9
-rw-r--r--src/DotNetOpenAuth/OAuth2/ChannelElements/AccessRequestBindingElement.cs15
-rw-r--r--src/DotNetOpenAuth/OAuth2/ChannelElements/AuthorizationCodeBindingElement.cs4
-rw-r--r--src/DotNetOpenAuth/OAuth2/ChannelElements/EndUserAuthorizationResponseTypeEncoder.cs14
-rw-r--r--src/DotNetOpenAuth/OAuth2/ChannelElements/GrantTypeEncoder.cs8
-rw-r--r--src/DotNetOpenAuth/OAuth2/ChannelElements/IAuthorizationCarryingRequest.cs (renamed from src/DotNetOpenAuth/OAuth2/ChannelElements/ITokenCarryingRequest.cs)4
-rw-r--r--src/DotNetOpenAuth/OAuth2/ChannelElements/OAuth2ChannelBase.cs1
-rw-r--r--src/DotNetOpenAuth/OAuth2/ChannelElements/OAuth2ResourceServerChannel.cs79
-rw-r--r--src/DotNetOpenAuth/OAuth2/ChannelElements/ScopeEncoder.cs2
-rw-r--r--src/DotNetOpenAuth/OAuth2/ClientBase.cs2
-rw-r--r--src/DotNetOpenAuth/OAuth2/Messages/AccessProtectedResourceRequest.cs86
-rw-r--r--src/DotNetOpenAuth/OAuth2/Messages/AccessTokenAssertionRequest.cs49
-rw-r--r--src/DotNetOpenAuth/OAuth2/Messages/AccessTokenAuthorizationCodeRequest.cs8
-rw-r--r--src/DotNetOpenAuth/OAuth2/Messages/AccessTokenClientCredentialsRequest.cs4
-rw-r--r--src/DotNetOpenAuth/OAuth2/Messages/AccessTokenRefreshRequest.cs9
-rw-r--r--src/DotNetOpenAuth/OAuth2/Messages/AccessTokenRequestBase.cs8
-rw-r--r--src/DotNetOpenAuth/OAuth2/Messages/AccessTokenResourceOwnerPasswordCredentialsRequest.cs2
-rw-r--r--src/DotNetOpenAuth/OAuth2/Messages/AccessTokenSuccessResponse.cs11
-rw-r--r--src/DotNetOpenAuth/OAuth2/Messages/EndUserAuthorizationFailedResponse.cs10
-rw-r--r--src/DotNetOpenAuth/OAuth2/Messages/EndUserAuthorizationRequest.cs10
-rw-r--r--src/DotNetOpenAuth/OAuth2/Messages/EndUserAuthorizationResponseType.cs12
-rw-r--r--src/DotNetOpenAuth/OAuth2/Messages/EndUserAuthorizationSuccessAccessTokenResponse.cs32
-rw-r--r--src/DotNetOpenAuth/OAuth2/Messages/EndUserAuthorizationSuccessAuthCodeResponse.cs8
-rw-r--r--src/DotNetOpenAuth/OAuth2/Messages/GrantType.cs2
-rw-r--r--src/DotNetOpenAuth/OAuth2/Messages/OAuth 2 Messages.cd177
-rw-r--r--src/DotNetOpenAuth/OAuth2/Messages/ScopedAccessTokenRequest.cs34
-rw-r--r--src/DotNetOpenAuth/OAuth2/Messages/UnauthorizedResponse.cs2
-rw-r--r--src/DotNetOpenAuth/OAuth2/OAuthUtilities.cs4
-rw-r--r--src/DotNetOpenAuth/OAuth2/Protocol.cs47
35 files changed, 1230 insertions, 399 deletions
diff --git a/doc/specs/draft-ietf-oauth-v2-bearer-05.txt b/doc/specs/draft-ietf-oauth-v2-bearer-05.txt
new file mode 100644
index 0000000..a446893
--- /dev/null
+++ b/doc/specs/draft-ietf-oauth-v2-bearer-05.txt
@@ -0,0 +1,952 @@
+
+
+
+Network Working Group M. Jones
+Internet-Draft Microsoft
+Intended status: Standards Track D. Hardt
+Expires: November 22, 2011 independent
+ D. Recordon
+ Facebook
+ May 21, 2011
+
+
+ The OAuth 2.0 Protocol: Bearer Tokens
+ draft-ietf-oauth-v2-bearer-05
+
+Abstract
+
+ This specification describes how to use bearer tokens when accessing
+ OAuth 2.0 protected resources.
+
+Status of this Memo
+
+ 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 http://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 November 22, 2011.
+
+Copyright Notice
+
+ Copyright (c) 2011 IETF Trust and the persons identified as the
+ document authors. All rights reserved.
+
+ This document is subject to BCP 78 and the IETF Trust's Legal
+ Provisions Relating to IETF Documents
+ (http://trustee.ietf.org/license-info) in effect on the date of
+ publication of this document. Please review these documents
+ carefully, as they describe your rights and restrictions with respect
+ to this document. Code Components extracted from this document must
+ include Simplified BSD License text as described in Section 4.e of
+ the Trust Legal Provisions and are provided without warranty as
+ described in the Simplified BSD License.
+
+
+
+Jones, et al. Expires November 22, 2011 [Page 1]
+
+Internet-Draft OAuth 2.0 Bearer Tokens May 2011
+
+
+Table of Contents
+
+ 1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . . 3
+ 1.1. Notational Conventions . . . . . . . . . . . . . . . . . . 3
+ 1.2. Terminology . . . . . . . . . . . . . . . . . . . . . . . 3
+ 1.3. Overview . . . . . . . . . . . . . . . . . . . . . . . . . 3
+ 2. Authenticated Requests . . . . . . . . . . . . . . . . . . . . 4
+ 2.1. The Authorization Request Header Field . . . . . . . . . . 5
+ 2.2. Form-Encoded Body Parameter . . . . . . . . . . . . . . . 5
+ 2.3. URI Query Parameter . . . . . . . . . . . . . . . . . . . 6
+ 2.4. The WWW-Authenticate Response Header Field . . . . . . . . 7
+ 2.4.1. Error Codes . . . . . . . . . . . . . . . . . . . . . 8
+ 3. Security Considerations . . . . . . . . . . . . . . . . . . . 9
+ 3.1. Security Threats . . . . . . . . . . . . . . . . . . . . . 9
+ 3.2. Threat Mitigation . . . . . . . . . . . . . . . . . . . . 9
+ 3.3. Summary of Recommendations . . . . . . . . . . . . . . . . 11
+ 4. IANA Considerations . . . . . . . . . . . . . . . . . . . . . 11
+ 4.1. OAuth Access Token Type Registration . . . . . . . . . . . 11
+ 4.1.1. The "Bearer" OAuth Access Token Type . . . . . . . . . 12
+ 5. References . . . . . . . . . . . . . . . . . . . . . . . . . . 12
+ 5.1. Normative References . . . . . . . . . . . . . . . . . . . 12
+ 5.2. Informative References . . . . . . . . . . . . . . . . . . 13
+ Appendix A. Acknowledgements . . . . . . . . . . . . . . . . . . 13
+ Appendix B. Document History . . . . . . . . . . . . . . . . . . 14
+ Authors' Addresses . . . . . . . . . . . . . . . . . . . . . . . . 16
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Jones, et al. Expires November 22, 2011 [Page 2]
+
+Internet-Draft OAuth 2.0 Bearer Tokens May 2011
+
+
+1. Introduction
+
+ OAuth enables clients to access protected resources by obtaining an
+ access token, which is defined in [I-D.ietf-oauth-v2] 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 [RFC2616] using TLS [RFC5246]. Other specifications may extend
+ it for use with other transport protocols.
+
+1.1. Notational Conventions
+
+ 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 [RFC2119].
+
+ This document uses the Augmented Backus-Naur Form (ABNF) notation of
+ [I-D.ietf-httpbis-p1-messaging], which is based upon the Augmented
+ Backus-Naur Form (ABNF) notation of [RFC5234]. Additionally, the
+ following rules are included from [RFC2617]: auth-param and realm;
+ from [RFC3986]: URI-Reference; and from
+ [I-D.ietf-httpbis-p1-messaging]: RWS and quoted-string.
+
+ Unless otherwise noted, all the protocol parameter names and values
+ are case sensitive.
+
+1.2. Terminology
+
+ Bearer Token
+ 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 [I-D.ietf-oauth-v2].
+
+1.3. Overview
+
+ OAuth provides a method for clients to access a protected resource on
+ behalf of a resource owner. Before a client can access a protected
+
+
+
+Jones, et al. Expires November 22, 2011 [Page 3]
+
+Internet-Draft OAuth 2.0 Bearer Tokens May 2011
+
+
+ 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.
+
+ +--------+ +---------------+
+ | |--(A)- Authorization Request ->| Resource |
+ | | | Owner |
+ | |<-(B)----- Access Grant -------| |
+ | | +---------------+
+ | |
+ | | Access Grant & +---------------+
+ | |--(C)--- Client Credentials -->| Authorization |
+ | Client | | Server |
+ | |<-(D)----- Access Token -------| |
+ | | +---------------+
+ | |
+ | | +---------------+
+ | |--(E)----- Access Token ------>| Resource |
+ | | | Server |
+ | |<-(F)--- Protected Resource ---| |
+ +--------+ +---------------+
+
+ Figure 1: Abstract Protocol Flow
+
+ The abstract flow illustrated in Figure 1 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.
+
+
+2. Authenticated Requests
+
+ Clients SHOULD make authenticated requests with a bearer token using
+ the "Authorization" request header field defined by [RFC2617].
+
+
+
+Jones, et al. Expires November 22, 2011 [Page 4]
+
+Internet-Draft OAuth 2.0 Bearer Tokens May 2011
+
+
+ Resource servers MUST accept authenticated requests using the
+ "Bearer" HTTP authorization scheme as described in Section 2.1, 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 Section 2.2; or clients MAY transmit the access token in
+ the HTTP request URI in the query component as described in
+ Section 2.3. 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 (Section 3) associated with
+ the URI method, it SHOULD NOT be used unless no other method is
+ feasible.
+
+2.1. The Authorization Request Header Field
+
+ 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.
+
+ For example:
+
+ GET /resource HTTP/1.1
+ Host: server.example.com
+ Authorization: Bearer vF9dft4qmT
+
+ The "Authorization" header field uses the framework defined by
+ [RFC2617] as follows:
+
+ credentials = "Bearer" RWS access-token
+ access-token = 1*( quoted-char / <"> )
+
+ quoted-char = ALPHA / DIGIT /
+ "!" / "#" / "$" / "%" / "&" / "'" / "(" / ")" /
+ "*" / "+" / "-" / "." / "/" / ":" / "<" / "=" /
+ ">" / "?" / "@" / "[" / "]" / "^" / "_" / "`" /
+ "{" / "|" / "}" / "~" / "\" / "," / ";"
+
+2.2. Form-Encoded Body Parameter
+
+ When including the access token in the HTTP request entity-body, the
+ client adds the access token to the request body using the
+ "bearer_token" parameter. The client MUST NOT use this method unless
+ the following conditions are met:
+
+
+
+Jones, et al. Expires November 22, 2011 [Page 5]
+
+Internet-Draft OAuth 2.0 Bearer Tokens May 2011
+
+
+ o The HTTP request entity-body is single-part.
+
+ o The entity-body follows the encoding requirements of the
+ "application/x-www-form-urlencoded" content-type as defined by
+ [W3C.REC-html401-19991224].
+
+ o The HTTP request entity-header includes the "Content-Type" header
+ field set to "application/x-www-form-urlencoded".
+
+ o 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 "bearer_token" parameter MUST be properly separated
+ from the request-specific parameters by an "&" character (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
+
+ bearer_token=vF9dft4qmT
+
+ 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.
+
+2.3. URI Query Parameter
+
+ 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 [RFC3986] using the "bearer_token" parameter.
+
+ For example, the client makes the following HTTP request using
+ transport-layer security:
+
+ GET /resource?bearer_token=vF9dft4qmT HTTP/1.1
+ Host: server.example.com
+
+ The HTTP request URI query can include other request-specific
+ parameters, in which case, the "bearer_token" parameter MUST be
+ properly separated from the request-specific parameters by an "&"
+ character (ASCII code 38).
+
+
+
+
+Jones, et al. Expires November 22, 2011 [Page 6]
+
+Internet-Draft OAuth 2.0 Bearer Tokens May 2011
+
+
+ For example:
+
+ http://example.com/resource?x=y&bearer_token=vF9dft4qmT
+
+ Because of the Security Considerations (Section 3) associated with
+ the URI method, it SHOULD NOT be used unless no other method is
+ feasible.
+
+2.4. The WWW-Authenticate Response Header Field
+
+ 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
+ [RFC2617] as follows:
+
+ challenge = "Bearer" [ RWS 1#param ]
+
+ param = realm / scope /
+ error / error-desc / error-uri /
+ auth-param
+
+ scope = "scope" "=" <"> scope-v *( SP scope-v ) <">
+ scope-v = 1*quoted-char
+
+ quoted-char = ALPHA / DIGIT /
+ "!" / "#" / "$" / "%" / "&" / "'" / "(" / ")" /
+ "*" / "+" / "-" / "." / "/" / ":" / "<" / "=" /
+ ">" / "?" / "@" / "[" / "]" / "^" / "_" / "`" /
+ "{" / "|" / "}" / "~" / "\" / "," / ";"
+
+ error = "error" "=" quoted-string
+ error-desc = "error_description" "=" quoted-string
+ error-uri = "error_uri" "=" <"> URI-reference <">
+
+ 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
+ Section 2.4.1. 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
+
+
+
+Jones, et al. Expires November 22, 2011 [Page 7]
+
+Internet-Draft OAuth 2.0 Bearer Tokens May 2011
+
+
+ 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 ]]
+
+ 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"
+
+2.4.1. Error Codes
+
+ 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:
+
+ invalid_request
+ 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 401 (Unauthorized) status code.
+
+ invalid_token
+ 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.
+
+ insufficient_scope
+ 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
+
+
+
+Jones, et al. Expires November 22, 2011 [Page 8]
+
+Internet-Draft OAuth 2.0 Bearer Tokens May 2011
+
+
+ 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"
+
+
+3. Security Considerations
+
+ This section describes the relevant security threats regarding token
+ handling when using bearer tokens and describes how to mitigate these
+ threats.
+
+3.1. Security 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 [NIST800-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.
+
+ Token manufacture/modification: 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.
+
+ Token disclosure: Tokens may contain authentication and attribute
+ statements that include sensitive information.
+
+ Token redirect: An attacker uses the token generated for consumption
+ by resource server to obtain access to another resource server.
+
+ Token replay: An attacker attempts to use a token that has already
+ been used with that resource server in the past.
+
+3.2. Threat Mitigation
+
+ 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
+
+
+
+Jones, et al. Expires November 22, 2011 [Page 9]
+
+Internet-Draft OAuth 2.0 Bearer Tokens May 2011
+
+
+ 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 [RFC5246] 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
+ [RFC5246]. 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 [RFC2818]. 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.
+
+
+
+
+
+
+Jones, et al. Expires November 22, 2011 [Page 10]
+
+Internet-Draft OAuth 2.0 Bearer Tokens May 2011
+
+
+3.3. Summary of Recommendations
+
+ Safeguard bearer tokens 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.
+
+ Validate SSL certificate chains 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.
+
+ Always use TLS (https) Clients MUST always use TLS [RFC5246] (https)
+ when making requests with bearer tokens. Failing to do so exposes
+ the token to numerous attacks that could give attackers unintended
+ access.
+
+ Don't store bearer tokens in cookies Implementations MUST NOT store
+ bearer tokens within cookies that can be sent in the clear (which
+ is the default transmission mode for cookies).
+
+ Issue short-lived bearer tokens 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 scoped bearer tokens Issue bearer tokens that contain an
+ audience restriction, scoping their use to the intended relying
+ party or set of relying parties.
+
+ Don't pass bearer tokens in page URLs 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.
+
+
+4. IANA Considerations
+
+4.1. OAuth Access Token Type Registration
+
+ This specification registers the following access token type in the
+ OAuth Access Token Type Registry.
+
+
+
+Jones, et al. Expires November 22, 2011 [Page 11]
+
+Internet-Draft OAuth 2.0 Bearer Tokens May 2011
+
+
+4.1.1. The "Bearer" OAuth Access Token Type
+
+ Type name:
+ Bearer
+
+ Additional Token Endpoint Response Parameters:
+ (none)
+
+ HTTP Authentication Scheme(s):
+ Bearer
+
+ Change controller:
+ IETF
+
+ Specification document(s):
+ [[ this document ]]
+
+
+5. References
+
+5.1. Normative References
+
+ [I-D.ietf-httpbis-p1-messaging]
+ Fielding, R., Gettys, J., Mogul, J., Nielsen, H.,
+ Masinter, L., Leach, P., Berners-Lee, T., and J. Reschke,
+ "HTTP/1.1, part 1: URIs, Connections, and Message
+ Parsing", draft-ietf-httpbis-p1-messaging-14 (work in
+ progress), April 2011.
+
+ [I-D.ietf-oauth-v2]
+ Hammer-Lahav, E., Recordon, D., and D. Hardt, "The OAuth
+ 2.0 Authorization Protocol", draft-ietf-oauth-v2-16 (work
+ in progress), May 2011.
+
+ [RFC2119] Bradner, S., "Key words for use in RFCs to Indicate
+ Requirement Levels", BCP 14, RFC 2119, March 1997.
+
+ [RFC2616] Fielding, R., Gettys, J., Mogul, J., Frystyk, H.,
+ Masinter, L., Leach, P., and T. Berners-Lee, "Hypertext
+ Transfer Protocol -- HTTP/1.1", RFC 2616, June 1999.
+
+ [RFC2617] Franks, J., Hallam-Baker, P., Hostetler, J., Lawrence, S.,
+ Leach, P., Luotonen, A., and L. Stewart, "HTTP
+ Authentication: Basic and Digest Access Authentication",
+ RFC 2617, June 1999.
+
+ [RFC2818] Rescorla, E., "HTTP Over TLS", RFC 2818, May 2000.
+
+
+
+
+Jones, et al. Expires November 22, 2011 [Page 12]
+
+Internet-Draft OAuth 2.0 Bearer Tokens May 2011
+
+
+ [RFC3986] Berners-Lee, T., Fielding, R., and L. Masinter, "Uniform
+ Resource Identifier (URI): Generic Syntax", STD 66,
+ RFC 3986, January 2005.
+
+ [RFC5234] Crocker, D. and P. Overell, "Augmented BNF for Syntax
+ Specifications: ABNF", STD 68, RFC 5234, January 2008.
+
+ [RFC5246] Dierks, T. and E. Rescorla, "The Transport Layer Security
+ (TLS) Protocol Version 1.2", RFC 5246, August 2008.
+
+ [W3C.REC-html401-19991224]
+ Hors, A., Jacobs, I., and D. Raggett, "HTML 4.01
+ Specification", World Wide Web Consortium
+ Recommendation REC-html401-19991224, December 1999,
+ <http://www.w3.org/TR/1999/REC-html401-19991224>.
+
+5.2. Informative References
+
+ [I-D.ietf-httpbis-p7-auth]
+ Fielding, R., Gettys, J., Mogul, J., Nielsen, H.,
+ Masinter, L., Leach, P., Berners-Lee, T., and J. Reschke,
+ "HTTP/1.1, part 7: Authentication",
+ draft-ietf-httpbis-p7-auth-13 (work in progress),
+ March 2011.
+
+ [NIST800-63]
+ Burr, W., Dodson, D., Perlner, R., Polk, T., Gupta, S.,
+ and E. Nabbus, "NIST Special Publication 800-63-1,
+ INFORMATION SECURITY", December 2008.
+
+
+Appendix A. Acknowledgements
+
+ 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 hOra, 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,
+
+
+
+Jones, et al. Expires November 22, 2011 [Page 13]
+
+Internet-Draft OAuth 2.0 Bearer Tokens May 2011
+
+
+ Justin Smith, Jeremy Suriel, Christian Stuebner, Paul Tarjan, and
+ Franklin Tse.
+
+
+Appendix B. Document History
+
+ [[ to be removed by the RFC editor before publication as an RFC ]]
+
+ -05
+
+ o Removed OAuth Errors Registry, per design team input.
+
+ o 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 ]].
+
+ o Added missing quotation marks in error-uri definition.
+
+ o Added note to add language and encoding information to
+ error_description if the core specification does.
+
+ o Explicitly reference the Augmented Backus-Naur Form (ABNF) defined
+ in [RFC5234].
+
+ o Use auth-param instead of repeating its definition, which is (
+ token "=" ( token / quoted-string ) ).
+
+ o 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
+
+ o Edits responding to working group last call feedback on -03.
+ Specific edits enumerated below.
+
+ o Added Bearer Token definition in Terminology section.
+
+ o Changed parameter name "oauth_token" to "bearer_token".
+
+ o Added realm parameter to "WWW-Authenticate" response to comply
+ with [RFC2617].
+
+ o Removed "[ RWS 1#auth-param ]" from "credentials" definition since
+ it did not comply with the ABNF in [I-D.ietf-httpbis-p7-auth].
+
+ o Removed restriction that the "bearer_token" (formerly
+ "oauth_token") parameter be the last parameter in the entity-body
+
+
+
+Jones, et al. Expires November 22, 2011 [Page 14]
+
+Internet-Draft OAuth 2.0 Bearer Tokens May 2011
+
+
+ and the HTTP request URI query.
+
+ o 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.
+
+ o Removed OAuth Parameters registry extension.
+
+ o Numerous editorial improvements suggested by working group
+ members.
+
+ -03
+
+ o Restored the WWW-Authenticate response header functionality
+ deleted from the framework specification in draft 12 based upon
+ the specification text from draft 11.
+
+ o Augmented the OAuth Parameters registry by adding two additional
+ parameter usage locations: "resource request" and "resource
+ response".
+
+ o Registered the "oauth_token" OAuth parameter with usage location
+ "resource request".
+
+ o Registered the "error" OAuth parameter.
+
+ o Created the OAuth Error registry and registered errors.
+
+ o Changed the "OAuth2" OAuth access token type name to "Bearer".
+
+ -02
+
+ o Incorporated feedback received on draft 01. Most changes were to
+ the security considerations section. No normative changes were
+ made. Specific changes included:
+
+ o Changed terminology from "token reuse" to "token capture and
+ replay".
+
+ o Removed sentence "Encrypting the token contents is another
+ alternative" from the security considerations since it was
+ redundant and potentially confusing.
+
+ o Corrected some references to "resource server" to be
+ "authorization server" in the security considerations.
+
+
+
+
+
+Jones, et al. Expires November 22, 2011 [Page 15]
+
+Internet-Draft OAuth 2.0 Bearer Tokens May 2011
+
+
+ o Generalized security considerations language about obtaining
+ consent of the resource owner.
+
+ o Broadened scope of security considerations description for
+ recommendation "Don't pass bearer tokens in page URLs".
+
+ o Removed unused reference to OAuth 1.0.
+
+ o Updated reference to framework specification and updated David
+ Recordon's e-mail address.
+
+ o Removed security considerations text on authenticating clients.
+
+ o Registered the "OAuth2" OAuth access token type and "oauth_token"
+ parameter.
+
+ -01
+
+ o 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
+
+ o Initial draft based on preliminary version of OAuth 2.0 draft 11.
+
+
+Authors' Addresses
+
+ Michael B. Jones
+ Microsoft
+
+ Email: mbj@microsoft.com
+ URI: http://self-issued.info/
+
+
+ Dick Hardt
+ independent
+
+ Email: dick.hardt@gmail.com
+ URI: http://dickhardt.org/
+
+
+
+
+
+
+
+
+
+
+Jones, et al. Expires November 22, 2011 [Page 16]
+
+Internet-Draft OAuth 2.0 Bearer Tokens May 2011
+
+
+ David Recordon
+ Facebook
+
+ Email: dr@fb.com
+ URI: http://www.davidrecordon.com/
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Jones, et al. Expires November 22, 2011 [Page 17]
+
diff --git a/projecttemplates/RelyingPartyLogic/OAuthAuthorizationServer.cs b/projecttemplates/RelyingPartyLogic/OAuthAuthorizationServer.cs
index 69757be..f0608d5 100644
--- a/projecttemplates/RelyingPartyLogic/OAuthAuthorizationServer.cs
+++ b/projecttemplates/RelyingPartyLogic/OAuthAuthorizationServer.cs
@@ -98,7 +98,7 @@ namespace RelyingPartyLogic {
// NEVER issue an auto-approval to a client that would end up getting an access token immediately
// (without a client secret), as that would allow ANY client to spoof an approved client's identity
// and obtain unauthorized access to user data.
- if (EndUserAuthorizationRequest.ResponseType == EndUserAuthorizationResponseTypes.AuthorizationCode) {
+ if (authorizationRequest.ResponseType == EndUserAuthorizationResponseType.AuthorizationCode) {
// Never issue auto-approval if the client secret is blank, since that too makes it easy to spoof
// a client's identity and obtain unauthorized access.
var requestingClient = Database.DataContext.Clients.First(c => c.ClientIdentifier == authorizationRequest.ClientIdentifier);
diff --git a/samples/OAuthAuthorizationServer/Code/OAuth2AuthorizationServer.cs b/samples/OAuthAuthorizationServer/Code/OAuth2AuthorizationServer.cs
index d2583a2..e2e4325 100644
--- a/samples/OAuthAuthorizationServer/Code/OAuth2AuthorizationServer.cs
+++ b/samples/OAuthAuthorizationServer/Code/OAuth2AuthorizationServer.cs
@@ -53,7 +53,7 @@
// NEVER issue an auto-approval to a client that would end up getting an access token immediately
// (without a client secret), as that would allow ANY client to spoof an approved client's identity
// and obtain unauthorized access to user data.
- if (EndUserAuthorizationRequest.ResponseType == EndUserAuthorizationResponseTypes.AuthorizationCode) {
+ if (authorizationRequest.ResponseType == EndUserAuthorizationResponseType.AuthorizationCode) {
// Never issue auto-approval if the client secret is blank, since that too makes it easy to spoof
// a client's identity and obtain unauthorized access.
var requestingClient = MvcApplication.DataContext.Clients.First(c => c.ClientIdentifier == authorizationRequest.ClientIdentifier);
diff --git a/src/DotNetOpenAuth.Test/OAuth2/MessageFactoryTests.cs b/src/DotNetOpenAuth.Test/OAuth2/MessageFactoryTests.cs
index 0e82154..e6237ca 100644
--- a/src/DotNetOpenAuth.Test/OAuth2/MessageFactoryTests.cs
+++ b/src/DotNetOpenAuth.Test/OAuth2/MessageFactoryTests.cs
@@ -122,18 +122,6 @@ namespace DotNetOpenAuth.Test.OAuth2 {
Assert.IsInstanceOf(typeof(AccessTokenClientCredentialsRequest), request);
}
- [TestCase]
- public void AccessTokenAssertionRequest() {
- var fields = new Dictionary<string, string> {
- { Protocol.client_id, "abc" },
- { Protocol.assertion_type, "abc" },
- { Protocol.assertion, "abc" },
- { Protocol.grant_type, "assertion" },
- };
- IDirectedProtocolMessage request = this.messageFactory.GetNewRequestMessage(this.recipient, fields);
- Assert.IsInstanceOf(typeof(AccessTokenAssertionRequest), request);
- }
-
#endregion
}
}
diff --git a/src/DotNetOpenAuth/DotNetOpenAuth.csproj b/src/DotNetOpenAuth/DotNetOpenAuth.csproj
index 8123d7a..60f2b8e 100644
--- a/src/DotNetOpenAuth/DotNetOpenAuth.csproj
+++ b/src/DotNetOpenAuth/DotNetOpenAuth.csproj
@@ -370,7 +370,7 @@ http://opensource.org/licenses/ms-pl.html
<Compile Include="OAuth2\ChannelElements\ScopeEncoder.cs" />
<Compile Include="Messaging\UriStyleMessageFormatter.cs" />
<Compile Include="OAuth2\ChannelElements\IAuthorizationDescription.cs" />
- <Compile Include="OAuth2\ChannelElements\ITokenCarryingRequest.cs" />
+ <Compile Include="OAuth2\ChannelElements\IAuthorizationCarryingRequest.cs" />
<Compile Include="OAuth2\ChannelElements\OAuth2ResourceServerChannel.cs" />
<Compile Include="Messaging\StandardMessageFactoryChannel.cs" />
<Compile Include="OAuth2\ChannelElements\RefreshToken.cs" />
@@ -385,7 +385,6 @@ http://opensource.org/licenses/ms-pl.html
<Compile Include="OAuth2\IClientAuthorizationTracker.cs" />
<Compile Include="OAuth2\IConsumerDescription.cs" />
<Compile Include="OAuth2\Messages\AccessProtectedResourceRequest.cs" />
- <Compile Include="OAuth2\Messages\AccessTokenAssertionRequest.cs" />
<Compile Include="OAuth2\Messages\AccessTokenAuthorizationCodeRequest.cs" />
<Compile Include="OAuth2\Messages\AccessTokenResourceOwnerPasswordCredentialsRequest.cs" />
<Compile Include="OAuth2\Messages\AccessTokenRequestBase.cs" />
@@ -398,6 +397,7 @@ http://opensource.org/licenses/ms-pl.html
<Compile Include="OAuth2\Messages\AccessTokenRefreshRequest.cs" />
<Compile Include="OAuth2\Messages\EndUserAuthorizationResponseType.cs" />
<Compile Include="OAuth2\Messages\IMessageWithClientState.cs" />
+ <Compile Include="OAuth2\Messages\ScopedAccessTokenRequest.cs" />
<Compile Include="OAuth2\Messages\UnauthorizedResponse.cs" />
<Compile Include="OAuth2\Messages\AccessTokenFailedResponse.cs" />
<Compile Include="OAuth2\Messages\AccessTokenSuccessResponse.cs" />
diff --git a/src/DotNetOpenAuth/Messaging/MessagingUtilities.cs b/src/DotNetOpenAuth/Messaging/MessagingUtilities.cs
index 4be9eb5..8fc691f 100644
--- a/src/DotNetOpenAuth/Messaging/MessagingUtilities.cs
+++ b/src/DotNetOpenAuth/Messaging/MessagingUtilities.cs
@@ -421,10 +421,10 @@ namespace DotNetOpenAuth.Messaging {
string prefix = scheme + " ";
if (authorizationHeader != null) {
// The authorization header may have multiple sections. Look for the appropriate one.
- string[] authorizationSections = authorizationHeader.Split(';'); // TODO: is this the right delimiter?
+ string[] authorizationSections = new string[] { authorizationHeader }; // what is the right delimiter, if any?
foreach (string authorization in authorizationSections) {
string trimmedAuth = authorization.Trim();
- if (trimmedAuth.StartsWith(prefix, StringComparison.OrdinalIgnoreCase)) {
+ if (trimmedAuth.StartsWith(prefix, StringComparison.OrdinalIgnoreCase)) { // RFC 2617 says this is case INsensitive
string data = trimmedAuth.Substring(prefix.Length);
return from element in data.Split(CommaArray)
let parts = element.Split(EqualsArray, 2)
diff --git a/src/DotNetOpenAuth/OAuth2/AuthorizationServer.cs b/src/DotNetOpenAuth/OAuth2/AuthorizationServer.cs
index ea8be94..e95835c 100644
--- a/src/DotNetOpenAuth/OAuth2/AuthorizationServer.cs
+++ b/src/DotNetOpenAuth/OAuth2/AuthorizationServer.cs
@@ -187,12 +187,11 @@ namespace DotNetOpenAuth.OAuth2 {
var client = this.AuthorizationServerServices.GetClientOrThrow(authorizationRequest.ClientIdentifier);
EndUserAuthorizationSuccessResponseBase response;
- switch (EndUserAuthorizationRequest.ResponseType) {
- case EndUserAuthorizationResponseTypes.AccessToken:
+ switch (authorizationRequest.ResponseType) {
+ case EndUserAuthorizationResponseType.AccessToken:
response = new EndUserAuthorizationSuccessAccessTokenResponse(callback, authorizationRequest);
break;
- case EndUserAuthorizationResponseTypes.Both:
- case EndUserAuthorizationResponseTypes.AuthorizationCode:
+ case EndUserAuthorizationResponseType.AuthorizationCode:
response = new EndUserAuthorizationSuccessAuthCodeResponse(callback, authorizationRequest);
break;
default:
@@ -221,7 +220,7 @@ namespace DotNetOpenAuth.OAuth2 {
Contract.Requires<ArgumentNullException>(request != null);
Contract.Requires<ArgumentNullException>(accessTokenEncryptingPublicKey != null);
- var tokenRequest = (ITokenCarryingRequest)request;
+ var tokenRequest = (IAuthorizationCarryingRequest)request;
using (var crypto = this.AuthorizationServerServices.CreateAccessTokenSigningCryptoServiceProvider()) {
var accessTokenFormatter = AccessToken.CreateFormatter(crypto, accessTokenEncryptingPublicKey);
var accessToken = new AccessToken(tokenRequest.AuthorizationDescription, accessTokenLifetime);
diff --git a/src/DotNetOpenAuth/OAuth2/ChannelElements/AccessRequestBindingElement.cs b/src/DotNetOpenAuth/OAuth2/ChannelElements/AccessRequestBindingElement.cs
index b772c0e..0210bd1 100644
--- a/src/DotNetOpenAuth/OAuth2/ChannelElements/AccessRequestBindingElement.cs
+++ b/src/DotNetOpenAuth/OAuth2/ChannelElements/AccessRequestBindingElement.cs
@@ -53,7 +53,7 @@ namespace DotNetOpenAuth.OAuth2.ChannelElements {
/// <see cref="MessagePartAttribute.RequiredProtection"/> properties where applicable.
/// </remarks>
public override MessageProtections? ProcessOutgoingMessage(IProtocolMessage message) {
- var response = message as ITokenCarryingRequest;
+ var response = message as IAuthorizationCarryingRequest;
if (response != null) {
switch (response.CodeOrTokenType) {
case CodeOrTokenType.AuthorizationCode:
@@ -72,7 +72,7 @@ namespace DotNetOpenAuth.OAuth2.ChannelElements {
if (accessTokenResponse != null) {
var directResponseMessage = (IDirectResponseProtocolMessage)accessTokenResponse;
var accessTokenRequest = (AccessTokenRequestBase)directResponseMessage.OriginatingRequest;
- ErrorUtilities.VerifyProtocol(accessTokenRequest.GrantType != GrantType.None || accessTokenResponse.RefreshToken == null, OAuthStrings.NoGrantNoRefreshToken);
+ ErrorUtilities.VerifyProtocol(accessTokenRequest.GrantType != GrantType.ClientCredentials || accessTokenResponse.RefreshToken == null, OAuthStrings.NoGrantNoRefreshToken);
}
return null;
@@ -96,7 +96,7 @@ namespace DotNetOpenAuth.OAuth2.ChannelElements {
/// <see cref="MessagePartAttribute.RequiredProtection"/> properties where applicable.
/// </remarks>
public override MessageProtections? ProcessIncomingMessage(IProtocolMessage message) {
- var tokenRequest = message as ITokenCarryingRequest;
+ var tokenRequest = message as IAuthorizationCarryingRequest;
if (tokenRequest != null) {
try {
switch (tokenRequest.CodeOrTokenType) {
@@ -124,10 +124,13 @@ namespace DotNetOpenAuth.OAuth2.ChannelElements {
// Check that the client secret is correct.
var client = this.AuthorizationServer.GetClientOrThrow(accessRequest.ClientIdentifier);
- ErrorUtilities.VerifyProtocol(string.Equals(client.Secret, accessRequest.ClientSecret, StringComparison.Ordinal), Protocol.incorrect_client_credentials);
+ ErrorUtilities.VerifyProtocol(MessagingUtilities.EqualsConstantTime(client.Secret, accessRequest.ClientSecret), Protocol.incorrect_client_credentials);
- // Make sure the scope the client is requesting does not exceed the scope in the grant.
- ErrorUtilities.VerifyProtocol(accessRequest.Scope.IsSubsetOf(tokenRequest.AuthorizationDescription.Scope), OAuthStrings.AccessScopeExceedsGrantScope, accessRequest.Scope, tokenRequest.AuthorizationDescription.Scope);
+ var scopedAccessRequest = accessRequest as ScopedAccessTokenRequest;
+ if (scopedAccessRequest != null) {
+ // Make sure the scope the client is requesting does not exceed the scope in the grant.
+ ErrorUtilities.VerifyProtocol(scopedAccessRequest.Scope.IsSubsetOf(tokenRequest.AuthorizationDescription.Scope), OAuthStrings.AccessScopeExceedsGrantScope, scopedAccessRequest.Scope, tokenRequest.AuthorizationDescription.Scope);
+ }
}
// Make sure the authorization this token represents hasn't already been revoked.
diff --git a/src/DotNetOpenAuth/OAuth2/ChannelElements/AuthorizationCodeBindingElement.cs b/src/DotNetOpenAuth/OAuth2/ChannelElements/AuthorizationCodeBindingElement.cs
index 58f3d42..31322a0 100644
--- a/src/DotNetOpenAuth/OAuth2/ChannelElements/AuthorizationCodeBindingElement.cs
+++ b/src/DotNetOpenAuth/OAuth2/ChannelElements/AuthorizationCodeBindingElement.cs
@@ -59,7 +59,7 @@ namespace DotNetOpenAuth.OAuth2.ChannelElements {
if (response != null) {
var directResponse = (IDirectResponseProtocolMessage)response;
var request = (EndUserAuthorizationRequest)directResponse.OriginatingRequest;
- ITokenCarryingRequest tokenCarryingResponse = response;
+ IAuthorizationCarryingRequest tokenCarryingResponse = response;
tokenCarryingResponse.AuthorizationDescription = new AuthorizationCode(request.ClientIdentifier, request.Callback, request.Scope, response.AuthorizingUsername);
return MessageProtections.None;
@@ -88,7 +88,7 @@ namespace DotNetOpenAuth.OAuth2.ChannelElements {
public override MessageProtections? ProcessIncomingMessage(IProtocolMessage message) {
var request = message as AccessTokenAuthorizationCodeRequest;
if (request != null) {
- ITokenCarryingRequest tokenRequest = request;
+ IAuthorizationCarryingRequest tokenRequest = request;
((AuthorizationCode)tokenRequest.AuthorizationDescription).VerifyCallback(request.Callback);
return MessageProtections.None;
diff --git a/src/DotNetOpenAuth/OAuth2/ChannelElements/EndUserAuthorizationResponseTypeEncoder.cs b/src/DotNetOpenAuth/OAuth2/ChannelElements/EndUserAuthorizationResponseTypeEncoder.cs
index 33986c7..139025d 100644
--- a/src/DotNetOpenAuth/OAuth2/ChannelElements/EndUserAuthorizationResponseTypeEncoder.cs
+++ b/src/DotNetOpenAuth/OAuth2/ChannelElements/EndUserAuthorizationResponseTypeEncoder.cs
@@ -30,14 +30,12 @@ namespace DotNetOpenAuth.OAuth2.ChannelElements {
/// The <paramref name="value"/> in string form, ready for message transport.
/// </returns>
public string Encode(object value) {
- var responseType = (EndUserAuthorizationResponseTypes)value;
+ var responseType = (EndUserAuthorizationResponseType)value;
switch (responseType)
{
- case EndUserAuthorizationResponseTypes.Both:
- return Protocol.ResponseTypes.CodeAndToken;
- case EndUserAuthorizationResponseTypes.AccessToken:
+ case EndUserAuthorizationResponseType.AccessToken:
return Protocol.ResponseTypes.Token;
- case EndUserAuthorizationResponseTypes.AuthorizationCode:
+ case EndUserAuthorizationResponseType.AuthorizationCode:
return Protocol.ResponseTypes.Code;
default:
throw ErrorUtilities.ThrowFormat(MessagingStrings.UnexpectedMessagePartValue, Protocol.response_type, value);
@@ -54,12 +52,10 @@ namespace DotNetOpenAuth.OAuth2.ChannelElements {
/// <exception cref="FormatException">Thrown when the string value given cannot be decoded into the required object type.</exception>
public object Decode(string value) {
switch (value) {
- case Protocol.ResponseTypes.CodeAndToken:
- return EndUserAuthorizationResponseTypes.Both;
case Protocol.ResponseTypes.Token:
- return EndUserAuthorizationResponseTypes.AccessToken;
+ return EndUserAuthorizationResponseType.AccessToken;
case Protocol.ResponseTypes.Code:
- return EndUserAuthorizationResponseTypes.AuthorizationCode;
+ return EndUserAuthorizationResponseType.AuthorizationCode;
default:
throw ErrorUtilities.ThrowFormat(MessagingStrings.UnexpectedMessagePartValue, Protocol.response_type, value);
}
diff --git a/src/DotNetOpenAuth/OAuth2/ChannelElements/GrantTypeEncoder.cs b/src/DotNetOpenAuth/OAuth2/ChannelElements/GrantTypeEncoder.cs
index bd1c614..78ed975 100644
--- a/src/DotNetOpenAuth/OAuth2/ChannelElements/GrantTypeEncoder.cs
+++ b/src/DotNetOpenAuth/OAuth2/ChannelElements/GrantTypeEncoder.cs
@@ -33,8 +33,8 @@ namespace DotNetOpenAuth.OAuth2.ChannelElements {
var responseType = (GrantType)value;
switch (responseType)
{
- case GrantType.None:
- return Protocol.GrantTypes.None;
+ case GrantType.ClientCredentials:
+ return Protocol.GrantTypes.ClientCredentials;
case GrantType.AuthorizationCode:
return Protocol.GrantTypes.AuthorizationCode;
case GrantType.RefreshToken:
@@ -58,8 +58,8 @@ namespace DotNetOpenAuth.OAuth2.ChannelElements {
/// <exception cref="FormatException">Thrown when the string value given cannot be decoded into the required object type.</exception>
public object Decode(string value) {
switch (value) {
- case Protocol.GrantTypes.None:
- return GrantType.None;
+ case Protocol.GrantTypes.ClientCredentials:
+ return GrantType.ClientCredentials;
case Protocol.GrantTypes.Assertion:
return GrantType.Assertion;
case Protocol.GrantTypes.Password:
diff --git a/src/DotNetOpenAuth/OAuth2/ChannelElements/ITokenCarryingRequest.cs b/src/DotNetOpenAuth/OAuth2/ChannelElements/IAuthorizationCarryingRequest.cs
index 4c8d33f..e450131 100644
--- a/src/DotNetOpenAuth/OAuth2/ChannelElements/ITokenCarryingRequest.cs
+++ b/src/DotNetOpenAuth/OAuth2/ChannelElements/IAuthorizationCarryingRequest.cs
@@ -1,5 +1,5 @@
//-----------------------------------------------------------------------
-// <copyright file="ITokenCarryingRequest.cs" company="Andrew Arnott">
+// <copyright file="IAuthorizationCarryingRequest.cs" company="Andrew Arnott">
// Copyright (c) Andrew Arnott. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------
@@ -33,7 +33,7 @@ namespace DotNetOpenAuth.OAuth2.ChannelElements {
/// <summary>
/// A message that carries some kind of token from the client to the authorization or resource server.
/// </summary>
- internal interface ITokenCarryingRequest : IDirectedProtocolMessage {
+ internal interface IAuthorizationCarryingRequest : IDirectedProtocolMessage {
/// <summary>
/// Gets or sets the verification code or refresh/access token.
/// </summary>
diff --git a/src/DotNetOpenAuth/OAuth2/ChannelElements/OAuth2ChannelBase.cs b/src/DotNetOpenAuth/OAuth2/ChannelElements/OAuth2ChannelBase.cs
index d53e7ef..a646f51 100644
--- a/src/DotNetOpenAuth/OAuth2/ChannelElements/OAuth2ChannelBase.cs
+++ b/src/DotNetOpenAuth/OAuth2/ChannelElements/OAuth2ChannelBase.cs
@@ -24,7 +24,6 @@ namespace DotNetOpenAuth.OAuth2.ChannelElements {
typeof(AccessTokenRefreshRequest),
typeof(AccessTokenAuthorizationCodeRequest),
typeof(AccessTokenResourceOwnerPasswordCredentialsRequest),
- typeof(AccessTokenAssertionRequest),
typeof(AccessTokenClientCredentialsRequest),
typeof(AccessTokenSuccessResponse),
typeof(AccessTokenFailedResponse),
diff --git a/src/DotNetOpenAuth/OAuth2/ChannelElements/OAuth2ResourceServerChannel.cs b/src/DotNetOpenAuth/OAuth2/ChannelElements/OAuth2ResourceServerChannel.cs
index 60e464c..a292977 100644
--- a/src/DotNetOpenAuth/OAuth2/ChannelElements/OAuth2ResourceServerChannel.cs
+++ b/src/DotNetOpenAuth/OAuth2/ChannelElements/OAuth2ResourceServerChannel.cs
@@ -49,39 +49,11 @@ namespace DotNetOpenAuth.OAuth2.ChannelElements {
/// The deserialized message, if one is found. Null otherwise.
/// </returns>
protected override IDirectedProtocolMessage ReadFromRequestCore(HttpRequestInfo request) {
- // First search the Authorization header.
- var fields = MessagingUtilities.ParseAuthorizationHeader(
- Protocol.HttpAuthorizationScheme,
- request.Headers[HttpRequestHeader.Authorization]).ToDictionary();
-
- // Failing that, try the query string (for GET or POST or any other method)
- if (fields.Count == 0) {
- if (request.QueryStringBeforeRewriting["oauth_token"] != null) {
- // We're only interested in the oauth_token parameter -- not the others that can appear in an Authorization header.
- // Note that we intentionally change the name of the key here
- // because depending on the method used to obtain the token, the token's key changes
- // but we need to consolidate to one name so it works with the rest of the system.
- fields.Add("token", request.QueryStringBeforeRewriting["oauth_token"]);
- }
- }
-
- // Failing that, scan the entity
- if (fields.Count == 0) {
- // The spec calls out that this is allowed only for these three HTTP methods.
- if (request.HttpMethod == "POST" || request.HttpMethod == "DELETE" || request.HttpMethod == "PUT") {
- if (!string.IsNullOrEmpty(request.Headers[HttpRequestHeader.ContentType])) {
- var contentType = new ContentType(request.Headers[HttpRequestHeader.ContentType]);
- if (string.Equals(contentType.MediaType, HttpFormUrlEncoded, StringComparison.Ordinal)) {
- if (request.Form["oauth_token"] != null) {
- // We're only interested in the oauth_token parameter -- not the others that can appear in an Authorization header.
- // Note that we intentionally change the name of the key here
- // because depending on the method used to obtain the token, the token's key changes
- // but we need to consolidate to one name so it works with the rest of the system.
- fields.Add("token", request.Form["oauth_token"]);
- }
- }
- }
- }
+ var fields = new Dictionary<string, string>();
+ string accessToken;
+ if ((accessToken = SearchForBearerAccessTokenInRequest(request)) != null) {
+ fields["token_type"] = Protocol.AccessTokenTypes.Bearer;
+ fields["access_token"] = accessToken;
}
if (fields.Count > 0) {
@@ -93,9 +65,6 @@ namespace DotNetOpenAuth.OAuth2.ChannelElements {
return null;
}
- // TODO: remove this after signatures are supported.
- ErrorUtilities.VerifyProtocol(!fields.ContainsKey("signature"), "OAuth signatures not supported yet.");
-
// Deserialize the message using all the data we've collected.
var message = (IDirectedProtocolMessage)this.Receive(fields, recipient);
return message;
@@ -145,8 +114,44 @@ namespace DotNetOpenAuth.OAuth2.ChannelElements {
// Now serialize all the message parts into the WWW-Authenticate header.
var fields = this.MessageDescriptions.GetAccessor(response);
- webResponse.Headers[HttpResponseHeader.WwwAuthenticate] = MessagingUtilities.AssembleAuthorizationHeader(Protocol.HttpAuthorizationScheme, fields);
+ webResponse.Headers[HttpResponseHeader.WwwAuthenticate] = MessagingUtilities.AssembleAuthorizationHeader(Protocol.BearerHttpAuthorizationScheme, fields);
return webResponse;
}
+
+ /// <summary>
+ /// Searches for a bearer access token in the request.
+ /// </summary>
+ /// <param name="request">The request.</param>
+ /// <returns>The bearer access token, if one exists. Otherwise <c>null</c>.</returns>
+ private static string SearchForBearerAccessTokenInRequest(HttpRequestInfo request) {
+ Contract.Requires<ArgumentNullException>(request != null, "request");
+
+ // First search the authorization header.
+ string authorizationHeader = request.Headers[HttpRequestHeader.Authorization];
+ if (authorizationHeader.StartsWith(Protocol.BearerHttpAuthorizationSchemeWithTrailingSpace, StringComparison.OrdinalIgnoreCase)) {
+ return authorizationHeader.Substring(Protocol.BearerHttpAuthorizationSchemeWithTrailingSpace.Length);
+ }
+
+ // Failing that, scan the entity
+ if (!string.IsNullOrEmpty(request.Headers[HttpRequestHeader.ContentType])) {
+ var contentType = new ContentType(request.Headers[HttpRequestHeader.ContentType]);
+ if (string.Equals(contentType.MediaType, HttpFormUrlEncoded, StringComparison.Ordinal)) {
+ if (request.Form[Protocol.BearerTokenEncodedUrlParameterName] != null) {
+ // We're only interested in the oauth_token parameter -- not the others that can appear in an Authorization header.
+ // Note that we intentionally change the name of the key here
+ // because depending on the method used to obtain the token, the token's key changes
+ // but we need to consolidate to one name so it works with the rest of the system.
+ return request.Form[Protocol.BearerTokenEncodedUrlParameterName];
+ }
+ }
+ }
+
+ // Finally, check the least desirable location: the query string
+ if (!String.IsNullOrEmpty(request.QueryStringBeforeRewriting[Protocol.BearerTokenEncodedUrlParameterName])) {
+ return request.QueryStringBeforeRewriting[Protocol.BearerTokenEncodedUrlParameterName];
+ }
+
+ return null;
+ }
}
}
diff --git a/src/DotNetOpenAuth/OAuth2/ChannelElements/ScopeEncoder.cs b/src/DotNetOpenAuth/OAuth2/ChannelElements/ScopeEncoder.cs
index d35f982..7ae5fbf 100644
--- a/src/DotNetOpenAuth/OAuth2/ChannelElements/ScopeEncoder.cs
+++ b/src/DotNetOpenAuth/OAuth2/ChannelElements/ScopeEncoder.cs
@@ -33,7 +33,7 @@ namespace DotNetOpenAuth.OAuth2.ChannelElements {
public string Encode(object value) {
var scopes = (IEnumerable<string>)value;
ErrorUtilities.VerifyProtocol(!scopes.Any(scope => scope.Contains(" ")), OAuthStrings.ScopesMayNotContainSpaces);
- return scopes != null ? string.Join(" ", scopes.ToArray()) : null;
+ return (scopes != null && scopes.Any()) ? string.Join(" ", scopes.ToArray()) : null;
}
/// <summary>
diff --git a/src/DotNetOpenAuth/OAuth2/ClientBase.cs b/src/DotNetOpenAuth/OAuth2/ClientBase.cs
index 045fdf2..f91b1f5 100644
--- a/src/DotNetOpenAuth/OAuth2/ClientBase.cs
+++ b/src/DotNetOpenAuth/OAuth2/ClientBase.cs
@@ -66,7 +66,7 @@ namespace DotNetOpenAuth.OAuth2 {
Contract.Requires<ArgumentNullException>(request != null);
Contract.Requires<ArgumentException>(!string.IsNullOrEmpty(accessToken));
- OAuthUtilities.AuthorizeWithOAuthWrap(request, accessToken);
+ OAuthUtilities.AuthorizeWithBearerToken(request, accessToken);
}
/// <summary>
diff --git a/src/DotNetOpenAuth/OAuth2/Messages/AccessProtectedResourceRequest.cs b/src/DotNetOpenAuth/OAuth2/Messages/AccessProtectedResourceRequest.cs
index 410592f..2e94156 100644
--- a/src/DotNetOpenAuth/OAuth2/Messages/AccessProtectedResourceRequest.cs
+++ b/src/DotNetOpenAuth/OAuth2/Messages/AccessProtectedResourceRequest.cs
@@ -15,7 +15,12 @@ namespace DotNetOpenAuth.OAuth2.Messages {
/// <summary>
/// A message that accompanies an HTTP request to a resource server that provides authorization.
/// </summary>
- internal class AccessProtectedResourceRequest : MessageBase, ITokenCarryingRequest {
+ /// <remarks>
+ /// In its current form, this class only accepts bearer access tokens.
+ /// When support for additional access token types is added, this class should probably be refactored
+ /// into derived types, where each derived type supports a particular access token type.
+ /// </remarks>
+ internal class AccessProtectedResourceRequest : MessageBase, IAuthorizationCarryingRequest {
/// <summary>
/// Initializes a new instance of the <see cref="AccessProtectedResourceRequest"/> class.
/// </summary>
@@ -29,7 +34,7 @@ namespace DotNetOpenAuth.OAuth2.Messages {
/// Gets the type of the code or token.
/// </summary>
/// <value>The type of the code or token.</value>
- CodeOrTokenType ITokenCarryingRequest.CodeOrTokenType {
+ CodeOrTokenType IAuthorizationCarryingRequest.CodeOrTokenType {
get { return CodeOrTokenType.AccessToken; }
}
@@ -37,7 +42,7 @@ namespace DotNetOpenAuth.OAuth2.Messages {
/// Gets or sets the verification code or refresh/access token.
/// </summary>
/// <value>The code or token.</value>
- string ITokenCarryingRequest.CodeOrToken {
+ string IAuthorizationCarryingRequest.CodeOrToken {
get { return this.AccessToken; }
set { this.AccessToken = value; }
}
@@ -45,75 +50,24 @@ namespace DotNetOpenAuth.OAuth2.Messages {
/// <summary>
/// Gets or sets the authorization that the token describes.
/// </summary>
- IAuthorizationDescription ITokenCarryingRequest.AuthorizationDescription { get; set; }
+ IAuthorizationDescription IAuthorizationCarryingRequest.AuthorizationDescription { get; set; }
/// <summary>
- /// Gets or sets the access token.
- /// </summary>
- /// <value>The access token.</value>
- [MessagePart("token", IsRequired = true)]
- internal string AccessToken { get; set; }
-
- /// <summary>
- /// Gets or sets the nonce.
- /// </summary>
- /// <value>The nonce.</value>
- [MessagePart("nonce")]
- internal string Nonce { get; set; }
-
- /// <summary>
- /// Gets or sets the timestamp.
- /// </summary>
- /// <value>The timestamp.</value>
- [MessagePart("timestamp", Encoder = typeof(TimestampEncoder))]
- internal DateTime? Timestamp { get; set; }
-
- /// <summary>
- /// Gets or sets the signature.
+ /// Gets the type of the access token.
/// </summary>
- /// <value>The signature.</value>
- [MessagePart("signature")]
- internal string Signature { get; set; }
-
- /// <summary>
- /// Gets or sets the algorithm.
- /// </summary>
- /// <value>The algorithm.</value>
- [MessagePart("algorithm")]
- internal string Algorithm { get; set; }
-
- /// <summary>
- /// Gets a value indicating whether this request is signed.
- /// </summary>
- internal bool SignedRequest {
- get { return this.Signature != null; }
+ /// <value>
+ /// Always "bearer".
+ /// </value>
+ [MessagePart("token_type", IsRequired = true)]
+ internal string TokenType {
+ get { return Protocol.AccessTokenTypes.Bearer; }
}
/// <summary>
- /// Checks the message state for conformity to the protocol specification
- /// and throws an exception if the message is invalid.
+ /// Gets or sets the access token.
/// </summary>
- /// <remarks>
- /// <para>Some messages have required fields, or combinations of fields that must relate to each other
- /// in specialized ways. After deserializing a message, this method checks the state of the
- /// message to see if it conforms to the protocol.</para>
- /// <para>Note that this property should <i>not</i> check signatures or perform any state checks
- /// outside this scope of this particular message.</para>
- /// </remarks>
- /// <exception cref="ProtocolException">Thrown if the message is invalid.</exception>
- protected override void EnsureValidMessage() {
- base.EnsureValidMessage();
-
- // If any of the optional parameters are present, all of them are required.
- if (this.Signature == null) {
- ErrorUtilities.VerifyProtocol(this.Algorithm == null, this, MessagingStrings.UnexpectedMessagePartValue, "algorithm", this.Algorithm);
- ErrorUtilities.VerifyProtocol(!this.Timestamp.HasValue, this, MessagingStrings.UnexpectedMessagePartValue, "timestamp", this.Timestamp);
- ErrorUtilities.VerifyProtocol(this.Nonce == null, this, MessagingStrings.UnexpectedMessagePartValue, "nonce", this.Nonce);
- } else {
- ErrorUtilities.VerifyProtocol(this.Algorithm != null, this, MessagingStrings.RequiredParametersMissing, "algorithm");
- ErrorUtilities.VerifyProtocol(this.Timestamp.HasValue, this, MessagingStrings.RequiredParametersMissing, "timestamp");
- ErrorUtilities.VerifyProtocol(this.Nonce != null, this, MessagingStrings.RequiredParametersMissing, "nonce");
- }
- }
+ /// <value>The access token.</value>
+ [MessagePart("access_token", IsRequired = true)]
+ internal string AccessToken { get; set; }
}
}
diff --git a/src/DotNetOpenAuth/OAuth2/Messages/AccessTokenAssertionRequest.cs b/src/DotNetOpenAuth/OAuth2/Messages/AccessTokenAssertionRequest.cs
deleted file mode 100644
index fa50f6b..0000000
--- a/src/DotNetOpenAuth/OAuth2/Messages/AccessTokenAssertionRequest.cs
+++ /dev/null
@@ -1,49 +0,0 @@
-//-----------------------------------------------------------------------
-// <copyright file="AccessTokenAssertionRequest.cs" company="Andrew Arnott">
-// Copyright (c) Andrew Arnott. All rights reserved.
-// </copyright>
-//-----------------------------------------------------------------------
-
-namespace DotNetOpenAuth.OAuth2.Messages {
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using DotNetOpenAuth.Messaging;
-
- /// <summary>
- /// A request from a Client to an Authorization Server to exchange some assertion for an access token.
- /// </summary>
- internal class AccessTokenAssertionRequest : AccessTokenRequestBase {
- /// <summary>
- /// Initializes a new instance of the <see cref="AccessTokenAssertionRequest"/> class.
- /// </summary>
- /// <param name="tokenEndpoint">The Authorization Server's access token endpoint URL.</param>
- /// <param name="version">The version.</param>
- internal AccessTokenAssertionRequest(Uri tokenEndpoint, Version version)
- : base(tokenEndpoint, version) {
- }
-
- /// <summary>
- /// Gets or sets the format of the assertion as defined by the Authorization Server.
- /// </summary>
- /// <value>The assertion format.</value>
- [MessagePart(Protocol.assertion_type, IsRequired = true)]
- internal Uri AssertionType { get; set; }
-
- /// <summary>
- /// Gets or sets the assertion.
- /// </summary>
- /// <value>The assertion.</value>
- [MessagePart(Protocol.assertion, IsRequired = true)]
- internal string Assertion { get; set; }
-
- /// <summary>
- /// Gets the type of the grant.
- /// </summary>
- /// <value>The type of the grant.</value>
- internal override GrantType GrantType {
- get { return GrantType.Assertion; }
- }
- }
-}
diff --git a/src/DotNetOpenAuth/OAuth2/Messages/AccessTokenAuthorizationCodeRequest.cs b/src/DotNetOpenAuth/OAuth2/Messages/AccessTokenAuthorizationCodeRequest.cs
index 3c7202e..b45b7ad 100644
--- a/src/DotNetOpenAuth/OAuth2/Messages/AccessTokenAuthorizationCodeRequest.cs
+++ b/src/DotNetOpenAuth/OAuth2/Messages/AccessTokenAuthorizationCodeRequest.cs
@@ -17,7 +17,7 @@ namespace DotNetOpenAuth.OAuth2.Messages {
/// <summary>
/// A request from a Client to an Authorization Server to exchange an authorization code for an access token.
/// </summary>
- internal class AccessTokenAuthorizationCodeRequest : AccessTokenRequestBase, ITokenCarryingRequest {
+ internal class AccessTokenAuthorizationCodeRequest : AccessTokenRequestBase, IAuthorizationCarryingRequest {
/// <summary>
/// Initializes a new instance of the <see cref="AccessTokenAuthorizationCodeRequest"/> class.
/// </summary>
@@ -41,7 +41,7 @@ namespace DotNetOpenAuth.OAuth2.Messages {
/// Gets the type of the code or token.
/// </summary>
/// <value>The type of the code or token.</value>
- CodeOrTokenType ITokenCarryingRequest.CodeOrTokenType {
+ CodeOrTokenType IAuthorizationCarryingRequest.CodeOrTokenType {
get { return CodeOrTokenType.AuthorizationCode; }
}
@@ -49,7 +49,7 @@ namespace DotNetOpenAuth.OAuth2.Messages {
/// Gets or sets the verification code or refresh/access token.
/// </summary>
/// <value>The code or token.</value>
- string ITokenCarryingRequest.CodeOrToken {
+ string IAuthorizationCarryingRequest.CodeOrToken {
get { return this.AuthorizationCode; }
set { this.AuthorizationCode = value; }
}
@@ -57,7 +57,7 @@ namespace DotNetOpenAuth.OAuth2.Messages {
/// <summary>
/// Gets or sets the authorization that the token describes.
/// </summary>
- IAuthorizationDescription ITokenCarryingRequest.AuthorizationDescription { get; set; }
+ IAuthorizationDescription IAuthorizationCarryingRequest.AuthorizationDescription { get; set; }
/// <summary>
/// Gets the type of the grant.
diff --git a/src/DotNetOpenAuth/OAuth2/Messages/AccessTokenClientCredentialsRequest.cs b/src/DotNetOpenAuth/OAuth2/Messages/AccessTokenClientCredentialsRequest.cs
index 475a170..01e1633 100644
--- a/src/DotNetOpenAuth/OAuth2/Messages/AccessTokenClientCredentialsRequest.cs
+++ b/src/DotNetOpenAuth/OAuth2/Messages/AccessTokenClientCredentialsRequest.cs
@@ -19,7 +19,7 @@ namespace DotNetOpenAuth.OAuth2.Messages {
/// <remarks>
/// This is somewhat analogous to 2-legged OAuth.
/// </remarks>
- internal class AccessTokenClientCredentialsRequest : AccessTokenRequestBase {
+ internal class AccessTokenClientCredentialsRequest : ScopedAccessTokenRequest {
/// <summary>
/// Initializes a new instance of the <see cref="AccessTokenClientCredentialsRequest"/> class.
/// </summary>
@@ -35,7 +35,7 @@ namespace DotNetOpenAuth.OAuth2.Messages {
/// </summary>
/// <value>The type of the grant.</value>
internal override GrantType GrantType {
- get { return Messages.GrantType.None; }
+ get { return Messages.GrantType.ClientCredentials; }
}
}
}
diff --git a/src/DotNetOpenAuth/OAuth2/Messages/AccessTokenRefreshRequest.cs b/src/DotNetOpenAuth/OAuth2/Messages/AccessTokenRefreshRequest.cs
index c193392..22354e4 100644
--- a/src/DotNetOpenAuth/OAuth2/Messages/AccessTokenRefreshRequest.cs
+++ b/src/DotNetOpenAuth/OAuth2/Messages/AccessTokenRefreshRequest.cs
@@ -6,6 +6,7 @@
namespace DotNetOpenAuth.OAuth2.Messages {
using System;
+ using System.Collections.Generic;
using DotNetOpenAuth.Messaging;
using DotNetOpenAuth.OAuth2.ChannelElements;
@@ -13,7 +14,7 @@ namespace DotNetOpenAuth.OAuth2.Messages {
/// A request from the client to the token endpoint for a new access token
/// in exchange for a refresh token that the client has previously obtained.
/// </summary>
- internal class AccessTokenRefreshRequest : AccessTokenRequestBase, ITokenCarryingRequest {
+ internal class AccessTokenRefreshRequest : ScopedAccessTokenRequest, IAuthorizationCarryingRequest {
/// <summary>
/// Initializes a new instance of the <see cref="AccessTokenRefreshRequest"/> class.
/// </summary>
@@ -35,7 +36,7 @@ namespace DotNetOpenAuth.OAuth2.Messages {
/// Gets the type of the code or token.
/// </summary>
/// <value>The type of the code or token.</value>
- CodeOrTokenType ITokenCarryingRequest.CodeOrTokenType {
+ CodeOrTokenType IAuthorizationCarryingRequest.CodeOrTokenType {
get { return CodeOrTokenType.RefreshToken; }
}
@@ -43,7 +44,7 @@ namespace DotNetOpenAuth.OAuth2.Messages {
/// Gets or sets the verification code or refresh/access token.
/// </summary>
/// <value>The code or token.</value>
- string ITokenCarryingRequest.CodeOrToken {
+ string IAuthorizationCarryingRequest.CodeOrToken {
get { return this.RefreshToken; }
set { this.RefreshToken = value; }
}
@@ -51,7 +52,7 @@ namespace DotNetOpenAuth.OAuth2.Messages {
/// <summary>
/// Gets or sets the authorization that the token describes.
/// </summary>
- IAuthorizationDescription ITokenCarryingRequest.AuthorizationDescription { get; set; }
+ IAuthorizationDescription IAuthorizationCarryingRequest.AuthorizationDescription { get; set; }
/// <summary>
/// Gets or sets the refresh token.
diff --git a/src/DotNetOpenAuth/OAuth2/Messages/AccessTokenRequestBase.cs b/src/DotNetOpenAuth/OAuth2/Messages/AccessTokenRequestBase.cs
index 55387a6..a71dc70 100644
--- a/src/DotNetOpenAuth/OAuth2/Messages/AccessTokenRequestBase.cs
+++ b/src/DotNetOpenAuth/OAuth2/Messages/AccessTokenRequestBase.cs
@@ -25,7 +25,6 @@ namespace DotNetOpenAuth.OAuth2.Messages {
protected AccessTokenRequestBase(Uri tokenEndpoint, Version version)
: base(tokenEndpoint, version) {
this.HttpMethods = HttpDeliveryMethods.PostRequest;
- this.Scope = new HashSet<string>(OAuthUtilities.ScopeStringComparer);
}
/// <summary>
@@ -36,13 +35,6 @@ namespace DotNetOpenAuth.OAuth2.Messages {
internal abstract GrantType GrantType { get; }
/// <summary>
- /// Gets the set of scopes the Client would like the access token to provide access to.
- /// </summary>
- /// <value>A set of scopes. Never null.</value>
- [MessagePart(Protocol.scope, IsRequired = false, Encoder = typeof(ScopeEncoder))]
- internal HashSet<string> Scope { get; private set; }
-
- /// <summary>
/// Checks the message state for conformity to the protocol specification
/// and throws an exception if the message is invalid.
/// </summary>
diff --git a/src/DotNetOpenAuth/OAuth2/Messages/AccessTokenResourceOwnerPasswordCredentialsRequest.cs b/src/DotNetOpenAuth/OAuth2/Messages/AccessTokenResourceOwnerPasswordCredentialsRequest.cs
index ed22843..82febe9 100644
--- a/src/DotNetOpenAuth/OAuth2/Messages/AccessTokenResourceOwnerPasswordCredentialsRequest.cs
+++ b/src/DotNetOpenAuth/OAuth2/Messages/AccessTokenResourceOwnerPasswordCredentialsRequest.cs
@@ -15,7 +15,7 @@ namespace DotNetOpenAuth.OAuth2.Messages {
/// <summary>
/// A request from a Client to an Authorization Server to exchange the user's username and password for an access token.
/// </summary>
- internal class AccessTokenResourceOwnerPasswordCredentialsRequest : AccessTokenRequestBase {
+ internal class AccessTokenResourceOwnerPasswordCredentialsRequest : ScopedAccessTokenRequest {
/// <summary>
/// Initializes a new instance of the <see cref="AccessTokenResourceOwnerPasswordCredentialsRequest"/> class.
/// </summary>
diff --git a/src/DotNetOpenAuth/OAuth2/Messages/AccessTokenSuccessResponse.cs b/src/DotNetOpenAuth/OAuth2/Messages/AccessTokenSuccessResponse.cs
index bae2dd9..b7d8dea 100644
--- a/src/DotNetOpenAuth/OAuth2/Messages/AccessTokenSuccessResponse.cs
+++ b/src/DotNetOpenAuth/OAuth2/Messages/AccessTokenSuccessResponse.cs
@@ -26,6 +26,7 @@ namespace DotNetOpenAuth.OAuth2.Messages {
internal AccessTokenSuccessResponse(AccessTokenRequestBase request)
: base(request) {
this.Scope = new HashSet<string>(OAuthUtilities.ScopeStringComparer);
+ this.TokenType = Protocol.AccessTokenTypes.Bearer;
}
/// <summary>
@@ -57,6 +58,16 @@ namespace DotNetOpenAuth.OAuth2.Messages {
public string AccessToken { get; internal set; }
/// <summary>
+ /// Gets or sets the token type.
+ /// </summary>
+ /// <value>Usually "bearer".</value>
+ /// <remarks>
+ /// Described in OAuth 2.0 section 7.1.
+ /// </remarks>
+ [MessagePart(Protocol.token_type, IsRequired = true)]
+ public string TokenType { get; internal set; }
+
+ /// <summary>
/// Gets or sets the lifetime of the access token.
/// </summary>
/// <value>The lifetime.</value>
diff --git a/src/DotNetOpenAuth/OAuth2/Messages/EndUserAuthorizationFailedResponse.cs b/src/DotNetOpenAuth/OAuth2/Messages/EndUserAuthorizationFailedResponse.cs
index fc11831..5497e1b 100644
--- a/src/DotNetOpenAuth/OAuth2/Messages/EndUserAuthorizationFailedResponse.cs
+++ b/src/DotNetOpenAuth/OAuth2/Messages/EndUserAuthorizationFailedResponse.cs
@@ -42,7 +42,15 @@ namespace DotNetOpenAuth.OAuth2.Messages {
/// <summary>
/// Gets or sets the error.
/// </summary>
- /// <value>One of the values given in <see cref="Protocol.EndUserAuthorizationRequestErrorCodes"/>.</value>
+ /// <value>
+ /// One of the values given in <see cref="Protocol.EndUserAuthorizationRequestErrorCodes"/>.
+ /// OR a numerical HTTP status code from the 4xx or 5xx
+ /// range, with the exception of the 400 (Bad Request) and
+ /// 401 (Unauthorized) status codes. For example, if the
+ /// service is temporarily unavailable, the authorization
+ /// server MAY return an error response with "error" set to
+ /// "503".
+ /// </value>
[MessagePart(Protocol.error, IsRequired = true)]
public string Error { get; set; }
diff --git a/src/DotNetOpenAuth/OAuth2/Messages/EndUserAuthorizationRequest.cs b/src/DotNetOpenAuth/OAuth2/Messages/EndUserAuthorizationRequest.cs
index fa270ee..802aed6 100644
--- a/src/DotNetOpenAuth/OAuth2/Messages/EndUserAuthorizationRequest.cs
+++ b/src/DotNetOpenAuth/OAuth2/Messages/EndUserAuthorizationRequest.cs
@@ -31,6 +31,7 @@ namespace DotNetOpenAuth.OAuth2.Messages {
Contract.Requires<ArgumentNullException>(version != null);
this.HttpMethods = HttpDeliveryMethods.GetRequest | HttpDeliveryMethods.PostRequest;
this.Scope = new HashSet<string>(OAuthUtilities.ScopeStringComparer);
+ this.ResponseType = EndUserAuthorizationResponseType.AuthorizationCode;
}
/// <summary>
@@ -45,14 +46,11 @@ namespace DotNetOpenAuth.OAuth2.Messages {
}
/// <summary>
- /// Gets the grant type that the client expects of the authorization server.
+ /// Gets or sets the grant type that the client expects of the authorization server.
/// </summary>
- /// <value>Always <see cref="EndUserAuthorizationResponseTypes.AuthorizationCode"/>. Other response types are not supported.</value>
+ /// <value>Always <see cref="EndUserAuthorizationResponseType.AuthorizationCode"/>. Other response types are not supported.</value>
[MessagePart(Protocol.response_type, IsRequired = true, Encoder = typeof(EndUserAuthorizationResponseTypeEncoder))]
- public static EndUserAuthorizationResponseTypes ResponseType
- {
- get { return EndUserAuthorizationResponseTypes.AuthorizationCode; }
- }
+ public EndUserAuthorizationResponseType ResponseType { get; set; }
/// <summary>
/// Gets or sets the identifier by which this client is known to the Authorization Server.
diff --git a/src/DotNetOpenAuth/OAuth2/Messages/EndUserAuthorizationResponseType.cs b/src/DotNetOpenAuth/OAuth2/Messages/EndUserAuthorizationResponseType.cs
index 814f625..815fef6 100644
--- a/src/DotNetOpenAuth/OAuth2/Messages/EndUserAuthorizationResponseType.cs
+++ b/src/DotNetOpenAuth/OAuth2/Messages/EndUserAuthorizationResponseType.cs
@@ -11,21 +11,15 @@ namespace DotNetOpenAuth.OAuth2.Messages {
/// An indication of what kind of response the client is requesting from the authorization server
/// after the user has granted authorized access.
/// </summary>
- [Flags]
- public enum EndUserAuthorizationResponseTypes {
+ public enum EndUserAuthorizationResponseType {
/// <summary>
/// An access token should be returned immediately.
/// </summary>
- AccessToken = 0x1,
+ AccessToken,
/// <summary>
/// An authorization code should be returned, which can later be exchanged for refresh and access tokens.
/// </summary>
- AuthorizationCode = 0x2,
-
- /// <summary>
- /// Both an access token and an authorization code should be returned.
- /// </summary>
- Both = AccessToken | AuthorizationCode,
+ AuthorizationCode,
}
}
diff --git a/src/DotNetOpenAuth/OAuth2/Messages/EndUserAuthorizationSuccessAccessTokenResponse.cs b/src/DotNetOpenAuth/OAuth2/Messages/EndUserAuthorizationSuccessAccessTokenResponse.cs
index 46bbc87..f5edfa8 100644
--- a/src/DotNetOpenAuth/OAuth2/Messages/EndUserAuthorizationSuccessAccessTokenResponse.cs
+++ b/src/DotNetOpenAuth/OAuth2/Messages/EndUserAuthorizationSuccessAccessTokenResponse.cs
@@ -19,7 +19,7 @@ namespace DotNetOpenAuth.OAuth2.Messages {
/// to indicate that user authorization was granted, carrying only an access token,
/// and to return the user to the Client where they started their experience.
/// </summary>
- internal class EndUserAuthorizationSuccessAccessTokenResponse : EndUserAuthorizationSuccessResponseBase, ITokenCarryingRequest {
+ internal class EndUserAuthorizationSuccessAccessTokenResponse : EndUserAuthorizationSuccessResponseBase, IAuthorizationCarryingRequest, IHttpIndirectResponse {
/// <summary>
/// Initializes a new instance of the <see cref="EndUserAuthorizationSuccessAccessTokenResponse"/> class.
/// </summary>
@@ -49,7 +49,7 @@ namespace DotNetOpenAuth.OAuth2.Messages {
/// Gets or sets the verification code or refresh/access token.
/// </summary>
/// <value>The code or token.</value>
- string ITokenCarryingRequest.CodeOrToken {
+ string IAuthorizationCarryingRequest.CodeOrToken {
get { return this.AccessToken; }
set { this.AccessToken = value; }
}
@@ -58,7 +58,7 @@ namespace DotNetOpenAuth.OAuth2.Messages {
/// Gets the type of the code or token.
/// </summary>
/// <value>The type of the code or token.</value>
- CodeOrTokenType ITokenCarryingRequest.CodeOrTokenType {
+ CodeOrTokenType IAuthorizationCarryingRequest.CodeOrTokenType {
get { return CodeOrTokenType.AccessToken; }
}
@@ -66,15 +66,37 @@ namespace DotNetOpenAuth.OAuth2.Messages {
/// Gets or sets the authorization that the token describes.
/// </summary>
/// <value></value>
- IAuthorizationDescription ITokenCarryingRequest.AuthorizationDescription { get; set; }
+ IAuthorizationDescription IAuthorizationCarryingRequest.AuthorizationDescription { get; set; }
#endregion
+ #region IHttpIndirectResponse Members
+
+ /// <summary>
+ /// Gets a value indicating whether the payload for the message should be included
+ /// in the redirect fragment instead of the query string or POST entity.
+ /// </summary>
+ bool IHttpIndirectResponse.Include301RedirectPayloadInFragment {
+ get { return true; }
+ }
+
+ #endregion
+
+ /// <summary>
+ /// Gets or sets the token type.
+ /// </summary>
+ /// <value>Usually "bearer".</value>
+ /// <remarks>
+ /// Described in OAuth 2.0 section 7.1.
+ /// </remarks>
+ [MessagePart(Protocol.token_type, IsRequired = true)]
+ public string TokenType { get; internal set; }
+
/// <summary>
/// Gets or sets the access token.
/// </summary>
/// <value>The access token.</value>
[MessagePart(Protocol.access_token, IsRequired = true)]
- internal string AccessToken { get; set; }
+ public string AccessToken { get; set; }
}
}
diff --git a/src/DotNetOpenAuth/OAuth2/Messages/EndUserAuthorizationSuccessAuthCodeResponse.cs b/src/DotNetOpenAuth/OAuth2/Messages/EndUserAuthorizationSuccessAuthCodeResponse.cs
index 6302304..af7f913 100644
--- a/src/DotNetOpenAuth/OAuth2/Messages/EndUserAuthorizationSuccessAuthCodeResponse.cs
+++ b/src/DotNetOpenAuth/OAuth2/Messages/EndUserAuthorizationSuccessAuthCodeResponse.cs
@@ -16,7 +16,7 @@ namespace DotNetOpenAuth.OAuth2.Messages {
/// to indicate that user authorization was granted, carrying an authorization code and possibly an access token,
/// and to return the user to the Client where they started their experience.
/// </summary>
- internal class EndUserAuthorizationSuccessAuthCodeResponse : EndUserAuthorizationSuccessResponseBase, ITokenCarryingRequest {
+ internal class EndUserAuthorizationSuccessAuthCodeResponse : EndUserAuthorizationSuccessResponseBase, IAuthorizationCarryingRequest {
/// <summary>
/// Initializes a new instance of the <see cref="EndUserAuthorizationSuccessAuthCodeResponse"/> class.
/// </summary>
@@ -46,7 +46,7 @@ namespace DotNetOpenAuth.OAuth2.Messages {
/// Gets or sets the verification code or refresh/access token.
/// </summary>
/// <value>The code or token.</value>
- string ITokenCarryingRequest.CodeOrToken {
+ string IAuthorizationCarryingRequest.CodeOrToken {
get { return this.AuthorizationCode; }
set { this.AuthorizationCode = value; }
}
@@ -55,14 +55,14 @@ namespace DotNetOpenAuth.OAuth2.Messages {
/// Gets the type of the code or token.
/// </summary>
/// <value>The type of the code or token.</value>
- CodeOrTokenType ITokenCarryingRequest.CodeOrTokenType {
+ CodeOrTokenType IAuthorizationCarryingRequest.CodeOrTokenType {
get { return CodeOrTokenType.AuthorizationCode; }
}
/// <summary>
/// Gets or sets the authorization that the token describes.
/// </summary>
- IAuthorizationDescription ITokenCarryingRequest.AuthorizationDescription { get; set; }
+ IAuthorizationDescription IAuthorizationCarryingRequest.AuthorizationDescription { get; set; }
#endregion
diff --git a/src/DotNetOpenAuth/OAuth2/Messages/GrantType.cs b/src/DotNetOpenAuth/OAuth2/Messages/GrantType.cs
index c119ffd..4580a7f 100644
--- a/src/DotNetOpenAuth/OAuth2/Messages/GrantType.cs
+++ b/src/DotNetOpenAuth/OAuth2/Messages/GrantType.cs
@@ -37,6 +37,6 @@ namespace DotNetOpenAuth.OAuth2.Messages {
/// <remarks>
/// When requesting an access token using the none access grant type (no access grant is included), the client is requesting access to the protected resources under its control, or those of another resource owner which has been previously arranged with the authorization server (the method of which is beyond the scope of this specification).
/// </remarks>
- None,
+ ClientCredentials,
}
}
diff --git a/src/DotNetOpenAuth/OAuth2/Messages/OAuth 2 Messages.cd b/src/DotNetOpenAuth/OAuth2/Messages/OAuth 2 Messages.cd
index 86a0335..9ddd0cc 100644
--- a/src/DotNetOpenAuth/OAuth2/Messages/OAuth 2 Messages.cd
+++ b/src/DotNetOpenAuth/OAuth2/Messages/OAuth 2 Messages.cd
@@ -1,68 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>
<ClassDiagram MajorVersion="1" MinorVersion="1">
<Class Name="DotNetOpenAuth.OAuth2.Messages.MessageBase" Collapsed="true">
- <Position X="0.5" Y="4" Width="1.5" />
+ <Position X="0.5" Y="0.5" Width="1.5" />
<TypeIdentifier>
<HashCode>IAAMACQAQAAAgAkAAAAIAAYACgAAIAAAIACAACAAAIA=</HashCode>
<FileName>OAuth2\Messages\MessageBase.cs</FileName>
</TypeIdentifier>
<Lollipop Position="0.2" />
</Class>
- <Class Name="DotNetOpenAuth.OAuth2.Messages.AccessTokenAssertionRequest" Collapsed="true">
- <Position X="11" Y="5.5" Width="2.25" />
- <InheritanceLine Type="DotNetOpenAuth.OAuth2.Messages.AccessTokenRequestBase" ManuallyRouted="true" FixedFromPoint="true">
- <Path>
- <Point X="9.75" Y="7.562" />
- <Point X="10.771" Y="7.562" />
- <Point X="10.771" Y="5.846" />
- <Point X="11" Y="5.846" />
- </Path>
- </InheritanceLine>
- <TypeIdentifier>
- <HashCode>AAAIAAAAAAAAAAAAAgAAAAAQAAAAAAAAAAAAAAAAAAA=</HashCode>
- <FileName>OAuth2\Messages\AccessTokenAssertionRequest.cs</FileName>
- </TypeIdentifier>
- </Class>
<Class Name="DotNetOpenAuth.OAuth2.Messages.AccessTokenAuthorizationCodeRequest" Collapsed="true">
- <Position X="11" Y="6.5" Width="3" />
- <InheritanceLine Type="DotNetOpenAuth.OAuth2.Messages.AccessTokenRequestBase" ManuallyRouted="true" FixedFromPoint="true">
- <Path>
- <Point X="9.75" Y="7.562" />
- <Point X="10.781" Y="7.562" />
- <Point X="10.781" Y="6.846" />
- <Point X="11" Y="6.846" />
- </Path>
- </InheritanceLine>
+ <Position X="6.75" Y="6.75" Width="3" />
<TypeIdentifier>
- <HashCode>CCAAAAAAAAACAAAAAAAAAAAQAAAAAAAAAAAAAAAAQAA=</HashCode>
+ <HashCode>ACAAEAAAAAAAAAAAAAAAAAAQAAAAAAAAAAAgAAAARAA=</HashCode>
<FileName>OAuth2\Messages\AccessTokenAuthorizationCodeRequest.cs</FileName>
</TypeIdentifier>
<Lollipop Position="0.2" />
</Class>
<Class Name="DotNetOpenAuth.OAuth2.Messages.AccessTokenClientCredentialsRequest" Collapsed="true">
- <Position X="11" Y="3.75" Width="2.75" />
- <InheritanceLine Type="DotNetOpenAuth.OAuth2.Messages.AccessTokenRequestBase" FixedFromPoint="true">
- <Path>
- <Point X="9.75" Y="7.562" />
- <Point X="10.76" Y="7.562" />
- <Point X="10.76" Y="4.096" />
- <Point X="11" Y="4.096" />
- </Path>
- </InheritanceLine>
+ <Position X="8.5" Y="8.75" Width="2.75" />
<TypeIdentifier>
<HashCode>AAAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAA=</HashCode>
<FileName>OAuth2\Messages\AccessTokenClientCredentialsRequest.cs</FileName>
</TypeIdentifier>
</Class>
<Class Name="DotNetOpenAuth.OAuth2.Messages.AccessTokenFailedResponse" Collapsed="true">
- <Position X="3.25" Y="1.75" Width="2.25" />
- <InheritanceLine Type="DotNetOpenAuth.OAuth2.Messages.MessageBase" FixedToPoint="true">
- <Path>
- <Point X="1.25" Y="4" />
- <Point X="1.25" Y="2.062" />
- <Point X="3.25" Y="2.062" />
- </Path>
- </InheritanceLine>
+ <Position X="3.25" Y="8.5" Width="2.25" />
<TypeIdentifier>
<HashCode>AAAAAIAAAAAAAQAAAABAAAQAAAAAAAEQAAAAAAAAAAA=</HashCode>
<FileName>OAuth2\Messages\AccessTokenFailedResponse.cs</FileName>
@@ -70,87 +32,44 @@
<Lollipop Position="0.2" />
</Class>
<Class Name="DotNetOpenAuth.OAuth2.Messages.AccessTokenRefreshRequest" Collapsed="true">
- <Position X="11" Y="4.75" Width="2.25" />
- <InheritanceLine Type="DotNetOpenAuth.OAuth2.Messages.AccessTokenRequestBase" FixedFromPoint="true">
- <Path>
- <Point X="9.75" Y="7.562" />
- <Point X="10.76" Y="7.562" />
- <Point X="10.76" Y="5.096" />
- <Point X="11" Y="5.096" />
- </Path>
- </InheritanceLine>
+ <Position X="8.5" Y="9.75" Width="2.25" />
<TypeIdentifier>
- <HashCode>CCAAAAAAQAACAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAA=</HashCode>
+ <HashCode>AAAAEAAAQAAAAAAAAAAAAAAQAAAAAAAAAAAgAAAABAA=</HashCode>
<FileName>OAuth2\Messages\AccessTokenRefreshRequest.cs</FileName>
</TypeIdentifier>
<Lollipop Position="0.2" />
</Class>
<Class Name="DotNetOpenAuth.OAuth2.Messages.AccessTokenRequestBase" Collapsed="true">
- <Position X="7.75" Y="7.25" Width="2" />
- <InheritanceLine Type="DotNetOpenAuth.OAuth2.Messages.AuthenticatedClientRequestBase" FixedFromPoint="true">
- <Path>
- <Point X="5.5" Y="7.625" />
- <Point X="7.75" Y="7.625" />
- </Path>
- </InheritanceLine>
+ <Position X="5.75" Y="5.75" Width="2" />
<TypeIdentifier>
- <HashCode>AAAAAAAAQAAAACAAAAAAAAAQAAAAAAAAAAAAAAAAAAA=</HashCode>
+ <HashCode>AAAAAAAAQAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAA=</HashCode>
<FileName>OAuth2\Messages\AccessTokenRequestBase.cs</FileName>
</TypeIdentifier>
</Class>
<Class Name="DotNetOpenAuth.OAuth2.Messages.AccessTokenResourceOwnerPasswordCredentialsRequest" Collapsed="true">
- <Position X="11" Y="7.25" Width="4" />
- <InheritanceLine Type="DotNetOpenAuth.OAuth2.Messages.AccessTokenRequestBase" ManuallyRouted="true" FixedFromPoint="true">
- <Path>
- <Point X="9.75" Y="7.562" />
- <Point X="10.711" Y="7.562" />
- <Point X="10.711" Y="7.752" />
- <Point X="11" Y="7.752" />
- </Path>
- </InheritanceLine>
+ <Position X="8.5" Y="10.5" Width="4" />
<TypeIdentifier>
<HashCode>AAAAAAAAAAAAAAAAAAAAAAAQAAAAAAACAQAAAAAAAAA=</HashCode>
<FileName>OAuth2\Messages\AccessTokenResourceOwnerPasswordCredentialsRequest.cs</FileName>
</TypeIdentifier>
</Class>
<Class Name="DotNetOpenAuth.OAuth2.Messages.AccessTokenSuccessResponse" Collapsed="true">
- <Position X="3.25" Y="2.75" Width="2.25" />
- <InheritanceLine Type="DotNetOpenAuth.OAuth2.Messages.MessageBase" FixedToPoint="true">
- <Path>
- <Point X="1.25" Y="4" />
- <Point X="1.25" Y="3.125" />
- <Point X="3.25" Y="3.125" />
- </Path>
- </InheritanceLine>
+ <Position X="3.25" Y="7.5" Width="2.25" />
<TypeIdentifier>
- <HashCode>AAAAAAAAQAAAACAAAAAAAAQAEAAAAAAQAEAAAAAAAAA=</HashCode>
+ <HashCode>AAAAAAAAQAAAACAAAAAAAAQAEAAAAAAQAEAAAAAAAgA=</HashCode>
<FileName>OAuth2\Messages\AccessTokenSuccessResponse.cs</FileName>
</TypeIdentifier>
<Lollipop Position="0.2" />
</Class>
<Class Name="DotNetOpenAuth.OAuth2.Messages.AuthenticatedClientRequestBase" Collapsed="true">
- <Position X="3.25" Y="7.25" Width="2.25" />
- <InheritanceLine Type="DotNetOpenAuth.OAuth2.Messages.MessageBase" FixedToPoint="true">
- <Path>
- <Point X="1.25" Y="4.562" />
- <Point X="1.25" Y="7.688" />
- <Point X="3.25" Y="7.688" />
- </Path>
- </InheritanceLine>
+ <Position X="3.25" Y="5.25" Width="2.25" />
<TypeIdentifier>
<HashCode>AAAAAAAAAAAAAAAAAAAAAAAAAAwAAAAAAAAAAAAAAAA=</HashCode>
<FileName>OAuth2\Messages\AuthenticatedClientRequestBase.cs</FileName>
</TypeIdentifier>
</Class>
<Class Name="DotNetOpenAuth.OAuth2.Messages.EndUserAuthorizationFailedResponse" Collapsed="true">
- <Position X="3.25" Y="6.5" Width="2.75" />
- <InheritanceLine Type="DotNetOpenAuth.OAuth2.Messages.MessageBase" FixedToPoint="true">
- <Path>
- <Point X="1.25" Y="4.562" />
- <Point X="1.25" Y="6.875" />
- <Point X="3.25" Y="6.875" />
- </Path>
- </InheritanceLine>
+ <Position X="3.25" Y="4.5" Width="2.75" />
<TypeIdentifier>
<HashCode>AAAAAIAAAAAAAQAAAAAAAAgAAAAAAAEAAAAAAAAAAAA=</HashCode>
<FileName>OAuth2\Messages\EndUserAuthorizationFailedResponse.cs</FileName>
@@ -158,53 +77,30 @@
<Lollipop Position="0.2" />
</Class>
<Class Name="DotNetOpenAuth.OAuth2.Messages.EndUserAuthorizationRequest" Collapsed="true">
- <Position X="3.25" Y="5.5" Width="2.25" />
- <InheritanceLine Type="DotNetOpenAuth.OAuth2.Messages.MessageBase" FixedToPoint="true">
- <Path>
- <Point X="1.25" Y="4.562" />
- <Point X="1.25" Y="5.812" />
- <Point X="3.25" Y="5.812" />
- </Path>
- </InheritanceLine>
+ <Position X="3.25" Y="0.5" Width="2.25" />
<TypeIdentifier>
<HashCode>AAAAAAAAQAAAACAAAAAAAACAAAQAAAQAAAAAAAAAQAA=</HashCode>
<FileName>OAuth2\Messages\EndUserAuthorizationRequest.cs</FileName>
</TypeIdentifier>
</Class>
<Class Name="DotNetOpenAuth.OAuth2.Messages.EndUserAuthorizationSuccessAccessTokenResponse" Collapsed="true">
- <Position X="6.75" Y="4.25" Width="3.75" />
- <InheritanceLine Type="DotNetOpenAuth.OAuth2.Messages.EndUserAuthorizationSuccessResponseBase" FixedFromPoint="true">
- <Path>
- <Point X="6" Y="4.062" />
- <Point X="6.375" Y="4.062" />
- <Point X="6.375" Y="4.596" />
- <Point X="6.75" Y="4.596" />
- </Path>
- </InheritanceLine>
+ <Position X="6.25" Y="3.75" Width="3.75" />
<TypeIdentifier>
- <HashCode>CCAAAAAAAAACAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAA=</HashCode>
+ <HashCode>AAAAEAAAAAAAAAAAAAAAAAACEAAAAAAAAAAgAAAABgA=</HashCode>
<FileName>OAuth2\Messages\EndUserAuthorizationSuccessAccessTokenResponse.cs</FileName>
</TypeIdentifier>
<Lollipop Position="0.2" />
</Class>
<Class Name="DotNetOpenAuth.OAuth2.Messages.EndUserAuthorizationSuccessAuthCodeResponse" Collapsed="true">
- <Position X="6.75" Y="3.25" Width="3.5" />
- <InheritanceLine Type="DotNetOpenAuth.OAuth2.Messages.EndUserAuthorizationSuccessResponseBase" FixedFromPoint="true">
- <Path>
- <Point X="6" Y="4.062" />
- <Point X="6.375" Y="4.062" />
- <Point X="6.375" Y="3.596" />
- <Point X="6.75" Y="3.596" />
- </Path>
- </InheritanceLine>
+ <Position X="6.25" Y="2.5" Width="3.5" />
<TypeIdentifier>
- <HashCode>CCAAAAAAAAACAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAA=</HashCode>
+ <HashCode>ACAAEAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAgAAAABAA=</HashCode>
<FileName>OAuth2\Messages\EndUserAuthorizationSuccessAuthCodeResponse.cs</FileName>
</TypeIdentifier>
<Lollipop Position="0.2" />
</Class>
<Class Name="DotNetOpenAuth.OAuth2.Messages.EndUserAuthorizationSuccessResponseBase" Collapsed="true">
- <Position X="3.25" Y="3.75" Width="2.75" />
+ <Position X="3.25" Y="1.5" Width="2.75" />
<TypeIdentifier>
<HashCode>AAACAAAAAAAAACAAAAAAAAgAAAAAAAAAAEAAAAAAAAA=</HashCode>
<FileName>OAuth2\Messages\EndUserAuthorizationSuccessResponseBase.cs</FileName>
@@ -212,35 +108,28 @@
<Lollipop Position="0.2" />
</Class>
<Class Name="DotNetOpenAuth.OAuth2.Messages.AccessProtectedResourceRequest" Collapsed="true">
- <Position X="3.25" Y="4.75" Width="2.5" />
- <InheritanceLine Type="DotNetOpenAuth.OAuth2.Messages.MessageBase" FixedToPoint="true">
- <Path>
- <Point X="1.25" Y="4.562" />
- <Point X="1.25" Y="5.125" />
- <Point X="3.25" Y="5.125" />
- </Path>
- </InheritanceLine>
+ <Position X="3.25" Y="9.75" Width="2.5" />
<TypeIdentifier>
- <HashCode>CCAAAAAAQAACAAAAAAACAAAAEAAAAAAAAAEAAAQACAE=</HashCode>
+ <HashCode>AAAAEAAAQAAAAAAAAAACAAAAEAAAAAAAAAEgAAQADAE=</HashCode>
<FileName>OAuth2\Messages\AccessProtectedResourceRequest.cs</FileName>
</TypeIdentifier>
<Lollipop Position="0.2" />
</Class>
<Class Name="DotNetOpenAuth.OAuth2.Messages.UnauthorizedResponse" Collapsed="true">
- <Position X="3.25" Y="0.75" Width="2" />
- <InheritanceLine Type="DotNetOpenAuth.OAuth2.Messages.MessageBase" FixedToPoint="true">
- <Path>
- <Point X="1.25" Y="4" />
- <Point X="1.25" Y="1.125" />
- <Point X="3.25" Y="1.125" />
- </Path>
- </InheritanceLine>
+ <Position X="3.25" Y="10.75" Width="2" />
<TypeIdentifier>
<HashCode>AUABAAAAAAAAACAAAAAAAAQIAAAAAAAQAAAAAAAAABA=</HashCode>
<FileName>OAuth2\Messages\UnauthorizedResponse.cs</FileName>
</TypeIdentifier>
<Lollipop Position="0.2" />
</Class>
+ <Class Name="DotNetOpenAuth.OAuth2.Messages.ScopedAccessTokenRequest" Collapsed="true">
+ <Position X="6.75" Y="7.75" Width="2.25" />
+ <TypeIdentifier>
+ <HashCode>AAAAAAAAAAAAACAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=</HashCode>
+ <FileName>OAuth2\Messages\ScopedAccessTokenRequest.cs</FileName>
+ </TypeIdentifier>
+ </Class>
<Interface Name="DotNetOpenAuth.OAuth2.Messages.IMessageWithClientState">
<Position X="11.5" Y="0.5" Width="2" />
<TypeIdentifier>
@@ -248,17 +137,17 @@
<FileName>OAuth2\Messages\IMessageWithClientState.cs</FileName>
</TypeIdentifier>
</Interface>
- <Enum Name="DotNetOpenAuth.OAuth2.Messages.EndUserAuthorizationResponseTypes">
+ <Enum Name="DotNetOpenAuth.OAuth2.Messages.EndUserAuthorizationResponseType">
<Position X="8" Y="0.5" Width="3" />
<TypeIdentifier>
- <HashCode>ACAAAAAAAAAAAAAAAgAAAAAAEAAAAAAAAAAAAAAAAAA=</HashCode>
+ <HashCode>ACAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAA=</HashCode>
<FileName>OAuth2\Messages\EndUserAuthorizationResponseType.cs</FileName>
</TypeIdentifier>
</Enum>
<Enum Name="DotNetOpenAuth.OAuth2.Messages.GrantType">
<Position X="6.25" Y="0.5" Width="1.5" />
<TypeIdentifier>
- <HashCode>ACAAAAAAQAAAAAAAAgAAAAAAAAAAAAACAAAAAAEAAAA=</HashCode>
+ <HashCode>ACAAAAAAQAAAAAQAAgAAAAAAAAAAAAACAAAAAAAAAAA=</HashCode>
<FileName>OAuth2\Messages\GrantType.cs</FileName>
</TypeIdentifier>
</Enum>
diff --git a/src/DotNetOpenAuth/OAuth2/Messages/ScopedAccessTokenRequest.cs b/src/DotNetOpenAuth/OAuth2/Messages/ScopedAccessTokenRequest.cs
new file mode 100644
index 0000000..0e0329b
--- /dev/null
+++ b/src/DotNetOpenAuth/OAuth2/Messages/ScopedAccessTokenRequest.cs
@@ -0,0 +1,34 @@
+//-----------------------------------------------------------------------
+// <copyright file="ScopedAccessTokenRequest.cs" company="Andrew Arnott">
+// Copyright (c) Andrew Arnott. All rights reserved.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace DotNetOpenAuth.OAuth2.Messages {
+ using System;
+ using System.Collections.Generic;
+ using DotNetOpenAuth.Messaging;
+ using DotNetOpenAuth.OAuth2.ChannelElements;
+
+ /// <summary>
+ /// An access token request that includes a scope parameter.
+ /// </summary>
+ internal abstract class ScopedAccessTokenRequest : AccessTokenRequestBase {
+ /// <summary>
+ /// Initializes a new instance of the <see cref="ScopedAccessTokenRequest"/> class.
+ /// </summary>
+ /// <param name="tokenEndpoint">The Authorization Server's access token endpoint URL.</param>
+ /// <param name="version">The version.</param>
+ internal ScopedAccessTokenRequest(Uri tokenEndpoint, Version version)
+ : base(tokenEndpoint, version) {
+ this.Scope = new HashSet<string>(OAuthUtilities.ScopeStringComparer);
+ }
+
+ /// <summary>
+ /// Gets the set of scopes the Client would like the access token to provide access to.
+ /// </summary>
+ /// <value>A set of scopes. Never null.</value>
+ [MessagePart(Protocol.scope, IsRequired = false, Encoder = typeof(ScopeEncoder))]
+ internal HashSet<string> Scope { get; private set; }
+ }
+}
diff --git a/src/DotNetOpenAuth/OAuth2/Messages/UnauthorizedResponse.cs b/src/DotNetOpenAuth/OAuth2/Messages/UnauthorizedResponse.cs
index 34da922..d79c00b 100644
--- a/src/DotNetOpenAuth/OAuth2/Messages/UnauthorizedResponse.cs
+++ b/src/DotNetOpenAuth/OAuth2/Messages/UnauthorizedResponse.cs
@@ -63,7 +63,7 @@ namespace DotNetOpenAuth.OAuth2.Messages {
WebHeaderCollection IHttpDirectResponse.Headers {
get {
return new WebHeaderCollection() {
- { HttpResponseHeader.WwwAuthenticate, Protocol.HttpAuthorizationScheme },
+ { HttpResponseHeader.WwwAuthenticate, Protocol.BearerHttpAuthorizationScheme },
};
}
}
diff --git a/src/DotNetOpenAuth/OAuth2/OAuthUtilities.cs b/src/DotNetOpenAuth/OAuth2/OAuthUtilities.cs
index 74d5791..c2b2f5f 100644
--- a/src/DotNetOpenAuth/OAuth2/OAuthUtilities.cs
+++ b/src/DotNetOpenAuth/OAuth2/OAuthUtilities.cs
@@ -90,14 +90,14 @@ namespace DotNetOpenAuth.OAuth2 {
/// </summary>
/// <param name="request">The request to authorize.</param>
/// <param name="accessToken">The access token previously obtained from the Authorization Server.</param>
- internal static void AuthorizeWithOAuthWrap(this HttpWebRequest request, string accessToken) {
+ internal static void AuthorizeWithBearerToken(this HttpWebRequest request, string accessToken) {
Contract.Requires<ArgumentNullException>(request != null);
Contract.Requires<ArgumentException>(!string.IsNullOrEmpty(accessToken));
ErrorUtilities.VerifyProtocol(accessToken.All(ch => accessTokenAuthorizationHeaderAllowedCharacters.IndexOf(ch) >= 0), "The access token contains characters that must not appear in the HTTP Authorization header.");
request.Headers[HttpRequestHeader.Authorization] = string.Format(
CultureInfo.InvariantCulture,
- Protocol.HttpAuthorizationHeaderFormat,
+ Protocol.BearerHttpAuthorizationHeaderFormat,
accessToken);
}
diff --git a/src/DotNetOpenAuth/OAuth2/Protocol.cs b/src/DotNetOpenAuth/OAuth2/Protocol.cs
index 12b9f5e..d9d7dd2 100644
--- a/src/DotNetOpenAuth/OAuth2/Protocol.cs
+++ b/src/DotNetOpenAuth/OAuth2/Protocol.cs
@@ -24,14 +24,25 @@ namespace DotNetOpenAuth.OAuth2 {
/// </summary>
internal class Protocol {
/// <summary>
- /// The HTTP authorization scheme "OAuth";
+ /// The HTTP authorization scheme "Bearer";
/// </summary>
- internal const string HttpAuthorizationScheme = "OAuth";
+ internal const string BearerHttpAuthorizationScheme = "Bearer";
/// <summary>
- /// The format of the HTTP Authorization header value that authorizes OAuth 2.0 requests.
+ /// The HTTP authorization scheme "Bearer ";
/// </summary>
- internal const string HttpAuthorizationHeaderFormat = "OAuth token=\"{0}\"";
+ internal const string BearerHttpAuthorizationSchemeWithTrailingSpace = BearerHttpAuthorizationScheme + " ";
+
+ /// <summary>
+ /// The format of the HTTP Authorization header value that authorizes OAuth 2.0 requests using bearer access tokens.
+ /// </summary>
+ internal const string BearerHttpAuthorizationHeaderFormat = BearerHttpAuthorizationSchemeWithTrailingSpace + "{0}";
+
+ /// <summary>
+ /// The name of the parameter whose value is an OAuth 2.0 bearer access token, as it is defined
+ /// in a URL-encoded POST entity or URL query string.
+ /// </summary>
+ internal const string BearerTokenEncodedUrlParameterName = "bearer_token";
/// <summary>
/// The "type" string.
@@ -124,6 +135,11 @@ namespace DotNetOpenAuth.OAuth2 {
internal const string access_token_secret = "access_token_secret";
/// <summary>
+ /// The "token_type" string.
+ /// </summary>
+ internal const string token_type = "token_type";
+
+ /// <summary>
/// The "refresh_token" string.
/// </summary>
internal const string refresh_token = "refresh_token";
@@ -230,11 +246,20 @@ namespace DotNetOpenAuth.OAuth2 {
}
}
+ /// <summary>
+ /// Values for the "response_type" parameter.
+ /// </summary>
internal static class ResponseTypes
{
+ /// <summary>
+ /// The string "code".
+ /// </summary>
internal const string Code = "code";
+
+ /// <summary>
+ /// The string "token".
+ /// </summary>
internal const string Token = "token";
- internal const string CodeAndToken = "code_and_token";
}
internal static class GrantTypes
@@ -247,7 +272,7 @@ namespace DotNetOpenAuth.OAuth2 {
internal const string RefreshToken = "refresh_token";
- internal const string None = "none";
+ internal const string ClientCredentials = "client_credentials";
}
/// <summary>
@@ -311,5 +336,15 @@ namespace DotNetOpenAuth.OAuth2 {
/// </summary>
internal const string InvalidScope = "invalid_scope";
}
+
+ /// <summary>
+ /// Recognized access token types.
+ /// </summary>
+ internal static class AccessTokenTypes {
+ /// <summary>
+ /// The "bearer" token type.
+ /// </summary>
+ internal const string Bearer = "bearer";
+ }
}
}