summaryrefslogtreecommitdiffstats
path: root/src/DotNetOpenAuth.OAuth2.AuthorizationServer/OAuth2
diff options
context:
space:
mode:
Diffstat (limited to 'src/DotNetOpenAuth.OAuth2.AuthorizationServer/OAuth2')
-rw-r--r--src/DotNetOpenAuth.OAuth2.AuthorizationServer/OAuth2/AuthorizationServer.cs94
-rw-r--r--src/DotNetOpenAuth.OAuth2.AuthorizationServer/OAuth2/AuthorizationServerAccessToken.cs16
-rw-r--r--src/DotNetOpenAuth.OAuth2.AuthorizationServer/OAuth2/ChannelElements/AuthServerBindingElementBase.cs10
-rw-r--r--src/DotNetOpenAuth.OAuth2.AuthorizationServer/OAuth2/ChannelElements/MessageValidationBindingElement.cs21
-rw-r--r--src/DotNetOpenAuth.OAuth2.AuthorizationServer/OAuth2/ChannelElements/OAuth2AuthorizationServerChannel.cs24
-rw-r--r--src/DotNetOpenAuth.OAuth2.AuthorizationServer/OAuth2/ChannelElements/TokenCodeSerializationBindingElement.cs14
-rw-r--r--src/DotNetOpenAuth.OAuth2.AuthorizationServer/OAuth2/ClientDescription.cs33
7 files changed, 137 insertions, 75 deletions
diff --git a/src/DotNetOpenAuth.OAuth2.AuthorizationServer/OAuth2/AuthorizationServer.cs b/src/DotNetOpenAuth.OAuth2.AuthorizationServer/OAuth2/AuthorizationServer.cs
index a5f7d9b..e7edb66 100644
--- a/src/DotNetOpenAuth.OAuth2.AuthorizationServer/OAuth2/AuthorizationServer.cs
+++ b/src/DotNetOpenAuth.OAuth2.AuthorizationServer/OAuth2/AuthorizationServer.cs
@@ -12,6 +12,8 @@ namespace DotNetOpenAuth.OAuth2 {
using System.Net.Http;
using System.Security.Cryptography;
using System.Text;
+ using System.Threading;
+ using System.Threading.Tasks;
using System.Web;
using DotNetOpenAuth.Configuration;
using DotNetOpenAuth.Messaging;
@@ -46,7 +48,7 @@ namespace DotNetOpenAuth.OAuth2 {
Requires.NotNull(authorizationServer, "authorizationServer");
this.aggregatingClientAuthenticationModule = new AggregatingClientCredentialReader(this.clientAuthenticationModules);
this.Channel = new OAuth2AuthorizationServerChannel(authorizationServer, this.aggregatingClientAuthenticationModule);
- this.clientAuthenticationModules.AddRange(OAuth2AuthorizationServerSection.Configuration.ClientAuthenticationModules.CreateInstances(true));
+ this.clientAuthenticationModules.AddRange(OAuth2AuthorizationServerSection.Configuration.ClientAuthenticationModules.CreateInstances(true, null));
this.ScopeSatisfiedCheck = DefaultScopeSatisfiedCheck;
}
@@ -84,16 +86,17 @@ namespace DotNetOpenAuth.OAuth2 {
/// the user to authorize the Client's access of some protected resource(s).
/// </summary>
/// <param name="request">The HTTP request to read from.</param>
- /// <returns>The incoming request, or null if no OAuth message was attached.</returns>
+ /// <param name="cancellationToken">The cancellation token.</param>
+ /// <returns>
+ /// The incoming request, or null if no OAuth message was attached.
+ /// </returns>
/// <exception cref="ProtocolException">Thrown if an unexpected OAuth message is attached to the incoming request.</exception>
[SuppressMessage("Microsoft.Naming", "CA2204:Literals should be spelled correctly", MessageId = "unauthorizedclient", Justification = "Protocol required.")]
- public EndUserAuthorizationRequest ReadAuthorizationRequest(HttpRequestBase request = null) {
- if (request == null) {
- request = this.Channel.GetRequestFromContext();
- }
+ public async Task<EndUserAuthorizationRequest> ReadAuthorizationRequestAsync(HttpRequestMessage request, CancellationToken cancellationToken = default(CancellationToken)) {
+ Requires.NotNull(request, "request");
- EndUserAuthorizationRequest message;
- if (this.Channel.TryReadFromRequest(request, out message)) {
+ var message = await this.Channel.TryReadFromRequestAsync<EndUserAuthorizationRequest>(request, cancellationToken);
+ if (message != null) {
if (message.ResponseType == EndUserAuthorizationResponseType.AuthorizationCode) {
// Clients with no secrets can only request implicit grant types.
var client = this.AuthorizationServerServices.GetClientOrThrow(message.ClientIdentifier);
@@ -105,38 +108,34 @@ namespace DotNetOpenAuth.OAuth2 {
}
/// <summary>
- /// Approves an authorization request and sends an HTTP response to the user agent to redirect the user back to the Client.
- /// </summary>
- /// <param name="authorizationRequest">The authorization request to approve.</param>
- /// <param name="userName">The username of the account that approved the request (or whose data will be accessed by the client).</param>
- /// <param name="scopes">The scope of access the client should be granted. If <c>null</c>, all scopes in the original request will be granted.</param>
- /// <param name="callback">The Client callback URL to use when formulating the redirect to send the user agent back to the Client.</param>
- public void ApproveAuthorizationRequest(EndUserAuthorizationRequest authorizationRequest, string userName, IEnumerable<string> scopes = null, Uri callback = null) {
- Requires.NotNull(authorizationRequest, "authorizationRequest");
-
- var response = this.PrepareApproveAuthorizationRequest(authorizationRequest, userName, scopes, callback);
- this.Channel.Respond(response);
- }
-
- /// <summary>
- /// Rejects an authorization request and sends an HTTP response to the user agent to redirect the user back to the Client.
+ /// Reads in a client's request for the Authorization Server to obtain permission from
+ /// the user to authorize the Client's access of some protected resource(s).
/// </summary>
- /// <param name="authorizationRequest">The authorization request to disapprove.</param>
- /// <param name="callback">The Client callback URL to use when formulating the redirect to send the user agent back to the Client.</param>
- public void RejectAuthorizationRequest(EndUserAuthorizationRequest authorizationRequest, Uri callback = null) {
- Requires.NotNull(authorizationRequest, "authorizationRequest");
-
- var response = this.PrepareRejectAuthorizationRequest(authorizationRequest, callback);
- this.Channel.Respond(response);
+ /// <param name="request">The HTTP request to read from.</param>
+ /// <param name="cancellationToken">The cancellation token.</param>
+ /// <returns>
+ /// The incoming request, or null if no OAuth message was attached.
+ /// </returns>
+ /// <exception cref="ProtocolException">Thrown if an unexpected OAuth message is attached to the incoming request.</exception>
+ public Task<EndUserAuthorizationRequest> ReadAuthorizationRequestAsync(
+ HttpRequestBase request = null, CancellationToken cancellationToken = default(CancellationToken)) {
+ request = request ?? this.Channel.GetRequestFromContext();
+ return this.ReadAuthorizationRequestAsync(request.AsHttpRequestMessage(), cancellationToken);
}
/// <summary>
- /// Handles an incoming request to the authorization server's token endpoint.
+ /// Reads in a client's request for the Authorization Server to obtain permission from
+ /// the user to authorize the Client's access of some protected resource(s).
/// </summary>
- /// <param name="request">The HTTP request.</param>
- /// <returns>The HTTP response to send to the client.</returns>
- public OutgoingWebResponse HandleTokenRequest(HttpRequestMessage request) {
- return this.HandleTokenRequest(new HttpRequestInfo(request));
+ /// <param name="requestUri">The URL that carries the authorization request.</param>
+ /// <param name="cancellationToken">The cancellation token.</param>
+ /// <returns>
+ /// The incoming request, or null if no OAuth message was attached.
+ /// </returns>
+ /// <exception cref="ProtocolException">Thrown if an unexpected OAuth message is attached to the incoming request.</exception>
+ public Task<EndUserAuthorizationRequest> ReadAuthorizationRequestAsync(Uri requestUri, CancellationToken cancellationToken = default(CancellationToken)) {
+ var request = new HttpRequestMessage(HttpMethod.Get, requestUri);
+ return this.ReadAuthorizationRequestAsync(request, cancellationToken);
}
/// <summary>
@@ -144,15 +143,13 @@ namespace DotNetOpenAuth.OAuth2 {
/// </summary>
/// <param name="request">The HTTP request.</param>
/// <returns>The HTTP response to send to the client.</returns>
- public OutgoingWebResponse HandleTokenRequest(HttpRequestBase request = null) {
- if (request == null) {
- request = this.Channel.GetRequestFromContext();
- }
+ public async Task<HttpResponseMessage> HandleTokenRequestAsync(HttpRequestMessage request, CancellationToken cancellationToken = default(CancellationToken)) {
+ Requires.NotNull(request, "request");
- AccessTokenRequestBase requestMessage;
IProtocolMessage responseMessage;
try {
- if (this.Channel.TryReadFromRequest(request, out requestMessage)) {
+ AccessTokenRequestBase requestMessage = await this.Channel.TryReadFromRequestAsync<AccessTokenRequestBase>(request, cancellationToken);
+ if (requestMessage != null) {
var accessTokenResult = this.AuthorizationServerServices.CreateAccessToken(requestMessage);
ErrorUtilities.VerifyHost(accessTokenResult != null, "IAuthorizationServerHost.CreateAccessToken must not return null.");
@@ -179,7 +176,20 @@ namespace DotNetOpenAuth.OAuth2 {
responseMessage = new AccessTokenFailedResponse() { Error = Protocol.AccessTokenRequestErrorCodes.InvalidRequest };
}
- return this.Channel.PrepareResponse(responseMessage);
+ return await this.Channel.PrepareResponseAsync(responseMessage, cancellationToken);
+ }
+
+ /// <summary>
+ /// Handles an incoming request to the authorization server's token endpoint.
+ /// </summary>
+ /// <param name="request">The HTTP request.</param>
+ /// <param name="cancellationToken">The cancellation token.</param>
+ /// <returns>
+ /// The HTTP response to send to the client.
+ /// </returns>
+ public Task<HttpResponseMessage> HandleTokenRequestAsync(HttpRequestBase request = null, CancellationToken cancellationToken = default(CancellationToken)) {
+ request = request ?? this.Channel.GetRequestFromContext();
+ return this.HandleTokenRequestAsync(request.AsHttpRequestMessage(), cancellationToken);
}
/// <summary>
diff --git a/src/DotNetOpenAuth.OAuth2.AuthorizationServer/OAuth2/AuthorizationServerAccessToken.cs b/src/DotNetOpenAuth.OAuth2.AuthorizationServer/OAuth2/AuthorizationServerAccessToken.cs
index 7c9f808..cbf4b09 100644
--- a/src/DotNetOpenAuth.OAuth2.AuthorizationServer/OAuth2/AuthorizationServerAccessToken.cs
+++ b/src/DotNetOpenAuth.OAuth2.AuthorizationServer/OAuth2/AuthorizationServerAccessToken.cs
@@ -11,6 +11,7 @@ namespace DotNetOpenAuth.OAuth2 {
using System.Security.Cryptography;
using System.Text;
using DotNetOpenAuth.Messaging;
+ using DotNetOpenAuth.Messaging.Bindings;
using DotNetOpenAuth.OAuth2.ChannelElements;
/// <summary>
@@ -40,12 +41,23 @@ namespace DotNetOpenAuth.OAuth2 {
public RSACryptoServiceProvider ResourceServerEncryptionKey { get; set; }
/// <summary>
+ /// Gets or sets the symmetric key store to use if the asymmetric key properties are not set.
+ /// </summary>
+ public ICryptoKeyStore SymmetricKeyStore { get; set; }
+
+ /// <summary>
/// Serializes this instance to a simple string for transmission to the client.
/// </summary>
/// <returns>A non-empty string.</returns>
protected internal override string Serialize() {
- ErrorUtilities.VerifyHost(this.AccessTokenSigningKey != null, AuthServerStrings.AccessTokenSigningKeyMissing);
- var formatter = CreateFormatter(this.AccessTokenSigningKey, this.ResourceServerEncryptionKey);
+ ErrorUtilities.VerifyHost(this.AccessTokenSigningKey != null || this.SymmetricKeyStore != null, AuthServerStrings.AccessTokenSigningKeyMissing);
+ IDataBagFormatter<AccessToken> formatter;
+ if (this.AccessTokenSigningKey != null) {
+ formatter = CreateFormatter(this.AccessTokenSigningKey, this.ResourceServerEncryptionKey);
+ } else {
+ formatter = CreateFormatter(this.SymmetricKeyStore);
+ }
+
return formatter.Serialize(this);
}
}
diff --git a/src/DotNetOpenAuth.OAuth2.AuthorizationServer/OAuth2/ChannelElements/AuthServerBindingElementBase.cs b/src/DotNetOpenAuth.OAuth2.AuthorizationServer/OAuth2/ChannelElements/AuthServerBindingElementBase.cs
index 9d3a52c..f77ca91 100644
--- a/src/DotNetOpenAuth.OAuth2.AuthorizationServer/OAuth2/ChannelElements/AuthServerBindingElementBase.cs
+++ b/src/DotNetOpenAuth.OAuth2.AuthorizationServer/OAuth2/ChannelElements/AuthServerBindingElementBase.cs
@@ -9,6 +9,8 @@ namespace DotNetOpenAuth.OAuth2.ChannelElements {
using System.Collections.Generic;
using System.Linq;
using System.Text;
+ using System.Threading;
+ using System.Threading.Tasks;
using Messaging;
/// <summary>
@@ -56,21 +58,23 @@ namespace DotNetOpenAuth.OAuth2.ChannelElements {
/// 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>
+ /// <param name="cancellationToken">The cancellation token.</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.
+ /// <see cref="MessagePartAttribute.RequiredProtection" /> properties where applicable.
/// </remarks>
- public abstract MessageProtections? ProcessOutgoingMessage(IProtocolMessage message);
+ public abstract Task<MessageProtections?> ProcessOutgoingMessageAsync(IProtocolMessage message, CancellationToken cancellationToken);
/// <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>
+ /// <param name="cancellationToken">The cancellation token.</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.
@@ -83,6 +87,6 @@ namespace DotNetOpenAuth.OAuth2.ChannelElements {
/// Implementations that provide message protection must honor the
/// <see cref="MessagePartAttribute.RequiredProtection"/> properties where applicable.
/// </remarks>
- public abstract MessageProtections? ProcessIncomingMessage(IProtocolMessage message);
+ public abstract Task<MessageProtections?> ProcessIncomingMessageAsync(IProtocolMessage message, CancellationToken cancellationToken);
}
}
diff --git a/src/DotNetOpenAuth.OAuth2.AuthorizationServer/OAuth2/ChannelElements/MessageValidationBindingElement.cs b/src/DotNetOpenAuth.OAuth2.AuthorizationServer/OAuth2/ChannelElements/MessageValidationBindingElement.cs
index 6d4220b..823baaf 100644
--- a/src/DotNetOpenAuth.OAuth2.AuthorizationServer/OAuth2/ChannelElements/MessageValidationBindingElement.cs
+++ b/src/DotNetOpenAuth.OAuth2.AuthorizationServer/OAuth2/ChannelElements/MessageValidationBindingElement.cs
@@ -10,6 +10,8 @@ namespace DotNetOpenAuth.OAuth2.ChannelElements {
using System.Globalization;
using System.Linq;
using System.Text;
+ using System.Threading;
+ using System.Threading.Tasks;
using DotNetOpenAuth.OAuth2.Messages;
using Messaging;
using Validation;
@@ -52,6 +54,7 @@ namespace DotNetOpenAuth.OAuth2.ChannelElements {
/// 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>
+ /// <param name="cancellationToken">The cancellation token.</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.
@@ -60,7 +63,7 @@ namespace DotNetOpenAuth.OAuth2.ChannelElements {
/// Implementations that provide message protection must honor the
/// <see cref="MessagePartAttribute.RequiredProtection"/> properties where applicable.
/// </remarks>
- public override MessageProtections? ProcessOutgoingMessage(IProtocolMessage message) {
+ public override Task<MessageProtections?> ProcessOutgoingMessageAsync(IProtocolMessage message, CancellationToken cancellationToken) {
var accessTokenResponse = message as AccessTokenSuccessResponse;
if (accessTokenResponse != null) {
var directResponseMessage = (IDirectResponseProtocolMessage)accessTokenResponse;
@@ -68,7 +71,7 @@ namespace DotNetOpenAuth.OAuth2.ChannelElements {
ErrorUtilities.VerifyProtocol(accessTokenRequest.GrantType != GrantType.ClientCredentials || accessTokenResponse.RefreshToken == null, OAuthStrings.NoGrantNoRefreshToken);
}
- return null;
+ return MessageProtectionTasks.Null;
}
/// <summary>
@@ -76,19 +79,19 @@ namespace DotNetOpenAuth.OAuth2.ChannelElements {
/// validates an incoming message based on the rules of this channel binding element.
/// </summary>
/// <param name="message">The incoming message to process.</param>
+ /// <param name="cancellationToken">The cancellation token.</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>
+ /// <exception cref="TokenEndpointProtocolException">Thrown when an authorization or protocol rule is violated.</exception>
+ /// <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.
+ /// <see cref="MessagePartAttribute.RequiredProtection" /> properties where applicable.
/// </remarks>
- public override MessageProtections? ProcessIncomingMessage(IProtocolMessage message) {
+ public override Task<MessageProtections?> ProcessIncomingMessageAsync(IProtocolMessage message, CancellationToken cancellationToken) {
bool applied = false;
// Check that the client secret is correct for client authenticated messages.
@@ -201,7 +204,7 @@ namespace DotNetOpenAuth.OAuth2.ChannelElements {
}
}
- return applied ? (MessageProtections?)MessageProtections.None : null;
+ return applied ? MessageProtectionTasks.None : MessageProtectionTasks.Null;
}
}
}
diff --git a/src/DotNetOpenAuth.OAuth2.AuthorizationServer/OAuth2/ChannelElements/OAuth2AuthorizationServerChannel.cs b/src/DotNetOpenAuth.OAuth2.AuthorizationServer/OAuth2/ChannelElements/OAuth2AuthorizationServerChannel.cs
index 249f5e7..609cedb 100644
--- a/src/DotNetOpenAuth.OAuth2.AuthorizationServer/OAuth2/ChannelElements/OAuth2AuthorizationServerChannel.cs
+++ b/src/DotNetOpenAuth.OAuth2.AuthorizationServer/OAuth2/ChannelElements/OAuth2AuthorizationServerChannel.cs
@@ -7,7 +7,12 @@
namespace DotNetOpenAuth.OAuth2.ChannelElements {
using System;
using System.Collections.Generic;
+ using System.Net.Http;
+ using System.Net.Http.Headers;
using System.Net.Mime;
+ using System.Text;
+ using System.Threading;
+ using System.Threading.Tasks;
using System.Web;
using DotNetOpenAuth.Messaging;
using DotNetOpenAuth.OAuth2.AuthServer.Messages;
@@ -61,7 +66,7 @@ namespace DotNetOpenAuth.OAuth2.ChannelElements {
/// 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) {
+ protected override Task<IDictionary<string, string>> ReadFromResponseCoreAsync(HttpResponseMessage response, CancellationToken cancellationToken) {
throw new NotImplementedException();
}
@@ -75,11 +80,11 @@ namespace DotNetOpenAuth.OAuth2.ChannelElements {
/// <remarks>
/// This method implements spec OAuth V1.0 section 5.3.
/// </remarks>
- protected override OutgoingWebResponse PrepareDirectResponse(IProtocolMessage response) {
- var webResponse = new OutgoingWebResponse();
+ protected override HttpResponseMessage PrepareDirectResponse(IProtocolMessage response) {
+ var webResponse = new HttpResponseMessage();
ApplyMessageTemplate(response, webResponse);
string json = this.SerializeAsJson(response);
- webResponse.SetResponse(json, new ContentType(JsonEncoded));
+ webResponse.Content = new StringContent(json, Encoding.UTF8, JsonEncoded);
return webResponse;
}
@@ -87,12 +92,15 @@ namespace DotNetOpenAuth.OAuth2.ChannelElements {
/// 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>
+ /// <param name="cancellationToken">The cancellation token.</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();
+ protected override async Task<IDirectedProtocolMessage> ReadFromRequestCoreAsync(HttpRequestMessage request, CancellationToken cancellationToken) {
+ Requires.NotNull(request, "request");
+
+ if (!string.IsNullOrEmpty(request.RequestUri.Fragment)) {
+ var fields = HttpUtility.ParseQueryString(request.RequestUri.Fragment.Substring(1)).ToDictionary();
MessageReceivingEndpoint recipient;
try {
@@ -105,7 +113,7 @@ namespace DotNetOpenAuth.OAuth2.ChannelElements {
return (IDirectedProtocolMessage)this.Receive(fields, recipient);
}
- return base.ReadFromRequestCore(request);
+ return await base.ReadFromRequestCoreAsync(request, cancellationToken);
}
/// <summary>
diff --git a/src/DotNetOpenAuth.OAuth2.AuthorizationServer/OAuth2/ChannelElements/TokenCodeSerializationBindingElement.cs b/src/DotNetOpenAuth.OAuth2.AuthorizationServer/OAuth2/ChannelElements/TokenCodeSerializationBindingElement.cs
index 5a1dbae..938e587 100644
--- a/src/DotNetOpenAuth.OAuth2.AuthorizationServer/OAuth2/ChannelElements/TokenCodeSerializationBindingElement.cs
+++ b/src/DotNetOpenAuth.OAuth2.AuthorizationServer/OAuth2/ChannelElements/TokenCodeSerializationBindingElement.cs
@@ -12,6 +12,8 @@ namespace DotNetOpenAuth.OAuth2.ChannelElements {
using System.Linq;
using System.Security.Cryptography;
using System.Text;
+ using System.Threading;
+ using System.Threading.Tasks;
using DotNetOpenAuth.Messaging;
using DotNetOpenAuth.Messaging.Bindings;
using DotNetOpenAuth.OAuth2.AuthServer.ChannelElements;
@@ -37,6 +39,7 @@ namespace DotNetOpenAuth.OAuth2.ChannelElements {
/// 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>
+ /// <param name="cancellationToken">The cancellation token.</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.
@@ -45,7 +48,7 @@ namespace DotNetOpenAuth.OAuth2.ChannelElements {
/// Implementations that provide message protection must honor the
/// <see cref="MessagePartAttribute.RequiredProtection"/> properties where applicable.
/// </remarks>
- public override MessageProtections? ProcessOutgoingMessage(IProtocolMessage message) {
+ public override Task<MessageProtections?> ProcessOutgoingMessageAsync(IProtocolMessage message, CancellationToken cancellationToken) {
var directResponse = message as IDirectResponseProtocolMessage;
var request = directResponse != null ? directResponse.OriginatingRequest as IAccessTokenRequestInternal : null;
@@ -55,7 +58,7 @@ namespace DotNetOpenAuth.OAuth2.ChannelElements {
var codeFormatter = AuthorizationCode.CreateFormatter(this.AuthorizationServer);
var code = authCodeCarrier.AuthorizationDescription;
authCodeCarrier.Code = codeFormatter.Serialize(code);
- return MessageProtections.None;
+ return MessageProtectionTasks.None;
}
// Serialize the refresh token, if applicable.
@@ -74,7 +77,7 @@ namespace DotNetOpenAuth.OAuth2.ChannelElements {
accessTokenResponse.AccessToken = accessTokenResponse.AuthorizationDescription.Serialize();
}
- return null;
+ return MessageProtectionTasks.Null;
}
/// <summary>
@@ -82,6 +85,7 @@ namespace DotNetOpenAuth.OAuth2.ChannelElements {
/// validates an incoming message based on the rules of this channel binding element.
/// </summary>
/// <param name="message">The incoming message to process.</param>
+ /// <param name="cancellationToken">The cancellation token.</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.
@@ -98,7 +102,7 @@ namespace DotNetOpenAuth.OAuth2.ChannelElements {
[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) {
+ public override Task<MessageProtections?> ProcessIncomingMessageAsync(IProtocolMessage message, CancellationToken cancellationToken) {
var authCodeCarrier = message as IAuthorizationCodeCarryingRequest;
if (authCodeCarrier != null) {
var authorizationCodeFormatter = AuthorizationCode.CreateFormatter(this.AuthorizationServer);
@@ -115,7 +119,7 @@ namespace DotNetOpenAuth.OAuth2.ChannelElements {
refreshTokenCarrier.AuthorizationDescription = refreshToken;
}
- return null;
+ return MessageProtectionTasks.Null;
}
}
}
diff --git a/src/DotNetOpenAuth.OAuth2.AuthorizationServer/OAuth2/ClientDescription.cs b/src/DotNetOpenAuth.OAuth2.AuthorizationServer/OAuth2/ClientDescription.cs
index a10e1aa..6d77f14 100644
--- a/src/DotNetOpenAuth.OAuth2.AuthorizationServer/OAuth2/ClientDescription.cs
+++ b/src/DotNetOpenAuth.OAuth2.AuthorizationServer/OAuth2/ClientDescription.cs
@@ -22,15 +22,36 @@ namespace DotNetOpenAuth.OAuth2 {
private readonly string secret;
/// <summary>
- /// Initializes a new instance of the <see cref="ClientDescription"/> class.
+ /// Initializes a new instance of the <see cref="ClientDescription"/> class
+ /// to represent a confidential client (one that has an authenticating secret.)
/// </summary>
/// <param name="secret">The secret.</param>
/// <param name="defaultCallback">The default callback.</param>
- /// <param name="clientType">Type of the client.</param>
- public ClientDescription(string secret, Uri defaultCallback, ClientType clientType) {
+ public ClientDescription(string secret, Uri defaultCallback) {
+ Requires.NotNullOrEmpty(secret, "secret");
+ Requires.NotNull(defaultCallback, "defaultCallback");
+
this.secret = secret;
this.DefaultCallback = defaultCallback;
- this.ClientType = clientType;
+ this.ClientType = ClientType.Confidential;
+ }
+
+ /// <summary>
+ /// Initializes a new instance of the <see cref="ClientDescription"/> class
+ /// to represent a public client (one that does not have an authenticating secret.)
+ /// </summary>
+ /// <param name="defaultCallback">The default callback.</param>
+ public ClientDescription(Uri defaultCallback) {
+ Requires.NotNull(defaultCallback, "defaultCallback");
+
+ this.DefaultCallback = defaultCallback;
+ this.ClientType = ClientType.Public;
+ }
+
+ /// <summary>
+ /// Initializes a new instance of the <see cref="ClientDescription"/> class.
+ /// </summary>
+ protected ClientDescription() {
}
#region IClientDescription Members
@@ -42,12 +63,12 @@ namespace DotNetOpenAuth.OAuth2 {
/// <value>
/// An absolute URL; or <c>null</c> if none is registered.
/// </value>
- public Uri DefaultCallback { get; private set; }
+ public Uri DefaultCallback { get; protected set; }
/// <summary>
/// Gets the type of the client.
/// </summary>
- public ClientType ClientType { get; private set; }
+ public ClientType ClientType { get; protected set; }
/// <summary>
/// Gets a value indicating whether a non-empty secret is registered for this client.