Advertisement
CodeWarrior-Hawaii

Startup config

Jan 17th, 2015
355
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. public class Startup
  2. {
  3. public void Configuration(IAppBuilder app)
  4. {
  5. ConfigureOAuth(app);
  6. HttpConfiguration config = new HttpConfiguration();
  7. WebApiConfig.Register(config);
  8. var tokenCorsPolicy = new CorsPolicy
  9. {
  10. AllowAnyOrigin = true,
  11. AllowAnyHeader = true,
  12. AllowAnyMethod = true
  13. };
  14.  
  15.  
  16. var corsOptions = new CorsOptions
  17. {
  18. PolicyProvider = new CorsPolicyProvider
  19. {
  20. PolicyResolver = request => Task.FromResult(request.Path.ToString().StartsWith("/token") ? tokenCorsPolicy : null)
  21. }
  22. };
  23.  
  24. app.UseCors(corsOptions);
  25. app.UseWebApi(config);
  26. }
  27.  
  28. public void ConfigureOAuth(IAppBuilder app)
  29. {
  30. OAuthAuthorizationServerOptions OAuthServerOptions = new OAuthAuthorizationServerOptions()
  31. {
  32. AllowInsecureHttp = true,
  33. TokenEndpointPath = new PathString("/token"),
  34. AccessTokenExpireTimeSpan = TimeSpan.FromDays(1),
  35. Provider = new SimpleAuthorizationServerProvider()
  36. };
  37.  
  38. // Token Generation
  39. app.UseOAuthAuthorizationServer(OAuthServerOptions);
  40. app.UseOAuthBearerAuthentication(new OAuthBearerAuthenticationOptions());
  41.  
  42. }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement