2 using Microsoft.AspNet.Identity;
3 using Microsoft.AspNet.Identity.Owin;
5 using Microsoft.Owin.Security.Cookies;
6 using Microsoft.Owin.Security.Google;
12 public partial class Startup
14 // For more information on configuring authentication, please visit http://go.microsoft.com/fwlink/?LinkId=301864
15 public void ConfigureAuth(IAppBuilder app)
17 // Configure the db context, user manager and signin manager to use a single instance per request
18 app.CreatePerOwinContext(ApplicationDbContext.Create);
19 app.CreatePerOwinContext<ApplicationUserManager>(ApplicationUserManager.Create);
20 app.CreatePerOwinContext<ApplicationSignInManager>(ApplicationSignInManager.Create);
22 // Enable the application to use a cookie to store information for the signed in user
23 // and to use a cookie to temporarily store information about a user logging in with a third party login provider
24 // Configure the sign in cookie
25 app.UseCookieAuthentication(new CookieAuthenticationOptions
27 AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
28 LoginPath = new PathString("/Account/Login"),
29 Provider = new CookieAuthenticationProvider
31 // Enables the application to validate the security stamp when the user logs in.
32 // This is a security feature which is used when you change a password or add an external login to your account.
33 OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, ApplicationUser>(
34 validateInterval: TimeSpan.FromMinutes(30),
35 regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager))
38 app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);
40 // Enables the application to temporarily store user information when they are verifying the second factor in the two-factor authentication process.
41 app.UseTwoFactorSignInCookie(DefaultAuthenticationTypes.TwoFactorCookie, TimeSpan.FromMinutes(5));
43 // Enables the application to remember the second login verification factor such as phone or email.
44 // 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.
45 // This is similar to the RememberMe option when you log in.
46 app.UseTwoFactorRememberBrowserCookie(DefaultAuthenticationTypes.TwoFactorRememberBrowserCookie);
48 // Uncomment the following lines to enable logging in with third party login providers
49 //app.UseMicrosoftAccountAuthentication(
53 //app.UseTwitterAuthentication(
55 // consumerSecret: "");
57 //app.UseFacebookAuthentication(
61 //app.UseGoogleAuthentication(new GoogleOAuth2AuthenticationOptions()