You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

65 lines
2.6 KiB

  1. using Microsoft.AspNet.Identity;
  2. using Microsoft.Owin;
  3. using Microsoft.Owin.Security.Cookies;
  4. using Microsoft.Owin.Security.OAuth;
  5. using Owin;
  6. using System;
  7. //using ThirdPartyAPIs.Providers;
  8. namespace ThirdPartyAPIs
  9. {
  10. public partial class Startup
  11. {
  12. public static OAuthAuthorizationServerOptions OAuthOptions { get; private set; }
  13. public static string PublicClientId { get; private set; }
  14. // For more information on configuring authentication, please visit https://go.microsoft.com/fwlink/?LinkId=301864
  15. public void ConfigureAuth(IAppBuilder app)
  16. {
  17. // Configure the db context and user manager to use a single instance per request
  18. //app.CreatePerOwinContext(ApplicationDbContext.Create);
  19. //app.CreatePerOwinContext<ApplicationUserManager>(ApplicationUserManager.Create);
  20. // Enable the application to use a cookie to store information for the signed in user and
  21. // to use a cookie to temporarily store information about a user logging in with a third
  22. // party login provider
  23. app.UseCookieAuthentication(new CookieAuthenticationOptions());
  24. app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);
  25. // Configure the application for OAuth based flow
  26. PublicClientId = "self";
  27. OAuthOptions = new OAuthAuthorizationServerOptions
  28. {
  29. TokenEndpointPath = new PathString("/Token"),
  30. //Provider = new ApplicationOAuthProvider(PublicClientId),
  31. AuthorizeEndpointPath = new PathString("/api/Account/ExternalLogin"),
  32. AccessTokenExpireTimeSpan = TimeSpan.FromDays(14),
  33. // In production mode set AllowInsecureHttp = false
  34. AllowInsecureHttp = true
  35. };
  36. // Enable the application to use bearer tokens to authenticate users
  37. app.UseOAuthBearerTokens(OAuthOptions);
  38. // Uncomment the following lines to enable logging in with third party login providers
  39. //app.UseMicrosoftAccountAuthentication(
  40. // clientId: "",
  41. // clientSecret: "");
  42. //app.UseTwitterAuthentication(
  43. // consumerKey: "",
  44. // consumerSecret: "");
  45. //app.UseFacebookAuthentication(
  46. // appId: "",
  47. // appSecret: "");
  48. //app.UseGoogleAuthentication(new GoogleOAuth2AuthenticationOptions()
  49. //{
  50. // ClientId = "",
  51. // ClientSecret = ""
  52. //});
  53. }
  54. }
  55. }