Created
September 9, 2015 10:16
-
-
Save khellang/4105b2bc3295f9af7536 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
using AppFunc = Func<IDictionary<string, object>, Task>; | |
using AddMiddleware = Action<Func< | |
Func<IDictionary<string, object>, Task>, | |
Func<IDictionary<string, object>, Task> | |
>>; | |
public class Startup | |
{ | |
public void Configure(IApplicationBuilder app) | |
{ | |
var oAuthOptions = new OAuthAuthorizationServerOptions | |
{ | |
TokenEndpointPath = new PathString("/token"), | |
AuthorizeEndpointPath = new PathString("/external-login"), | |
}; | |
var twitterOptions = new TwitterAuthenticationOptions | |
{ | |
ConsumerKey = "lKtgWiK8KSvnP6QF45Zeq2rJm", | |
ConsumerSecret = "EYbUk9pqhtsIzUA82hSgjqxwXDt2KFGZVaaNeCggHUj7oVHUEI", | |
AuthenticationMode = AuthenticationMode.Active | |
}; | |
app.UseOwin(owin => | |
{ | |
owin.UseKatana(katana => | |
{ | |
katana.UseCookieAuthentication(new CookieAuthenticationOptions()); | |
katana.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie); | |
katana.UseOAuthBearerTokens(oAuthOptions); | |
katana.UseTwitterAuthentication(twitterOptions); | |
}); | |
owin.UseNancy(); | |
}); | |
} | |
} | |
public class Module : NancyModule | |
{ | |
public Module() | |
{ | |
this.RequiresAuthentication(); | |
Get["/"] = _ => "Hello World!"; | |
} | |
} | |
public static class OwinExtensions | |
{ | |
public static AddMiddleware UseKatana(this AddMiddleware addMiddleware, Action<IAppBuilder> builderAction) | |
{ | |
addMiddleware.Invoke(next => | |
{ | |
var appBuilder = new AppBuilder(); | |
appBuilder.Properties["builder.DefaultApp"] = next; | |
appBuilder.Properties["host.AppName"] = "Whatever"; | |
builderAction.Invoke(appBuilder); | |
return appBuilder.Build<AppFunc>(); | |
}); | |
return addMiddleware; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment