Skip to content

Instantly share code, notes, and snippets.

@howarddierking
Created October 12, 2011 03:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save howarddierking/1280213 to your computer and use it in GitHub Desktop.
Save howarddierking/1280213 to your computer and use it in GitHub Desktop.
Web API helper extension methods for OAuth registration
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