Advertisement
Guest User

Untitled

a guest
Sep 23rd, 2014
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.45 KB | None | 0 0
  1. using System;
  2. using Domain;
  3. using Domain.Entities;
  4. using Microsoft.AspNet.Identity;
  5. using Microsoft.AspNet.Identity.Owin;
  6. using Microsoft.Owin;
  7. using Microsoft.Owin.Security.Cookies;
  8. using Microsoft.Owin.Security.Google;
  9. using Owin;
  10. using CKBase.Models;
  11.  
  12. namespace CKBase
  13. {
  14.     public partial class Startup
  15.     {
  16.         // For more information on configuring authentication, please visit http://go.microsoft.com/fwlink/?LinkId=301864
  17.         public void ConfigureAuth(IAppBuilder app)
  18.         {
  19.             // Configure the db context, user manager and signin manager to use a single instance per request
  20.             app.CreatePerOwinContext(YourDbNameHere.Create);
  21.             app.CreatePerOwinContext<ApplicationUserManager>(ApplicationUserManager.Create);
  22.             app.CreatePerOwinContext<ApplicationSignInManager>(ApplicationSignInManager.Create);
  23.  
  24.             // Enable the application to use a cookie to store information for the signed in user
  25.             // and to use a cookie to temporarily store information about a user logging in with a third party login provider
  26.             // Configure the sign in cookie
  27.             app.UseCookieAuthentication(new CookieAuthenticationOptions
  28.             {
  29.                 AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
  30.                 LoginPath = new PathString("/Account/Login"),
  31.                 Provider = new CookieAuthenticationProvider
  32.                 {
  33.                     // Enables the application to validate the security stamp when the user logs in.
  34.                     // This is a security feature which is used when you change a password or add an external login to your account.  
  35.                     OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, User>(
  36.                         validateInterval: TimeSpan.FromMinutes(30),
  37.                         regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager))
  38.                 }
  39.             });            
  40.             app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);
  41.  
  42.             // Enables the application to temporarily store user information when they are verifying the second factor in the two-factor authentication process.
  43.             app.UseTwoFactorSignInCookie(DefaultAuthenticationTypes.TwoFactorCookie, TimeSpan.FromMinutes(5));
  44.  
  45.             // Enables the application to remember the second login verification factor such as phone or email.
  46.             // 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.
  47.             // This is similar to the RememberMe option when you log in.
  48.             app.UseTwoFactorRememberBrowserCookie(DefaultAuthenticationTypes.TwoFactorRememberBrowserCookie);
  49.  
  50.             // Uncomment the following lines to enable logging in with third party login providers
  51.             //app.UseMicrosoftAccountAuthentication(
  52.             //    clientId: "",
  53.             //    clientSecret: "");
  54.  
  55.             //app.UseTwitterAuthentication(
  56.             //   consumerKey: "",
  57.             //   consumerSecret: "");
  58.  
  59.             //app.UseFacebookAuthentication(
  60.             //   appId: "",
  61.             //   appSecret: "");
  62.  
  63.             //app.UseGoogleAuthentication(new GoogleOAuth2AuthenticationOptions()
  64.             //{
  65.             //    ClientId = "",
  66.             //    ClientSecret = ""
  67.             //});
  68.         }
  69.     }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement