Created
October 12, 2011 03:47
-
-
Save howarddierking/1280213 to your computer and use it in GitHub Desktop.
Web API helper extension methods for OAuth registration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void RegisterOAuth(this HttpConfiguration config, FacebookOAuthClient client) { | |
var existingFactory = config.RequestHandlers; | |
config.RequestHandlers = (c, e, od) => { | |
if (existingFactory != null) | |
existingFactory(c, e, od); | |
var authorizeAttribute = od.Attributes.OfType<AuthorizeAttribute>().FirstOrDefault(); | |
if (authorizeAttribute == null) return; | |
if (od.Name == "GetCommentsOauth") { | |
c.Add(new OAuthFacebookOpHandler(authorizeAttribute, client.AppId)); | |
} | |
}; | |
var handlers = new List<DelegatingHandler>(); | |
if (config.MessageHandlerFactory != null) | |
handlers.AddRange(config.MessageHandlerFactory()); | |
config.MessageHandlerFactory = () => { | |
handlers.Add(new OAuthFacebookMessageHandler(client.AppId, client.Secret)); | |
return handlers; | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment