summaryrefslogtreecommitdiffstats
path: root/src/DotNetOpenAuth.OAuth2
diff options
context:
space:
mode:
authorAndrew Arnott <andrewarnott@gmail.com>2012-03-16 22:41:46 -0700
committerAndrew Arnott <andrewarnott@gmail.com>2012-03-16 22:41:46 -0700
commit1068d8217e19c6ac300a1077e13c2b1dae01bc4b (patch)
tree018d648707e90520f32f97462dbac78d12da2cb6 /src/DotNetOpenAuth.OAuth2
parent9f35726ca8389fb29aee849a8133e6672c4c55d6 (diff)
downloadDotNetOpenAuth-1068d8217e19c6ac300a1077e13c2b1dae01bc4b.zip
DotNetOpenAuth-1068d8217e19c6ac300a1077e13c2b1dae01bc4b.tar.gz
DotNetOpenAuth-1068d8217e19c6ac300a1077e13c2b1dae01bc4b.tar.bz2
Redistributed OAuth2 code into their more specific assemblies.
Diffstat (limited to 'src/DotNetOpenAuth.OAuth2')
-rw-r--r--src/DotNetOpenAuth.OAuth2/DotNetOpenAuth.OAuth2.csproj37
-rw-r--r--src/DotNetOpenAuth.OAuth2/OAuth2/AccessTokenParameters.cs80
-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/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/IAuthorizationServer.cs264
-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/ScopedAccessTokenRequest.cs41
-rw-r--r--src/DotNetOpenAuth.OAuth2/OAuth2/OAuthUtilities.cs21
-rw-r--r--src/DotNetOpenAuth.OAuth2/Properties/AssemblyInfo.cs2
40 files changed, 83 insertions, 3049 deletions
diff --git a/src/DotNetOpenAuth.OAuth2/DotNetOpenAuth.OAuth2.csproj b/src/DotNetOpenAuth.OAuth2/DotNetOpenAuth.OAuth2.csproj
index 438a21d..f22a7c5 100644
--- a/src/DotNetOpenAuth.OAuth2/DotNetOpenAuth.OAuth2.csproj
+++ b/src/DotNetOpenAuth.OAuth2/DotNetOpenAuth.OAuth2.csproj
@@ -19,61 +19,26 @@
</PropertyGroup>
<ItemGroup>
<Compile Include="GlobalSuppressions.cs" />
+ <Compile Include="OAuth2\AccessTokenParameters.cs" />
<Compile Include="OAuth2\AuthorizationState.cs" />
- <Compile Include="OAuth2\ChannelElements\AccessRequestBindingElement.cs" />
<Compile Include="OAuth2\ChannelElements\AccessToken.cs" />
- <Compile Include="OAuth2\ChannelElements\AccessTokenBindingElement.cs" />
<Compile Include="OAuth2\ChannelElements\AuthorizationDataBag.cs" />
- <Compile Include="OAuth2\ChannelElements\AuthServerBindingElementBase.cs" />
- <Compile Include="OAuth2\ChannelElements\GrantTypeEncoder.cs" />
- <Compile Include="OAuth2\ChannelElements\EndUserAuthorizationResponseTypeEncoder.cs" />
<Compile Include="OAuth2\ChannelElements\IAccessTokenCarryingRequest.cs" />
- <Compile Include="OAuth2\ChannelElements\IAuthorizationCodeCarryingRequest.cs" />
- <Compile Include="OAuth2\ChannelElements\IOAuth2ChannelWithAuthorizationServer.cs" />
- <Compile Include="OAuth2\ChannelElements\IRefreshTokenCarryingRequest.cs" />
- <Compile Include="OAuth2\ChannelElements\OAuth2ChannelBase.cs" />
- <Compile Include="OAuth2\ChannelElements\OAuth2ClientChannel.cs" />
<Compile Include="OAuth2\ChannelElements\ScopeEncoder.cs" />
<Compile Include="OAuth2\ChannelElements\IAuthorizationDescription.cs" />
<Compile Include="OAuth2\ChannelElements\IAuthorizationCarryingRequest.cs" />
- <Compile Include="OAuth2\ChannelElements\OAuth2ResourceServerChannel.cs" />
- <Compile Include="OAuth2\ChannelElements\RefreshToken.cs" />
- <Compile Include="OAuth2\ChannelElements\AuthorizationCode.cs" />
- <Compile Include="OAuth2\ChannelElements\AuthorizationCodeBindingElement.cs" />
- <Compile Include="OAuth2\ChannelElements\AuthServerAllFlowsBindingElement.cs" />
<Compile Include="OAuth2\ClientDescription.cs" />
<Compile Include="OAuth2\ClientType.cs" />
<Compile Include="OAuth2\IAccessTokenAnalyzer.cs" />
- <Compile Include="OAuth2\IAuthorizationServer.cs" />
<Compile Include="OAuth2\IAuthorizationState.cs" />
<Compile Include="OAuth2\IClientAuthorizationTracker.cs" />
<Compile Include="OAuth2\IClientDescription.cs" />
<Compile Include="OAuth2\Messages\AccessProtectedResourceRequest.cs" />
- <Compile Include="OAuth2\Messages\AccessTokenAuthorizationCodeRequest.cs" />
- <Compile Include="OAuth2\Messages\AccessTokenResourceOwnerPasswordCredentialsRequest.cs" />
- <Compile Include="OAuth2\Messages\AccessTokenRequestBase.cs" />
- <Compile Include="OAuth2\Messages\AccessTokenClientCredentialsRequest.cs" />
- <Compile Include="OAuth2\Messages\AuthenticatedClientRequestBase.cs" />
- <Compile Include="OAuth2\Messages\EndUserAuthorizationImplicitRequest.cs" />
- <Compile Include="OAuth2\Messages\EndUserAuthorizationSuccessAccessTokenResponse.cs" />
- <Compile Include="OAuth2\Messages\EndUserAuthorizationFailedResponse.cs" />
- <Compile Include="OAuth2\Messages\EndUserAuthorizationSuccessAuthCodeResponse.cs" />
- <Compile Include="OAuth2\Messages\GrantType.cs" />
- <Compile Include="OAuth2\Messages\AccessTokenRefreshRequest.cs" />
- <Compile Include="OAuth2\Messages\EndUserAuthorizationResponseType.cs" />
- <Compile Include="OAuth2\Messages\IAccessTokenRequest.cs" />
- <Compile Include="OAuth2\Messages\IMessageWithClientState.cs" />
- <Compile Include="OAuth2\Messages\ScopedAccessTokenRequest.cs" />
<Compile Include="OAuth2\Messages\UnauthorizedResponse.cs" />
- <Compile Include="OAuth2\Messages\AccessTokenFailedResponse.cs" />
- <Compile Include="OAuth2\Messages\AccessTokenSuccessResponse.cs" />
- <Compile Include="OAuth2\Messages\EndUserAuthorizationSuccessResponseBase.cs" />
<Compile Include="OAuth2\StandardAccessTokenAnalyzer.cs" />
<Compile Include="OAuth2\OAuthUtilities.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
- <Compile Include="OAuth2\ChannelElements\OAuth2AuthorizationServerChannel.cs" />
<Compile Include="OAuth2\Messages\MessageBase.cs" />
- <Compile Include="OAuth2\Messages\EndUserAuthorizationRequest.cs" />
<Compile Include="OAuth2\Protocol.cs" />
<Compile Include="OAuth2\OAuthStrings.Designer.cs">
<AutoGen>True</AutoGen>
diff --git a/src/DotNetOpenAuth.OAuth2/OAuth2/AccessTokenParameters.cs b/src/DotNetOpenAuth.OAuth2/OAuth2/AccessTokenParameters.cs
new file mode 100644
index 0000000..a214f20
--- /dev/null
+++ b/src/DotNetOpenAuth.OAuth2/OAuth2/AccessTokenParameters.cs
@@ -0,0 +1,80 @@
+//-----------------------------------------------------------------------
+// <copyright file="AccessTokenParameters.cs" company="Andrew Arnott">
+// Copyright (c) Andrew Arnott. All rights reserved.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace DotNetOpenAuth.OAuth2 {
+ using System;
+ using System.Collections.Generic;
+ using System.Linq;
+ using System.Security.Cryptography;
+ using System.Text;
+
+ /// <summary>
+ /// Describes the parameters to be fed into creating a response to an access token request.
+ /// </summary>
+ public class AccessTokenParameters : IDisposable {
+ /// <summary>
+ /// Initializes a new instance of the <see cref="AccessTokenParameters"/> class.
+ /// </summary>
+ public AccessTokenParameters() {
+ this.IncludeRefreshToken = true;
+ this.AccessTokenLifetime = TimeSpan.FromHours(1);
+ }
+
+ /// <summary>
+ /// Gets or sets the access token lifetime.
+ /// </summary>
+ /// <value>
+ /// A positive timespan.
+ /// </value>
+ /// <remarks>
+ /// Note that within this lifetime, authorization <i>may</i> not be revokable.
+ /// Short lifetimes are recommended (e.g. one hour), particularly when the client is not authenticated or
+ /// the resources to which access is being granted are sensitive.
+ /// </remarks>
+ public TimeSpan AccessTokenLifetime { get; set; }
+
+ /// <summary>
+ /// Gets or sets the key to encrypt the access token.
+ /// </summary>
+ public RSACryptoServiceProvider ResourceServerEncryptionKey { get; set; }
+
+ /// <summary>
+ /// Gets or sets a value indicating whether to provide the client with a refresh token, when applicable.
+ /// </summary>
+ /// <value>The default value is <c>true</c>.</value>
+ /// <remarks>>
+ /// The refresh token will never be provided when this value is false.
+ /// The refresh token <em>may</em> be provided when this value is true.
+ /// </remarks>
+ public bool IncludeRefreshToken { get; set; }
+
+ #region Implementation of IDisposable
+
+ /// <summary>
+ /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
+ /// </summary>
+ /// <filterpriority>2</filterpriority>
+ public void Dispose() {
+ this.Dispose(true);
+ GC.SuppressFinalize(this);
+ }
+
+ /// <summary>
+ /// Releases unmanaged and - optionally - managed resources
+ /// </summary>
+ /// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
+ protected virtual void Dispose(bool disposing) {
+ if (disposing) {
+ if (this.ResourceServerEncryptionKey != null) {
+ IDisposable value = this.ResourceServerEncryptionKey;
+ value.Dispose();
+ }
+ }
+ }
+
+ #endregion
+ }
+}
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/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/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/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/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/OAuthUtilities.cs b/src/DotNetOpenAuth.OAuth2/OAuth2/OAuthUtilities.cs
index dd7909b..eb5c8e4 100644
--- a/src/DotNetOpenAuth.OAuth2/OAuth2/OAuthUtilities.cs
+++ b/src/DotNetOpenAuth.OAuth2/OAuth2/OAuthUtilities.cs
@@ -129,26 +129,5 @@ namespace DotNetOpenAuth.OAuth2 {
Protocol.BearerHttpAuthorizationHeaderFormat,
accessToken);
}
-
- /// <summary>
- /// Gets information about the client with a given identifier.
- /// </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);
- }
- }
}
}
diff --git a/src/DotNetOpenAuth.OAuth2/Properties/AssemblyInfo.cs b/src/DotNetOpenAuth.OAuth2/Properties/AssemblyInfo.cs
index 14fb526..26b1318 100644
--- a/src/DotNetOpenAuth.OAuth2/Properties/AssemblyInfo.cs
+++ b/src/DotNetOpenAuth.OAuth2/Properties/AssemblyInfo.cs
@@ -50,11 +50,13 @@ using System.Web.UI;
[assembly: InternalsVisibleTo("DotNetOpenAuth.OAuth2.AuthorizationServer, PublicKey=0024000004800000940000000602000000240000525341310004000001000100AD093C3765257C89A7010E853F2C7C741FF92FA8ACE06D7B8254702CAD5CF99104447F63AB05F8BB6F51CE0D81C8C93D2FCE8C20AAFF7042E721CBA16EAAE98778611DED11C0ABC8900DC5667F99B50A9DADEC24DBD8F2C91E3E8AD300EF64F1B4B9536CEB16FB440AF939F57624A9B486F867807C649AE4830EAB88C6C03998")]
[assembly: InternalsVisibleTo("DotNetOpenAuth.OAuth2.ResourceServer, PublicKey=0024000004800000940000000602000000240000525341310004000001000100AD093C3765257C89A7010E853F2C7C741FF92FA8ACE06D7B8254702CAD5CF99104447F63AB05F8BB6F51CE0D81C8C93D2FCE8C20AAFF7042E721CBA16EAAE98778611DED11C0ABC8900DC5667F99B50A9DADEC24DBD8F2C91E3E8AD300EF64F1B4B9536CEB16FB440AF939F57624A9B486F867807C649AE4830EAB88C6C03998")]
[assembly: InternalsVisibleTo("DotNetOpenAuth.OAuth2.Client, PublicKey=0024000004800000940000000602000000240000525341310004000001000100AD093C3765257C89A7010E853F2C7C741FF92FA8ACE06D7B8254702CAD5CF99104447F63AB05F8BB6F51CE0D81C8C93D2FCE8C20AAFF7042E721CBA16EAAE98778611DED11C0ABC8900DC5667F99B50A9DADEC24DBD8F2C91E3E8AD300EF64F1B4B9536CEB16FB440AF939F57624A9B486F867807C649AE4830EAB88C6C03998")]
+[assembly: InternalsVisibleTo("DotNetOpenAuth.OAuth2.ClientAuthorization, PublicKey=0024000004800000940000000602000000240000525341310004000001000100AD093C3765257C89A7010E853F2C7C741FF92FA8ACE06D7B8254702CAD5CF99104447F63AB05F8BB6F51CE0D81C8C93D2FCE8C20AAFF7042E721CBA16EAAE98778611DED11C0ABC8900DC5667F99B50A9DADEC24DBD8F2C91E3E8AD300EF64F1B4B9536CEB16FB440AF939F57624A9B486F867807C649AE4830EAB88C6C03998")]
[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2, PublicKey=0024000004800000940000000602000000240000525341310004000001000100c547cac37abd99c8db225ef2f6c8a3602f3b3606cc9891605d02baa56104f4cfc0734aa39b93bf7852f7d9266654753cc297e7d2edfe0bac1cdcf9f717241550e0a7b191195b7667bb4f64bcb8e2121380fd1d9d46ad2d92d2d15605093924cceaf74c4861eff62abf69b9291ed0a340e113be11e6a7d3113e92484cf7045cc7")]
#else
[assembly: InternalsVisibleTo("DotNetOpenAuth.Test")]
[assembly: InternalsVisibleTo("DotNetOpenAuth.OAuth2.AuthorizationServer")]
[assembly: InternalsVisibleTo("DotNetOpenAuth.OAuth2.ResourceServer")]
[assembly: InternalsVisibleTo("DotNetOpenAuth.OAuth2.Client")]
+[assembly: InternalsVisibleTo("DotNetOpenAuth.OAuth2.ClientAuthorization")]
[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2")]
#endif