Advertisement
Guest User

OAuth 2.0

a guest
Aug 12th, 2016
332
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.13 KB | None | 0 0
  1. public partial class Startup {
  2.  
  3.         // For more information on configuring authentication, please visit http://go.microsoft.com/fwlink/?LinkId=301883
  4.         public void ConfigureAuth(IAppBuilder app)
  5.         {
  6.             // Configure the db context, user manager and signin manager to use a single instance per request
  7.             app.CreatePerOwinContext(ApplicationDbContext.Create);
  8.             app.CreatePerOwinContext<ApplicationUserManager>(ApplicationUserManager.Create);
  9.             app.CreatePerOwinContext<ApplicationSignInManager>(ApplicationSignInManager.Create);
  10.  
  11.             // Enable the application to use a cookie to store information for the signed in user
  12.             // and to use a cookie to temporarily store information about a user logging in with a third party login provider
  13.             // Configure the sign in cookie
  14.             app.UseCookieAuthentication(new CookieAuthenticationOptions
  15.             {
  16.                 AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
  17.                 LoginPath = new PathString("/Account/Login"),
  18.                 Provider = new CookieAuthenticationProvider
  19.                 {
  20.                     OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, ApplicationUser>(
  21.                         validateInterval: TimeSpan.FromMinutes(30),
  22.                         regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager))
  23.                 }
  24.             });
  25.             // Use a cookie to temporarily store information about a user logging in with a third party login provider
  26.             app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);
  27.  
  28.             // Enables the application to temporarily store user information when they are verifying the second factor in the two-factor authentication process.
  29.             app.UseTwoFactorSignInCookie(DefaultAuthenticationTypes.TwoFactorCookie, TimeSpan.FromMinutes(5));
  30.  
  31.             // Enables the application to remember the second login verification factor such as phone or email.
  32.             // Once you check this option, your second step of verification during the login process will be remembered on the device where you logged in from.
  33.             // This is similar to the RememberMe option when you log in.
  34.             app.UseTwoFactorRememberBrowserCookie(DefaultAuthenticationTypes.TwoFactorRememberBrowserCookie);
  35.  
  36.             // Uncomment the following lines to enable logging in with third party login providers
  37.             //app.UseMicrosoftAccountAuthentication(
  38.             //    clientId: "",
  39.             //    clientSecret: "");
  40.  
  41.             //app.UseTwitterAuthentication(
  42.             //   consumerKey: "",
  43.             //   consumerSecret: "");
  44.  
  45.             //app.UseFacebookAuthentication(
  46.             //   appId: "",
  47.             //   appSecret: "");
  48.  
  49.  
  50.             app.UseGoogleAuthentication(new GoogleOAuth2AuthenticationOptions()
  51.             {
  52.                 ClientId = "*******************************************.apps.googleusercontent.com",
  53.                 ClientSecret = "**********************"
  54.             });
  55.         }
  56.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement