summaryrefslogtreecommitdiffstats
path: root/src/DotNetOpenAuth.AspNet/Clients/OAuth2/OAuth2Client.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/DotNetOpenAuth.AspNet/Clients/OAuth2/OAuth2Client.cs')
-rw-r--r--src/DotNetOpenAuth.AspNet/Clients/OAuth2/OAuth2Client.cs48
1 files changed, 26 insertions, 22 deletions
diff --git a/src/DotNetOpenAuth.AspNet/Clients/OAuth2/OAuth2Client.cs b/src/DotNetOpenAuth.AspNet/Clients/OAuth2/OAuth2Client.cs
index 014f459..8e6b5f3 100644
--- a/src/DotNetOpenAuth.AspNet/Clients/OAuth2/OAuth2Client.cs
+++ b/src/DotNetOpenAuth.AspNet/Clients/OAuth2/OAuth2Client.cs
@@ -8,8 +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 Validation;
+ using System.Collections.Specialized;
/// <summary>
/// Represents the base class for OAuth 2.0 clients
@@ -57,30 +63,31 @@ 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.
- /// </param>
- /// <param name="returnUrl">
- /// The return url after users have completed authenticating against external website.
- /// </param>
- public virtual void RequestAuthentication(HttpContextBase context, Uri returnUrl) {
+ /// <param name="context">The context.</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>
+ public virtual Task RequestAuthenticationAsync(HttpContextBase context, Uri returnUrl, CancellationToken cancellationToken = default(CancellationToken)) {
Requires.NotNull(context, "context");
Requires.NotNull(returnUrl, "returnUrl");
string redirectUrl = this.GetServiceLoginUrl(returnUrl).AbsoluteUri;
context.Response.Redirect(redirectUrl, endResponse: true);
+ return MessagingUtilities.CompletedTask;
}
/// <summary>
/// Check if authentication succeeded after user is redirected back from the service provider.
/// </summary>
- /// <param name="context">
- /// The context.
- /// </param>
+ /// <param name="context">The context.</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 AuthenticationResult VerifyAuthentication(HttpContextBase context) {
+ /// <exception cref="System.InvalidOperationException">Always thrown.</exception>
+ public Task<AuthenticationResult> VerifyAuthenticationAsync(HttpContextBase context, CancellationToken cancellationToken = default(CancellationToken)) {
throw new InvalidOperationException(WebResources.OAuthRequireReturnUrl);
}
@@ -89,10 +96,11 @@ namespace DotNetOpenAuth.AspNet.Clients {
/// </summary>
/// <param name="context">The context.</param>
/// <param name="returnPageUrl">The return URL which should match the value passed to RequestAuthentication() method.</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, Uri returnPageUrl) {
+ public virtual async Task<AuthenticationResult> VerifyAuthenticationAsync(HttpContextBase context, Uri returnPageUrl, CancellationToken cancellationToken = default(CancellationToken)) {
Requires.NotNull(context, "context");
string code = context.Request.QueryString["code"];
@@ -105,19 +113,15 @@ namespace DotNetOpenAuth.AspNet.Clients {
return AuthenticationResult.Failed;
}
- IDictionary<string, string> userData = this.GetUserData(accessToken);
+ var userData = this.GetUserData(accessToken);
if (userData == null) {
return AuthenticationResult.Failed;
}
- string id = userData["id"];
- string name;
-
// Some oAuth providers do not return value for the 'username' attribute.
// In that case, try the 'name' attribute. If it's still unavailable, fall back to 'id'
- if (!userData.TryGetValue("username", out name) && !userData.TryGetValue("name", out name)) {
- name = id;
- }
+ string id = userData["id"];
+ string name = userData["username"] ?? userData["name"] ?? id;
// add the access token to the user data dictionary just in case page developers want to use it
userData["accesstoken"] = accessToken;
@@ -152,7 +156,7 @@ namespace DotNetOpenAuth.AspNet.Clients {
/// <returns>
/// A dictionary contains key-value pairs of user data
/// </returns>
- protected abstract IDictionary<string, string> GetUserData(string accessToken);
+ protected abstract NameValueCollection GetUserData(string accessToken);
/// <summary>
/// Queries the access token from the specified authorization code.