summaryrefslogtreecommitdiffstats
path: root/src/DotNetOpenAuth.OAuth2/OAuth2
diff options
context:
space:
mode:
Diffstat (limited to 'src/DotNetOpenAuth.OAuth2/OAuth2')
-rw-r--r--src/DotNetOpenAuth.OAuth2/OAuth2/AccessToken.cs (renamed from src/DotNetOpenAuth.OAuth2/OAuth2/ChannelElements/AccessToken.cs)18
-rw-r--r--src/DotNetOpenAuth.OAuth2/OAuth2/AuthorizationServerDescription.cs62
-rw-r--r--src/DotNetOpenAuth.OAuth2/OAuth2/AuthorizationState.cs93
-rw-r--r--src/DotNetOpenAuth.OAuth2/OAuth2/ChannelElements/AccessRequestBindingElement.cs183
-rw-r--r--src/DotNetOpenAuth.OAuth2/OAuth2/ChannelElements/AccessTokenBindingElement.cs93
-rw-r--r--src/DotNetOpenAuth.OAuth2/OAuth2/ChannelElements/AuthServerAllFlowsBindingElement.cs83
-rw-r--r--src/DotNetOpenAuth.OAuth2/OAuth2/ChannelElements/AuthServerBindingElementBase.cs81
-rw-r--r--src/DotNetOpenAuth.OAuth2/OAuth2/ChannelElements/AuthorizationCode.cs110
-rw-r--r--src/DotNetOpenAuth.OAuth2/OAuth2/ChannelElements/AuthorizationCodeBindingElement.cs101
-rw-r--r--src/DotNetOpenAuth.OAuth2/OAuth2/ChannelElements/AuthorizationDataBag.cs3
-rw-r--r--src/DotNetOpenAuth.OAuth2/OAuth2/ChannelElements/ClientAuthenticationResult.cs32
-rw-r--r--src/DotNetOpenAuth.OAuth2/OAuth2/ChannelElements/EndUserAuthorizationResponseTypeEncoder.cs66
-rw-r--r--src/DotNetOpenAuth.OAuth2/OAuth2/ChannelElements/GrantTypeEncoder.cs78
-rw-r--r--src/DotNetOpenAuth.OAuth2/OAuth2/ChannelElements/IAuthorizationCodeCarryingRequest.cs22
-rw-r--r--src/DotNetOpenAuth.OAuth2/OAuth2/ChannelElements/IOAuth2ChannelWithAuthorizationServer.cs19
-rw-r--r--src/DotNetOpenAuth.OAuth2/OAuth2/ChannelElements/IRefreshTokenCarryingRequest.cs22
-rw-r--r--src/DotNetOpenAuth.OAuth2/OAuth2/ChannelElements/OAuth2AuthorizationServerChannel.cs109
-rw-r--r--src/DotNetOpenAuth.OAuth2/OAuth2/ChannelElements/OAuth2ChannelBase.cs70
-rw-r--r--src/DotNetOpenAuth.OAuth2/OAuth2/ChannelElements/OAuth2ClientChannel.cs122
-rw-r--r--src/DotNetOpenAuth.OAuth2/OAuth2/ChannelElements/OAuth2ResourceServerChannel.cs153
-rw-r--r--src/DotNetOpenAuth.OAuth2/OAuth2/ChannelElements/RefreshToken.cs56
-rw-r--r--src/DotNetOpenAuth.OAuth2/OAuth2/ClientDescription.cs71
-rw-r--r--src/DotNetOpenAuth.OAuth2/OAuth2/ClientType.cs47
-rw-r--r--src/DotNetOpenAuth.OAuth2/OAuth2/IAccessTokenAnalyzer.cs64
-rw-r--r--src/DotNetOpenAuth.OAuth2/OAuth2/IAuthorizationServer.cs264
-rw-r--r--src/DotNetOpenAuth.OAuth2/OAuth2/IAuthorizationState.cs67
-rw-r--r--src/DotNetOpenAuth.OAuth2/OAuth2/IClientAuthorizationTracker.cs53
-rw-r--r--src/DotNetOpenAuth.OAuth2/OAuth2/IClientDescription.cs113
-rw-r--r--src/DotNetOpenAuth.OAuth2/OAuth2/Messages/AccessTokenAuthorizationCodeRequest.cs100
-rw-r--r--src/DotNetOpenAuth.OAuth2/OAuth2/Messages/AccessTokenClientCredentialsRequest.cs83
-rw-r--r--src/DotNetOpenAuth.OAuth2/OAuth2/Messages/AccessTokenFailedResponse.cs93
-rw-r--r--src/DotNetOpenAuth.OAuth2/OAuth2/Messages/AccessTokenRefreshRequest.cs78
-rw-r--r--src/DotNetOpenAuth.OAuth2/OAuth2/Messages/AccessTokenRequestBase.cs78
-rw-r--r--src/DotNetOpenAuth.OAuth2/OAuth2/Messages/AccessTokenResourceOwnerPasswordCredentialsRequest.cs93
-rw-r--r--src/DotNetOpenAuth.OAuth2/OAuth2/Messages/AccessTokenSuccessResponse.cs113
-rw-r--r--src/DotNetOpenAuth.OAuth2/OAuth2/Messages/AuthenticatedClientRequestBase.cs42
-rw-r--r--src/DotNetOpenAuth.OAuth2/OAuth2/Messages/EndUserAuthorizationFailedResponse.cs81
-rw-r--r--src/DotNetOpenAuth.OAuth2/OAuth2/Messages/EndUserAuthorizationImplicitRequest.cs63
-rw-r--r--src/DotNetOpenAuth.OAuth2/OAuth2/Messages/EndUserAuthorizationRequest.cs114
-rw-r--r--src/DotNetOpenAuth.OAuth2/OAuth2/Messages/EndUserAuthorizationResponseType.cs25
-rw-r--r--src/DotNetOpenAuth.OAuth2/OAuth2/Messages/EndUserAuthorizationSuccessAccessTokenResponse.cs111
-rw-r--r--src/DotNetOpenAuth.OAuth2/OAuth2/Messages/EndUserAuthorizationSuccessAuthCodeResponse.cs74
-rw-r--r--src/DotNetOpenAuth.OAuth2/OAuth2/Messages/EndUserAuthorizationSuccessResponseBase.cs71
-rw-r--r--src/DotNetOpenAuth.OAuth2/OAuth2/Messages/GrantType.cs42
-rw-r--r--src/DotNetOpenAuth.OAuth2/OAuth2/Messages/IAccessTokenRequest.cs37
-rw-r--r--src/DotNetOpenAuth.OAuth2/OAuth2/Messages/IMessageWithClientState.cs21
-rw-r--r--src/DotNetOpenAuth.OAuth2/OAuth2/Messages/OAuth 2 Messages.cd164
-rw-r--r--src/DotNetOpenAuth.OAuth2/OAuth2/Messages/ScopedAccessTokenRequest.cs41
-rw-r--r--src/DotNetOpenAuth.OAuth2/OAuth2/OAuthStrings.Designer.cs74
-rw-r--r--src/DotNetOpenAuth.OAuth2/OAuth2/OAuthStrings.resx24
-rw-r--r--src/DotNetOpenAuth.OAuth2/OAuth2/OAuthUtilities.cs74
-rw-r--r--src/DotNetOpenAuth.OAuth2/OAuth2/Protocol.cs102
-rw-r--r--src/DotNetOpenAuth.OAuth2/OAuth2/StandardAccessTokenAnalyzer.cs66
53 files changed, 117 insertions, 4002 deletions
diff --git a/src/DotNetOpenAuth.OAuth2/OAuth2/ChannelElements/AccessToken.cs b/src/DotNetOpenAuth.OAuth2/OAuth2/AccessToken.cs
index 84b17cc..3a12faa 100644
--- a/src/DotNetOpenAuth.OAuth2/OAuth2/ChannelElements/AccessToken.cs
+++ b/src/DotNetOpenAuth.OAuth2/OAuth2/AccessToken.cs
@@ -4,18 +4,19 @@
// </copyright>
//-----------------------------------------------------------------------
-namespace DotNetOpenAuth.OAuth2.ChannelElements {
+namespace DotNetOpenAuth.OAuth2 {
using System;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.Security.Cryptography;
using DotNetOpenAuth.Messaging;
using DotNetOpenAuth.Messaging.Bindings;
+ using DotNetOpenAuth.OAuth2.ChannelElements;
/// <summary>
/// A short-lived token that accompanies HTTP requests to protected data to authorize the request.
/// </summary>
- internal class AccessToken : AuthorizationDataBag {
+ public class AccessToken : AuthorizationDataBag {
/// <summary>
/// Initializes a new instance of the <see cref="AccessToken"/> class.
/// </summary>
@@ -40,14 +41,15 @@ namespace DotNetOpenAuth.OAuth2.ChannelElements {
/// <summary>
/// Initializes a new instance of the <see cref="AccessToken"/> class.
/// </summary>
- /// <param name="clientIdentifier">The client identifier.</param>
/// <param name="scopes">The scopes.</param>
/// <param name="username">The username of the account that authorized this token.</param>
/// <param name="lifetime">The lifetime for this access token.</param>
- internal AccessToken(string clientIdentifier, IEnumerable<string> scopes, string username, TimeSpan? lifetime) {
- Requires.NotNullOrEmpty(clientIdentifier, "clientIdentifier");
-
- this.ClientIdentifier = clientIdentifier;
+ /// <remarks>
+ /// The <see cref="AuthorizationDataBag.ClientIdentifier"/> is left <c>null</c> in this case because this constructor
+ /// is invoked in the case where the client is <em>not</em> authenticated, and therefore no
+ /// trust in the client_id is appropriate.
+ /// </remarks>
+ internal AccessToken(IEnumerable<string> scopes, string username, TimeSpan? lifetime) {
this.Scope.ResetContents(scopes);
this.User = username;
this.Lifetime = lifetime;
@@ -59,7 +61,7 @@ namespace DotNetOpenAuth.OAuth2.ChannelElements {
/// </summary>
/// <value>The lifetime.</value>
[MessagePart(Encoder = typeof(TimespanSecondsEncoder))]
- internal TimeSpan? Lifetime { get; set; }
+ public TimeSpan? Lifetime { get; set; }
/// <summary>
/// Creates a formatter capable of serializing/deserializing an access token.
diff --git a/src/DotNetOpenAuth.OAuth2/OAuth2/AuthorizationServerDescription.cs b/src/DotNetOpenAuth.OAuth2/OAuth2/AuthorizationServerDescription.cs
deleted file mode 100644
index 38a9ff9..0000000
--- a/src/DotNetOpenAuth.OAuth2/OAuth2/AuthorizationServerDescription.cs
+++ /dev/null
@@ -1,62 +0,0 @@
-//-----------------------------------------------------------------------
-// <copyright file="AuthorizationServerDescription.cs" company="Outercurve Foundation">
-// Copyright (c) Outercurve Foundation. All rights reserved.
-// </copyright>
-//-----------------------------------------------------------------------
-
-namespace DotNetOpenAuth.OAuth2 {
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
-
- /// <summary>
- /// A description of an OAuth Authorization Server as seen by an OAuth Client.
- /// </summary>
- public class AuthorizationServerDescription {
- /// <summary>
- /// Initializes a new instance of the <see cref="AuthorizationServerDescription"/> class.
- /// </summary>
- public AuthorizationServerDescription() {
- this.ProtocolVersion = Protocol.Default.ProtocolVersion;
- }
-
- /// <summary>
- /// Gets or sets the Authorization Server URL from which an Access Token is requested by the Client.
- /// </summary>
- /// <value>An HTTPS URL.</value>
- /// <remarks>
- /// <para>After obtaining authorization from the resource owner, clients request an access token from the authorization server's token endpoint.</para>
- /// <para>The URI of the token endpoint can be found in the service documentation, or can be obtained by the client by making an unauthorized protected resource request (from the WWW-Authenticate response header token-uri (The 'authorization-uri' Attribute) attribute).</para>
- /// <para>The token endpoint advertised by the resource server MAY include a query component as defined by [RFC3986] (Berners-Lee, T., Fielding, R., and L. Masinter, “Uniform Resource Identifier (URI): Generic Syntax,” January 2005.) section 3.</para>
- /// <para>Since requests to the token endpoint result in the transmission of plain text credentials in the HTTP request and response, the authorization server MUST require the use of a transport-layer mechanism such as TLS/SSL (or a secure channel with equivalent protections) when sending requests to the token endpoints. </para>
- /// </remarks>
- public Uri TokenEndpoint { get; set; }
-
- /// <summary>
- /// Gets or sets the Authorization Server URL where the Client (re)directs the User
- /// to make an authorization request.
- /// </summary>
- /// <value>An HTTPS URL.</value>
- /// <remarks>
- /// <para>Clients direct the resource owner to the authorization endpoint to approve their access request. Before granting access, the resource owner first authenticates with the authorization server. The way in which the authorization server authenticates the end-user (e.g. username and password login, OpenID, session cookies) and in which the authorization server obtains the end-user's authorization, including whether it uses a secure channel such as TLS/SSL, is beyond the scope of this specification. However, the authorization server MUST first verify the identity of the end-user.</para>
- /// <para>The URI of the authorization endpoint can be found in the service documentation, or can be obtained by the client by making an unauthorized protected resource request (from the WWW-Authenticate response header auth-uri (The 'authorization-uri' Attribute) attribute).</para>
- /// <para>The authorization endpoint advertised by the resource server MAY include a query component as defined by [RFC3986] (Berners-Lee, T., Fielding, R., and L. Masinter, “Uniform Resource Identifier (URI): Generic Syntax,” January 2005.) section 3.</para>
- /// <para>Since requests to the authorization endpoint result in user authentication and the transmission of sensitive values, the authorization server SHOULD require the use of a transport-layer mechanism such as TLS/SSL (or a secure channel with equivalent protections) when sending requests to the authorization endpoints.</para>
- /// </remarks>
- public Uri AuthorizationEndpoint { get; set; }
-
- /// <summary>
- /// Gets or sets the OAuth version supported by the Authorization Server.
- /// </summary>
- public ProtocolVersion ProtocolVersion { get; set; }
-
- /// <summary>
- /// Gets the version of the OAuth protocol to use with this Authorization Server.
- /// </summary>
- /// <value>The version.</value>
- internal Version Version {
- get { return Protocol.Lookup(this.ProtocolVersion).Version; }
- }
- }
-}
diff --git a/src/DotNetOpenAuth.OAuth2/OAuth2/AuthorizationState.cs b/src/DotNetOpenAuth.OAuth2/OAuth2/AuthorizationState.cs
deleted file mode 100644
index 4117b3c..0000000
--- a/src/DotNetOpenAuth.OAuth2/OAuth2/AuthorizationState.cs
+++ /dev/null
@@ -1,93 +0,0 @@
-//-----------------------------------------------------------------------
-// <copyright file="AuthorizationState.cs" company="Outercurve Foundation">
-// Copyright (c) Outercurve Foundation. All rights reserved.
-// </copyright>
-//-----------------------------------------------------------------------
-
-namespace DotNetOpenAuth.OAuth2 {
- using System;
- using System.Collections.Generic;
-
- using DotNetOpenAuth.Messaging;
-
- /// <summary>
- /// A simple in-memory copy of an authorization state.
- /// </summary>
- [Serializable]
- public class AuthorizationState : IAuthorizationState {
- /// <summary>
- /// Initializes a new instance of the <see cref="AuthorizationState"/> class.
- /// </summary>
- /// <param name="scopes">The scopes of access being requested or that was obtained.</param>
- public AuthorizationState(IEnumerable<string> scopes = null) {
- this.Scope = new HashSet<string>(OAuthUtilities.ScopeStringComparer);
- if (scopes != null) {
- this.Scope.AddRange(scopes);
- }
- }
-
- /// <summary>
- /// Gets or sets the callback URL used to obtain authorization.
- /// </summary>
- /// <value>The callback URL.</value>
- public Uri Callback { get; set; }
-
- /// <summary>
- /// Gets or sets the long-lived token used to renew the short-lived <see cref="AccessToken"/>.
- /// </summary>
- /// <value>The refresh token.</value>
- public string RefreshToken { get; set; }
-
- /// <summary>
- /// Gets or sets the access token.
- /// </summary>
- /// <value>The access token.</value>
- public string AccessToken { get; set; }
-
- /// <summary>
- /// Gets or sets the access token UTC expiration date.
- /// </summary>
- /// <value></value>
- public DateTime? AccessTokenExpirationUtc { get; set; }
-
- /// <summary>
- /// Gets or sets the access token issue date UTC.
- /// </summary>
- /// <value>The access token issue date UTC.</value>
- public DateTime? AccessTokenIssueDateUtc { get; set; }
-
- /// <summary>
- /// Gets the scope the token is (to be) authorized for.
- /// </summary>
- /// <value>The scope.</value>
- public HashSet<string> Scope { get; private set; }
-
- /// <summary>
- /// Gets or sets a value indicating whether this instance is deleted.
- /// </summary>
- /// <value>
- /// <c>true</c> if this instance is deleted; otherwise, <c>false</c>.
- /// </value>
- public bool IsDeleted { get; set; }
-
- /// <summary>
- /// Deletes this authorization, including access token and refresh token where applicable.
- /// </summary>
- /// <remarks>
- /// This method is invoked when an authorization attempt fails, is rejected, is revoked, or
- /// expires and cannot be renewed.
- /// </remarks>
- public virtual void Delete() {
- this.IsDeleted = true;
- }
-
- /// <summary>
- /// Saves any changes made to this authorization object's properties.
- /// </summary>
- /// <remarks>
- /// This method is invoked after DotNetOpenAuth changes any property.
- /// </remarks>
- public virtual void SaveChanges() {
- }
- }
-} \ No newline at end of file
diff --git a/src/DotNetOpenAuth.OAuth2/OAuth2/ChannelElements/AccessRequestBindingElement.cs b/src/DotNetOpenAuth.OAuth2/OAuth2/ChannelElements/AccessRequestBindingElement.cs
deleted file mode 100644
index 7a68060..0000000
--- a/src/DotNetOpenAuth.OAuth2/OAuth2/ChannelElements/AccessRequestBindingElement.cs
+++ /dev/null
@@ -1,183 +0,0 @@
-//-----------------------------------------------------------------------
-// <copyright file="AccessRequestBindingElement.cs" company="Outercurve Foundation">
-// Copyright (c) Outercurve Foundation. All rights reserved.
-// </copyright>
-//-----------------------------------------------------------------------
-
-namespace DotNetOpenAuth.OAuth2.ChannelElements {
- using System;
- using System.Collections.Generic;
- using System.Diagnostics.CodeAnalysis;
- using System.Globalization;
- using System.Linq;
- using System.Security.Cryptography;
- using System.Text;
- using DotNetOpenAuth.Messaging;
- using DotNetOpenAuth.Messaging.Bindings;
- using DotNetOpenAuth.OAuth2.Messages;
-
- /// <summary>
- /// Decodes verification codes, refresh tokens and access tokens on incoming messages.
- /// </summary>
- /// <remarks>
- /// This binding element also ensures that the code/token coming in is issued to
- /// the same client that is sending the code/token and that the authorization has
- /// not been revoked and that an access token has not expired.
- /// </remarks>
- internal class AccessRequestBindingElement : AuthServerBindingElementBase {
- /// <summary>
- /// Initializes a new instance of the <see cref="AccessRequestBindingElement"/> class.
- /// </summary>
- internal AccessRequestBindingElement() {
- }
-
- /// <summary>
- /// Gets the protection commonly offered (if any) by this binding element.
- /// </summary>
- /// <value></value>
- /// <remarks>
- /// This value is used to assist in sorting binding elements in the channel stack.
- /// </remarks>
- public override MessageProtections Protection {
- get { return MessageProtections.None; }
- }
-
- /// <summary>
- /// Prepares a message for sending based on the rules of this channel binding element.
- /// </summary>
- /// <param name="message">The message to prepare for sending.</param>
- /// <returns>
- /// The protections (if any) that this binding element applied to the message.
- /// Null if this binding element did not even apply to this binding element.
- /// </returns>
- /// <remarks>
- /// Implementations that provide message protection must honor the
- /// <see cref="MessagePartAttribute.RequiredProtection"/> properties where applicable.
- /// </remarks>
- public override MessageProtections? ProcessOutgoingMessage(IProtocolMessage message) {
- var authCodeCarrier = message as IAuthorizationCodeCarryingRequest;
- if (authCodeCarrier != null) {
- var codeFormatter = AuthorizationCode.CreateFormatter(this.AuthorizationServer);
- var code = authCodeCarrier.AuthorizationDescription;
- authCodeCarrier.Code = codeFormatter.Serialize(code);
- return MessageProtections.None;
- }
-
- var accessTokenCarrier = message as IAccessTokenCarryingRequest;
- if (accessTokenCarrier != null) {
- var responseWithOriginatingRequest = (IDirectResponseProtocolMessage)message;
- var request = (IAccessTokenRequest)responseWithOriginatingRequest.OriginatingRequest;
-
- using (var resourceServerKey = this.AuthorizationServer.GetResourceServerEncryptionKey(request)) {
- var tokenFormatter = AccessToken.CreateFormatter(this.AuthorizationServer.AccessTokenSigningKey, resourceServerKey);
- var token = accessTokenCarrier.AuthorizationDescription;
- accessTokenCarrier.AccessToken = tokenFormatter.Serialize(token);
- }
-
- return MessageProtections.None;
- }
-
- var accessTokenResponse = message as AccessTokenSuccessResponse;
- if (accessTokenResponse != null) {
- var directResponseMessage = (IDirectResponseProtocolMessage)accessTokenResponse;
- var accessTokenRequest = (AccessTokenRequestBase)directResponseMessage.OriginatingRequest;
- ErrorUtilities.VerifyProtocol(accessTokenRequest.GrantType != GrantType.ClientCredentials || accessTokenResponse.RefreshToken == null, OAuthStrings.NoGrantNoRefreshToken);
- }
-
- return null;
- }
-
- /// <summary>
- /// Performs any transformation on an incoming message that may be necessary and/or
- /// validates an incoming message based on the rules of this channel binding element.
- /// </summary>
- /// <param name="message">The incoming message to process.</param>
- /// <returns>
- /// The protections (if any) that this binding element applied to the message.
- /// Null if this binding element did not even apply to this binding element.
- /// </returns>
- /// <exception cref="ProtocolException">
- /// Thrown when the binding element rules indicate that this message is invalid and should
- /// NOT be processed.
- /// </exception>
- /// <remarks>
- /// Implementations that provide message protection must honor the
- /// <see cref="MessagePartAttribute.RequiredProtection"/> properties where applicable.
- /// </remarks>
- [SuppressMessage("Microsoft.Naming", "CA2204:Literals should be spelled correctly", MessageId = "unauthorizedclient", Justification = "Protocol requirement")]
- [SuppressMessage("Microsoft.Naming", "CA2204:Literals should be spelled correctly", MessageId = "incorrectclientcredentials", Justification = "Protocol requirement")]
- [SuppressMessage("Microsoft.Naming", "CA2204:Literals should be spelled correctly", MessageId = "authorizationexpired", Justification = "Protocol requirement")]
- [SuppressMessage("Microsoft.Globalization", "CA1303:Do not pass literals as localized parameters", MessageId = "DotNetOpenAuth.Messaging.ErrorUtilities.VerifyProtocol(System.Boolean,System.String,System.Object[])", Justification = "Protocol requirement")]
- public override MessageProtections? ProcessIncomingMessage(IProtocolMessage message) {
- var tokenRequest = message as IAuthorizationCarryingRequest;
- if (tokenRequest != null) {
- try {
- var authCodeCarrier = message as IAuthorizationCodeCarryingRequest;
- var refreshTokenCarrier = message as IRefreshTokenCarryingRequest;
- var resourceOwnerPasswordCarrier = message as AccessTokenResourceOwnerPasswordCredentialsRequest;
- var clientCredentialOnly = message as AccessTokenClientCredentialsRequest;
- if (authCodeCarrier != null) {
- var authorizationCodeFormatter = AuthorizationCode.CreateFormatter(this.AuthorizationServer);
- var authorizationCode = authorizationCodeFormatter.Deserialize(message, authCodeCarrier.Code, Protocol.code);
- authCodeCarrier.AuthorizationDescription = authorizationCode;
- } else if (refreshTokenCarrier != null) {
- var refreshTokenFormatter = RefreshToken.CreateFormatter(this.AuthorizationServer.CryptoKeyStore);
- var refreshToken = refreshTokenFormatter.Deserialize(message, refreshTokenCarrier.RefreshToken, Protocol.refresh_token);
- refreshTokenCarrier.AuthorizationDescription = refreshToken;
- } else if (resourceOwnerPasswordCarrier != null) {
- try {
- if (this.AuthorizationServer.IsResourceOwnerCredentialValid(resourceOwnerPasswordCarrier.UserName, resourceOwnerPasswordCarrier.Password)) {
- resourceOwnerPasswordCarrier.CredentialsValidated = true;
- } else {
- Logger.OAuth.WarnFormat(
- "Resource owner password credential for user \"{0}\" rejected by authorization server host.",
- resourceOwnerPasswordCarrier.UserName);
-
- // TODO: fix this to report the appropriate error code for a bad credential.
- throw new ProtocolException();
- }
- } catch (NotSupportedException) {
- // TODO: fix this to return the appropriate error code for not supporting resource owner password credentials
- throw new ProtocolException();
- } catch (NotImplementedException) {
- // TODO: fix this to return the appropriate error code for not supporting resource owner password credentials
- throw new ProtocolException();
- }
- } else if (clientCredentialOnly != null) {
- // this method will throw later if the credentials are false.
- clientCredentialOnly.CredentialsValidated = true;
- } else {
- throw ErrorUtilities.ThrowInternal("Unexpected message type: " + tokenRequest.GetType());
- }
- } catch (ExpiredMessageException ex) {
- throw ErrorUtilities.Wrap(ex, Protocol.authorization_expired);
- }
-
- var accessRequest = tokenRequest as AccessTokenRequestBase;
- if (accessRequest != null) {
- // Make sure the client sending us this token is the client we issued the token to.
- ErrorUtilities.VerifyProtocol(string.Equals(accessRequest.ClientIdentifier, tokenRequest.AuthorizationDescription.ClientIdentifier, StringComparison.Ordinal), Protocol.incorrect_client_credentials);
-
- // Check that the client secret is correct.
- var client = this.AuthorizationServer.GetClientOrThrow(accessRequest.ClientIdentifier);
- string secret = client.Secret;
- ErrorUtilities.VerifyProtocol(!string.IsNullOrEmpty(secret), Protocol.unauthorized_client); // an empty secret is not allowed for client authenticated calls.
- ErrorUtilities.VerifyProtocol(MessagingUtilities.EqualsConstantTime(secret, accessRequest.ClientSecret), Protocol.incorrect_client_credentials);
-
- 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.
- ErrorUtilities.VerifyProtocol(this.AuthorizationServer.IsAuthorizationValid(tokenRequest.AuthorizationDescription), Protocol.authorization_expired);
-
- return MessageProtections.None;
- }
-
- return null;
- }
- }
-}
diff --git a/src/DotNetOpenAuth.OAuth2/OAuth2/ChannelElements/AccessTokenBindingElement.cs b/src/DotNetOpenAuth.OAuth2/OAuth2/ChannelElements/AccessTokenBindingElement.cs
deleted file mode 100644
index 4c63f29..0000000
--- a/src/DotNetOpenAuth.OAuth2/OAuth2/ChannelElements/AccessTokenBindingElement.cs
+++ /dev/null
@@ -1,93 +0,0 @@
-//-----------------------------------------------------------------------
-// <copyright file="AccessTokenBindingElement.cs" company="Outercurve Foundation">
-// Copyright (c) Outercurve Foundation. All rights reserved.
-// </copyright>
-//-----------------------------------------------------------------------
-
-namespace DotNetOpenAuth.OAuth2.ChannelElements {
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Security.Cryptography;
- using System.Text;
- using DotNetOpenAuth.Messaging;
- using DotNetOpenAuth.OAuth2.Messages;
-
- /// <summary>
- /// Serializes access tokens inside an outgoing message.
- /// </summary>
- internal class AccessTokenBindingElement : AuthServerBindingElementBase {
- /// <summary>
- /// Initializes a new instance of the <see cref="AccessTokenBindingElement"/> class.
- /// </summary>
- internal AccessTokenBindingElement() {
- }
-
- /// <summary>
- /// Gets the protection commonly offered (if any) by this binding element.
- /// </summary>
- /// <value>Always <c>MessageProtections.None</c></value>
- /// <remarks>
- /// This value is used to assist in sorting binding elements in the channel stack.
- /// </remarks>
- public override MessageProtections Protection {
- get { return MessageProtections.None; }
- }
-
- /// <summary>
- /// Prepares a message for sending based on the rules of this channel binding element.
- /// </summary>
- /// <param name="message">The message to prepare for sending.</param>
- /// <returns>
- /// The protections (if any) that this binding element applied to the message.
- /// Null if this binding element did not even apply to this binding element.
- /// </returns>
- public override MessageProtections? ProcessOutgoingMessage(IProtocolMessage message) {
- var directResponse = message as IDirectResponseProtocolMessage;
- IAccessTokenRequest request = directResponse != null ? directResponse.OriginatingRequest as IAccessTokenRequest : null;
-
- var implicitGrantResponse = message as EndUserAuthorizationSuccessAccessTokenResponse;
- if (implicitGrantResponse != null) {
- IAccessTokenCarryingRequest tokenCarryingResponse = implicitGrantResponse;
- tokenCarryingResponse.AuthorizationDescription = new AccessToken(request.ClientIdentifier, implicitGrantResponse.Scope, implicitGrantResponse.AuthorizingUsername, implicitGrantResponse.Lifetime);
-
- return MessageProtections.None;
- }
-
- var accessTokenResponse = message as AccessTokenSuccessResponse;
- if (accessTokenResponse != null) {
- var authCarryingRequest = (IAuthorizationCarryingRequest)request;
- var accessToken = new AccessToken(authCarryingRequest.AuthorizationDescription, accessTokenResponse.Lifetime);
- using (var resourceServerEncryptionKey = this.AuthorizationServer.GetResourceServerEncryptionKey(request)) {
- var accessTokenFormatter = AccessToken.CreateFormatter(this.AuthorizationServer.AccessTokenSigningKey, resourceServerEncryptionKey);
- accessTokenResponse.AccessToken = accessTokenFormatter.Serialize(accessToken);
- }
-
- if (accessTokenResponse.HasRefreshToken) {
- var refreshToken = new RefreshToken(authCarryingRequest.AuthorizationDescription);
- var refreshTokenFormatter = RefreshToken.CreateFormatter(this.AuthorizationServer.CryptoKeyStore);
- accessTokenResponse.RefreshToken = refreshTokenFormatter.Serialize(refreshToken);
- }
- }
-
- return null;
- }
-
- /// <summary>
- /// Performs any transformation on an incoming message that may be necessary and/or
- /// validates an incoming message based on the rules of this channel binding element.
- /// </summary>
- /// <param name="message">The incoming message to process.</param>
- /// <returns>
- /// The protections (if any) that this binding element applied to the message.
- /// Null if this binding element did not even apply to this binding element.
- /// </returns>
- /// <exception cref="ProtocolException">
- /// Thrown when the binding element rules indicate that this message is invalid and should
- /// NOT be processed.
- /// </exception>
- public override MessageProtections? ProcessIncomingMessage(IProtocolMessage message) {
- return null;
- }
- }
-}
diff --git a/src/DotNetOpenAuth.OAuth2/OAuth2/ChannelElements/AuthServerAllFlowsBindingElement.cs b/src/DotNetOpenAuth.OAuth2/OAuth2/ChannelElements/AuthServerAllFlowsBindingElement.cs
deleted file mode 100644
index 24ac020..0000000
--- a/src/DotNetOpenAuth.OAuth2/OAuth2/ChannelElements/AuthServerAllFlowsBindingElement.cs
+++ /dev/null
@@ -1,83 +0,0 @@
-//-----------------------------------------------------------------------
-// <copyright file="AuthServerAllFlowsBindingElement.cs" company="Outercurve Foundation">
-// Copyright (c) Outercurve Foundation. All rights reserved.
-// </copyright>
-//-----------------------------------------------------------------------
-
-namespace DotNetOpenAuth.OAuth2.ChannelElements {
- using System;
- using System.Collections.Generic;
- using System.Diagnostics.Contracts;
- using System.Linq;
- using System.Text;
- using DotNetOpenAuth.OAuth2.Messages;
- using Messaging;
-
- /// <summary>
- /// A binding element that should be applied for authorization server channels regardless of which flows
- /// are supported.
- /// </summary>
- internal class AuthServerAllFlowsBindingElement : AuthServerBindingElementBase {
- /// <summary>
- /// Initializes a new instance of the <see cref="AuthServerAllFlowsBindingElement"/> class.
- /// </summary>
- internal AuthServerAllFlowsBindingElement() {
- }
-
- /// <summary>
- /// Gets the protection commonly offered (if any) by this binding element.
- /// </summary>
- /// <remarks>
- /// This value is used to assist in sorting binding elements in the channel stack.
- /// </remarks>
- public override MessageProtections Protection {
- get { return MessageProtections.None; }
- }
-
- /// <summary>
- /// Prepares a message for sending based on the rules of this channel binding element.
- /// </summary>
- /// <param name="message">The message to prepare for sending.</param>
- /// <returns>
- /// The protections (if any) that this binding element applied to the message.
- /// Null if this binding element did not even apply to this binding element.
- /// </returns>
- /// <remarks>
- /// Implementations that provide message protection must honor the
- /// <see cref="MessagePartAttribute.RequiredProtection"/> properties where applicable.
- /// </remarks>
- public override MessageProtections? ProcessOutgoingMessage(IProtocolMessage message) {
- return null;
- }
-
- /// <summary>
- /// Performs any transformation on an incoming message that may be necessary and/or
- /// validates an incoming message based on the rules of this channel binding element.
- /// </summary>
- /// <param name="message">The incoming message to process.</param>
- /// <returns>
- /// The protections (if any) that this binding element applied to the message.
- /// Null if this binding element did not even apply to this binding element.
- /// </returns>
- /// <exception cref="ProtocolException">
- /// Thrown when the binding element rules indicate that this message is invalid and should
- /// NOT be processed.
- /// </exception>
- /// <remarks>
- /// Implementations that provide message protection must honor the
- /// <see cref="MessagePartAttribute.RequiredProtection"/> properties where applicable.
- /// </remarks>
- public override MessageProtections? ProcessIncomingMessage(IProtocolMessage message) {
- var authorizationRequest = message as EndUserAuthorizationRequest;
- if (authorizationRequest != null) {
- var client = this.AuthorizationServer.GetClientOrThrow(authorizationRequest.ClientIdentifier);
- ErrorUtilities.VerifyProtocol(authorizationRequest.Callback == null || client.IsCallbackAllowed(authorizationRequest.Callback), OAuthStrings.ClientCallbackDisallowed, authorizationRequest.Callback);
- ErrorUtilities.VerifyProtocol(authorizationRequest.Callback != null || client.DefaultCallback != null, OAuthStrings.NoCallback);
-
- return MessageProtections.None;
- }
-
- return null;
- }
- }
-}
diff --git a/src/DotNetOpenAuth.OAuth2/OAuth2/ChannelElements/AuthServerBindingElementBase.cs b/src/DotNetOpenAuth.OAuth2/OAuth2/ChannelElements/AuthServerBindingElementBase.cs
deleted file mode 100644
index 49f820d..0000000
--- a/src/DotNetOpenAuth.OAuth2/OAuth2/ChannelElements/AuthServerBindingElementBase.cs
+++ /dev/null
@@ -1,81 +0,0 @@
-//-----------------------------------------------------------------------
-// <copyright file="AuthServerBindingElementBase.cs" company="Outercurve Foundation">
-// Copyright (c) Outercurve Foundation. All rights reserved.
-// </copyright>
-//-----------------------------------------------------------------------
-
-namespace DotNetOpenAuth.OAuth2.ChannelElements {
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using Messaging;
-
- /// <summary>
- /// The base class for any authorization server channel binding element.
- /// </summary>
- internal abstract class AuthServerBindingElementBase : IChannelBindingElement {
- /// <summary>
- /// Initializes a new instance of the <see cref="AuthServerBindingElementBase"/> class.
- /// </summary>
- protected AuthServerBindingElementBase() {
- }
-
- /// <summary>
- /// Gets or sets the channel that this binding element belongs to.
- /// </summary>
- /// <remarks>
- /// This property is set by the channel when it is first constructed.
- /// </remarks>
- public Channel Channel { get; set; }
-
- /// <summary>
- /// Gets the protection commonly offered (if any) by this binding element.
- /// </summary>
- /// <remarks>
- /// This value is used to assist in sorting binding elements in the channel stack.
- /// </remarks>
- public abstract MessageProtections Protection { get; }
-
- /// <summary>
- /// Gets the authorization server hosting this channel.
- /// </summary>
- /// <value>The authorization server.</value>
- protected IAuthorizationServer AuthorizationServer {
- get { return ((IOAuth2ChannelWithAuthorizationServer)this.Channel).AuthorizationServer; }
- }
-
- /// <summary>
- /// Prepares a message for sending based on the rules of this channel binding element.
- /// </summary>
- /// <param name="message">The message to prepare for sending.</param>
- /// <returns>
- /// The protections (if any) that this binding element applied to the message.
- /// Null if this binding element did not even apply to this binding element.
- /// </returns>
- /// <remarks>
- /// Implementations that provide message protection must honor the
- /// <see cref="MessagePartAttribute.RequiredProtection"/> properties where applicable.
- /// </remarks>
- public abstract MessageProtections? ProcessOutgoingMessage(IProtocolMessage message);
-
- /// <summary>
- /// Performs any transformation on an incoming message that may be necessary and/or
- /// validates an incoming message based on the rules of this channel binding element.
- /// </summary>
- /// <param name="message">The incoming message to process.</param>
- /// <returns>
- /// The protections (if any) that this binding element applied to the message.
- /// Null if this binding element did not even apply to this binding element.
- /// </returns>
- /// <exception cref="ProtocolException">
- /// Thrown when the binding element rules indicate that this message is invalid and should
- /// NOT be processed.
- /// </exception>
- /// <remarks>
- /// Implementations that provide message protection must honor the
- /// <see cref="MessagePartAttribute.RequiredProtection"/> properties where applicable.
- /// </remarks>
- public abstract MessageProtections? ProcessIncomingMessage(IProtocolMessage message);
- }
-}
diff --git a/src/DotNetOpenAuth.OAuth2/OAuth2/ChannelElements/AuthorizationCode.cs b/src/DotNetOpenAuth.OAuth2/OAuth2/ChannelElements/AuthorizationCode.cs
deleted file mode 100644
index 111c007..0000000
--- a/src/DotNetOpenAuth.OAuth2/OAuth2/ChannelElements/AuthorizationCode.cs
+++ /dev/null
@@ -1,110 +0,0 @@
-//-----------------------------------------------------------------------
-// <copyright file="AuthorizationCode.cs" company="Outercurve Foundation">
-// Copyright (c) Outercurve Foundation. All rights reserved.
-// </copyright>
-//-----------------------------------------------------------------------
-
-namespace DotNetOpenAuth.OAuth2.ChannelElements {
- using System;
- using System.Collections.Generic;
- using System.Diagnostics.CodeAnalysis;
- using System.Diagnostics.Contracts;
- using System.Security.Cryptography;
- using System.Text;
- using DotNetOpenAuth.Messaging;
-
- /// <summary>
- /// Represents the authorization code created when a user approves authorization that
- /// allows the client to request an access/refresh token.
- /// </summary>
- internal class AuthorizationCode : AuthorizationDataBag {
- /// <summary>
- /// The name of the bucket for symmetric keys used to sign authorization codes.
- /// </summary>
- internal const string AuthorizationCodeKeyBucket = "https://localhost/dnoa/oauth_authorization_code";
-
- /// <summary>
- /// Initializes a new instance of the <see cref="AuthorizationCode"/> class.
- /// </summary>
- public AuthorizationCode() {
- }
-
- /// <summary>
- /// Initializes a new instance of the <see cref="AuthorizationCode"/> class.
- /// </summary>
- /// <param name="clientIdentifier">The client identifier.</param>
- /// <param name="callback">The callback the client used to obtain authorization, if one was explicitly included in the request.</param>
- /// <param name="scopes">The authorized scopes.</param>
- /// <param name="username">The name on the account that authorized access.</param>
- internal AuthorizationCode(string clientIdentifier, Uri callback, IEnumerable<string> scopes, string username) {
- Requires.NotNullOrEmpty(clientIdentifier, "clientIdentifier");
-
- this.ClientIdentifier = clientIdentifier;
- this.CallbackHash = CalculateCallbackHash(callback);
- this.Scope.ResetContents(scopes);
- this.User = username;
- this.UtcCreationDate = DateTime.UtcNow;
- }
-
- /// <summary>
- /// Gets or sets the hash of the callback URL.
- /// </summary>
- [MessagePart("cb")]
- private byte[] CallbackHash { get; set; }
-
- /// <summary>
- /// Creates a serializer/deserializer for this type.
- /// </summary>
- /// <param name="authorizationServer">The authorization server that will be serializing/deserializing this authorization code. Must not be null.</param>
- /// <returns>A DataBag formatter.</returns>
- internal static IDataBagFormatter<AuthorizationCode> CreateFormatter(IAuthorizationServer authorizationServer) {
- Requires.NotNull(authorizationServer, "authorizationServer");
- Contract.Ensures(Contract.Result<IDataBagFormatter<AuthorizationCode>>() != null);
-
- var cryptoStore = authorizationServer.CryptoKeyStore;
- ErrorUtilities.VerifyHost(cryptoStore != null, OAuthStrings.ResultShouldNotBeNull, authorizationServer.GetType(), "CryptoKeyStore");
-
- return new UriStyleMessageFormatter<AuthorizationCode>(
- cryptoStore,
- AuthorizationCodeKeyBucket,
- signed: true,
- encrypted: true,
- compressed: false,
- maximumAge: AuthorizationCodeBindingElement.MaximumMessageAge,
- decodeOnceOnly: authorizationServer.VerificationCodeNonceStore);
- }
-
- /// <summary>
- /// Verifies the the given callback URL matches the callback originally given in the authorization request.
- /// </summary>
- /// <param name="callback">The callback.</param>
- /// <remarks>
- /// This method serves to verify that the callback URL given in the original authorization request
- /// and the callback URL given in the access token request match.
- /// </remarks>
- /// <exception cref="ProtocolException">Thrown when the callback URLs do not match.</exception>
- [SuppressMessage("Microsoft.Naming", "CA2204:Literals should be spelled correctly", MessageId = "redirecturimismatch", Justification = "Protocol requirement")]
- [SuppressMessage("Microsoft.Globalization", "CA1303:Do not pass literals as localized parameters", MessageId = "DotNetOpenAuth.Messaging.ErrorUtilities.VerifyProtocol(System.Boolean,System.String,System.Object[])", Justification = "Protocol requirement")]
- internal void VerifyCallback(Uri callback) {
- ErrorUtilities.VerifyProtocol(MessagingUtilities.AreEquivalent(this.CallbackHash, CalculateCallbackHash(callback)), Protocol.redirect_uri_mismatch);
- }
-
- /// <summary>
- /// Calculates the hash of the callback URL.
- /// </summary>
- /// <param name="callback">The callback whose hash should be calculated.</param>
- /// <returns>
- /// A base64 encoding of the hash of the URL.
- /// </returns>
- [SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope", Justification = "False positive.")]
- private static byte[] CalculateCallbackHash(Uri callback) {
- if (callback == null) {
- return null;
- }
-
- using (var hasher = new SHA256Managed()) {
- return hasher.ComputeHash(Encoding.UTF8.GetBytes(callback.AbsoluteUri));
- }
- }
- }
-}
diff --git a/src/DotNetOpenAuth.OAuth2/OAuth2/ChannelElements/AuthorizationCodeBindingElement.cs b/src/DotNetOpenAuth.OAuth2/OAuth2/ChannelElements/AuthorizationCodeBindingElement.cs
deleted file mode 100644
index d602cae..0000000
--- a/src/DotNetOpenAuth.OAuth2/OAuth2/ChannelElements/AuthorizationCodeBindingElement.cs
+++ /dev/null
@@ -1,101 +0,0 @@
-//-----------------------------------------------------------------------
-// <copyright file="AuthorizationCodeBindingElement.cs" company="Outercurve Foundation">
-// Copyright (c) Outercurve Foundation. All rights reserved.
-// </copyright>
-//-----------------------------------------------------------------------
-
-namespace DotNetOpenAuth.OAuth2.ChannelElements {
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using Messages;
- using Messaging;
- using Messaging.Bindings;
-
- /// <summary>
- /// A binding element for OAuth 2.0 authorization servers that create/verify
- /// issued authorization codes as part of obtaining access/refresh tokens.
- /// </summary>
- internal class AuthorizationCodeBindingElement : AuthServerBindingElementBase {
- /// <summary>
- /// Initializes a new instance of the <see cref="AuthorizationCodeBindingElement"/> class.
- /// </summary>
- internal AuthorizationCodeBindingElement() {
- }
-
- /// <summary>
- /// Gets the protection commonly offered (if any) by this binding element.
- /// </summary>
- /// <value>Always <c>MessageProtections.None</c></value>
- /// <remarks>
- /// This value is used to assist in sorting binding elements in the channel stack.
- /// </remarks>
- public override MessageProtections Protection {
- get { return MessageProtections.None; }
- }
-
- /// <summary>
- /// Gets the maximum message age from the standard expiration binding element.
- /// </summary>
- /// <value>This interval need not account for clock skew because it is only compared within a single authorization server or farm of servers.</value>
- internal static TimeSpan MaximumMessageAge {
- get { return Configuration.DotNetOpenAuthSection.Messaging.MaximumMessageLifetimeNoSkew; }
- }
-
- /// <summary>
- /// Prepares a message for sending based on the rules of this channel binding element.
- /// </summary>
- /// <param name="message">The message to prepare for sending.</param>
- /// <returns>
- /// The protections (if any) that this binding element applied to the message.
- /// Null if this binding element did not even apply to this binding element.
- /// </returns>
- /// <remarks>
- /// Implementations that provide message protection must honor the
- /// <see cref="MessagePartAttribute.RequiredProtection"/> properties where applicable.
- /// </remarks>
- public override MessageProtections? ProcessOutgoingMessage(IProtocolMessage message) {
- var response = message as EndUserAuthorizationSuccessAuthCodeResponse;
- if (response != null) {
- var directResponse = (IDirectResponseProtocolMessage)response;
- var request = (EndUserAuthorizationRequest)directResponse.OriginatingRequest;
- IAuthorizationCodeCarryingRequest tokenCarryingResponse = response;
- tokenCarryingResponse.AuthorizationDescription = new AuthorizationCode(request.ClientIdentifier, request.Callback, response.Scope, response.AuthorizingUsername);
-
- return MessageProtections.None;
- }
-
- return null;
- }
-
- /// <summary>
- /// Performs any transformation on an incoming message that may be necessary and/or
- /// validates an incoming message based on the rules of this channel binding element.
- /// </summary>
- /// <param name="message">The incoming message to process.</param>
- /// <returns>
- /// The protections (if any) that this binding element applied to the message.
- /// Null if this binding element did not even apply to this binding element.
- /// </returns>
- /// <exception cref="ProtocolException">
- /// Thrown when the binding element rules indicate that this message is invalid and should
- /// NOT be processed.
- /// </exception>
- /// <remarks>
- /// Implementations that provide message protection must honor the
- /// <see cref="MessagePartAttribute.RequiredProtection"/> properties where applicable.
- /// </remarks>
- public override MessageProtections? ProcessIncomingMessage(IProtocolMessage message) {
- var request = message as AccessTokenAuthorizationCodeRequest;
- if (request != null) {
- IAuthorizationCarryingRequest tokenRequest = request;
- ((AuthorizationCode)tokenRequest.AuthorizationDescription).VerifyCallback(request.Callback);
-
- return MessageProtections.None;
- }
-
- return null;
- }
- }
-}
diff --git a/src/DotNetOpenAuth.OAuth2/OAuth2/ChannelElements/AuthorizationDataBag.cs b/src/DotNetOpenAuth.OAuth2/OAuth2/ChannelElements/AuthorizationDataBag.cs
index cee38db..c073008 100644
--- a/src/DotNetOpenAuth.OAuth2/OAuth2/ChannelElements/AuthorizationDataBag.cs
+++ b/src/DotNetOpenAuth.OAuth2/OAuth2/ChannelElements/AuthorizationDataBag.cs
@@ -13,7 +13,7 @@ namespace DotNetOpenAuth.OAuth2.ChannelElements {
/// <summary>
/// A data bag that stores authorization data.
/// </summary>
- internal abstract class AuthorizationDataBag : DataBag, IAuthorizationDescription {
+ public abstract class AuthorizationDataBag : DataBag, IAuthorizationDescription {
/// <summary>
/// Initializes a new instance of the <see cref="AuthorizationDataBag"/> class.
/// </summary>
@@ -24,7 +24,6 @@ namespace DotNetOpenAuth.OAuth2.ChannelElements {
/// <summary>
/// Gets or sets the identifier of the client authorized to access protected data.
/// </summary>
- /// <value></value>
[MessagePart]
public string ClientIdentifier { get; set; }
diff --git a/src/DotNetOpenAuth.OAuth2/OAuth2/ChannelElements/ClientAuthenticationResult.cs b/src/DotNetOpenAuth.OAuth2/OAuth2/ChannelElements/ClientAuthenticationResult.cs
new file mode 100644
index 0000000..b0f86a9
--- /dev/null
+++ b/src/DotNetOpenAuth.OAuth2/OAuth2/ChannelElements/ClientAuthenticationResult.cs
@@ -0,0 +1,32 @@
+//-----------------------------------------------------------------------
+// <copyright file="ClientAuthenticationResult.cs" company="Andrew Arnott">
+// Copyright (c) Andrew Arnott. All rights reserved.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace DotNetOpenAuth.OAuth2.ChannelElements {
+ /// <summary>
+ /// Describes the various levels at which client information may be extracted from an inbound message.
+ /// </summary>
+ public enum ClientAuthenticationResult {
+ /// <summary>
+ /// No client identification or authentication was discovered.
+ /// </summary>
+ NoAuthenticationRecognized,
+
+ /// <summary>
+ /// The client identified itself, but did not attempt to authenticate itself.
+ /// </summary>
+ ClientIdNotAuthenticated,
+
+ /// <summary>
+ /// The client authenticated itself (provided compelling evidence that it was who it claims to be).
+ /// </summary>
+ ClientAuthenticated,
+
+ /// <summary>
+ /// The client failed in an attempt to authenticate itself, claimed to be an unrecognized client, or otherwise messed up.
+ /// </summary>
+ ClientAuthenticationRejected,
+ }
+}
diff --git a/src/DotNetOpenAuth.OAuth2/OAuth2/ChannelElements/EndUserAuthorizationResponseTypeEncoder.cs b/src/DotNetOpenAuth.OAuth2/OAuth2/ChannelElements/EndUserAuthorizationResponseTypeEncoder.cs
deleted file mode 100644
index 2fba721..0000000
--- a/src/DotNetOpenAuth.OAuth2/OAuth2/ChannelElements/EndUserAuthorizationResponseTypeEncoder.cs
+++ /dev/null
@@ -1,66 +0,0 @@
-//-----------------------------------------------------------------------
-// <copyright file="EndUserAuthorizationResponseTypeEncoder.cs" company="Outercurve Foundation">
-// Copyright (c) Outercurve Foundation. All rights reserved.
-// </copyright>
-//-----------------------------------------------------------------------
-
-namespace DotNetOpenAuth.OAuth2.ChannelElements {
- using System;
- using DotNetOpenAuth.Messaging;
- using DotNetOpenAuth.Messaging.Reflection;
- using DotNetOpenAuth.OAuth2.Messages;
-
- /// <summary>
- /// Encodes/decodes the OAuth 2.0 response_type argument.
- /// </summary>
- internal class EndUserAuthorizationResponseTypeEncoder : IMessagePartEncoder {
- /// <summary>
- /// Initializes a new instance of the <see cref="EndUserAuthorizationResponseTypeEncoder"/> class.
- /// </summary>
- public EndUserAuthorizationResponseTypeEncoder() {
- }
-
- #region IMessagePartEncoder Members
-
- /// <summary>
- /// Encodes the specified value.
- /// </summary>
- /// <param name="value">The value. Guaranteed to never be null.</param>
- /// <returns>
- /// The <paramref name="value"/> in string form, ready for message transport.
- /// </returns>
- public string Encode(object value) {
- var responseType = (EndUserAuthorizationResponseType)value;
- switch (responseType)
- {
- case EndUserAuthorizationResponseType.AccessToken:
- return Protocol.ResponseTypes.Token;
- case EndUserAuthorizationResponseType.AuthorizationCode:
- return Protocol.ResponseTypes.Code;
- default:
- throw ErrorUtilities.ThrowFormat(MessagingStrings.UnexpectedMessagePartValue, Protocol.response_type, value);
- }
- }
-
- /// <summary>
- /// Decodes the specified value.
- /// </summary>
- /// <param name="value">The string value carried by the transport. Guaranteed to never be null, although it may be empty.</param>
- /// <returns>
- /// The deserialized form of the given string.
- /// </returns>
- /// <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.Token:
- return EndUserAuthorizationResponseType.AccessToken;
- case Protocol.ResponseTypes.Code:
- return EndUserAuthorizationResponseType.AuthorizationCode;
- default:
- throw ErrorUtilities.ThrowFormat(MessagingStrings.UnexpectedMessagePartValue, Protocol.response_type, value);
- }
- }
-
- #endregion
- }
-}
diff --git a/src/DotNetOpenAuth.OAuth2/OAuth2/ChannelElements/GrantTypeEncoder.cs b/src/DotNetOpenAuth.OAuth2/OAuth2/ChannelElements/GrantTypeEncoder.cs
deleted file mode 100644
index e0e8329..0000000
--- a/src/DotNetOpenAuth.OAuth2/OAuth2/ChannelElements/GrantTypeEncoder.cs
+++ /dev/null
@@ -1,78 +0,0 @@
-//-----------------------------------------------------------------------
-// <copyright file="GrantTypeEncoder.cs" company="Outercurve Foundation">
-// Copyright (c) Outercurve Foundation. All rights reserved.
-// </copyright>
-//-----------------------------------------------------------------------
-
-namespace DotNetOpenAuth.OAuth2.ChannelElements {
- using System;
- using DotNetOpenAuth.Messaging;
- using DotNetOpenAuth.Messaging.Reflection;
- using DotNetOpenAuth.OAuth2.Messages;
-
- /// <summary>
- /// Encodes/decodes the OAuth 2.0 grant_type argument.
- /// </summary>
- internal class GrantTypeEncoder : IMessagePartEncoder {
- /// <summary>
- /// Initializes a new instance of the <see cref="GrantTypeEncoder"/> class.
- /// </summary>
- public GrantTypeEncoder() {
- }
-
- #region IMessagePartEncoder Members
-
- /// <summary>
- /// Encodes the specified value.
- /// </summary>
- /// <param name="value">The value. Guaranteed to never be null.</param>
- /// <returns>
- /// The <paramref name="value"/> in string form, ready for message transport.
- /// </returns>
- public string Encode(object value) {
- var responseType = (GrantType)value;
- switch (responseType)
- {
- case GrantType.ClientCredentials:
- return Protocol.GrantTypes.ClientCredentials;
- case GrantType.AuthorizationCode:
- return Protocol.GrantTypes.AuthorizationCode;
- case GrantType.RefreshToken:
- return Protocol.GrantTypes.RefreshToken;
- case GrantType.Password:
- return Protocol.GrantTypes.Password;
- case GrantType.Assertion:
- return Protocol.GrantTypes.Assertion;
- default:
- throw ErrorUtilities.ThrowFormat(MessagingStrings.UnexpectedMessagePartValue, Protocol.grant_type, value);
- }
- }
-
- /// <summary>
- /// Decodes the specified value.
- /// </summary>
- /// <param name="value">The string value carried by the transport. Guaranteed to never be null, although it may be empty.</param>
- /// <returns>
- /// The deserialized form of the given string.
- /// </returns>
- /// <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.ClientCredentials:
- return GrantType.ClientCredentials;
- case Protocol.GrantTypes.Assertion:
- return GrantType.Assertion;
- case Protocol.GrantTypes.Password:
- return GrantType.Password;
- case Protocol.GrantTypes.RefreshToken:
- return GrantType.RefreshToken;
- case Protocol.GrantTypes.AuthorizationCode:
- return GrantType.AuthorizationCode;
- default:
- throw ErrorUtilities.ThrowFormat(MessagingStrings.UnexpectedMessagePartValue, Protocol.grant_type, value);
- }
- }
-
- #endregion
- }
-}
diff --git a/src/DotNetOpenAuth.OAuth2/OAuth2/ChannelElements/IAuthorizationCodeCarryingRequest.cs b/src/DotNetOpenAuth.OAuth2/OAuth2/ChannelElements/IAuthorizationCodeCarryingRequest.cs
deleted file mode 100644
index 045cb80..0000000
--- a/src/DotNetOpenAuth.OAuth2/OAuth2/ChannelElements/IAuthorizationCodeCarryingRequest.cs
+++ /dev/null
@@ -1,22 +0,0 @@
-//-----------------------------------------------------------------------
-// <copyright file="IAuthorizationCodeCarryingRequest.cs" company="Outercurve Foundation">
-// Copyright (c) Outercurve Foundation. All rights reserved.
-// </copyright>
-//-----------------------------------------------------------------------
-
-namespace DotNetOpenAuth.OAuth2.ChannelElements {
- /// <summary>
- /// A message that carries an authorization code between client and authorization server.
- /// </summary>
- internal interface IAuthorizationCodeCarryingRequest : IAuthorizationCarryingRequest {
- /// <summary>
- /// Gets or sets the authorization code.
- /// </summary>
- string Code { get; set; }
-
- /// <summary>
- /// Gets or sets the authorization that the code describes.
- /// </summary>
- new AuthorizationCode AuthorizationDescription { get; set; }
- }
-}
diff --git a/src/DotNetOpenAuth.OAuth2/OAuth2/ChannelElements/IOAuth2ChannelWithAuthorizationServer.cs b/src/DotNetOpenAuth.OAuth2/OAuth2/ChannelElements/IOAuth2ChannelWithAuthorizationServer.cs
deleted file mode 100644
index 5fc73ce..0000000
--- a/src/DotNetOpenAuth.OAuth2/OAuth2/ChannelElements/IOAuth2ChannelWithAuthorizationServer.cs
+++ /dev/null
@@ -1,19 +0,0 @@
-//-----------------------------------------------------------------------
-// <copyright file="IOAuth2ChannelWithAuthorizationServer.cs" company="Outercurve Foundation">
-// Copyright (c) Outercurve Foundation. All rights reserved.
-// </copyright>
-//-----------------------------------------------------------------------
-
-namespace DotNetOpenAuth.OAuth2.ChannelElements {
- /// <summary>
- /// An interface on an OAuth 2 Authorization Server channel
- /// to expose the host provided authorization server object.
- /// </summary>
- internal interface IOAuth2ChannelWithAuthorizationServer {
- /// <summary>
- /// Gets the authorization server.
- /// </summary>
- /// <value>The authorization server.</value>
- IAuthorizationServer AuthorizationServer { get; }
- }
-}
diff --git a/src/DotNetOpenAuth.OAuth2/OAuth2/ChannelElements/IRefreshTokenCarryingRequest.cs b/src/DotNetOpenAuth.OAuth2/OAuth2/ChannelElements/IRefreshTokenCarryingRequest.cs
deleted file mode 100644
index ce27538..0000000
--- a/src/DotNetOpenAuth.OAuth2/OAuth2/ChannelElements/IRefreshTokenCarryingRequest.cs
+++ /dev/null
@@ -1,22 +0,0 @@
-//-----------------------------------------------------------------------
-// <copyright file="IRefreshTokenCarryingRequest.cs" company="Outercurve Foundation">
-// Copyright (c) Outercurve Foundation. All rights reserved.
-// </copyright>
-//-----------------------------------------------------------------------
-
-namespace DotNetOpenAuth.OAuth2.ChannelElements {
- /// <summary>
- /// A message that carries a refresh token between client and authorization server.
- /// </summary>
- internal interface IRefreshTokenCarryingRequest : IAuthorizationCarryingRequest {
- /// <summary>
- /// Gets or sets the refresh token.
- /// </summary>
- string RefreshToken { get; set; }
-
- /// <summary>
- /// Gets or sets the authorization that the token describes.
- /// </summary>
- new RefreshToken AuthorizationDescription { get; set; }
- }
-}
diff --git a/src/DotNetOpenAuth.OAuth2/OAuth2/ChannelElements/OAuth2AuthorizationServerChannel.cs b/src/DotNetOpenAuth.OAuth2/OAuth2/ChannelElements/OAuth2AuthorizationServerChannel.cs
deleted file mode 100644
index 6717717..0000000
--- a/src/DotNetOpenAuth.OAuth2/OAuth2/ChannelElements/OAuth2AuthorizationServerChannel.cs
+++ /dev/null
@@ -1,109 +0,0 @@
-//-----------------------------------------------------------------------
-// <copyright file="OAuth2AuthorizationServerChannel.cs" company="Outercurve Foundation">
-// Copyright (c) Outercurve Foundation. All rights reserved.
-// </copyright>
-//-----------------------------------------------------------------------
-
-namespace DotNetOpenAuth.OAuth2.ChannelElements {
- using System;
- using System.Collections.Generic;
- using System.Diagnostics.Contracts;
- using System.Net.Mime;
- using System.Web;
- using DotNetOpenAuth.Messaging;
-
- /// <summary>
- /// The channel for the OAuth protocol.
- /// </summary>
- internal class OAuth2AuthorizationServerChannel : OAuth2ChannelBase, IOAuth2ChannelWithAuthorizationServer {
- /// <summary>
- /// Initializes a new instance of the <see cref="OAuth2AuthorizationServerChannel"/> class.
- /// </summary>
- /// <param name="authorizationServer">The authorization server.</param>
- protected internal OAuth2AuthorizationServerChannel(IAuthorizationServer authorizationServer)
- : base(InitializeBindingElements(authorizationServer)) {
- Requires.NotNull(authorizationServer, "authorizationServer");
- this.AuthorizationServer = authorizationServer;
- }
-
- /// <summary>
- /// Gets the authorization server.
- /// </summary>
- /// <value>The authorization server.</value>
- public IAuthorizationServer AuthorizationServer { get; private set; }
-
- /// <summary>
- /// Gets the protocol message that may be in the given HTTP response.
- /// </summary>
- /// <param name="response">The response that is anticipated to contain an protocol message.</param>
- /// <returns>
- /// The deserialized message parts, if found. Null otherwise.
- /// </returns>
- /// <exception cref="ProtocolException">Thrown when the response is not valid.</exception>
- protected override IDictionary<string, string> ReadFromResponseCore(IncomingWebResponse response) {
- throw new NotImplementedException();
- }
-
- /// <summary>
- /// Queues a message for sending in the response stream.
- /// </summary>
- /// <param name="response">The message to send as a response.</param>
- /// <returns>
- /// The pending user agent redirect based message to be sent as an HttpResponse.
- /// </returns>
- /// <remarks>
- /// This method implements spec OAuth V1.0 section 5.3.
- /// </remarks>
- protected override OutgoingWebResponse PrepareDirectResponse(IProtocolMessage response) {
- var webResponse = new OutgoingWebResponse();
- ApplyMessageTemplate(response, webResponse);
- string json = this.SerializeAsJson(response);
- webResponse.SetResponse(json, new ContentType(JsonEncoded));
- return webResponse;
- }
-
- /// <summary>
- /// Gets the protocol message that may be embedded in the given HTTP request.
- /// </summary>
- /// <param name="request">The request to search for an embedded message.</param>
- /// <returns>
- /// The deserialized message, if one is found. Null otherwise.
- /// </returns>
- protected override IDirectedProtocolMessage ReadFromRequestCore(HttpRequestBase request) {
- if (!string.IsNullOrEmpty(request.Url.Fragment)) {
- var fields = HttpUtility.ParseQueryString(request.Url.Fragment.Substring(1)).ToDictionary();
-
- MessageReceivingEndpoint recipient;
- try {
- recipient = request.GetRecipient();
- } catch (ArgumentException ex) {
- Logger.Messaging.WarnFormat("Unrecognized HTTP request: " + ex.ToString());
- return null;
- }
-
- return (IDirectedProtocolMessage)this.Receive(fields, recipient);
- }
-
- return base.ReadFromRequestCore(request);
- }
-
- /// <summary>
- /// Initializes the binding elements for the OAuth channel.
- /// </summary>
- /// <param name="authorizationServer">The authorization server.</param>
- /// <returns>
- /// An array of binding elements used to initialize the channel.
- /// </returns>
- private static IChannelBindingElement[] InitializeBindingElements(IAuthorizationServer authorizationServer) {
- Requires.NotNull(authorizationServer, "authorizationServer");
- var bindingElements = new List<IChannelBindingElement>();
-
- bindingElements.Add(new AuthServerAllFlowsBindingElement());
- bindingElements.Add(new AuthorizationCodeBindingElement());
- bindingElements.Add(new AccessTokenBindingElement());
- bindingElements.Add(new AccessRequestBindingElement());
-
- return bindingElements.ToArray();
- }
- }
-}
diff --git a/src/DotNetOpenAuth.OAuth2/OAuth2/ChannelElements/OAuth2ChannelBase.cs b/src/DotNetOpenAuth.OAuth2/OAuth2/ChannelElements/OAuth2ChannelBase.cs
deleted file mode 100644
index 51ac58a..0000000
--- a/src/DotNetOpenAuth.OAuth2/OAuth2/ChannelElements/OAuth2ChannelBase.cs
+++ /dev/null
@@ -1,70 +0,0 @@
-//-----------------------------------------------------------------------
-// <copyright file="OAuth2ChannelBase.cs" company="Outercurve Foundation">
-// Copyright (c) Outercurve Foundation. All rights reserved.
-// </copyright>
-//-----------------------------------------------------------------------
-
-namespace DotNetOpenAuth.OAuth2.ChannelElements {
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
-
- using DotNetOpenAuth.Messaging;
- using DotNetOpenAuth.OAuth2.Messages;
-
- /// <summary>
- /// The base messaging channel used by OAuth 2.0 parties.
- /// </summary>
- internal abstract class OAuth2ChannelBase : StandardMessageFactoryChannel {
- /// <summary>
- /// The messages receivable by this channel.
- /// </summary>
- private static readonly Type[] MessageTypes = new Type[] {
- typeof(AccessTokenRefreshRequest),
- typeof(AccessTokenAuthorizationCodeRequest),
- typeof(AccessTokenResourceOwnerPasswordCredentialsRequest),
- typeof(AccessTokenClientCredentialsRequest),
- typeof(AccessTokenSuccessResponse),
- typeof(AccessTokenFailedResponse),
- typeof(EndUserAuthorizationRequest),
- typeof(EndUserAuthorizationImplicitRequest),
- typeof(EndUserAuthorizationSuccessAuthCodeResponse),
- typeof(EndUserAuthorizationSuccessAccessTokenResponse),
- typeof(EndUserAuthorizationFailedResponse),
- typeof(UnauthorizedResponse),
- };
-
- /// <summary>
- /// The protocol versions supported by this channel.
- /// </summary>
- private static readonly Version[] Versions = Protocol.AllVersions.Select(v => v.Version).ToArray();
-
- /// <summary>
- /// Initializes a new instance of the <see cref="OAuth2ChannelBase"/> class.
- /// </summary>
- /// <param name="channelBindingElements">The channel binding elements.</param>
- internal OAuth2ChannelBase(params IChannelBindingElement[] channelBindingElements)
- : base(MessageTypes, Versions, channelBindingElements) {
- }
-
- /// <summary>
- /// Allows preprocessing and validation of message data before an appropriate message type is
- /// selected or deserialized.
- /// </summary>
- /// <param name="fields">The received message data.</param>
- protected override void FilterReceivedFields(IDictionary<string, string> fields) {
- base.FilterReceivedFields(fields);
-
- // Apply the OAuth 2.0 section 2.1 requirement:
- // Parameters sent without a value MUST be treated as if they were omitted from the request.
- // The authorization server SHOULD ignore unrecognized request parameters.
- var emptyKeys = from pair in fields
- where string.IsNullOrEmpty(pair.Value)
- select pair.Key;
- foreach (string emptyKey in emptyKeys.ToList()) {
- fields.Remove(emptyKey);
- }
- }
- }
-}
diff --git a/src/DotNetOpenAuth.OAuth2/OAuth2/ChannelElements/OAuth2ClientChannel.cs b/src/DotNetOpenAuth.OAuth2/OAuth2/ChannelElements/OAuth2ClientChannel.cs
deleted file mode 100644
index c9981d3..0000000
--- a/src/DotNetOpenAuth.OAuth2/OAuth2/ChannelElements/OAuth2ClientChannel.cs
+++ /dev/null
@@ -1,122 +0,0 @@
-//-----------------------------------------------------------------------
-// <copyright file="OAuth2ClientChannel.cs" company="Outercurve Foundation">
-// Copyright (c) Outercurve Foundation. All rights reserved.
-// </copyright>
-//-----------------------------------------------------------------------
-
-namespace DotNetOpenAuth.OAuth2.ChannelElements {
- using System;
- using System.Collections.Generic;
- using System.Collections.Specialized;
- using System.Diagnostics.Contracts;
- using System.Net;
- using System.Web;
-
- using DotNetOpenAuth.Messaging;
-
- /// <summary>
- /// The messaging channel used by OAuth 2.0 Clients.
- /// </summary>
- internal class OAuth2ClientChannel : OAuth2ChannelBase {
- /// <summary>
- /// Initializes a new instance of the <see cref="OAuth2ClientChannel"/> class.
- /// </summary>
- internal OAuth2ClientChannel() {
- }
-
- /// <summary>
- /// Prepares an HTTP request that carries a given message.
- /// </summary>
- /// <param name="request">The message to send.</param>
- /// <returns>
- /// The <see cref="HttpWebRequest"/> prepared to send the request.
- /// </returns>
- /// <remarks>
- /// This method must be overridden by a derived class, unless the <see cref="Channel.RequestCore"/> method
- /// is overridden and does not require this method.
- /// </remarks>
- protected override HttpWebRequest CreateHttpRequest(IDirectedProtocolMessage request) {
- HttpWebRequest httpRequest;
- if ((request.HttpMethods & HttpDeliveryMethods.GetRequest) != 0) {
- httpRequest = InitializeRequestAsGet(request);
- } else if ((request.HttpMethods & HttpDeliveryMethods.PostRequest) != 0) {
- httpRequest = InitializeRequestAsPost(request);
- } else {
- throw new NotSupportedException();
- }
-
- return httpRequest;
- }
-
- /// <summary>
- /// Gets the protocol message that may be in the given HTTP response.
- /// </summary>
- /// <param name="response">The response that is anticipated to contain an protocol message.</param>
- /// <returns>
- /// The deserialized message parts, if found. Null otherwise.
- /// </returns>
- /// <exception cref="ProtocolException">Thrown when the response is not valid.</exception>
- protected override IDictionary<string, string> ReadFromResponseCore(IncomingWebResponse response) {
- // The spec says direct responses should be JSON objects, but Facebook uses HttpFormUrlEncoded instead, calling it text/plain
- // Others return text/javascript. Again bad.
- string body = response.GetResponseReader().ReadToEnd();
- if (response.ContentType.MediaType == JsonEncoded || response.ContentType.MediaType == JsonTextEncoded) {
- return this.DeserializeFromJson(body);
- } else if (response.ContentType.MediaType == HttpFormUrlEncoded || response.ContentType.MediaType == PlainTextEncoded) {
- return HttpUtility.ParseQueryString(body).ToDictionary();
- } else {
- throw ErrorUtilities.ThrowProtocol(OAuthStrings.UnexpectedResponseContentType, response.ContentType.MediaType);
- }
- }
-
- /// <summary>
- /// Gets the protocol message that may be embedded in the given HTTP request.
- /// </summary>
- /// <param name="request">The request to search for an embedded message.</param>
- /// <returns>
- /// The deserialized message, if one is found. Null otherwise.
- /// </returns>
- protected override IDirectedProtocolMessage ReadFromRequestCore(HttpRequestBase request) {
- Logger.Channel.DebugFormat("Incoming HTTP request: {0} {1}", request.HttpMethod, request.GetPublicFacingUrl().AbsoluteUri);
-
- var fields = request.GetQueryStringBeforeRewriting().ToDictionary();
-
- // Also read parameters from the fragment, if it's available.
- // Typically the fragment is not available because the browser doesn't send it to a web server
- // but this request may have been fabricated by an installed desktop app, in which case
- // the fragment is available.
- string fragment = request.GetPublicFacingUrl().Fragment;
- if (!string.IsNullOrEmpty(fragment)) {
- foreach (var pair in HttpUtility.ParseQueryString(fragment.Substring(1)).ToDictionary()) {
- fields.Add(pair.Key, pair.Value);
- }
- }
-
- MessageReceivingEndpoint recipient;
- try {
- recipient = request.GetRecipient();
- } catch (ArgumentException ex) {
- Logger.Messaging.WarnFormat("Unrecognized HTTP request: ", ex);
- return null;
- }
-
- return (IDirectedProtocolMessage)this.Receive(fields, recipient);
- }
-
- /// <summary>
- /// Queues a message for sending in the response stream where the fields
- /// are sent in the response stream in querystring style.
- /// </summary>
- /// <param name="response">The message to send as a response.</param>
- /// <returns>
- /// The pending user agent redirect based message to be sent as an HttpResponse.
- /// </returns>
- /// <remarks>
- /// This method implements spec OAuth V1.0 section 5.3.
- /// </remarks>
- protected override OutgoingWebResponse PrepareDirectResponse(IProtocolMessage response) {
- // Clients don't ever send direct responses.
- throw new NotImplementedException();
- }
- }
-}
diff --git a/src/DotNetOpenAuth.OAuth2/OAuth2/ChannelElements/OAuth2ResourceServerChannel.cs b/src/DotNetOpenAuth.OAuth2/OAuth2/ChannelElements/OAuth2ResourceServerChannel.cs
deleted file mode 100644
index 947c044..0000000
--- a/src/DotNetOpenAuth.OAuth2/OAuth2/ChannelElements/OAuth2ResourceServerChannel.cs
+++ /dev/null
@@ -1,153 +0,0 @@
-//-----------------------------------------------------------------------
-// <copyright file="OAuth2ResourceServerChannel.cs" company="Outercurve Foundation">
-// Copyright (c) Outercurve Foundation. All rights reserved.
-// </copyright>
-//-----------------------------------------------------------------------
-
-namespace DotNetOpenAuth.OAuth2.ChannelElements {
- using System;
- using System.Collections.Generic;
- using System.Diagnostics.Contracts;
- using System.Linq;
- using System.Net;
- using System.Net.Mime;
- using System.Text;
- using System.Web;
- using DotNetOpenAuth.Messaging;
- using DotNetOpenAuth.Messaging.Reflection;
- using DotNetOpenAuth.OAuth2.Messages;
-
- /// <summary>
- /// The channel for the OAuth protocol.
- /// </summary>
- internal class OAuth2ResourceServerChannel : StandardMessageFactoryChannel {
- /// <summary>
- /// The messages receivable by this channel.
- /// </summary>
- private static readonly Type[] MessageTypes = new Type[] {
- typeof(Messages.AccessProtectedResourceRequest),
- };
-
- /// <summary>
- /// The protocol versions supported by this channel.
- /// </summary>
- private static readonly Version[] Versions = Protocol.AllVersions.Select(v => v.Version).ToArray();
-
- /// <summary>
- /// Initializes a new instance of the <see cref="OAuth2ResourceServerChannel"/> class.
- /// </summary>
- protected internal OAuth2ResourceServerChannel()
- : base(MessageTypes, Versions) {
- // TODO: add signing (authenticated request) binding element.
- }
-
- /// <summary>
- /// Gets the protocol message that may be embedded in the given HTTP request.
- /// </summary>
- /// <param name="request">The request to search for an embedded message.</param>
- /// <returns>
- /// The deserialized message, if one is found. Null otherwise.
- /// </returns>
- protected override IDirectedProtocolMessage ReadFromRequestCore(HttpRequestBase request) {
- 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) {
- MessageReceivingEndpoint recipient;
- try {
- recipient = request.GetRecipient();
- } catch (ArgumentException ex) {
- Logger.OAuth.WarnFormat("Unrecognized HTTP request: " + ex.ToString());
- return null;
- }
-
- // Deserialize the message using all the data we've collected.
- var message = (IDirectedProtocolMessage)this.Receive(fields, recipient);
- return message;
- }
-
- return null;
- }
-
- /// <summary>
- /// Gets the protocol message that may be in the given HTTP response.
- /// </summary>
- /// <param name="response">The response that is anticipated to contain an protocol message.</param>
- /// <returns>
- /// The deserialized message parts, if found. Null otherwise.
- /// </returns>
- /// <exception cref="ProtocolException">Thrown when the response is not valid.</exception>
- protected override IDictionary<string, string> ReadFromResponseCore(IncomingWebResponse response) {
- // We never expect resource servers to send out direct requests,
- // and therefore won't have direct responses.
- throw new NotImplementedException();
- }
-
- /// <summary>
- /// Queues a message for sending in the response stream where the fields
- /// are sent in the response stream in querystring style.
- /// </summary>
- /// <param name="response">The message to send as a response.</param>
- /// <returns>
- /// The pending user agent redirect based message to be sent as an HttpResponse.
- /// </returns>
- /// <remarks>
- /// This method implements spec OAuth V1.0 section 5.3.
- /// </remarks>
- protected override OutgoingWebResponse PrepareDirectResponse(IProtocolMessage response) {
- var webResponse = new OutgoingWebResponse();
-
- // The only direct response from a resource server is a 401 Unauthorized error.
- var unauthorizedResponse = response as UnauthorizedResponse;
- ErrorUtilities.VerifyInternal(unauthorizedResponse != null, "Only unauthorized responses are expected.");
-
- // First initialize based on the specifics within the message.
- ApplyMessageTemplate(response, webResponse);
- if (!(response is IHttpDirectResponse)) {
- webResponse.Status = HttpStatusCode.Unauthorized;
- }
-
- // Now serialize all the message parts into the WWW-Authenticate header.
- var fields = this.MessageDescriptions.GetAccessor(response);
- 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(HttpRequestBase request) {
- Requires.NotNull(request, "request");
-
- // First search the authorization header.
- string authorizationHeader = request.Headers[HttpRequestHeaders.Authorization];
- if (!string.IsNullOrEmpty(authorizationHeader) && authorizationHeader.StartsWith(Protocol.BearerHttpAuthorizationSchemeWithTrailingSpace, StringComparison.OrdinalIgnoreCase)) {
- return authorizationHeader.Substring(Protocol.BearerHttpAuthorizationSchemeWithTrailingSpace.Length);
- }
-
- // Failing that, scan the entity
- if (!string.IsNullOrEmpty(request.Headers[HttpRequestHeaders.ContentType])) {
- var contentType = new ContentType(request.Headers[HttpRequestHeaders.ContentType]);
- if (string.Equals(contentType.MediaType, HttpFormUrlEncoded, StringComparison.Ordinal)) {
- if (request.Form[Protocol.BearerTokenEncodedUrlParameterName] != null) {
- return request.Form[Protocol.BearerTokenEncodedUrlParameterName];
- }
- }
- }
-
- // Finally, check the least desirable location: the query string
- var unrewrittenQuery = request.GetQueryStringBeforeRewriting();
- if (!string.IsNullOrEmpty(unrewrittenQuery[Protocol.BearerTokenEncodedUrlParameterName])) {
- return unrewrittenQuery[Protocol.BearerTokenEncodedUrlParameterName];
- }
-
- return null;
- }
- }
-}
diff --git a/src/DotNetOpenAuth.OAuth2/OAuth2/ChannelElements/RefreshToken.cs b/src/DotNetOpenAuth.OAuth2/OAuth2/ChannelElements/RefreshToken.cs
deleted file mode 100644
index 993583c..0000000
--- a/src/DotNetOpenAuth.OAuth2/OAuth2/ChannelElements/RefreshToken.cs
+++ /dev/null
@@ -1,56 +0,0 @@
-//-----------------------------------------------------------------------
-// <copyright file="RefreshToken.cs" company="Outercurve Foundation">
-// Copyright (c) Outercurve Foundation. All rights reserved.
-// </copyright>
-//-----------------------------------------------------------------------
-
-namespace DotNetOpenAuth.OAuth2.ChannelElements {
- using System;
- using System.Diagnostics.Contracts;
- using DotNetOpenAuth.Messaging;
- using DotNetOpenAuth.Messaging.Bindings;
-
- /// <summary>
- /// The refresh token issued to a client by an authorization server that allows the client
- /// to periodically obtain new short-lived access tokens.
- /// </summary>
- internal class RefreshToken : AuthorizationDataBag {
- /// <summary>
- /// The name of the bucket for symmetric keys used to sign refresh tokens.
- /// </summary>
- internal const string RefreshTokenKeyBucket = "https://localhost/dnoa/oauth_refresh_token";
-
- /// <summary>
- /// Initializes a new instance of the <see cref="RefreshToken"/> class.
- /// </summary>
- public RefreshToken() {
- }
-
- /// <summary>
- /// Initializes a new instance of the <see cref="RefreshToken"/> class.
- /// </summary>
- /// <param name="authorization">The authorization this refresh token should describe.</param>
- internal RefreshToken(IAuthorizationDescription authorization) {
- Requires.NotNull(authorization, "authorization");
-
- this.ClientIdentifier = authorization.ClientIdentifier;
- this.UtcCreationDate = authorization.UtcIssued;
- this.User = authorization.User;
- this.Scope.ResetContents(authorization.Scope);
- }
-
- /// <summary>
- /// Creates a formatter capable of serializing/deserializing a refresh token.
- /// </summary>
- /// <param name="cryptoKeyStore">The crypto key store.</param>
- /// <returns>
- /// A DataBag formatter. Never null.
- /// </returns>
- internal static IDataBagFormatter<RefreshToken> CreateFormatter(ICryptoKeyStore cryptoKeyStore) {
- Requires.NotNull(cryptoKeyStore, "cryptoKeyStore");
- Contract.Ensures(Contract.Result<IDataBagFormatter<RefreshToken>>() != null);
-
- return new UriStyleMessageFormatter<RefreshToken>(cryptoKeyStore, RefreshTokenKeyBucket, signed: true, encrypted: true);
- }
- }
-}
diff --git a/src/DotNetOpenAuth.OAuth2/OAuth2/ClientDescription.cs b/src/DotNetOpenAuth.OAuth2/OAuth2/ClientDescription.cs
deleted file mode 100644
index 76c3ea6..0000000
--- a/src/DotNetOpenAuth.OAuth2/OAuth2/ClientDescription.cs
+++ /dev/null
@@ -1,71 +0,0 @@
-//-----------------------------------------------------------------------
-// <copyright file="ClientDescription.cs" company="Outercurve Foundation">
-// Copyright (c) Outercurve Foundation. All rights reserved.
-// </copyright>
-//-----------------------------------------------------------------------
-
-namespace DotNetOpenAuth.OAuth2 {
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
-
- /// <summary>
- /// A default implementation of the <see cref="IClientDescription"/> interface.
- /// </summary>
- public class ClientDescription : IClientDescription {
- /// <summary>
- /// A delegate that determines whether the callback is allowed.
- /// </summary>
- private readonly Func<Uri, bool> isCallbackAllowed;
-
- /// <summary>
- /// Initializes a new instance of the <see cref="ClientDescription"/> class.
- /// </summary>
- /// <param name="secret">The secret.</param>
- /// <param name="defaultCallback">The default callback.</param>
- /// <param name="clientType">Type of the client.</param>
- /// <param name="isCallbackAllowed">A delegate that determines whether the callback is allowed.</param>
- public ClientDescription(string secret, Uri defaultCallback, ClientType clientType, Func<Uri, bool> isCallbackAllowed = null) {
- this.Secret = secret;
- this.DefaultCallback = defaultCallback;
- this.ClientType = clientType;
- this.isCallbackAllowed = isCallbackAllowed;
- }
-
- /// <summary>
- /// Gets the client secret.
- /// </summary>
- public string Secret { get; private set; }
-
- /// <summary>
- /// Gets the callback to use when an individual authorization request
- /// does not include an explicit callback URI.
- /// </summary>
- /// <value>
- /// An absolute URL; or <c>null</c> if none is registered.
- /// </value>
- public Uri DefaultCallback { get; private set; }
-
- /// <summary>
- /// Gets the type of the client.
- /// </summary>
- public ClientType ClientType { get; private set; }
-
- /// <summary>
- /// Determines whether a callback URI included in a client's authorization request
- /// is among those allowed callbacks for the registered client.
- /// </summary>
- /// <param name="callback">The absolute URI the client has requested the authorization result be received at.</param>
- /// <returns>
- /// <c>true</c> if the callback URL is allowable for this client; otherwise, <c>false</c>.
- /// </returns>
- public bool IsCallbackAllowed(Uri callback) {
- if (this.isCallbackAllowed != null) {
- return this.isCallbackAllowed(callback);
- }
-
- return EqualityComparer<Uri>.Default.Equals(this.DefaultCallback, callback);
- }
- }
-}
diff --git a/src/DotNetOpenAuth.OAuth2/OAuth2/ClientType.cs b/src/DotNetOpenAuth.OAuth2/OAuth2/ClientType.cs
deleted file mode 100644
index 9e8ed2a..0000000
--- a/src/DotNetOpenAuth.OAuth2/OAuth2/ClientType.cs
+++ /dev/null
@@ -1,47 +0,0 @@
-//-----------------------------------------------------------------------
-// <copyright file="ClientType.cs" company="Outercurve Foundation">
-// Copyright (c) Outercurve Foundation. All rights reserved.
-// </copyright>
-//-----------------------------------------------------------------------
-
-namespace DotNetOpenAuth.OAuth2 {
- /// <summary>
- /// OAuth 2 Client types
- /// </summary>
- /// <remarks>
- /// <para>Based on their ability to
- /// authenticate securely with the authorization server (i.e. ability to
- /// maintain the confidentiality of their client credentials).</para>
- /// <para>The client type designation is based on the authorization server's
- /// definition of secure authentication and its acceptable exposure
- /// levels of client credentials.</para>
- /// <para>The authorization server SHOULD NOT make assumptions about the client
- /// type, nor accept the type information provided by the client
- /// developer without first establishing trust.</para>
- /// <para>A client application consisting of multiple components, each with its
- /// own client type (e.g. a distributed client with both a confidential
- /// server-based component and a public browser-based component), MUST
- /// register each component separately as a different client to ensure
- /// proper handling by the authorization server. The authorization
- /// server MAY provider tools to manage such complex clients through a
- /// single administration interface.</para>
- /// </remarks>
- public enum ClientType {
- /// <summary>
- /// Clients capable of maintaining the confidentiality of their
- /// credentials (e.g. client implemented on a secure server with
- /// restricted access to the client credentials), or capable of secure
- /// client authentication using other means.
- /// </summary>
- Confidential,
-
- /// <summary>
- /// Clients incapable of maintaining the confidentiality of their
- /// credentials (e.g. clients executing on the device used by the
- /// resource owner such as an installed native application or a web
- /// browser-based application), and incapable of secure client
- /// authentication via any other means.
- /// </summary>
- Public,
- }
-}
diff --git a/src/DotNetOpenAuth.OAuth2/OAuth2/IAccessTokenAnalyzer.cs b/src/DotNetOpenAuth.OAuth2/OAuth2/IAccessTokenAnalyzer.cs
deleted file mode 100644
index 5aa1bb6..0000000
--- a/src/DotNetOpenAuth.OAuth2/OAuth2/IAccessTokenAnalyzer.cs
+++ /dev/null
@@ -1,64 +0,0 @@
-//-----------------------------------------------------------------------
-// <copyright file="IAccessTokenAnalyzer.cs" company="Outercurve Foundation">
-// Copyright (c) Outercurve Foundation. All rights reserved.
-// </copyright>
-//-----------------------------------------------------------------------
-
-namespace DotNetOpenAuth.OAuth2 {
- using System;
- using System.Collections.Generic;
- using System.Diagnostics.CodeAnalysis;
- using System.Diagnostics.Contracts;
- using System.Linq;
- using System.Text;
- using DotNetOpenAuth.Messaging;
-
- /// <summary>
- /// An interface that resource server hosts should implement if they accept access tokens
- /// issued by non-DotNetOpenAuth authorization servers.
- /// </summary>
- [ContractClass((typeof(IAccessTokenAnalyzerContract)))]
- public interface IAccessTokenAnalyzer {
- /// <summary>
- /// Reads an access token to find out what data it authorizes access to.
- /// </summary>
- /// <param name="message">The message carrying the access token.</param>
- /// <param name="accessToken">The access token.</param>
- /// <param name="user">The user whose data is accessible with this access token.</param>
- /// <param name="scope">The scope of access authorized by this access token.</param>
- /// <returns>A value indicating whether this access token is valid.</returns>
- [SuppressMessage("Microsoft.Design", "CA1021:AvoidOutParameters", MessageId = "1#", Justification = "Try pattern")]
- [SuppressMessage("Microsoft.Design", "CA1021:AvoidOutParameters", MessageId = "2#", Justification = "Try pattern")]
- bool TryValidateAccessToken(IDirectedProtocolMessage message, string accessToken, out string user, out HashSet<string> scope);
- }
-
- /// <summary>
- /// Code contract for the <see cref="IAccessTokenAnalyzer"/> interface.
- /// </summary>
- [ContractClassFor(typeof(IAccessTokenAnalyzer))]
- internal abstract class IAccessTokenAnalyzerContract : IAccessTokenAnalyzer {
- /// <summary>
- /// Prevents a default instance of the <see cref="IAccessTokenAnalyzerContract"/> class from being created.
- /// </summary>
- private IAccessTokenAnalyzerContract() {
- }
-
- /// <summary>
- /// Reads an access token to find out what data it authorizes access to.
- /// </summary>
- /// <param name="message">The message carrying the access token.</param>
- /// <param name="accessToken">The access token.</param>
- /// <param name="user">The user whose data is accessible with this access token.</param>
- /// <param name="scope">The scope of access authorized by this access token.</param>
- /// <returns>
- /// A value indicating whether this access token is valid.
- /// </returns>
- bool IAccessTokenAnalyzer.TryValidateAccessToken(IDirectedProtocolMessage message, string accessToken, out string user, out HashSet<string> scope) {
- Requires.NotNull(message, "message");
- Requires.NotNullOrEmpty(accessToken, "accessToken");
- Contract.Ensures(Contract.Result<bool>() == (Contract.ValueAtReturn<string>(out user) != null));
-
- throw new NotImplementedException();
- }
- }
-}
diff --git a/src/DotNetOpenAuth.OAuth2/OAuth2/IAuthorizationServer.cs b/src/DotNetOpenAuth.OAuth2/OAuth2/IAuthorizationServer.cs
deleted file mode 100644
index a0a2ad9..0000000
--- a/src/DotNetOpenAuth.OAuth2/OAuth2/IAuthorizationServer.cs
+++ /dev/null
@@ -1,264 +0,0 @@
-//-----------------------------------------------------------------------
-// <copyright file="IAuthorizationServer.cs" company="Outercurve Foundation">
-// Copyright (c) Outercurve Foundation. All rights reserved.
-// </copyright>
-//-----------------------------------------------------------------------
-
-namespace DotNetOpenAuth.OAuth2 {
- using System;
- using System.Collections.Generic;
- using System.Diagnostics.Contracts;
- using System.Linq;
- using System.Security.Cryptography;
- using System.Text;
- using DotNetOpenAuth.Messaging;
- using DotNetOpenAuth.Messaging.Bindings;
- using DotNetOpenAuth.OAuth2.ChannelElements;
- using DotNetOpenAuth.OAuth2.Messages;
-
- /// <summary>
- /// Provides host-specific authorization server services needed by this library.
- /// </summary>
- [ContractClass(typeof(IAuthorizationServerContract))]
- public interface IAuthorizationServer {
- /// <summary>
- /// Gets the store for storing crypto keys used to symmetrically encrypt and sign authorization codes and refresh tokens.
- /// </summary>
- /// <remarks>
- /// This store should be kept strictly confidential in the authorization server(s)
- /// and NOT shared with the resource server. Anyone with these secrets can mint
- /// tokens to essentially grant themselves access to anything they want.
- /// </remarks>
- ICryptoKeyStore CryptoKeyStore { get; }
-
- /// <summary>
- /// Gets the authorization code nonce store to use to ensure that authorization codes can only be used once.
- /// </summary>
- /// <value>The authorization code nonce store.</value>
- INonceStore VerificationCodeNonceStore { get; }
-
- /// <summary>
- /// Gets the crypto service provider with the asymmetric private key to use for signing access tokens.
- /// </summary>
- /// <returns>A crypto service provider instance that contains the private key.</returns>
- /// <value>Must not be null, and must contain the private key.</value>
- /// <remarks>
- /// The public key in the private/public key pair will be used by the resource
- /// servers to validate that the access token is minted by a trusted authorization server.
- /// </remarks>
- RSACryptoServiceProvider AccessTokenSigningKey { get; }
-
- /// <summary>
- /// Obtains the lifetime for a new access token.
- /// </summary>
- /// <param name="accessTokenRequestMessage">
- /// Details regarding the resources that the access token will grant access to, and the identity of the client
- /// that will receive that access.
- /// Based on this information the receiving resource server can be determined and the lifetime of the access
- /// token can be set based on the sensitivity of the resources.
- /// </param>
- /// <returns>
- /// Receives the lifetime for this access token. Note that within this lifetime, authorization <i>may</i> not be revokable.
- /// Short lifetimes are recommended (i.e. one hour), particularly when the client is not authenticated or
- /// the resources to which access is being granted are sensitive.
- /// </returns>
- TimeSpan GetAccessTokenLifetime(IAccessTokenRequest accessTokenRequestMessage);
-
- /// <summary>
- /// Obtains the encryption key for an access token being created.
- /// </summary>
- /// <param name="accessTokenRequestMessage">
- /// Details regarding the resources that the access token will grant access to, and the identity of the client
- /// that will receive that access.
- /// Based on this information the receiving resource server can be determined and the lifetime of the access
- /// token can be set based on the sensitivity of the resources.
- /// </param>
- /// <returns>
- /// The crypto service provider with the asymmetric public key to use for encrypting access tokens for a specific resource server.
- /// The caller is responsible to dispose of this value.
- /// </returns>
- /// <remarks>
- /// The caller is responsible to dispose of the returned value.
- /// </remarks>
- RSACryptoServiceProvider GetResourceServerEncryptionKey(IAccessTokenRequest accessTokenRequestMessage);
-
- /// <summary>
- /// Gets the client with a given identifier.
- /// </summary>
- /// <param name="clientIdentifier">The client identifier.</param>
- /// <returns>The client registration. Never null.</returns>
- /// <exception cref="ArgumentException">Thrown when no client with the given identifier is registered with this authorization server.</exception>
- IClientDescription GetClient(string clientIdentifier);
-
- /// <summary>
- /// Determines whether a described authorization is (still) valid.
- /// </summary>
- /// <param name="authorization">The authorization.</param>
- /// <returns>
- /// <c>true</c> if the original authorization is still valid; otherwise, <c>false</c>.
- /// </returns>
- /// <remarks>
- /// <para>When establishing that an authorization is still valid,
- /// it's very important to only match on recorded authorizations that
- /// meet these criteria:</para>
- /// 1) The client identifier matches.
- /// 2) The user account matches.
- /// 3) The scope on the recorded authorization must include all scopes in the given authorization.
- /// 4) The date the recorded authorization was issued must be <em>no later</em> that the date the given authorization was issued.
- /// <para>One possible scenario is where the user authorized a client, later revoked authorization,
- /// and even later reinstated authorization. This subsequent recorded authorization
- /// would not satisfy requirement #4 in the above list. This is important because the revocation
- /// the user went through should invalidate all previously issued tokens as a matter of
- /// security in the event the user was revoking access in order to sever authorization on a stolen
- /// account or piece of hardware in which the tokens were stored. </para>
- /// </remarks>
- bool IsAuthorizationValid(IAuthorizationDescription authorization);
-
- /// <summary>
- /// Determines whether a given set of resource owner credentials is valid based on the authorization server's user database.
- /// </summary>
- /// <param name="userName">Username on the account.</param>
- /// <param name="password">The user's password.</param>
- /// <returns>
- /// <c>true</c> if the given credentials are valid; otherwise, <c>false</c>.
- /// </returns>
- /// <exception cref="NotSupportedException">May be thrown if the authorization server does not support the resource owner password credential grant type.</exception>
- bool IsResourceOwnerCredentialValid(string userName, string password);
- }
-
- /// <summary>
- /// Code Contract for the <see cref="IAuthorizationServer"/> interface.
- /// </summary>
- [ContractClassFor(typeof(IAuthorizationServer))]
- internal abstract class IAuthorizationServerContract : IAuthorizationServer {
- /// <summary>
- /// Prevents a default instance of the <see cref="IAuthorizationServerContract"/> class from being created.
- /// </summary>
- private IAuthorizationServerContract() {
- }
-
- /// <summary>
- /// Gets the store for storeing crypto keys used to symmetrically encrypt and sign authorization codes and refresh tokens.
- /// </summary>
- ICryptoKeyStore IAuthorizationServer.CryptoKeyStore {
- get {
- Contract.Ensures(Contract.Result<ICryptoKeyStore>() != null);
- throw new NotImplementedException();
- }
- }
-
- /// <summary>
- /// Gets the authorization code nonce store to use to ensure that authorization codes can only be used once.
- /// </summary>
- /// <value>The authorization code nonce store.</value>
- INonceStore IAuthorizationServer.VerificationCodeNonceStore {
- get {
- Contract.Ensures(Contract.Result<INonceStore>() != null);
- throw new NotImplementedException();
- }
- }
-
- /// <summary>
- /// Gets the crypto service provider with the asymmetric private key to use for signing access tokens.
- /// </summary>
- /// <value>
- /// Must not be null, and must contain the private key.
- /// </value>
- /// <returns>A crypto service provider instance that contains the private key.</returns>
- RSACryptoServiceProvider IAuthorizationServer.AccessTokenSigningKey {
- get {
- Contract.Ensures(Contract.Result<RSACryptoServiceProvider>() != null);
- Contract.Ensures(!Contract.Result<RSACryptoServiceProvider>().PublicOnly);
- throw new NotImplementedException();
- }
- }
-
- /// <summary>
- /// Obtains the lifetime for a new access token.
- /// </summary>
- /// <param name="accessTokenRequestMessage">Details regarding the resources that the access token will grant access to, and the identity of the client
- /// that will receive that access.
- /// Based on this information the receiving resource server can be determined and the lifetime of the access
- /// token can be set based on the sensitivity of the resources.</param>
- /// <returns>
- /// Receives the lifetime for this access token. Note that within this lifetime, authorization <i>may</i> not be revokable.
- /// Short lifetimes are recommended (i.e. one hour), particularly when the client is not authenticated or
- /// the resources to which access is being granted are sensitive.
- /// </returns>
- TimeSpan IAuthorizationServer.GetAccessTokenLifetime(IAccessTokenRequest accessTokenRequestMessage) {
- Requires.NotNull(accessTokenRequestMessage, "accessTokenRequestMessage");
- throw new NotImplementedException();
- }
-
- /// <summary>
- /// Obtains the encryption key for an access token being created.
- /// </summary>
- /// <param name="accessTokenRequestMessage">Details regarding the resources that the access token will grant access to, and the identity of the client
- /// that will receive that access.
- /// Based on this information the receiving resource server can be determined and the lifetime of the access
- /// token can be set based on the sensitivity of the resources.</param>
- /// <returns>
- /// The crypto service provider with the asymmetric public key to use for encrypting access tokens for a specific resource server.
- /// The caller is responsible to dispose of this value.
- /// </returns>
- RSACryptoServiceProvider IAuthorizationServer.GetResourceServerEncryptionKey(IAccessTokenRequest accessTokenRequestMessage) {
- Requires.NotNull(accessTokenRequestMessage, "accessTokenRequestMessage");
- Contract.Ensures(Contract.Result<RSACryptoServiceProvider>() != null);
- throw new NotImplementedException();
- }
-
- /// <summary>
- /// Gets the client with a given identifier.
- /// </summary>
- /// <param name="clientIdentifier">The client identifier.</param>
- /// <returns>The client registration. Never null.</returns>
- /// <exception cref="ArgumentException">Thrown when no client with the given identifier is registered with this authorization server.</exception>
- IClientDescription IAuthorizationServer.GetClient(string clientIdentifier) {
- Requires.NotNullOrEmpty(clientIdentifier, "clientIdentifier");
- Contract.Ensures(Contract.Result<IClientDescription>() != null);
- throw new NotImplementedException();
- }
-
- /// <summary>
- /// Determines whether a described authorization is (still) valid.
- /// </summary>
- /// <param name="authorization">The authorization.</param>
- /// <returns>
- /// <c>true</c> if the original authorization is still valid; otherwise, <c>false</c>.
- /// </returns>
- /// <remarks>
- /// <para>When establishing that an authorization is still valid,
- /// it's very important to only match on recorded authorizations that
- /// meet these criteria:</para>
- /// 1) The client identifier matches.
- /// 2) The user account matches.
- /// 3) The scope on the recorded authorization must include all scopes in the given authorization.
- /// 4) The date the recorded authorization was issued must be <em>no later</em> that the date the given authorization was issued.
- /// <para>One possible scenario is where the user authorized a client, later revoked authorization,
- /// and even later reinstated authorization. This subsequent recorded authorization
- /// would not satisfy requirement #4 in the above list. This is important because the revocation
- /// the user went through should invalidate all previously issued tokens as a matter of
- /// security in the event the user was revoking access in order to sever authorization on a stolen
- /// account or piece of hardware in which the tokens were stored. </para>
- /// </remarks>
- bool IAuthorizationServer.IsAuthorizationValid(IAuthorizationDescription authorization) {
- Requires.NotNull(authorization, "authorization");
- throw new NotImplementedException();
- }
-
- /// <summary>
- /// Determines whether a given set of resource owner credentials is valid based on the authorization server's user database.
- /// </summary>
- /// <param name="userName">Username on the account.</param>
- /// <param name="password">The user's password.</param>
- /// <returns>
- /// <c>true</c> if the given credentials are valid; otherwise, <c>false</c>.
- /// </returns>
- /// <exception cref="NotSupportedException">May be thrown if the authorization server does not support the resource owner password credential grant type.</exception>
- bool IAuthorizationServer.IsResourceOwnerCredentialValid(string userName, string password) {
- Contract.Requires(!string.IsNullOrEmpty(userName));
- Contract.Requires(password != null);
- throw new NotImplementedException();
- }
- }
-}
diff --git a/src/DotNetOpenAuth.OAuth2/OAuth2/IAuthorizationState.cs b/src/DotNetOpenAuth.OAuth2/OAuth2/IAuthorizationState.cs
deleted file mode 100644
index f38df9a..0000000
--- a/src/DotNetOpenAuth.OAuth2/OAuth2/IAuthorizationState.cs
+++ /dev/null
@@ -1,67 +0,0 @@
-//-----------------------------------------------------------------------
-// <copyright file="IAuthorizationState.cs" company="Outercurve Foundation">
-// Copyright (c) Outercurve Foundation. All rights reserved.
-// </copyright>
-//-----------------------------------------------------------------------
-
-namespace DotNetOpenAuth.OAuth2 {
- using System;
- using System.Collections.Generic;
-
- /// <summary>
- /// Provides access to a persistent object that tracks the state of an authorization.
- /// </summary>
- public interface IAuthorizationState {
- /// <summary>
- /// Gets or sets the callback URL used to obtain authorization.
- /// </summary>
- /// <value>The callback URL.</value>
- Uri Callback { get; set; }
-
- /// <summary>
- /// Gets or sets the long-lived token used to renew the short-lived <see cref="AccessToken"/>.
- /// </summary>
- /// <value>The refresh token.</value>
- string RefreshToken { get; set; }
-
- /// <summary>
- /// Gets or sets the access token.
- /// </summary>
- /// <value>The access token.</value>
- string AccessToken { get; set; }
-
- /// <summary>
- /// Gets or sets the access token issue date UTC.
- /// </summary>
- /// <value>The access token issue date UTC.</value>
- DateTime? AccessTokenIssueDateUtc { get; set; }
-
- /// <summary>
- /// Gets or sets the access token UTC expiration date.
- /// </summary>
- DateTime? AccessTokenExpirationUtc { get; set; }
-
- /// <summary>
- /// Gets the scope the token is (to be) authorized for.
- /// </summary>
- /// <value>The scope.</value>
- HashSet<string> Scope { get; }
-
- /// <summary>
- /// Deletes this authorization, including access token and refresh token where applicable.
- /// </summary>
- /// <remarks>
- /// This method is invoked when an authorization attempt fails, is rejected, is revoked, or
- /// expires and cannot be renewed.
- /// </remarks>
- void Delete();
-
- /// <summary>
- /// Saves any changes made to this authorization object's properties.
- /// </summary>
- /// <remarks>
- /// This method is invoked after DotNetOpenAuth changes any property.
- /// </remarks>
- void SaveChanges();
- }
-} \ No newline at end of file
diff --git a/src/DotNetOpenAuth.OAuth2/OAuth2/IClientAuthorizationTracker.cs b/src/DotNetOpenAuth.OAuth2/OAuth2/IClientAuthorizationTracker.cs
deleted file mode 100644
index 73b7a44..0000000
--- a/src/DotNetOpenAuth.OAuth2/OAuth2/IClientAuthorizationTracker.cs
+++ /dev/null
@@ -1,53 +0,0 @@
-//-----------------------------------------------------------------------
-// <copyright file="IClientAuthorizationTracker.cs" company="Outercurve Foundation">
-// Copyright (c) Outercurve Foundation. All rights reserved.
-// </copyright>
-//-----------------------------------------------------------------------
-
-namespace DotNetOpenAuth.OAuth2 {
- using System;
- using System.Diagnostics.Contracts;
-
- /// <summary>
- /// A token manager implemented by some clients to assist in tracking authorization state.
- /// </summary>
- [ContractClass(typeof(IClientAuthorizationTrackerContract))]
- public interface IClientAuthorizationTracker {
- /// <summary>
- /// Gets the state of the authorization for a given callback URL and client state.
- /// </summary>
- /// <param name="callbackUrl">The callback URL.</param>
- /// <param name="clientState">State of the client stored at the beginning of an authorization request.</param>
- /// <returns>The authorization state; may be <c>null</c> if no authorization state matches.</returns>
- IAuthorizationState GetAuthorizationState(Uri callbackUrl, string clientState);
- }
-
- /// <summary>
- /// Contract class for the <see cref="IClientAuthorizationTracker"/> interface.
- /// </summary>
- [ContractClassFor(typeof(IClientAuthorizationTracker))]
- internal abstract class IClientAuthorizationTrackerContract : IClientAuthorizationTracker {
- /// <summary>
- /// Prevents a default instance of the <see cref="IClientAuthorizationTrackerContract"/> class from being created.
- /// </summary>
- private IClientAuthorizationTrackerContract() {
- }
-
- #region IClientTokenManager Members
-
- /// <summary>
- /// Gets the state of the authorization for a given callback URL and client state.
- /// </summary>
- /// <param name="callbackUrl">The callback URL.</param>
- /// <param name="clientState">State of the client stored at the beginning of an authorization request.</param>
- /// <returns>
- /// The authorization state; may be <c>null</c> if no authorization state matches.
- /// </returns>
- IAuthorizationState IClientAuthorizationTracker.GetAuthorizationState(Uri callbackUrl, string clientState) {
- Requires.NotNull(callbackUrl, "callbackUrl");
- throw new NotImplementedException();
- }
-
- #endregion
- }
-}
diff --git a/src/DotNetOpenAuth.OAuth2/OAuth2/IClientDescription.cs b/src/DotNetOpenAuth.OAuth2/OAuth2/IClientDescription.cs
deleted file mode 100644
index d30151b..0000000
--- a/src/DotNetOpenAuth.OAuth2/OAuth2/IClientDescription.cs
+++ /dev/null
@@ -1,113 +0,0 @@
-//-----------------------------------------------------------------------
-// <copyright file="IClientDescription.cs" company="Outercurve Foundation">
-// Copyright (c) Outercurve Foundation. All rights reserved.
-// </copyright>
-//-----------------------------------------------------------------------
-
-namespace DotNetOpenAuth.OAuth2 {
- using System;
- using System.Collections.Generic;
- using System.Diagnostics.Contracts;
-
- /// <summary>
- /// A description of a client from an Authorization Server's point of view.
- /// </summary>
- [ContractClass(typeof(IClientDescriptionContract))]
- public interface IClientDescription {
- /// <summary>
- /// Gets the client secret.
- /// </summary>
- string Secret { get; }
-
- /// <summary>
- /// Gets the callback to use when an individual authorization request
- /// does not include an explicit callback URI.
- /// </summary>
- /// <value>An absolute URL; or <c>null</c> if none is registered.</value>
- Uri DefaultCallback { get; }
-
- /// <summary>
- /// Gets the type of the client.
- /// </summary>
- ClientType ClientType { get; }
-
- /// <summary>
- /// Determines whether a callback URI included in a client's authorization request
- /// is among those allowed callbacks for the registered client.
- /// </summary>
- /// <param name="callback">The absolute URI the client has requested the authorization result be received at.</param>
- /// <returns>
- /// <c>true</c> if the callback URL is allowable for this client; otherwise, <c>false</c>.
- /// </returns>
- /// <remarks>
- /// <para>
- /// At the point this method is invoked, the identity of the client has <em>not</em>
- /// been confirmed. To avoid open redirector attacks, the alleged client's identity
- /// is used to lookup a list of allowable callback URLs to make sure that the callback URL
- /// the actual client is requesting is one of the expected ones.
- /// </para>
- /// <para>
- /// From OAuth 2.0 section 2.1:
- /// The authorization server SHOULD require the client to pre-register
- /// their redirection URI or at least certain components such as the
- /// scheme, host, port and path. If a redirection URI was registered,
- /// the authorization server MUST compare any redirection URI received at
- /// the authorization endpoint with the registered URI.
- /// </para>
- /// </remarks>
- bool IsCallbackAllowed(Uri callback);
- }
-
- /// <summary>
- /// Contract class for the <see cref="IClientDescription"/> interface.
- /// </summary>
- [ContractClassFor(typeof(IClientDescription))]
- internal abstract class IClientDescriptionContract : IClientDescription {
- #region IClientDescription Members
-
- /// <summary>
- /// Gets the client secret.
- /// </summary>
- /// <value></value>
- string IClientDescription.Secret {
- get { throw new NotImplementedException(); }
- }
-
- /// <summary>
- /// Gets the type of the client.
- /// </summary>
- ClientType IClientDescription.ClientType {
- get { throw new NotImplementedException(); }
- }
-
- /// <summary>
- /// Gets the callback to use when an individual authorization request
- /// does not include an explicit callback URI.
- /// </summary>
- /// <value>
- /// An absolute URL; or <c>null</c> if none is registered.
- /// </value>
- Uri IClientDescription.DefaultCallback {
- get {
- Contract.Ensures(Contract.Result<Uri>() == null || Contract.Result<Uri>().IsAbsoluteUri);
- throw new NotImplementedException();
- }
- }
-
- /// <summary>
- /// Determines whether a callback URI included in a client's authorization request
- /// is among those allowed callbacks for the registered client.
- /// </summary>
- /// <param name="callback">The requested callback URI.</param>
- /// <returns>
- /// <c>true</c> if the callback is allowed; otherwise, <c>false</c>.
- /// </returns>
- bool IClientDescription.IsCallbackAllowed(Uri callback) {
- Requires.NotNull(callback, "callback");
- Requires.True(callback.IsAbsoluteUri, "callback");
- throw new NotImplementedException();
- }
-
- #endregion
- }
-}
diff --git a/src/DotNetOpenAuth.OAuth2/OAuth2/Messages/AccessTokenAuthorizationCodeRequest.cs b/src/DotNetOpenAuth.OAuth2/OAuth2/Messages/AccessTokenAuthorizationCodeRequest.cs
deleted file mode 100644
index 1f244f9..0000000
--- a/src/DotNetOpenAuth.OAuth2/OAuth2/Messages/AccessTokenAuthorizationCodeRequest.cs
+++ /dev/null
@@ -1,100 +0,0 @@
-//-----------------------------------------------------------------------
-// <copyright file="AccessTokenAuthorizationCodeRequest.cs" company="Outercurve Foundation">
-// Copyright (c) Outercurve Foundation. All rights reserved.
-// </copyright>
-//-----------------------------------------------------------------------
-
-namespace DotNetOpenAuth.OAuth2.Messages {
- using System;
- using System.Collections.Generic;
- using System.Diagnostics.Contracts;
- using System.Linq;
- using System.Text;
-
- using DotNetOpenAuth.Messaging;
- using DotNetOpenAuth.OAuth2.ChannelElements;
-
- /// <summary>
- /// A request from a Client to an Authorization Server to exchange an authorization code for an access token,
- /// and (at the authorization server's option) a refresh token.
- /// </summary>
- internal class AccessTokenAuthorizationCodeRequest : AccessTokenRequestBase, IAuthorizationCodeCarryingRequest {
- /// <summary>
- /// Initializes a new instance of the <see cref="AccessTokenAuthorizationCodeRequest"/> class.
- /// </summary>
- /// <param name="tokenEndpoint">The Authorization Server's access token endpoint URL.</param>
- /// <param name="version">The version.</param>
- internal AccessTokenAuthorizationCodeRequest(Uri tokenEndpoint, Version version)
- : base(tokenEndpoint, version) {
- }
-
- /// <summary>
- /// Initializes a new instance of the <see cref="AccessTokenAuthorizationCodeRequest"/> class.
- /// </summary>
- /// <param name="authorizationServer">The authorization server.</param>
- internal AccessTokenAuthorizationCodeRequest(AuthorizationServerDescription authorizationServer)
- : this(authorizationServer.TokenEndpoint, authorizationServer.Version) {
- Requires.NotNull(authorizationServer, "authorizationServer");
- }
-
- #region IAuthorizationCodeCarryingRequest Members
-
- /// <summary>
- /// Gets or sets the verification code or refresh/access token.
- /// </summary>
- /// <value>The code or token.</value>
- string IAuthorizationCodeCarryingRequest.Code {
- get { return this.AuthorizationCode; }
- set { this.AuthorizationCode = value; }
- }
-
- /// <summary>
- /// Gets or sets the authorization that the token describes.
- /// </summary>
- AuthorizationCode IAuthorizationCodeCarryingRequest.AuthorizationDescription { get; set; }
-
- /// <summary>
- /// Gets the authorization that the code describes.
- /// </summary>
- IAuthorizationDescription IAuthorizationCarryingRequest.AuthorizationDescription {
- get { return ((IAuthorizationCodeCarryingRequest)this).AuthorizationDescription; }
- }
-
- #endregion
-
- /// <summary>
- /// Gets the type of the grant.
- /// </summary>
- /// <value>The type of the grant.</value>
- internal override GrantType GrantType {
- get { return Messages.GrantType.AuthorizationCode; }
- }
-
- /// <summary>
- /// Gets or sets the verification code previously communicated to the Client
- /// in <see cref="EndUserAuthorizationSuccessAuthCodeResponse.AuthorizationCode"/>.
- /// </summary>
- /// <value>The verification code received from the authorization server.</value>
- [MessagePart(Protocol.code, IsRequired = true)]
- internal string AuthorizationCode { get; set; }
-
- /// <summary>
- /// Gets or sets the callback URL used in <see cref="EndUserAuthorizationRequest.Callback"/>
- /// </summary>
- /// <value>
- /// The Callback URL used to obtain the Verification Code.
- /// </value>
- /// <remarks>
- /// REQUIRED, if the redirect_uri parameter was included in the authorization request as described in Section 4.1.1, and their values MUST be identical.
- /// </remarks>
- [MessagePart(Protocol.redirect_uri, IsRequired = false)]
- internal Uri Callback { get; set; }
-
- /// <summary>
- /// Gets the scope of operations the client is allowed to invoke.
- /// </summary>
- protected override HashSet<string> RequestedScope {
- get { return ((IAuthorizationCarryingRequest)this).AuthorizationDescription.Scope; }
- }
- }
-}
diff --git a/src/DotNetOpenAuth.OAuth2/OAuth2/Messages/AccessTokenClientCredentialsRequest.cs b/src/DotNetOpenAuth.OAuth2/OAuth2/Messages/AccessTokenClientCredentialsRequest.cs
deleted file mode 100644
index 48419eb..0000000
--- a/src/DotNetOpenAuth.OAuth2/OAuth2/Messages/AccessTokenClientCredentialsRequest.cs
+++ /dev/null
@@ -1,83 +0,0 @@
-//-----------------------------------------------------------------------
-// <copyright file="AccessTokenClientCredentialsRequest.cs" company="Outercurve Foundation">
-// Copyright (c) Outercurve Foundation. All rights reserved.
-// </copyright>
-//-----------------------------------------------------------------------
-
-namespace DotNetOpenAuth.OAuth2.Messages {
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using DotNetOpenAuth.Messaging;
- using DotNetOpenAuth.OAuth2.ChannelElements;
-
- /// <summary>
- /// A request for an access token for a client application that has its
- /// own (non-user affiliated) client name and password.
- /// </summary>
- /// <remarks>
- /// This is somewhat analogous to 2-legged OAuth.
- /// </remarks>
- internal class AccessTokenClientCredentialsRequest : ScopedAccessTokenRequest, IAuthorizationCarryingRequest, IAuthorizationDescription {
- /// <summary>
- /// Initializes a new instance of the <see cref="AccessTokenClientCredentialsRequest"/> class.
- /// </summary>
- /// <param name="tokenEndpoint">The authorization server.</param>
- /// <param name="version">The version.</param>
- internal AccessTokenClientCredentialsRequest(Uri tokenEndpoint, Version version)
- : base(tokenEndpoint, version) {
- this.HttpMethods = HttpDeliveryMethods.PostRequest;
- }
-
- #region IAuthorizationCarryingRequest members
-
- /// <summary>
- /// Gets the authorization that the code or token describes.
- /// </summary>
- IAuthorizationDescription IAuthorizationCarryingRequest.AuthorizationDescription {
- get { return this.CredentialsValidated ? this : null; }
- }
-
- #endregion
-
- #region IAuthorizationDescription Members
-
- /// <summary>
- /// Gets the date this authorization was established or the token was issued.
- /// </summary>
- /// <value>A date/time expressed in UTC.</value>
- DateTime IAuthorizationDescription.UtcIssued {
- get { return DateTime.UtcNow; }
- }
-
- /// <summary>
- /// Gets the name on the account whose data on the resource server is accessible using this authorization.
- /// </summary>
- string IAuthorizationDescription.User {
- get { return null; }
- }
-
- /// <summary>
- /// Gets the scope of operations the client is allowed to invoke.
- /// </summary>
- HashSet<string> IAuthorizationDescription.Scope {
- get { return this.Scope; }
- }
-
- #endregion
-
- /// <summary>
- /// Gets the type of the grant.
- /// </summary>
- /// <value>The type of the grant.</value>
- internal override GrantType GrantType {
- get { return Messages.GrantType.ClientCredentials; }
- }
-
- /// <summary>
- /// Gets or sets a value indicating whether the resource owner's credentials have been validated at the authorization server.
- /// </summary>
- internal bool CredentialsValidated { get; set; }
- }
-}
diff --git a/src/DotNetOpenAuth.OAuth2/OAuth2/Messages/AccessTokenFailedResponse.cs b/src/DotNetOpenAuth.OAuth2/OAuth2/Messages/AccessTokenFailedResponse.cs
deleted file mode 100644
index 8c4b1c3..0000000
--- a/src/DotNetOpenAuth.OAuth2/OAuth2/Messages/AccessTokenFailedResponse.cs
+++ /dev/null
@@ -1,93 +0,0 @@
-//-----------------------------------------------------------------------
-// <copyright file="AccessTokenFailedResponse.cs" company="Outercurve Foundation">
-// Copyright (c) Outercurve Foundation. All rights reserved.
-// </copyright>
-//-----------------------------------------------------------------------
-
-namespace DotNetOpenAuth.OAuth2.Messages {
- using System;
- using System.Net;
-
- using Messaging;
-
- /// <summary>
- /// A response from the Authorization Server to the Client to indicate that a
- /// request for an access token renewal failed, probably due to an invalid
- /// refresh token.
- /// </summary>
- /// <remarks>
- /// This message type is shared by the Web App, Rich App, and Username/Password profiles.
- /// </remarks>
- internal class AccessTokenFailedResponse : MessageBase, IHttpDirectResponse {
- /// <summary>
- /// A value indicating whether this error response is in result to a request that had invalid client credentials which were supplied in the HTTP Authorization header.
- /// </summary>
- private readonly bool invalidClientCredentialsInAuthorizationHeader;
-
- /// <summary>
- /// Initializes a new instance of the <see cref="AccessTokenFailedResponse"/> class.
- /// </summary>
- /// <param name="request">The faulty request.</param>
- internal AccessTokenFailedResponse(AccessTokenRequestBase request)
- : base(request) {
- }
-
- /// <summary>
- /// Initializes a new instance of the <see cref="AccessTokenFailedResponse"/> class.
- /// </summary>
- /// <param name="request">The faulty request.</param>
- /// <param name="invalidClientCredentialsInAuthorizationHeader">A value indicating whether this error response is in result to a request that had invalid client credentials which were supplied in the HTTP Authorization header.</param>
- internal AccessTokenFailedResponse(AccessTokenRequestBase request, bool invalidClientCredentialsInAuthorizationHeader)
- : base(request) {
- this.invalidClientCredentialsInAuthorizationHeader = invalidClientCredentialsInAuthorizationHeader;
- }
-
- /// <summary>
- /// Initializes a new instance of the <see cref="AccessTokenFailedResponse"/> class.
- /// </summary>
- /// <param name="version">The protocol version.</param>
- internal AccessTokenFailedResponse(Version version = null)
- : base(version ?? Protocol.Default.Version) {
- }
-
- #region IHttpDirectResponse Members
-
- /// <summary>
- /// Gets the HTTP status code that the direct response should be sent with.
- /// </summary>
- HttpStatusCode IHttpDirectResponse.HttpStatusCode {
- get { return this.invalidClientCredentialsInAuthorizationHeader ? HttpStatusCode.Unauthorized : HttpStatusCode.BadRequest; }
- }
-
- /// <summary>
- /// Gets the HTTP headers to add to the response.
- /// </summary>
- /// <value>May be an empty collection, but must not be <c>null</c>.</value>
- WebHeaderCollection IHttpDirectResponse.Headers {
- get { return new WebHeaderCollection(); }
- }
-
- #endregion
-
- /// <summary>
- /// Gets or sets the error.
- /// </summary>
- /// <value>One of the values given in <see cref="Protocol.AccessTokenRequestErrorCodes"/>.</value>
- [MessagePart(Protocol.error, IsRequired = true)]
- internal string Error { get; set; }
-
- /// <summary>
- /// Gets or sets a human readable description of the error.
- /// </summary>
- /// <value>Human-readable text providing additional information, used to assist in the understanding and resolution of the error that occurred.</value>
- [MessagePart(Protocol.error_description, IsRequired = false)]
- internal string ErrorDescription { get; set; }
-
- /// <summary>
- /// Gets or sets the location of the web page that describes the error and possible resolution.
- /// </summary>
- /// <value>A URI identifying a human-readable web page with information about the error, used to provide the end-user with additional information about the error.</value>
- [MessagePart(Protocol.error_uri, IsRequired = false)]
- internal Uri ErrorUri { get; set; }
- }
-}
diff --git a/src/DotNetOpenAuth.OAuth2/OAuth2/Messages/AccessTokenRefreshRequest.cs b/src/DotNetOpenAuth.OAuth2/OAuth2/Messages/AccessTokenRefreshRequest.cs
deleted file mode 100644
index 2c3ab25..0000000
--- a/src/DotNetOpenAuth.OAuth2/OAuth2/Messages/AccessTokenRefreshRequest.cs
+++ /dev/null
@@ -1,78 +0,0 @@
-//-----------------------------------------------------------------------
-// <copyright file="AccessTokenRefreshRequest.cs" company="Outercurve Foundation">
-// Copyright (c) Outercurve Foundation. All rights reserved.
-// </copyright>
-//-----------------------------------------------------------------------
-
-namespace DotNetOpenAuth.OAuth2.Messages {
- using System;
- using System.Collections.Generic;
- using DotNetOpenAuth.Messaging;
- using DotNetOpenAuth.OAuth2.ChannelElements;
-
- /// <summary>
- /// 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 : ScopedAccessTokenRequest, IRefreshTokenCarryingRequest {
- /// <summary>
- /// Initializes a new instance of the <see cref="AccessTokenRefreshRequest"/> class.
- /// </summary>
- /// <param name="tokenEndpoint">The token endpoint.</param>
- /// <param name="version">The version.</param>
- internal AccessTokenRefreshRequest(Uri tokenEndpoint, Version version)
- : base(tokenEndpoint, version) {
- }
-
- /// <summary>
- /// Initializes a new instance of the <see cref="AccessTokenRefreshRequest"/> class.
- /// </summary>
- /// <param name="authorizationServer">The authorization server.</param>
- internal AccessTokenRefreshRequest(AuthorizationServerDescription authorizationServer)
- : this(authorizationServer.TokenEndpoint, authorizationServer.Version) {
- }
-
- #region IRefreshTokenCarryingRequest members
-
- /// <summary>
- /// Gets or sets the verification code or refresh/access token.
- /// </summary>
- /// <value>The code or token.</value>
- string IRefreshTokenCarryingRequest.RefreshToken {
- get { return this.RefreshToken; }
- set { this.RefreshToken = value; }
- }
-
- /// <summary>
- /// Gets or sets the authorization that the token describes.
- /// </summary>
- RefreshToken IRefreshTokenCarryingRequest.AuthorizationDescription { get; set; }
-
- /// <summary>
- /// Gets the authorization that the token describes.
- /// </summary>
- IAuthorizationDescription IAuthorizationCarryingRequest.AuthorizationDescription {
- get { return ((IRefreshTokenCarryingRequest)this).AuthorizationDescription; }
- }
-
- #endregion
-
- /// <summary>
- /// Gets or sets the refresh token.
- /// </summary>
- /// <value>The refresh token.</value>
- /// <remarks>
- /// REQUIRED. The refresh token associated with the access token to be refreshed.
- /// </remarks>
- [MessagePart(Protocol.refresh_token, IsRequired = true)]
- internal string RefreshToken { get; set; }
-
- /// <summary>
- /// Gets the type of the grant.
- /// </summary>
- /// <value>The type of the grant.</value>
- internal override GrantType GrantType {
- get { return Messages.GrantType.RefreshToken; }
- }
- }
-}
diff --git a/src/DotNetOpenAuth.OAuth2/OAuth2/Messages/AccessTokenRequestBase.cs b/src/DotNetOpenAuth.OAuth2/OAuth2/Messages/AccessTokenRequestBase.cs
deleted file mode 100644
index 7e41fcd..0000000
--- a/src/DotNetOpenAuth.OAuth2/OAuth2/Messages/AccessTokenRequestBase.cs
+++ /dev/null
@@ -1,78 +0,0 @@
-//-----------------------------------------------------------------------
-// <copyright file="AccessTokenRequestBase.cs" company="Outercurve Foundation">
-// Copyright (c) Outercurve Foundation. All rights reserved.
-// </copyright>
-//-----------------------------------------------------------------------
-
-namespace DotNetOpenAuth.OAuth2.Messages {
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using DotNetOpenAuth.Configuration;
- using DotNetOpenAuth.Messaging;
- using DotNetOpenAuth.OAuth2.ChannelElements;
-
- /// <summary>
- /// A message sent from the client to the authorization server to exchange a previously obtained grant for an access token.
- /// </summary>
- public abstract class AccessTokenRequestBase : AuthenticatedClientRequestBase, IAccessTokenRequest {
- /// <summary>
- /// Initializes a new instance of the <see cref="AccessTokenRequestBase"/> class.
- /// </summary>
- /// <param name="tokenEndpoint">The Authorization Server's access token endpoint URL.</param>
- /// <param name="version">The version.</param>
- protected AccessTokenRequestBase(Uri tokenEndpoint, Version version)
- : base(tokenEndpoint, version) {
- this.HttpMethods = HttpDeliveryMethods.PostRequest;
- }
-
- /// <summary>
- /// Gets the scope of operations the client is allowed to invoke.
- /// </summary>
- HashSet<string> IAccessTokenRequest.Scope {
- get { return this.RequestedScope; }
- }
-
- /// <summary>
- /// Gets a value indicating whether the client requesting the access token has authenticated itself.
- /// </summary>
- /// <value>
- /// Always true, because of our base class.
- /// </value>
- bool IAccessTokenRequest.ClientAuthenticated {
- get { return true; }
- }
-
- /// <summary>
- /// Gets the type of the grant.
- /// </summary>
- /// <value>The type of the grant.</value>
- [MessagePart(Protocol.grant_type, IsRequired = true, Encoder = typeof(GrantTypeEncoder))]
- internal abstract GrantType GrantType { get; }
-
- /// <summary>
- /// Gets the scope of operations the client is allowed to invoke.
- /// </summary>
- protected abstract HashSet<string> RequestedScope { get; }
-
- /// <summary>
- /// Checks the message state for conformity to the protocol specification
- /// and throws an exception if the message is invalid.
- /// </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();
- ErrorUtilities.VerifyProtocol(
- DotNetOpenAuthSection.Messaging.RelaxSslRequirements || this.Recipient.IsTransportSecure(),
- OAuthStrings.HttpsRequired);
- }
- }
-}
diff --git a/src/DotNetOpenAuth.OAuth2/OAuth2/Messages/AccessTokenResourceOwnerPasswordCredentialsRequest.cs b/src/DotNetOpenAuth.OAuth2/OAuth2/Messages/AccessTokenResourceOwnerPasswordCredentialsRequest.cs
deleted file mode 100644
index 52e65be..0000000
--- a/src/DotNetOpenAuth.OAuth2/OAuth2/Messages/AccessTokenResourceOwnerPasswordCredentialsRequest.cs
+++ /dev/null
@@ -1,93 +0,0 @@
-//-----------------------------------------------------------------------
-// <copyright file="AccessTokenResourceOwnerPasswordCredentialsRequest.cs" company="Outercurve Foundation">
-// Copyright (c) Outercurve Foundation. All rights reserved.
-// </copyright>
-//-----------------------------------------------------------------------
-
-namespace DotNetOpenAuth.OAuth2.Messages {
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
-
- using DotNetOpenAuth.Messaging;
- using DotNetOpenAuth.OAuth2.ChannelElements;
-
- /// <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 : ScopedAccessTokenRequest, IAuthorizationCarryingRequest, IAuthorizationDescription {
- /// <summary>
- /// Initializes a new instance of the <see cref="AccessTokenResourceOwnerPasswordCredentialsRequest"/> class.
- /// </summary>
- /// <param name="accessTokenEndpoint">The access token endpoint.</param>
- /// <param name="version">The protocol version.</param>
- internal AccessTokenResourceOwnerPasswordCredentialsRequest(Uri accessTokenEndpoint, Version version)
- : base(accessTokenEndpoint, version) {
- }
-
- #region IAuthorizationCarryingRequest members
-
- /// <summary>
- /// Gets the authorization that the code or token describes.
- /// </summary>
- IAuthorizationDescription IAuthorizationCarryingRequest.AuthorizationDescription {
- get { return this.CredentialsValidated ? this : null; }
- }
-
- #endregion
-
- #region IAuthorizationDescription Members
-
- /// <summary>
- /// Gets the date this authorization was established or the token was issued.
- /// </summary>
- /// <value>A date/time expressed in UTC.</value>
- DateTime IAuthorizationDescription.UtcIssued {
- get { return DateTime.UtcNow; }
- }
-
- /// <summary>
- /// Gets the name on the account whose data on the resource server is accessible using this authorization.
- /// </summary>
- string IAuthorizationDescription.User {
- get { return this.UserName; }
- }
-
- /// <summary>
- /// Gets the scope of operations the client is allowed to invoke.
- /// </summary>
- HashSet<string> IAuthorizationDescription.Scope {
- get { return this.Scope; }
- }
-
- #endregion
-
- /// <summary>
- /// Gets the type of the grant.
- /// </summary>
- /// <value>The type of the grant.</value>
- internal override GrantType GrantType {
- get { return Messages.GrantType.Password; }
- }
-
- /// <summary>
- /// Gets or sets the user's account username.
- /// </summary>
- /// <value>The username on the user's account.</value>
- [MessagePart(Protocol.username, IsRequired = true)]
- internal string UserName { get; set; }
-
- /// <summary>
- /// Gets or sets the user's password.
- /// </summary>
- /// <value>The password.</value>
- [MessagePart(Protocol.password, IsRequired = true)]
- internal string Password { get; set; }
-
- /// <summary>
- /// Gets or sets a value indicating whether the resource owner's credentials have been validated at the authorization server.
- /// </summary>
- internal bool CredentialsValidated { get; set; }
- }
-}
diff --git a/src/DotNetOpenAuth.OAuth2/OAuth2/Messages/AccessTokenSuccessResponse.cs b/src/DotNetOpenAuth.OAuth2/OAuth2/Messages/AccessTokenSuccessResponse.cs
deleted file mode 100644
index 6d278c4..0000000
--- a/src/DotNetOpenAuth.OAuth2/OAuth2/Messages/AccessTokenSuccessResponse.cs
+++ /dev/null
@@ -1,113 +0,0 @@
-//-----------------------------------------------------------------------
-// <copyright file="AccessTokenSuccessResponse.cs" company="Outercurve Foundation">
-// Copyright (c) Outercurve Foundation. All rights reserved.
-// </copyright>
-//-----------------------------------------------------------------------
-
-namespace DotNetOpenAuth.OAuth2.Messages {
- using System;
- using System.Collections.Generic;
- using System.Net;
- using DotNetOpenAuth.Messaging;
- using DotNetOpenAuth.OAuth2.ChannelElements;
-
- /// <summary>
- /// A response from the Authorization Server to the Client containing a delegation code
- /// that the Client should use to obtain an access token.
- /// </summary>
- /// <remarks>
- /// This message type is shared by the Web App, Rich App, and Username/Password profiles.
- /// </remarks>
- internal class AccessTokenSuccessResponse : MessageBase, IHttpDirectResponse {
- /// <summary>
- /// Initializes a new instance of the <see cref="AccessTokenSuccessResponse"/> class.
- /// </summary>
- /// <param name="request">The request.</param>
- internal AccessTokenSuccessResponse(AccessTokenRequestBase request)
- : base(request) {
- this.Scope = new HashSet<string>(OAuthUtilities.ScopeStringComparer);
- this.TokenType = Protocol.AccessTokenTypes.Bearer;
- }
-
- /// <summary>
- /// Gets the HTTP status code that the direct response should be sent with.
- /// </summary>
- /// <value>Always HttpStatusCode.OK</value>
- HttpStatusCode IHttpDirectResponse.HttpStatusCode {
- get { return HttpStatusCode.OK; }
- }
-
- /// <summary>
- /// Gets the HTTP headers to add to the response.
- /// </summary>
- /// <value>May be an empty collection, but must not be <c>null</c>.</value>
- WebHeaderCollection IHttpDirectResponse.Headers {
- get {
- return new WebHeaderCollection
- {
- { HttpResponseHeader.CacheControl, "no-store" },
- { HttpResponseHeader.Pragma, "no-cache" },
- };
- }
- }
-
- /// <summary>
- /// Gets or sets the access token.
- /// </summary>
- /// <value>The access token.</value>
- [MessagePart(Protocol.access_token, IsRequired = true)]
- 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 = false)] // HACKHACK: This is actually required, but wasn't in older drafts of OAuth 2
- public string TokenType { get; internal set; }
-
- /// <summary>
- /// Gets or sets the lifetime of the access token.
- /// </summary>
- /// <value>The lifetime.</value>
- [MessagePart(Protocol.expires_in, IsRequired = false, Encoder = typeof(TimespanSecondsEncoder))]
- public TimeSpan? Lifetime { get; internal set; }
-
- /// <summary>
- /// Gets or sets the refresh token.
- /// </summary>
- /// <value>The refresh token.</value>
- /// <remarks>
- /// OPTIONAL. The refresh token used to obtain new access tokens using the same end-user access grant as described in Section 6 (Refreshing an Access Token).
- /// </remarks>
- [MessagePart(Protocol.refresh_token, IsRequired = false)]
- public string RefreshToken { get; internal set; }
-
- /// <summary>
- /// Gets the scope of access being requested.
- /// </summary>
- /// <value>The scope of the access request expressed as a list of space-delimited strings. The value of the scope parameter is defined by the authorization server. If the value contains multiple space-delimited strings, their order does not matter, and each string adds an additional access range to the requested scope.</value>
- [MessagePart(Protocol.scope, IsRequired = false, Encoder = typeof(ScopeEncoder))]
- public HashSet<string> Scope { get; private set; }
-
- /// <summary>
- /// Gets or sets a value indicating whether a refresh token is or should be included in the response.
- /// </summary>
- internal bool HasRefreshToken { get; set; }
-
- /// <summary>
- /// Checks the message state for conformity to the protocol specification
- /// and throws an exception if the message is invalid.
- /// </summary>
- /// <exception cref="ProtocolException">Thrown if the message is invalid.</exception>
- protected override void EnsureValidMessage() {
- base.EnsureValidMessage();
-
- // Per OAuth 2.0 section 4.4.3 (draft 23), refresh tokens should never be included
- // in a response to an access token request that used the client credential grant type.
- ErrorUtilities.VerifyProtocol(!this.HasRefreshToken || !(this.OriginatingRequest is AccessTokenClientCredentialsRequest), OAuthStrings.RefreshTokenInappropriateForRequestType, this.OriginatingRequest.GetType().Name);
- }
- }
-}
diff --git a/src/DotNetOpenAuth.OAuth2/OAuth2/Messages/AuthenticatedClientRequestBase.cs b/src/DotNetOpenAuth.OAuth2/OAuth2/Messages/AuthenticatedClientRequestBase.cs
deleted file mode 100644
index bc4d0ca..0000000
--- a/src/DotNetOpenAuth.OAuth2/OAuth2/Messages/AuthenticatedClientRequestBase.cs
+++ /dev/null
@@ -1,42 +0,0 @@
-//-----------------------------------------------------------------------
-// <copyright file="AuthenticatedClientRequestBase.cs" company="Outercurve Foundation">
-// Copyright (c) Outercurve Foundation. All rights reserved.
-// </copyright>
-//-----------------------------------------------------------------------
-
-namespace DotNetOpenAuth.OAuth2.Messages {
- using System;
-
- using DotNetOpenAuth.Messaging;
-
- /// <summary>
- /// A direct message from the client to the authorization server that includes the client's credentials.
- /// </summary>
- public abstract class AuthenticatedClientRequestBase : MessageBase {
- /// <summary>
- /// Initializes a new instance of the <see cref="AuthenticatedClientRequestBase"/> class.
- /// </summary>
- /// <param name="tokenEndpoint">The Authorization Server's access token endpoint URL.</param>
- /// <param name="version">The version.</param>
- protected AuthenticatedClientRequestBase(Uri tokenEndpoint, Version version)
- : base(version, MessageTransport.Direct, tokenEndpoint) {
- }
-
- /// <summary>
- /// Gets the client identifier previously obtained from the Authorization Server.
- /// </summary>
- /// <value>The client identifier.</value>
- [MessagePart(Protocol.client_id, IsRequired = true)]
- public string ClientIdentifier { get; internal set; }
-
- /// <summary>
- /// Gets the client secret.
- /// </summary>
- /// <value>The client secret.</value>
- /// <remarks>
- /// REQUIRED. The client secret as described in Section 2.1 (Client Credentials). OPTIONAL if no client secret was issued.
- /// </remarks>
- [MessagePart(Protocol.client_secret, IsRequired = false)]
- public string ClientSecret { get; internal set; }
- }
-} \ No newline at end of file
diff --git a/src/DotNetOpenAuth.OAuth2/OAuth2/Messages/EndUserAuthorizationFailedResponse.cs b/src/DotNetOpenAuth.OAuth2/OAuth2/Messages/EndUserAuthorizationFailedResponse.cs
deleted file mode 100644
index 7cc8e82..0000000
--- a/src/DotNetOpenAuth.OAuth2/OAuth2/Messages/EndUserAuthorizationFailedResponse.cs
+++ /dev/null
@@ -1,81 +0,0 @@
-//-----------------------------------------------------------------------
-// <copyright file="EndUserAuthorizationFailedResponse.cs" company="Outercurve Foundation">
-// Copyright (c) Outercurve Foundation. All rights reserved.
-// </copyright>
-//-----------------------------------------------------------------------
-
-namespace DotNetOpenAuth.OAuth2.Messages {
- using System;
- using System.Collections.Generic;
- using System.Diagnostics.Contracts;
- using System.Linq;
- using System.Runtime.Remoting.Messaging;
- using System.Text;
- using DotNetOpenAuth.Messaging;
-
- /// <summary>
- /// The message that an Authorization Server responds to a Client with when the user denies a user authorization request.
- /// </summary>
- public class EndUserAuthorizationFailedResponse : MessageBase, IMessageWithClientState {
- /// <summary>
- /// Initializes a new instance of the <see cref="EndUserAuthorizationFailedResponse"/> class.
- /// </summary>
- /// <param name="clientCallback">The URL to redirect to so the client receives the message. This may not be built into the request message if the client pre-registered the URL with the authorization server.</param>
- /// <param name="version">The protocol version.</param>
- internal EndUserAuthorizationFailedResponse(Uri clientCallback, Version version)
- : base(version, MessageTransport.Indirect, clientCallback) {
- Requires.NotNull(version, "version");
- Requires.NotNull(clientCallback, "clientCallback");
- }
-
- /// <summary>
- /// Initializes a new instance of the <see cref="EndUserAuthorizationFailedResponse"/> class.
- /// </summary>
- /// <param name="clientCallback">The URL to redirect to so the client receives the message. This may not be built into the request message if the client pre-registered the URL with the authorization server.</param>
- /// <param name="request">The authorization request from the user agent on behalf of the client.</param>
- internal EndUserAuthorizationFailedResponse(Uri clientCallback, EndUserAuthorizationRequest request)
- : base(((IProtocolMessage)request).Version, MessageTransport.Indirect, clientCallback) {
- Requires.NotNull(request, "request");
- ((IMessageWithClientState)this).ClientState = request.ClientState;
- }
-
- /// <summary>
- /// Gets or sets the error.
- /// </summary>
- /// <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; }
-
- /// <summary>
- /// Gets or sets a human readable description of the error.
- /// </summary>
- /// <value>Human-readable text providing additional information, used to assist in the understanding and resolution of the error that occurred.</value>
- [MessagePart(Protocol.error_description, IsRequired = false)]
- public string ErrorDescription { get; set; }
-
- /// <summary>
- /// Gets or sets the location of the web page that describes the error and possible resolution.
- /// </summary>
- /// <value>A URI identifying a human-readable web page with information about the error, used to provide the end-user with additional information about the error.</value>
- [MessagePart(Protocol.error_uri, IsRequired = false)]
- public Uri ErrorUri { get; set; }
-
- /// <summary>
- /// Gets or sets some state as provided by the client in the authorization request.
- /// </summary>
- /// <value>An opaque value defined by the client.</value>
- /// <remarks>
- /// REQUIRED if the Client sent the value in the <see cref="EndUserAuthorizationRequest"/>.
- /// </remarks>
- [MessagePart(Protocol.state, IsRequired = false)]
- string IMessageWithClientState.ClientState { get; set; }
- }
-}
diff --git a/src/DotNetOpenAuth.OAuth2/OAuth2/Messages/EndUserAuthorizationImplicitRequest.cs b/src/DotNetOpenAuth.OAuth2/OAuth2/Messages/EndUserAuthorizationImplicitRequest.cs
deleted file mode 100644
index f5a5d67..0000000
--- a/src/DotNetOpenAuth.OAuth2/OAuth2/Messages/EndUserAuthorizationImplicitRequest.cs
+++ /dev/null
@@ -1,63 +0,0 @@
-//-----------------------------------------------------------------------
-// <copyright file="EndUserAuthorizationImplicitRequest.cs" company="Outercurve Foundation">
-// Copyright (c) Outercurve Foundation. All rights reserved.
-// </copyright>
-//-----------------------------------------------------------------------
-
-namespace DotNetOpenAuth.OAuth2.Messages {
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using DotNetOpenAuth.Messaging;
- using DotNetOpenAuth.OAuth2.ChannelElements;
-
- /// <summary>
- /// A message sent by a web application Client to the AuthorizationServer
- /// via the user agent to obtain authorization from the user and prepare
- /// to issue an access token to the client if permission is granted.
- /// </summary>
- [Serializable]
- public class EndUserAuthorizationImplicitRequest : EndUserAuthorizationRequest, IAccessTokenRequest {
- /// <summary>
- /// Gets or sets the grant type that the client expects of the authorization server.
- /// </summary>
- /// <value>Always <see cref="EndUserAuthorizationResponseType.AccessToken"/>. Other response types are not supported.</value>
- [MessagePart(Protocol.response_type, IsRequired = true, Encoder = typeof(EndUserAuthorizationResponseTypeEncoder))]
- private const EndUserAuthorizationResponseType ResponseTypeConst = EndUserAuthorizationResponseType.AccessToken;
-
- /// <summary>
- /// Initializes a new instance of the <see cref="EndUserAuthorizationImplicitRequest"/> class.
- /// </summary>
- /// <param name="authorizationEndpoint">The Authorization Server's user authorization URL to direct the user to.</param>
- /// <param name="version">The protocol version.</param>
- internal EndUserAuthorizationImplicitRequest(Uri authorizationEndpoint, Version version)
- : base(authorizationEndpoint, version) {
- }
-
- /// <summary>
- /// Initializes a new instance of the <see cref="EndUserAuthorizationImplicitRequest"/> class.
- /// </summary>
- /// <param name="authorizationServer">The authorization server.</param>
- internal EndUserAuthorizationImplicitRequest(AuthorizationServerDescription authorizationServer)
- : this(authorizationServer.AuthorizationEndpoint, authorizationServer.Version) {
- }
-
- /// <summary>
- /// Gets the grant type that the client expects of the authorization server.
- /// </summary>
- public override EndUserAuthorizationResponseType ResponseType {
- get { return ResponseTypeConst; }
- }
-
- /// <summary>
- /// Gets a value indicating whether the client requesting the access token has authenticated itself.
- /// </summary>
- /// <value>
- /// Always false because authorization requests only include the client_id, without a secret.
- /// </value>
- bool IAccessTokenRequest.ClientAuthenticated {
- get { return false; }
- }
- }
-}
diff --git a/src/DotNetOpenAuth.OAuth2/OAuth2/Messages/EndUserAuthorizationRequest.cs b/src/DotNetOpenAuth.OAuth2/OAuth2/Messages/EndUserAuthorizationRequest.cs
deleted file mode 100644
index 45fa049..0000000
--- a/src/DotNetOpenAuth.OAuth2/OAuth2/Messages/EndUserAuthorizationRequest.cs
+++ /dev/null
@@ -1,114 +0,0 @@
-//-----------------------------------------------------------------------
-// <copyright file="EndUserAuthorizationRequest.cs" company="Outercurve Foundation">
-// Copyright (c) Outercurve Foundation. All rights reserved.
-// </copyright>
-//-----------------------------------------------------------------------
-
-namespace DotNetOpenAuth.OAuth2.Messages {
- using System;
- using System.Collections.Generic;
- using System.Diagnostics.CodeAnalysis;
- using System.Diagnostics.Contracts;
- using DotNetOpenAuth.Configuration;
- using DotNetOpenAuth.Messaging;
- using DotNetOpenAuth.OAuth2.ChannelElements;
-
- /// <summary>
- /// A message sent by a web application Client to the AuthorizationServer
- /// via the user agent to obtain authorization from the user and prepare
- /// to issue an access token to the client if permission is granted.
- /// </summary>
- [Serializable]
- public class EndUserAuthorizationRequest : MessageBase {
- /// <summary>
- /// Gets the grant type that the client expects of the authorization server.
- /// </summary>
- /// <value>Always <see cref="EndUserAuthorizationResponseType.AuthorizationCode"/>. Other response types are not supported.</value>
- [MessagePart(Protocol.response_type, IsRequired = true, Encoder = typeof(EndUserAuthorizationResponseTypeEncoder))]
- private const EndUserAuthorizationResponseType ResponseTypeConst = EndUserAuthorizationResponseType.AuthorizationCode;
-
- /// <summary>
- /// Initializes a new instance of the <see cref="EndUserAuthorizationRequest"/> class.
- /// </summary>
- /// <param name="authorizationEndpoint">The Authorization Server's user authorization URL to direct the user to.</param>
- /// <param name="version">The protocol version.</param>
- internal EndUserAuthorizationRequest(Uri authorizationEndpoint, Version version)
- : base(version, MessageTransport.Indirect, authorizationEndpoint) {
- Requires.NotNull(authorizationEndpoint, "authorizationEndpoint");
- Requires.NotNull(version, "version");
- this.HttpMethods = HttpDeliveryMethods.GetRequest | HttpDeliveryMethods.PostRequest;
- this.Scope = new HashSet<string>(OAuthUtilities.ScopeStringComparer);
- }
-
- /// <summary>
- /// Initializes a new instance of the <see cref="EndUserAuthorizationRequest"/> class.
- /// </summary>
- /// <param name="authorizationServer">The authorization server.</param>
- internal EndUserAuthorizationRequest(AuthorizationServerDescription authorizationServer)
- : this(authorizationServer.AuthorizationEndpoint, authorizationServer.Version) {
- Requires.NotNull(authorizationServer, "authorizationServer");
- Requires.True(authorizationServer.Version != null, "authorizationServer");
- Requires.True(authorizationServer.AuthorizationEndpoint != null, "authorizationServer");
- }
-
- /// <summary>
- /// Gets the grant type that the client expects of the authorization server.
- /// </summary>
- public virtual EndUserAuthorizationResponseType ResponseType {
- get { return ResponseTypeConst; }
- }
-
- /// <summary>
- /// Gets or sets the identifier by which this client is known to the Authorization Server.
- /// </summary>
- [MessagePart(Protocol.client_id, IsRequired = true)]
- public string ClientIdentifier { get; set; }
-
- /// <summary>
- /// Gets or sets the callback URL.
- /// </summary>
- /// <value>
- /// An absolute URL to which the Authorization Server will redirect the User back after
- /// the user has approved the authorization request.
- /// </value>
- /// <remarks>
- /// REQUIRED unless a redirection URI has been established between the client and authorization server via other means. An absolute URI to which the authorization server will redirect the user-agent to when the end-user authorization step is completed. The authorization server MAY require the client to pre-register their redirection URI. The redirection URI MUST NOT include a query component as defined by [RFC3986] (Berners-Lee, T., Fielding, R., and L. Masinter, “Uniform Resource Identifier (URI): Generic Syntax,” January 2005.) section 3 if the state parameter is present.
- /// </remarks>
- [MessagePart(Protocol.redirect_uri, IsRequired = false)]
- public Uri Callback { get; set; }
-
- /// <summary>
- /// Gets or sets state of the client that should be sent back with the authorization response.
- /// </summary>
- /// <value>
- /// An opaque value that Clients can use to maintain state associated with this request.
- /// </value>
- /// <remarks>
- /// This data is proprietary to the client and should be considered an opaque string to the
- /// authorization server.
- /// </remarks>
- [MessagePart(Protocol.state, IsRequired = false)]
- public string ClientState { get; set; }
-
- /// <summary>
- /// Gets the scope of access being requested.
- /// </summary>
- /// <value>The scope of the access request expressed as a list of space-delimited strings. The value of the scope parameter is defined by the authorization server. If the value contains multiple space-delimited strings, their order does not matter, and each string adds an additional access range to the requested scope.</value>
- [MessagePart(Protocol.scope, IsRequired = false, Encoder = typeof(ScopeEncoder))]
- public 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>
- /// <exception cref="ProtocolException">Thrown if the message is invalid.</exception>
- protected override void EnsureValidMessage() {
- base.EnsureValidMessage();
-
- ErrorUtilities.VerifyProtocol(
- DotNetOpenAuthSection.Messaging.RelaxSslRequirements || this.Recipient.IsTransportSecure(),
- OAuthStrings.HttpsRequired);
- ErrorUtilities.VerifyProtocol(this.Callback == null || this.Callback.IsAbsoluteUri, this, OAuthStrings.AbsoluteUriRequired, Protocol.redirect_uri);
- }
- }
-}
diff --git a/src/DotNetOpenAuth.OAuth2/OAuth2/Messages/EndUserAuthorizationResponseType.cs b/src/DotNetOpenAuth.OAuth2/OAuth2/Messages/EndUserAuthorizationResponseType.cs
deleted file mode 100644
index 75ece0f..0000000
--- a/src/DotNetOpenAuth.OAuth2/OAuth2/Messages/EndUserAuthorizationResponseType.cs
+++ /dev/null
@@ -1,25 +0,0 @@
-//-----------------------------------------------------------------------
-// <copyright file="EndUserAuthorizationResponseType.cs" company="Outercurve Foundation">
-// Copyright (c) Outercurve Foundation. All rights reserved.
-// </copyright>
-//-----------------------------------------------------------------------
-
-namespace DotNetOpenAuth.OAuth2.Messages {
- using System;
-
- /// <summary>
- /// An indication of what kind of response the client is requesting from the authorization server
- /// after the user has granted authorized access.
- /// </summary>
- public enum EndUserAuthorizationResponseType {
- /// <summary>
- /// An access token should be returned immediately.
- /// </summary>
- AccessToken,
-
- /// <summary>
- /// An authorization code should be returned, which can later be exchanged for refresh and access tokens.
- /// </summary>
- AuthorizationCode,
- }
-}
diff --git a/src/DotNetOpenAuth.OAuth2/OAuth2/Messages/EndUserAuthorizationSuccessAccessTokenResponse.cs b/src/DotNetOpenAuth.OAuth2/OAuth2/Messages/EndUserAuthorizationSuccessAccessTokenResponse.cs
deleted file mode 100644
index 5c03e7a..0000000
--- a/src/DotNetOpenAuth.OAuth2/OAuth2/Messages/EndUserAuthorizationSuccessAccessTokenResponse.cs
+++ /dev/null
@@ -1,111 +0,0 @@
-//-----------------------------------------------------------------------
-// <copyright file="EndUserAuthorizationSuccessAccessTokenResponse.cs" company="Outercurve Foundation">
-// Copyright (c) Outercurve Foundation. All rights reserved.
-// </copyright>
-//-----------------------------------------------------------------------
-
-namespace DotNetOpenAuth.OAuth2.Messages {
- using System;
- using System.Collections.Generic;
- using System.Diagnostics.Contracts;
- using System.Linq;
- using System.Text;
-
- using DotNetOpenAuth.Messaging;
- using DotNetOpenAuth.OAuth2.ChannelElements;
-
- /// <summary>
- /// The message sent by the Authorization Server to the Client via the user agent
- /// 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, IAccessTokenCarryingRequest, IHttpIndirectResponse {
- /// <summary>
- /// Initializes a new instance of the <see cref="EndUserAuthorizationSuccessAccessTokenResponse"/> class.
- /// </summary>
- /// <param name="clientCallback">The URL to redirect to so the client receives the message. This may not be built into the request message if the client pre-registered the URL with the authorization server.</param>
- /// <param name="version">The protocol version.</param>
- internal EndUserAuthorizationSuccessAccessTokenResponse(Uri clientCallback, Version version)
- : base(clientCallback, version) {
- Requires.NotNull(version, "version");
- Requires.NotNull(clientCallback, "clientCallback");
- this.TokenType = Protocol.AccessTokenTypes.Bearer;
- }
-
- /// <summary>
- /// Initializes a new instance of the <see cref="EndUserAuthorizationSuccessAccessTokenResponse"/> class.
- /// </summary>
- /// <param name="clientCallback">The URL to redirect to so the client receives the message. This may not be built into the request message if the client pre-registered the URL with the authorization server.</param>
- /// <param name="request">The authorization request from the user agent on behalf of the client.</param>
- internal EndUserAuthorizationSuccessAccessTokenResponse(Uri clientCallback, EndUserAuthorizationRequest request)
- : base(clientCallback, request) {
- Requires.NotNull(clientCallback, "clientCallback");
- Requires.NotNull(request, "request");
- ((IMessageWithClientState)this).ClientState = request.ClientState;
- this.TokenType = Protocol.AccessTokenTypes.Bearer;
- }
-
- #region IAccessTokenCarryingRequest Members
-
- /// <summary>
- /// Gets or sets the authorization that the token describes.
- /// </summary>
- /// <value></value>
- AccessToken IAccessTokenCarryingRequest.AuthorizationDescription { get; set; }
-
- /// <summary>
- /// Gets the authorization that the token describes.
- /// </summary>
- IAuthorizationDescription IAuthorizationCarryingRequest.AuthorizationDescription {
- get { return ((IAccessTokenCarryingRequest)this).AuthorizationDescription; }
- }
-
- #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)]
- public string AccessToken { get; set; }
-
- /// <summary>
- /// Gets or sets the scope of the <see cref="AccessToken"/> if one is given; otherwise the scope of the authorization code.
- /// </summary>
- /// <value>The scope.</value>
- [MessagePart(Protocol.scope, IsRequired = false, Encoder = typeof(ScopeEncoder))]
- public new ICollection<string> Scope {
- get { return base.Scope; }
- protected set { base.Scope = value; }
- }
-
- /// <summary>
- /// Gets or sets the lifetime of the authorization.
- /// </summary>
- /// <value>The lifetime.</value>
- [MessagePart(Protocol.expires_in, IsRequired = false, Encoder = typeof(TimespanSecondsEncoder))]
- internal TimeSpan? Lifetime { get; set; }
- }
-}
diff --git a/src/DotNetOpenAuth.OAuth2/OAuth2/Messages/EndUserAuthorizationSuccessAuthCodeResponse.cs b/src/DotNetOpenAuth.OAuth2/OAuth2/Messages/EndUserAuthorizationSuccessAuthCodeResponse.cs
deleted file mode 100644
index dcacc14..0000000
--- a/src/DotNetOpenAuth.OAuth2/OAuth2/Messages/EndUserAuthorizationSuccessAuthCodeResponse.cs
+++ /dev/null
@@ -1,74 +0,0 @@
-//-----------------------------------------------------------------------
-// <copyright file="EndUserAuthorizationSuccessAuthCodeResponse.cs" company="Outercurve Foundation">
-// Copyright (c) Outercurve Foundation. All rights reserved.
-// </copyright>
-//-----------------------------------------------------------------------
-
-namespace DotNetOpenAuth.OAuth2.Messages {
- using System;
- using System.Diagnostics.Contracts;
-
- using DotNetOpenAuth.Messaging;
- using DotNetOpenAuth.OAuth2.ChannelElements;
-
- /// <summary>
- /// The message sent by the Authorization Server to the Client via the user agent
- /// 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, IAuthorizationCodeCarryingRequest {
- /// <summary>
- /// Initializes a new instance of the <see cref="EndUserAuthorizationSuccessAuthCodeResponse"/> class.
- /// </summary>
- /// <param name="clientCallback">The URL to redirect to so the client receives the message. This may not be built into the request message if the client pre-registered the URL with the authorization server.</param>
- /// <param name="version">The protocol version.</param>
- internal EndUserAuthorizationSuccessAuthCodeResponse(Uri clientCallback, Version version)
- : base(clientCallback, version) {
- Requires.NotNull(version, "version");
- Requires.NotNull(clientCallback, "clientCallback");
- }
-
- /// <summary>
- /// Initializes a new instance of the <see cref="EndUserAuthorizationSuccessAuthCodeResponse"/> class.
- /// </summary>
- /// <param name="clientCallback">The URL to redirect to so the client receives the message. This may not be built into the request message if the client pre-registered the URL with the authorization server.</param>
- /// <param name="request">The authorization request from the user agent on behalf of the client.</param>
- internal EndUserAuthorizationSuccessAuthCodeResponse(Uri clientCallback, EndUserAuthorizationRequest request)
- : base(clientCallback, request) {
- Requires.NotNull(clientCallback, "clientCallback");
- Requires.NotNull(request, "request");
- ((IMessageWithClientState)this).ClientState = request.ClientState;
- }
-
- #region IAuthorizationCodeCarryingRequest Members
-
- /// <summary>
- /// Gets or sets the authorization code.
- /// </summary>
- string IAuthorizationCodeCarryingRequest.Code {
- get { return this.AuthorizationCode; }
- set { this.AuthorizationCode = value; }
- }
-
- /// <summary>
- /// Gets or sets the authorization that the token describes.
- /// </summary>
- AuthorizationCode IAuthorizationCodeCarryingRequest.AuthorizationDescription { get; set; }
-
- /// <summary>
- /// Gets the authorization that the code describes.
- /// </summary>
- IAuthorizationDescription IAuthorizationCarryingRequest.AuthorizationDescription {
- get { return ((IAuthorizationCodeCarryingRequest)this).AuthorizationDescription; }
- }
-
- #endregion
-
- /// <summary>
- /// Gets or sets the authorization code.
- /// </summary>
- /// <value>The authorization code.</value>
- [MessagePart(Protocol.code, IsRequired = true)]
- internal string AuthorizationCode { get; set; }
- }
-}
diff --git a/src/DotNetOpenAuth.OAuth2/OAuth2/Messages/EndUserAuthorizationSuccessResponseBase.cs b/src/DotNetOpenAuth.OAuth2/OAuth2/Messages/EndUserAuthorizationSuccessResponseBase.cs
deleted file mode 100644
index ef0010e..0000000
--- a/src/DotNetOpenAuth.OAuth2/OAuth2/Messages/EndUserAuthorizationSuccessResponseBase.cs
+++ /dev/null
@@ -1,71 +0,0 @@
-//-----------------------------------------------------------------------
-// <copyright file="EndUserAuthorizationSuccessResponseBase.cs" company="Outercurve Foundation">
-// Copyright (c) Outercurve Foundation. All rights reserved.
-// </copyright>
-//-----------------------------------------------------------------------
-
-namespace DotNetOpenAuth.OAuth2.Messages {
- using System;
- using System.Collections.Generic;
- using System.Diagnostics.CodeAnalysis;
- using System.Diagnostics.Contracts;
- using System.Security.Cryptography;
-
- using DotNetOpenAuth.Messaging;
- using DotNetOpenAuth.OAuth2.ChannelElements;
-
- /// <summary>
- /// The message sent by the Authorization Server to the Client via the user agent
- /// to indicate that user authorization was granted, and to return the user
- /// to the Client where they started their experience.
- /// </summary>
- public abstract class EndUserAuthorizationSuccessResponseBase : MessageBase, IMessageWithClientState {
- /// <summary>
- /// Initializes a new instance of the <see cref="EndUserAuthorizationSuccessResponseBase"/> class.
- /// </summary>
- /// <param name="clientCallback">The URL to redirect to so the client receives the message. This may not be built into the request message if the client pre-registered the URL with the authorization server.</param>
- /// <param name="version">The protocol version.</param>
- internal EndUserAuthorizationSuccessResponseBase(Uri clientCallback, Version version)
- : base(version, MessageTransport.Indirect, clientCallback) {
- Requires.NotNull(version, "version");
- Requires.NotNull(clientCallback, "clientCallback");
- this.Scope = new HashSet<string>(OAuthUtilities.ScopeStringComparer);
- }
-
- /// <summary>
- /// Initializes a new instance of the <see cref="EndUserAuthorizationSuccessResponseBase"/> class.
- /// </summary>
- /// <param name="clientCallback">The URL to redirect to so the client receives the message. This may not be built into the request message if the client pre-registered the URL with the authorization server.</param>
- /// <param name="request">The authorization request from the user agent on behalf of the client.</param>
- internal EndUserAuthorizationSuccessResponseBase(Uri clientCallback, EndUserAuthorizationRequest request)
- : base(request, clientCallback) {
- Requires.NotNull(clientCallback, "clientCallback");
- Requires.NotNull(request, "request");
- ((IMessageWithClientState)this).ClientState = request.ClientState;
- this.Scope = new HashSet<string>(OAuthUtilities.ScopeStringComparer);
- this.Scope.ResetContents(request.Scope);
- }
-
- /// <summary>
- /// Gets or sets some state as provided by the client in the authorization request.
- /// </summary>
- /// <value>An opaque value defined by the client.</value>
- /// <remarks>
- /// REQUIRED if the Client sent the value in the <see cref="EndUserAuthorizationRequest"/>.
- /// </remarks>
- [MessagePart(Protocol.state, IsRequired = false)]
- string IMessageWithClientState.ClientState { get; set; }
-
- /// <summary>
- /// Gets or sets the scope of the <see cref="AccessToken"/> if one is given; otherwise the scope of the authorization code.
- /// </summary>
- /// <value>The scope.</value>
- [SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly", Justification = "By design")]
- public ICollection<string> Scope { get; protected set; }
-
- /// <summary>
- /// Gets or sets the authorizing user's account name.
- /// </summary>
- internal string AuthorizingUsername { get; set; }
- }
-}
diff --git a/src/DotNetOpenAuth.OAuth2/OAuth2/Messages/GrantType.cs b/src/DotNetOpenAuth.OAuth2/OAuth2/Messages/GrantType.cs
deleted file mode 100644
index a26d405..0000000
--- a/src/DotNetOpenAuth.OAuth2/OAuth2/Messages/GrantType.cs
+++ /dev/null
@@ -1,42 +0,0 @@
-//-----------------------------------------------------------------------
-// <copyright file="GrantType.cs" company="Outercurve Foundation">
-// Copyright (c) Outercurve Foundation. All rights reserved.
-// </copyright>
-//-----------------------------------------------------------------------
-
-namespace DotNetOpenAuth.OAuth2.Messages {
- /// <summary>
- /// The types of authorizations that a client can use to obtain
- /// a refresh token and/or an access token.
- /// </summary>
- internal enum GrantType {
- /// <summary>
- /// The client is providing the authorization code previously obtained from an end user authorization response.
- /// </summary>
- AuthorizationCode,
-
- /// <summary>
- /// The client is providing the end user's username and password to the authorization server.
- /// </summary>
- Password,
-
- /// <summary>
- /// The client is providing an assertion it obtained from another source.
- /// </summary>
- Assertion,
-
- /// <summary>
- /// The client is providing a refresh token.
- /// </summary>
- RefreshToken,
-
- /// <summary>
- /// No authorization to access a user's data has been given. The client is requesting
- /// an access token authorized for its own private data. This fits the classic OAuth 1.0(a) "2-legged OAuth" scenario.
- /// </summary>
- /// <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>
- ClientCredentials,
- }
-}
diff --git a/src/DotNetOpenAuth.OAuth2/OAuth2/Messages/IAccessTokenRequest.cs b/src/DotNetOpenAuth.OAuth2/OAuth2/Messages/IAccessTokenRequest.cs
deleted file mode 100644
index 65378f9..0000000
--- a/src/DotNetOpenAuth.OAuth2/OAuth2/Messages/IAccessTokenRequest.cs
+++ /dev/null
@@ -1,37 +0,0 @@
-//-----------------------------------------------------------------------
-// <copyright file="IAccessTokenRequest.cs" company="Outercurve Foundation">
-// Copyright (c) Outercurve Foundation. All rights reserved.
-// </copyright>
-//-----------------------------------------------------------------------
-
-namespace DotNetOpenAuth.OAuth2.Messages {
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using DotNetOpenAuth.Messaging;
- using DotNetOpenAuth.OAuth2.ChannelElements;
-
- /// <summary>
- /// A request from a client that should be responded to directly with an access token.
- /// </summary>
- public interface IAccessTokenRequest : IMessage {
- /// <summary>
- /// Gets a value indicating whether the client requesting the access token has authenticated itself.
- /// </summary>
- /// <value>
- /// <c>false</c> for implicit grant requests; otherwise, <c>true</c>.
- /// </value>
- bool ClientAuthenticated { get; }
-
- /// <summary>
- /// Gets the identifier of the client authorized to access protected data.
- /// </summary>
- string ClientIdentifier { get; }
-
- /// <summary>
- /// Gets the scope of operations the client is allowed to invoke.
- /// </summary>
- HashSet<string> Scope { get; }
- }
-}
diff --git a/src/DotNetOpenAuth.OAuth2/OAuth2/Messages/IMessageWithClientState.cs b/src/DotNetOpenAuth.OAuth2/OAuth2/Messages/IMessageWithClientState.cs
deleted file mode 100644
index 71476f2..0000000
--- a/src/DotNetOpenAuth.OAuth2/OAuth2/Messages/IMessageWithClientState.cs
+++ /dev/null
@@ -1,21 +0,0 @@
-//-----------------------------------------------------------------------
-// <copyright file="IMessageWithClientState.cs" company="Outercurve Foundation">
-// Copyright (c) Outercurve Foundation. All rights reserved.
-// </copyright>
-//-----------------------------------------------------------------------
-
-namespace DotNetOpenAuth.OAuth2.Messages {
- using DotNetOpenAuth.Messaging;
-
- /// <summary>
- /// A message carrying client state the authorization server should preserve on behalf of the client
- /// during an authorization.
- /// </summary>
- internal interface IMessageWithClientState : IProtocolMessage {
- /// <summary>
- /// Gets or sets the state of the client.
- /// </summary>
- /// <value>The state of the client.</value>
- string ClientState { get; set; }
- }
-}
diff --git a/src/DotNetOpenAuth.OAuth2/OAuth2/Messages/OAuth 2 Messages.cd b/src/DotNetOpenAuth.OAuth2/OAuth2/Messages/OAuth 2 Messages.cd
deleted file mode 100644
index 05e3ad9..0000000
--- a/src/DotNetOpenAuth.OAuth2/OAuth2/Messages/OAuth 2 Messages.cd
+++ /dev/null
@@ -1,164 +0,0 @@
-<?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="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.AccessTokenAuthorizationCodeRequest" Collapsed="true">
- <Position X="8.5" Y="6.75" Width="3" />
- <TypeIdentifier>
- <HashCode>ACAAEAAAAAAAAAAAAAAAAAAQAAAAAAAAAAAgAAAATAA=</HashCode>
- <FileName>OAuth2\Messages\AccessTokenAuthorizationCodeRequest.cs</FileName>
- </TypeIdentifier>
- <Lollipop Position="0.2" />
- </Class>
- <Class Name="DotNetOpenAuth.OAuth2.Messages.AccessTokenClientCredentialsRequest" Collapsed="true">
- <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="8.5" Width="2.25" />
- <TypeIdentifier>
- <HashCode>AAAAAIAAAAAAAQAAAABAAAQAAAAAAAEQAAAAAAAAAAA=</HashCode>
- <FileName>OAuth2\Messages\AccessTokenFailedResponse.cs</FileName>
- </TypeIdentifier>
- <Lollipop Position="0.2" />
- </Class>
- <Class Name="DotNetOpenAuth.OAuth2.Messages.AccessTokenRefreshRequest" Collapsed="true">
- <Position X="8.5" Y="9.75" Width="2.25" />
- <TypeIdentifier>
- <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="5.75" Y="5.75" Width="2" />
- <TypeIdentifier>
- <HashCode>AAAAAAAAQABAAAAAAAAAAAAQAAAAAAAAAAAAAAAACAA=</HashCode>
- <FileName>OAuth2\Messages\AccessTokenRequestBase.cs</FileName>
- </TypeIdentifier>
- <Lollipop Position="0.2" />
- </Class>
- <Class Name="DotNetOpenAuth.OAuth2.Messages.AccessTokenResourceOwnerPasswordCredentialsRequest" Collapsed="true">
- <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="7.5" Width="2.25" />
- <TypeIdentifier>
- <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="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="4.5" Width="2.75" />
- <TypeIdentifier>
- <HashCode>AAAAAIAAAAAAAQAAAAAAAAgAAAAAAAEAAAAAAAAAAAA=</HashCode>
- <FileName>OAuth2\Messages\EndUserAuthorizationFailedResponse.cs</FileName>
- </TypeIdentifier>
- <Lollipop Position="0.2" />
- </Class>
- <Class Name="DotNetOpenAuth.OAuth2.Messages.EndUserAuthorizationRequest" Collapsed="true">
- <Position X="3.25" Y="0.5" Width="2.25" />
- <TypeIdentifier>
- <HashCode>AAAAAAAAQABAACAAAAAAAACAAAQAAAQAAAAAAAAAQAA=</HashCode>
- <FileName>OAuth2\Messages\EndUserAuthorizationRequest.cs</FileName>
- </TypeIdentifier>
- <Lollipop Position="0.2" />
- </Class>
- <Class Name="DotNetOpenAuth.OAuth2.Messages.EndUserAuthorizationSuccessAccessTokenResponse" Collapsed="true">
- <Position X="6.25" Y="3.75" Width="3.75" />
- <TypeIdentifier>
- <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.25" Y="2.5" Width="3.5" />
- <TypeIdentifier>
- <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="1.5" Width="2.75" />
- <TypeIdentifier>
- <HashCode>AAACAAAAAAAAACAAAAAAAAgAAAAAAAAAAEAAAAAAAAA=</HashCode>
- <FileName>OAuth2\Messages\EndUserAuthorizationSuccessResponseBase.cs</FileName>
- </TypeIdentifier>
- <Lollipop Position="0.2" />
- </Class>
- <Class Name="DotNetOpenAuth.OAuth2.Messages.AccessProtectedResourceRequest" Collapsed="true">
- <Position X="3.25" Y="9.75" Width="2.5" />
- <TypeIdentifier>
- <HashCode>AAAAEAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAgAAAABgA=</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="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>AAAAAAAAAAAAACAAAAAAAAAAAAAAAAAAAAAAAAAACAA=</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>
- <HashCode>AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAAAA=</HashCode>
- <FileName>OAuth2\Messages\IMessageWithClientState.cs</FileName>
- </TypeIdentifier>
- </Interface>
- <Interface Name="DotNetOpenAuth.OAuth2.ChannelElements.IAuthorizationCarryingRequest">
- <Position X="11.75" Y="2" Width="2.5" />
- <TypeIdentifier>
- <HashCode>AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADAEAAAAA=</HashCode>
- <FileName>OAuth2\ChannelElements\IAuthorizationCarryingRequest.cs</FileName>
- </TypeIdentifier>
- </Interface>
- <Enum Name="DotNetOpenAuth.OAuth2.Messages.EndUserAuthorizationResponseType">
- <Position X="8" Y="0.5" Width="3" />
- <TypeIdentifier>
- <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>ACAAAAAAQAAAAAQAAgAAAAAAAAAAAAACAAAAAAAAAAA=</HashCode>
- <FileName>OAuth2\Messages\GrantType.cs</FileName>
- </TypeIdentifier>
- </Enum>
- <Font Name="Segoe UI" Size="9" />
-</ClassDiagram> \ No newline at end of file
diff --git a/src/DotNetOpenAuth.OAuth2/OAuth2/Messages/ScopedAccessTokenRequest.cs b/src/DotNetOpenAuth.OAuth2/OAuth2/Messages/ScopedAccessTokenRequest.cs
deleted file mode 100644
index 0ea6efb..0000000
--- a/src/DotNetOpenAuth.OAuth2/OAuth2/Messages/ScopedAccessTokenRequest.cs
+++ /dev/null
@@ -1,41 +0,0 @@
-//-----------------------------------------------------------------------
-// <copyright file="ScopedAccessTokenRequest.cs" company="Outercurve Foundation">
-// Copyright (c) Outercurve Foundation. 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; }
-
- /// <summary>
- /// Gets the scope of operations the client is allowed to invoke.
- /// </summary>
- protected override HashSet<string> RequestedScope {
- get { return this.Scope; }
- }
- }
-}
diff --git a/src/DotNetOpenAuth.OAuth2/OAuth2/OAuthStrings.Designer.cs b/src/DotNetOpenAuth.OAuth2/OAuth2/OAuthStrings.Designer.cs
index 6ce3b53..051d0d5 100644
--- a/src/DotNetOpenAuth.OAuth2/OAuth2/OAuthStrings.Designer.cs
+++ b/src/DotNetOpenAuth.OAuth2/OAuth2/OAuthStrings.Designer.cs
@@ -1,7 +1,7 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
-// Runtime Version:4.0.30319.239
+// Runtime Version:4.0.30319.17614
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
@@ -70,15 +70,6 @@ namespace DotNetOpenAuth.OAuth2 {
}
/// <summary>
- /// Looks up a localized string similar to The requested access scope (&quot;{0}&quot;) exceeds the grant scope (&quot;{1}&quot;)..
- /// </summary>
- internal static string AccessScopeExceedsGrantScope {
- get {
- return ResourceManager.GetString("AccessScopeExceedsGrantScope", resourceCulture);
- }
- }
-
- /// <summary>
/// Looks up a localized string similar to The access token contains characters that must not appear in the HTTP Authorization header..
/// </summary>
internal static string AccessTokenInvalidForHttpAuthorizationHeader {
@@ -88,33 +79,6 @@ namespace DotNetOpenAuth.OAuth2 {
}
/// <summary>
- /// Looks up a localized string similar to Failed to obtain access token. Authorization Server reports reason: {0}.
- /// </summary>
- internal static string CannotObtainAccessTokenWithReason {
- get {
- return ResourceManager.GetString("CannotObtainAccessTokenWithReason", resourceCulture);
- }
- }
-
- /// <summary>
- /// Looks up a localized string similar to The callback URL ({0}) is not allowed for this client..
- /// </summary>
- internal static string ClientCallbackDisallowed {
- get {
- return ResourceManager.GetString("ClientCallbackDisallowed", resourceCulture);
- }
- }
-
- /// <summary>
- /// Looks up a localized string similar to Failure looking up secret for client or token..
- /// </summary>
- internal static string ClientOrTokenSecretNotFound {
- get {
- return ResourceManager.GetString("ClientOrTokenSecretNotFound", resourceCulture);
- }
- }
-
- /// <summary>
/// Looks up a localized string similar to This message can only be sent over HTTPS..
/// </summary>
internal static string HttpsRequired {
@@ -124,15 +88,6 @@ namespace DotNetOpenAuth.OAuth2 {
}
/// <summary>
- /// Looks up a localized string similar to Failed to obtain access token due to invalid Client Identifier or Client Secret..
- /// </summary>
- internal static string InvalidClientCredentials {
- get {
- return ResourceManager.GetString("InvalidClientCredentials", resourceCulture);
- }
- }
-
- /// <summary>
/// Looks up a localized string similar to The scope token &quot;{0}&quot; contains illegal characters or is empty..
/// </summary>
internal static string InvalidScopeToken {
@@ -142,15 +97,6 @@ namespace DotNetOpenAuth.OAuth2 {
}
/// <summary>
- /// Looks up a localized string similar to No callback URI was available for this request..
- /// </summary>
- internal static string NoCallback {
- get {
- return ResourceManager.GetString("NoCallback", resourceCulture);
- }
- }
-
- /// <summary>
/// Looks up a localized string similar to Refresh tokens should not be granted without the request including an access grant..
/// </summary>
internal static string NoGrantNoRefreshToken {
@@ -160,15 +106,6 @@ namespace DotNetOpenAuth.OAuth2 {
}
/// <summary>
- /// Looks up a localized string similar to The request message type {0} should not be responded to with a refresh token..
- /// </summary>
- internal static string RefreshTokenInappropriateForRequestType {
- get {
- return ResourceManager.GetString("RefreshTokenInappropriateForRequestType", resourceCulture);
- }
- }
-
- /// <summary>
/// Looks up a localized string similar to The return value of {0}.{1} should never be null..
/// </summary>
internal static string ResultShouldNotBeNull {
@@ -185,14 +122,5 @@ namespace DotNetOpenAuth.OAuth2 {
return ResourceManager.GetString("ScopesMayNotContainSpaces", resourceCulture);
}
}
-
- /// <summary>
- /// Looks up a localized string similar to Unexpected response Content-Type {0}.
- /// </summary>
- internal static string UnexpectedResponseContentType {
- get {
- return ResourceManager.GetString("UnexpectedResponseContentType", resourceCulture);
- }
- }
}
}
diff --git a/src/DotNetOpenAuth.OAuth2/OAuth2/OAuthStrings.resx b/src/DotNetOpenAuth.OAuth2/OAuth2/OAuthStrings.resx
index af1a955..4d9d248 100644
--- a/src/DotNetOpenAuth.OAuth2/OAuth2/OAuthStrings.resx
+++ b/src/DotNetOpenAuth.OAuth2/OAuth2/OAuthStrings.resx
@@ -120,46 +120,22 @@
<data name="AbsoluteUriRequired" xml:space="preserve">
<value>The value for message part "{0}" must be an absolute URI.</value>
</data>
- <data name="AccessScopeExceedsGrantScope" xml:space="preserve">
- <value>The requested access scope ("{0}") exceeds the grant scope ("{1}").</value>
- </data>
<data name="AccessTokenInvalidForHttpAuthorizationHeader" xml:space="preserve">
<value>The access token contains characters that must not appear in the HTTP Authorization header.</value>
</data>
- <data name="CannotObtainAccessTokenWithReason" xml:space="preserve">
- <value>Failed to obtain access token. Authorization Server reports reason: {0}</value>
- </data>
- <data name="ClientCallbackDisallowed" xml:space="preserve">
- <value>The callback URL ({0}) is not allowed for this client.</value>
- </data>
- <data name="ClientOrTokenSecretNotFound" xml:space="preserve">
- <value>Failure looking up secret for client or token.</value>
- </data>
<data name="HttpsRequired" xml:space="preserve">
<value>This message can only be sent over HTTPS.</value>
</data>
- <data name="InvalidClientCredentials" xml:space="preserve">
- <value>Failed to obtain access token due to invalid Client Identifier or Client Secret.</value>
- </data>
<data name="InvalidScopeToken" xml:space="preserve">
<value>The scope token "{0}" contains illegal characters or is empty.</value>
</data>
- <data name="NoCallback" xml:space="preserve">
- <value>No callback URI was available for this request.</value>
- </data>
<data name="NoGrantNoRefreshToken" xml:space="preserve">
<value>Refresh tokens should not be granted without the request including an access grant.</value>
</data>
- <data name="RefreshTokenInappropriateForRequestType" xml:space="preserve">
- <value>The request message type {0} should not be responded to with a refresh token.</value>
- </data>
<data name="ResultShouldNotBeNull" xml:space="preserve">
<value>The return value of {0}.{1} should never be null.</value>
</data>
<data name="ScopesMayNotContainSpaces" xml:space="preserve">
<value>Individual scopes may not contain spaces.</value>
</data>
- <data name="UnexpectedResponseContentType" xml:space="preserve">
- <value>Unexpected response Content-Type {0}</value>
- </data>
</root> \ No newline at end of file
diff --git a/src/DotNetOpenAuth.OAuth2/OAuth2/OAuthUtilities.cs b/src/DotNetOpenAuth.OAuth2/OAuth2/OAuthUtilities.cs
index dd7909b..661d102 100644
--- a/src/DotNetOpenAuth.OAuth2/OAuth2/OAuthUtilities.cs
+++ b/src/DotNetOpenAuth.OAuth2/OAuth2/OAuthUtilities.cs
@@ -24,9 +24,24 @@ namespace DotNetOpenAuth.OAuth2 {
public static readonly StringComparer ScopeStringComparer = StringComparer.Ordinal;
/// <summary>
+ /// The string "Basic ".
+ /// </summary>
+ private const string HttpBasicAuthScheme = "Basic ";
+
+ /// <summary>
/// The delimiter between scope elements.
/// </summary>
- private static char[] scopeDelimiter = new char[] { ' ' };
+ private static readonly char[] scopeDelimiter = new char[] { ' ' };
+
+ /// <summary>
+ /// A colon, in a 1-length character array.
+ /// </summary>
+ private static readonly char[] ColonSeparator = new char[] { ':' };
+
+ /// <summary>
+ /// The encoding to use when preparing credentials for transit in HTTP Basic base64 encoding form.
+ /// </summary>
+ private static readonly Encoding HttpBasicEncoding = Encoding.UTF8;
/// <summary>
/// The characters that may appear in an access token that is included in an HTTP Authorization header.
@@ -35,9 +50,9 @@ namespace DotNetOpenAuth.OAuth2 {
/// This is defined in OAuth 2.0 DRAFT 10, section 5.1.1. (http://tools.ietf.org/id/draft-ietf-oauth-v2-10.html#authz-header)
/// </remarks>
private static string accessTokenAuthorizationHeaderAllowedCharacters = MessagingUtilities.UppercaseLetters +
- MessagingUtilities.LowercaseLetters +
- MessagingUtilities.Digits +
- @"!#$%&'()*+-./:<=>?@[]^_`{|}~\,;";
+ MessagingUtilities.LowercaseLetters +
+ MessagingUtilities.Digits +
+ @"!#$%&'()*+-./:<=>?@[]^_`{|}~\,;";
/// <summary>
/// Determines whether one given scope is a subset of another scope.
@@ -131,24 +146,43 @@ namespace DotNetOpenAuth.OAuth2 {
}
/// <summary>
- /// Gets information about the client with a given identifier.
+ /// Applies the HTTP Authorization header for HTTP Basic authentication.
/// </summary>
- /// <param name="authorizationServer">The authorization server.</param>
- /// <param name="clientIdentifier">The client identifier.</param>
- /// <returns>The client information. Never null.</returns>
- internal static IClientDescription GetClientOrThrow(this IAuthorizationServer authorizationServer, string clientIdentifier) {
- Requires.NotNullOrEmpty(clientIdentifier, "clientIdentifier");
- Contract.Ensures(Contract.Result<IClientDescription>() != null);
-
- try {
- var result = authorizationServer.GetClient(clientIdentifier);
- ErrorUtilities.VerifyHost(result != null, OAuthStrings.ResultShouldNotBeNull, authorizationServer.GetType().FullName, "GetClient(string)");
- return result;
- } catch (KeyNotFoundException ex) {
- throw ErrorUtilities.Wrap(ex, OAuthStrings.ClientOrTokenSecretNotFound);
- } catch (ArgumentException ex) {
- throw ErrorUtilities.Wrap(ex, OAuthStrings.ClientOrTokenSecretNotFound);
+ /// <param name="headers">The headers collection to set the authorization header to.</param>
+ /// <param name="userName">The username. Cannot be empty.</param>
+ /// <param name="password">The password. Cannot be null.</param>
+ internal static void ApplyHttpBasicAuth(WebHeaderCollection headers, string userName, string password) {
+ Requires.NotNull(headers, "headers");
+ Requires.NotNullOrEmpty(userName, "userName");
+ Requires.NotNull(password, "password");
+
+ string concat = userName + ":" + password;
+ byte[] bits = HttpBasicEncoding.GetBytes(concat);
+ string base64 = Convert.ToBase64String(bits);
+ string header = HttpBasicAuthScheme + base64;
+ headers[HttpRequestHeader.Authorization] = header;
+ }
+
+ /// <summary>
+ /// Extracts the username and password from an HTTP Basic authorized web header.
+ /// </summary>
+ /// <param name="headers">The incoming web headers.</param>
+ /// <returns>The network credentials; or <c>null</c> if none could be discovered in the request.</returns>
+ internal static NetworkCredential ParseHttpBasicAuth(WebHeaderCollection headers) {
+ Requires.NotNull(headers, "headers");
+
+ string authorizationHeader = headers[HttpRequestHeaders.Authorization];
+ if (authorizationHeader != null && authorizationHeader.StartsWith(HttpBasicAuthScheme, StringComparison.Ordinal)) {
+ string base64 = authorizationHeader.Substring(HttpBasicAuthScheme.Length);
+ byte[] bits = Convert.FromBase64String(base64);
+ string usernameColonPassword = HttpBasicEncoding.GetString(bits);
+ string[] usernameAndPassword = usernameColonPassword.Split(ColonSeparator, 2);
+ if (usernameAndPassword.Length == 2) {
+ return new NetworkCredential(usernameAndPassword[0], usernameAndPassword[1]);
+ }
}
+
+ return null;
}
}
}
diff --git a/src/DotNetOpenAuth.OAuth2/OAuth2/Protocol.cs b/src/DotNetOpenAuth.OAuth2/OAuth2/Protocol.cs
index 19fe845..986af13 100644
--- a/src/DotNetOpenAuth.OAuth2/OAuth2/Protocol.cs
+++ b/src/DotNetOpenAuth.OAuth2/OAuth2/Protocol.cs
@@ -45,11 +45,6 @@ namespace DotNetOpenAuth.OAuth2 {
internal const string BearerTokenEncodedUrlParameterName = "access_token";
/// <summary>
- /// The "type" string.
- /// </summary>
- internal const string type = "type";
-
- /// <summary>
/// The "state" string.
/// </summary>
internal const string state = "state";
@@ -60,26 +55,6 @@ namespace DotNetOpenAuth.OAuth2 {
internal const string redirect_uri_mismatch = "redirect_uri_mismatch";
/// <summary>
- /// The "bad_verification_code" string.
- /// </summary>
- internal const string bad_verification_code = "bad_verification_code";
-
- /// <summary>
- /// The "incorrect_client_credentials" string.
- /// </summary>
- internal const string incorrect_client_credentials = "incorrect_client_credentials";
-
- /// <summary>
- /// The "unauthorized_client" string.
- /// </summary>
- internal const string unauthorized_client = "unauthorized_client";
-
- /// <summary>
- /// The "authorization_expired" string.
- /// </summary>
- internal const string authorization_expired = "authorization_expired";
-
- /// <summary>
/// The "redirect_uri" string.
/// </summary>
internal const string redirect_uri = "redirect_uri";
@@ -95,11 +70,6 @@ namespace DotNetOpenAuth.OAuth2 {
internal const string scope = "scope";
/// <summary>
- /// The "immediate" string.
- /// </summary>
- internal const string immediate = "immediate";
-
- /// <summary>
/// The "client_secret" string.
/// </summary>
internal const string client_secret = "client_secret";
@@ -110,21 +80,6 @@ namespace DotNetOpenAuth.OAuth2 {
internal const string code = "code";
/// <summary>
- /// The "user_code" string.
- /// </summary>
- internal const string user_code = "user_code";
-
- /// <summary>
- /// The "verification_uri" string.
- /// </summary>
- internal const string verification_uri = "verification_uri";
-
- /// <summary>
- /// The "interval" string.
- /// </summary>
- internal const string interval = "interval";
-
- /// <summary>
/// The "error" string.
/// </summary>
internal const string error = "error";
@@ -135,11 +90,6 @@ namespace DotNetOpenAuth.OAuth2 {
internal const string access_token = "access_token";
/// <summary>
- /// The "access_token_secret" string.
- /// </summary>
- internal const string access_token_secret = "access_token_secret";
-
- /// <summary>
/// The "token_type" string.
/// </summary>
internal const string token_type = "token_type";
@@ -155,11 +105,6 @@ namespace DotNetOpenAuth.OAuth2 {
internal const string expires_in = "expires_in";
/// <summary>
- /// The "expired_delegation_code" string.
- /// </summary>
- internal const string expired_delegation_code = "expired_delegation_code";
-
- /// <summary>
/// The "username" string.
/// </summary>
internal const string username = "username";
@@ -170,26 +115,6 @@ namespace DotNetOpenAuth.OAuth2 {
internal const string password = "password";
/// <summary>
- /// The "format" string.
- /// </summary>
- internal const string format = "format";
-
- /// <summary>
- /// The "assertion" string.
- /// </summary>
- internal const string assertion = "assertion";
-
- /// <summary>
- /// The "assertion_type" string.
- /// </summary>
- internal const string assertion_type = "assertion_type";
-
- /// <summary>
- /// The "user_denied" string.
- /// </summary>
- internal const string user_denied = "user_denied";
-
- /// <summary>
/// Gets the <see cref="Protocol"/> instance with values initialized for V1.0 of the protocol.
/// </summary>
internal static readonly Protocol V20 = new Protocol {
@@ -286,27 +211,38 @@ namespace DotNetOpenAuth.OAuth2 {
internal static class AccessTokenRequestErrorCodes
{
/// <summary>
- /// The request is missing a required parameter, includes an unknown parameter or parameter value, repeats a parameter, includes multiple credentials, utilizes more than one mechanism for authenticating the client, or is otherwise malformed.
+ /// The request is missing a required parameter, includes an unknown parameter or parameter value, repeats a parameter,
+ /// includes multiple credentials, utilizes more than one mechanism for authenticating the client, or is otherwise malformed.
/// </summary>
internal const string InvalidRequest = "invalid_request";
/// <summary>
- /// The client is not authorized to use the access grant type provided.
+ /// Client authentication failed (e.g. unknown client, no client authentication included, or unsupported authentication method).
+ /// The authorization server MAY return an HTTP 401 (Unauthorized) status code to indicate which HTTP authentication schemes are supported.
+ /// If the client attempted to authenticate via the Authorization request header field, the authorization server MUST respond with
+ /// an HTTP 401 (Unauthorized) status code, and include the WWW-Authenticate response header field matching the authentication scheme
+ /// used by the client.
/// </summary>
- internal const string UnauthorizedClient = "unauthorized_client";
+ internal const string InvalidClient = "invalid_client";
/// <summary>
- /// The resource owner or authorization server denied the request.
+ /// The provided authorization grant (e.g. authorization code, resource owner credentials) or refresh token is invalid, expired,
+ /// revoked, does not match the redirection URI used in the authorization request, or was issued to another client.
/// </summary>
- internal const string AccessDenied = "access_denied";
+ internal const string InvalidGrant = "invalid_grant";
+
+ /// <summary>
+ /// The authenticated client is not authorized to use this authorization grant type.
+ /// </summary>
+ internal const string UnauthorizedClient = "unauthorized_client";
/// <summary>
- /// The authorization server does not support obtaining an access token using this method.
+ /// The authorization grant type is not supported by the authorization server.
/// </summary>
- internal const string UnsupportedGrantType = "unsupported_response_type";
+ internal const string UnsupportedGrantType = "unsupported_grant_type";
/// <summary>
- /// The requested scope is invalid, unknown, malformed, or exceeds the previously granted scope.
+ /// The requested scope is invalid, unknown, malformed, or exceeds the scope granted by the resource owner.
/// </summary>
internal const string InvalidScope = "invalid_scope";
}
diff --git a/src/DotNetOpenAuth.OAuth2/OAuth2/StandardAccessTokenAnalyzer.cs b/src/DotNetOpenAuth.OAuth2/OAuth2/StandardAccessTokenAnalyzer.cs
deleted file mode 100644
index 636f490..0000000
--- a/src/DotNetOpenAuth.OAuth2/OAuth2/StandardAccessTokenAnalyzer.cs
+++ /dev/null
@@ -1,66 +0,0 @@
-//-----------------------------------------------------------------------
-// <copyright file="StandardAccessTokenAnalyzer.cs" company="Outercurve Foundation">
-// Copyright (c) Outercurve Foundation. All rights reserved.
-// </copyright>
-//-----------------------------------------------------------------------
-
-namespace DotNetOpenAuth.OAuth2 {
- using System;
- using System.Collections.Generic;
- using System.Diagnostics.Contracts;
- using System.Security.Cryptography;
- using DotNetOpenAuth.Messaging;
- using DotNetOpenAuth.OAuth2.ChannelElements;
-
- /// <summary>
- /// An access token reader that understands DotNetOpenAuth authorization server issued tokens.
- /// </summary>
- public class StandardAccessTokenAnalyzer : IAccessTokenAnalyzer {
- /// <summary>
- /// Initializes a new instance of the <see cref="StandardAccessTokenAnalyzer"/> class.
- /// </summary>
- /// <param name="authorizationServerPublicSigningKey">The crypto service provider with the authorization server public signing key.</param>
- /// <param name="resourceServerPrivateEncryptionKey">The crypto service provider with the resource server private encryption key.</param>
- public StandardAccessTokenAnalyzer(RSACryptoServiceProvider authorizationServerPublicSigningKey, RSACryptoServiceProvider resourceServerPrivateEncryptionKey) {
- Requires.NotNull(authorizationServerPublicSigningKey, "authorizationServerPublicSigningKey");
- Requires.NotNull(resourceServerPrivateEncryptionKey, "resourceServerPrivateEncryptionKey");
- Requires.True(!resourceServerPrivateEncryptionKey.PublicOnly, "resourceServerPrivateEncryptionKey");
- this.AuthorizationServerPublicSigningKey = authorizationServerPublicSigningKey;
- this.ResourceServerPrivateEncryptionKey = resourceServerPrivateEncryptionKey;
- }
-
- /// <summary>
- /// Gets the authorization server public signing key.
- /// </summary>
- /// <value>The authorization server public signing key.</value>
- public RSACryptoServiceProvider AuthorizationServerPublicSigningKey { get; private set; }
-
- /// <summary>
- /// Gets the resource server private encryption key.
- /// </summary>
- /// <value>The resource server private encryption key.</value>
- public RSACryptoServiceProvider ResourceServerPrivateEncryptionKey { get; private set; }
-
- /// <summary>
- /// Reads an access token to find out what data it authorizes access to.
- /// </summary>
- /// <param name="message">The message carrying the access token.</param>
- /// <param name="accessToken">The access token.</param>
- /// <param name="user">The user whose data is accessible with this access token.</param>
- /// <param name="scope">The scope of access authorized by this access token.</param>
- /// <returns>
- /// A value indicating whether this access token is valid.
- /// </returns>
- /// <remarks>
- /// This method also responsible to throw a <see cref="ProtocolException"/> or return
- /// <c>false</c> when the access token is expired, invalid, or from an untrusted authorization server.
- /// </remarks>
- public virtual bool TryValidateAccessToken(IDirectedProtocolMessage message, string accessToken, out string user, out HashSet<string> scope) {
- var accessTokenFormatter = AccessToken.CreateFormatter(this.AuthorizationServerPublicSigningKey, this.ResourceServerPrivateEncryptionKey);
- var token = accessTokenFormatter.Deserialize(message, accessToken, Protocol.access_token);
- user = token.User;
- scope = new HashSet<string>(token.Scope, OAuthUtilities.ScopeStringComparer);
- return true;
- }
- }
-}