initial commit
[CPE_learningsite] / CPE / CPE.App / CPE.App.Web / App_Start / Startup.Auth.cs
1 using System;
2 using Microsoft.AspNet.Identity;
3 using Microsoft.AspNet.Identity.Owin;
4 using Microsoft.Owin;
5 using Microsoft.Owin.Security.Cookies;
6 using Microsoft.Owin.Security.Google;
7 using Owin;
8 using CPE.App.Web.Models;
9
10 namespace CPE.App.Web
11 {
12     public partial class Startup
13     {
14         // For more information on configuring authentication, please visit http://go.microsoft.com/fwlink/?LinkId=301864
15         public void ConfigureAuth(IAppBuilder app)
16         {
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);
21
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
26             {
27                 AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
28                 LoginPath = new PathString("/Account/Login"),
29                 Provider = new CookieAuthenticationProvider
30                 {
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))
36                 }
37             });            
38             app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);
39
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));
42
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);
47
48             // Uncomment the following lines to enable logging in with third party login providers
49             //app.UseMicrosoftAccountAuthentication(
50             //    clientId: "",
51             //    clientSecret: "");
52
53             //app.UseTwitterAuthentication(
54             //   consumerKey: "",
55             //   consumerSecret: "");
56
57             //app.UseFacebookAuthentication(
58             //   appId: "",
59             //   appSecret: "");
60
61             //app.UseGoogleAuthentication(new GoogleOAuth2AuthenticationOptions()
62             //{
63             //    ClientId = "",
64             //    ClientSecret = ""
65             //});
66         }
67     }
68 }