summaryrefslogtreecommitdiffstats
path: root/samples/OAuthServiceProvider/Code
diff options
context:
space:
mode:
authorAndrew Arnott <andrewarnott@gmail.com>2013-01-24 21:05:46 -0800
committerAndrew Arnott <andrewarnott@gmail.com>2013-01-24 21:05:46 -0800
commit24e24a5f60f4f0eb67c5bdc47bea499cbf197fc7 (patch)
tree7506557356a23353a9905c1c0f607265f8f9bace /samples/OAuthServiceProvider/Code
parent98976665f90b20e4757e932ce3a33268f7e1daa6 (diff)
downloadDotNetOpenAuth-24e24a5f60f4f0eb67c5bdc47bea499cbf197fc7.zip
DotNetOpenAuth-24e24a5f60f4f0eb67c5bdc47bea499cbf197fc7.tar.gz
DotNetOpenAuth-24e24a5f60f4f0eb67c5bdc47bea499cbf197fc7.tar.bz2
More fixes
Diffstat (limited to 'samples/OAuthServiceProvider/Code')
-rw-r--r--samples/OAuthServiceProvider/Code/OAuthAuthorizationManager.cs58
1 files changed, 29 insertions, 29 deletions
diff --git a/samples/OAuthServiceProvider/Code/OAuthAuthorizationManager.cs b/samples/OAuthServiceProvider/Code/OAuthAuthorizationManager.cs
index 917a252..cf28c15 100644
--- a/samples/OAuthServiceProvider/Code/OAuthAuthorizationManager.cs
+++ b/samples/OAuthServiceProvider/Code/OAuthAuthorizationManager.cs
@@ -7,6 +7,7 @@
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.ServiceModel.Security;
+ using System.Threading.Tasks;
using DotNetOpenAuth;
using DotNetOpenAuth.OAuth;
@@ -25,41 +26,40 @@
HttpRequestMessageProperty httpDetails = operationContext.RequestContext.RequestMessage.Properties[HttpRequestMessageProperty.Name] as HttpRequestMessageProperty;
Uri requestUri = operationContext.RequestContext.RequestMessage.Properties.Via;
ServiceProvider sp = Constants.CreateServiceProvider();
- try {
- var auth = sp.ReadProtectedResourceAuthorization(httpDetails, requestUri);
- if (auth != null) {
- var accessToken = Global.DataContext.OAuthTokens.Single(token => token.Token == auth.AccessToken);
+ return Task.Run(
+ async delegate {
+ try {
+ var auth = await sp.ReadProtectedResourceAuthorizationAsync(httpDetails, requestUri);
+ if (auth != null) {
+ var accessToken = Global.DataContext.OAuthTokens.Single(token => token.Token == auth.AccessToken);
- var principal = sp.CreatePrincipal(auth);
- var policy = new OAuthPrincipalAuthorizationPolicy(principal);
- var policies = new List<IAuthorizationPolicy> {
- policy,
- };
+ var principal = sp.CreatePrincipal(auth);
+ var policy = new OAuthPrincipalAuthorizationPolicy(principal);
+ var policies = new List<IAuthorizationPolicy> { policy, };
- var securityContext = new ServiceSecurityContext(policies.AsReadOnly());
- if (operationContext.IncomingMessageProperties.Security != null) {
- operationContext.IncomingMessageProperties.Security.ServiceSecurityContext = securityContext;
- } else {
- operationContext.IncomingMessageProperties.Security = new SecurityMessageProperty {
- ServiceSecurityContext = securityContext,
- };
- }
+ var securityContext = new ServiceSecurityContext(policies.AsReadOnly());
+ if (operationContext.IncomingMessageProperties.Security != null) {
+ operationContext.IncomingMessageProperties.Security.ServiceSecurityContext = securityContext;
+ } else {
+ operationContext.IncomingMessageProperties.Security = new SecurityMessageProperty {
+ ServiceSecurityContext = securityContext,
+ };
+ }
- securityContext.AuthorizationContext.Properties["Identities"] = new List<IIdentity> {
- principal.Identity,
- };
+ securityContext.AuthorizationContext.Properties["Identities"] = new List<IIdentity> { principal.Identity, };
- // Only allow this method call if the access token scope permits it.
- string[] scopes = accessToken.Scope.Split('|');
- if (scopes.Contains(operationContext.IncomingMessageHeaders.Action)) {
- return true;
+ // Only allow this method call if the access token scope permits it.
+ string[] scopes = accessToken.Scope.Split('|');
+ if (scopes.Contains(operationContext.IncomingMessageHeaders.Action)) {
+ return true;
+ }
+ }
+ } catch (ProtocolException ex) {
+ Global.Logger.Error("Error processing OAuth messages.", ex);
}
- }
- } catch (ProtocolException ex) {
- Global.Logger.Error("Error processing OAuth messages.", ex);
- }
- return false;
+ return false;
+ }).GetAwaiter().GetResult();
}
}
} \ No newline at end of file