summaryrefslogtreecommitdiffstats
path: root/src/DotNetOpenAuth.AspNet/OpenAuthSecurityManager.cs
diff options
context:
space:
mode:
authorAndrew Arnott <andrewarnott@gmail.com>2012-05-07 10:03:12 -0700
committerAndrew Arnott <andrewarnott@gmail.com>2012-05-07 10:03:12 -0700
commit957a1811bc69a033a16b00d755a88ceeaf3fced6 (patch)
treeded97d06a1bec55e0d6bad85d079c2d4b412aa1d /src/DotNetOpenAuth.AspNet/OpenAuthSecurityManager.cs
parenta85cd1c7bb0a22ee08056a19ce60173e3ab8e0e0 (diff)
parentb6dff7d1a6b5b07450b82688ec4727b3e2617ff5 (diff)
downloadDotNetOpenAuth-957a1811bc69a033a16b00d755a88ceeaf3fced6.zip
DotNetOpenAuth-957a1811bc69a033a16b00d755a88ceeaf3fced6.tar.gz
DotNetOpenAuth-957a1811bc69a033a16b00d755a88ceeaf3fced6.tar.bz2
Merge pull request #140 from dotnetjunky/v4.0
Use cookie to store OAuth token and set it as default mechanism.
Diffstat (limited to 'src/DotNetOpenAuth.AspNet/OpenAuthSecurityManager.cs')
-rw-r--r--src/DotNetOpenAuth.AspNet/OpenAuthSecurityManager.cs39
1 files changed, 23 insertions, 16 deletions
diff --git a/src/DotNetOpenAuth.AspNet/OpenAuthSecurityManager.cs b/src/DotNetOpenAuth.AspNet/OpenAuthSecurityManager.cs
index ea2ba54..32e6b04 100644
--- a/src/DotNetOpenAuth.AspNet/OpenAuthSecurityManager.cs
+++ b/src/DotNetOpenAuth.AspNet/OpenAuthSecurityManager.cs
@@ -140,7 +140,8 @@ namespace DotNetOpenAuth.AspNet {
Uri uri;
if (!string.IsNullOrEmpty(returnUrl)) {
uri = UriHelper.ConvertToAbsoluteUri(returnUrl, this.requestContext);
- } else {
+ }
+ else {
uri = this.requestContext.Request.GetPublicFacingUrl();
}
@@ -155,24 +156,16 @@ namespace DotNetOpenAuth.AspNet {
/// </summary>
/// <returns>The result of the authentication.</returns>
public AuthenticationResult VerifyAuthentication() {
- AuthenticationResult result = this.authenticationProvider.VerifyAuthentication(this.requestContext);
- if (!result.IsSuccessful) {
- // if the result is a Failed result, creates a new Failed response which has providerName info.
- result = new AuthenticationResult(
- isSuccessful: false,
- provider: this.authenticationProvider.ProviderName,
- providerUserId: null,
- userName: null,
- extraData: null);
- }
-
- return result;
+ return this.VerifyAuthenticationCore(() => this.authenticationProvider.VerifyAuthentication(this.requestContext));
}
/// <summary>
/// Checks if user is successfully authenticated when user is redirected back to this user.
/// </summary>
/// <param name="returnUrl">The return Url which must match exactly the Url passed into RequestAuthentication() earlier.</param>
+ /// <remarks>
+ /// This method only applies to OAuth2 providers. For other providers, it ignores the returnUrl parameter.
+ /// </remarks>
/// <returns>
/// The result of the authentication.
/// </returns>
@@ -195,7 +188,21 @@ namespace DotNetOpenAuth.AspNet {
// the login when user is redirected back to this page
uri = uri.AttachQueryStringParameter(ProviderQueryStringName, this.authenticationProvider.ProviderName);
- AuthenticationResult result = oauth2Client.VerifyAuthentication(this.requestContext, uri);
+ return this.VerifyAuthenticationCore(() => oauth2Client.VerifyAuthentication(this.requestContext, uri));
+ }
+ else {
+ return this.VerifyAuthentication();
+ }
+ }
+
+ /// <summary>
+ /// Helper to verify authentiation.
+ /// </summary>
+ /// <param name="verifyAuthenticationCall">The real authentication action.</param>
+ /// <returns>Authentication result</returns>
+ private AuthenticationResult VerifyAuthenticationCore(Func<AuthenticationResult> verifyAuthenticationCall) {
+ try {
+ AuthenticationResult result = verifyAuthenticationCall();
if (!result.IsSuccessful) {
// if the result is a Failed result, creates a new Failed response which has providerName info.
result = new AuthenticationResult(
@@ -208,8 +215,8 @@ namespace DotNetOpenAuth.AspNet {
return result;
}
- else {
- return this.VerifyAuthentication();
+ catch (HttpException exception) {
+ return new AuthenticationResult(exception.GetBaseException(), this.authenticationProvider.ProviderName);
}
}