summaryrefslogtreecommitdiffstats
path: root/projecttemplates/RelyingPartyLogic/OAuthAuthenticationModule.cs
diff options
context:
space:
mode:
Diffstat (limited to 'projecttemplates/RelyingPartyLogic/OAuthAuthenticationModule.cs')
-rw-r--r--projecttemplates/RelyingPartyLogic/OAuthAuthenticationModule.cs25
1 files changed, 18 insertions, 7 deletions
diff --git a/projecttemplates/RelyingPartyLogic/OAuthAuthenticationModule.cs b/projecttemplates/RelyingPartyLogic/OAuthAuthenticationModule.cs
index 0e2618c..3d37e1f 100644
--- a/projecttemplates/RelyingPartyLogic/OAuthAuthenticationModule.cs
+++ b/projecttemplates/RelyingPartyLogic/OAuthAuthenticationModule.cs
@@ -8,7 +8,10 @@ namespace RelyingPartyLogic {
using System;
using System.Collections.Generic;
using System.Linq;
+ using System.Security.Claims;
using System.Security.Principal;
+ using System.Threading;
+ using System.Threading.Tasks;
using System.Web;
using System.Web.Security;
using DotNetOpenAuth.Messaging;
@@ -52,13 +55,21 @@ namespace RelyingPartyLogic {
using (var crypto = OAuthResourceServer.CreateRSA()) {
var tokenAnalyzer = new SpecialAccessTokenAnalyzer(crypto, crypto);
var resourceServer = new ResourceServer(tokenAnalyzer);
+ var context = this.application.Context;
+ Task.Run(
+ async delegate {
+ ProtocolFaultResponseException exception = null;
+ try {
+ IPrincipal principal = await resourceServer.GetPrincipalAsync(new HttpRequestWrapper(context.Request));
+ context.User = principal;
+ return;
+ } catch (ProtocolFaultResponseException ex) {
+ exception = ex;
+ }
- try {
- IPrincipal principal = resourceServer.GetPrincipal(new HttpRequestWrapper(this.application.Context.Request));
- this.application.Context.User = principal;
- } catch (ProtocolFaultResponseException ex) {
- ex.CreateErrorResponse().Send();
- }
+ var errorResponse = await exception.CreateErrorResponseAsync(CancellationToken.None);
+ await errorResponse.SendAsync();
+ }).Wait();
}
}
@@ -74,7 +85,7 @@ namespace RelyingPartyLogic {
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="System.Web.Security.RoleManagerEventArgs"/> instance containing the event data.</param>
private void roleManager_GetRoles(object sender, RoleManagerEventArgs e) {
- if (this.application.User is DotNetOpenAuth.OAuth.ChannelElements.OAuthPrincipal) {
+ if (this.application.User is ClaimsPrincipal) {
e.RolesPopulated = true;
}
}