summaryrefslogtreecommitdiffstats
path: root/src/DotNetOpenAuth.AspNet/Clients/OpenID/OpenIDClient.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/DotNetOpenAuth.AspNet/Clients/OpenID/OpenIDClient.cs')
-rw-r--r--src/DotNetOpenAuth.AspNet/Clients/OpenID/OpenIDClient.cs43
1 files changed, 21 insertions, 22 deletions
diff --git a/src/DotNetOpenAuth.AspNet/Clients/OpenID/OpenIDClient.cs b/src/DotNetOpenAuth.AspNet/Clients/OpenID/OpenIDClient.cs
index a41b504..901741b 100644
--- a/src/DotNetOpenAuth.AspNet/Clients/OpenID/OpenIDClient.cs
+++ b/src/DotNetOpenAuth.AspNet/Clients/OpenID/OpenIDClient.cs
@@ -8,11 +8,14 @@ namespace DotNetOpenAuth.AspNet.Clients {
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
+ using System.Threading;
+ using System.Threading.Tasks;
using System.Web;
using DotNetOpenAuth.Messaging;
using DotNetOpenAuth.OpenId;
using DotNetOpenAuth.OpenId.RelyingParty;
using Validation;
+ using System.Collections.Specialized;
/// <summary>
/// Base classes for OpenID clients.
@@ -79,51 +82,47 @@ namespace DotNetOpenAuth.AspNet.Clients {
/// <summary>
/// Attempts to authenticate users by forwarding them to an external website, and upon succcess or failure, redirect users back to the specified url.
/// </summary>
- /// <param name="context">
- /// The context of the current request.
- /// </param>
- /// <param name="returnUrl">
- /// The return url after users have completed authenticating against external website.
- /// </param>
+ /// <param name="context">The context of the current request.</param>
+ /// <param name="returnUrl">The return url after users have completed authenticating against external website.</param>
+ /// <param name="cancellationToken">The cancellation token.</param>
+ /// <returns>
+ /// A task that completes with the asynchronous operation.
+ /// </returns>
[SuppressMessage("Microsoft.Usage", "CA2234:PassSystemUriObjectsInsteadOfStrings",
Justification = "We don't have a Uri object handy.")]
- public virtual void RequestAuthentication(HttpContextBase context, Uri returnUrl) {
+ public virtual async Task RequestAuthenticationAsync(HttpContextBase context, Uri returnUrl, CancellationToken cancellationToken = default(CancellationToken)) {
Requires.NotNull(returnUrl, "returnUrl");
var realm = new Realm(returnUrl.GetComponents(UriComponents.SchemeAndServer, UriFormat.Unescaped));
- IAuthenticationRequest request = RelyingParty.CreateRequest(this.providerIdentifier, realm, returnUrl);
+ IAuthenticationRequest request = await RelyingParty.CreateRequestAsync(this.providerIdentifier, realm, returnUrl, cancellationToken);
// give subclasses a chance to modify request message, e.g. add extension attributes, etc.
this.OnBeforeSendingAuthenticationRequest(request);
- request.RedirectToProvider();
+ await request.RedirectToProviderAsync(context);
}
/// <summary>
/// Check if authentication succeeded after user is redirected back from the service provider.
/// </summary>
- /// <param name="context">
- /// The context of the current request.
- /// </param>
+ /// <param name="context">The context of the current request.</param>
+ /// <param name="cancellationToken">The cancellation token.</param>
/// <returns>
- /// An instance of <see cref="AuthenticationResult"/> containing authentication result.
+ /// An instance of <see cref="AuthenticationResult" /> containing authentication result.
/// </returns>
- public virtual AuthenticationResult VerifyAuthentication(HttpContextBase context) {
- IAuthenticationResponse response = RelyingParty.GetResponse();
+ /// <exception cref="System.InvalidOperationException">Thrown if no OpenID response was found in the incoming HTTP request.</exception>
+ public virtual async Task<AuthenticationResult> VerifyAuthenticationAsync(HttpContextBase context, CancellationToken cancellationToken = default(CancellationToken)) {
+ IAuthenticationResponse response = await RelyingParty.GetResponseAsync(context.Request, cancellationToken);
if (response == null) {
throw new InvalidOperationException(WebResources.OpenIDFailedToGetResponse);
}
if (response.Status == AuthenticationStatus.Authenticated) {
string id = response.ClaimedIdentifier;
- string username;
-
- Dictionary<string, string> extraData = this.GetExtraData(response) ?? new Dictionary<string, string>();
+ var extraData = this.GetExtraData(response) ?? new NameValueCollection();
// try to look up username from the 'username' or 'email' property. If not found, fall back to 'friendly id'
- if (!extraData.TryGetValue("username", out username) && !extraData.TryGetValue("email", out username)) {
- username = response.FriendlyIdentifierForDisplay;
- }
+ string username = extraData["username"] ?? extraData["email"] ?? response.FriendlyIdentifierForDisplay;
return new AuthenticationResult(true, this.ProviderName, id, username, extraData);
}
@@ -142,7 +141,7 @@ namespace DotNetOpenAuth.AspNet.Clients {
/// The response message.
/// </param>
/// <returns>Always null.</returns>
- protected virtual Dictionary<string, string> GetExtraData(IAuthenticationResponse response) {
+ protected virtual NameValueCollection GetExtraData(IAuthenticationResponse response) {
return null;
}