private async Task SignInAsync(AppMember appMember, bool isPersistent) { AuthenticationManager.SignOut(DefaultAuthenticationTypes.ExternalCookie, DefaultAuthenticationTypes.TwoFactorCookie); AuthenticationManager.SignIn(new AuthenticationProperties { IsPersistent = isPersistent }, await appMember.GenerateUserIdentityAsync(UserManager)); }
public void Configuration(IAppBuilder app) { app.CreatePerOwinContext <AppUserManager>(AppUserManager.Create); app.CreatePerOwinContext <AppRoleManager>(AppRoleManager.Create); app.CreatePerOwinContext <AppSignInManager>(AppSignInManager.Create); app.UseCookieAuthentication(new CookieAuthenticationOptions { AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie, LoginPath = new PathString("/Auth/Login"), Provider = new CookieAuthenticationProvider { // Enables the application to validate the security stamp when the AppMember logs in. // This is a security feature which is used when you change a password or add an external login to your account. OnValidateIdentity = SecurityStampValidator.OnValidateIdentity <AppUserManager, ExtendedUser, string>( validateInterval: TimeSpan.FromMinutes(30), regenerateIdentityCallback: (manager, AppMember) => AppMember.GenerateUserIdentityAsync(manager), getUserIdCallback: (id) => (id.GetUserId())) } }); app.UseCookieAuthentication(new CookieAuthenticationOptions { AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie }); }
public void Configuration(IAppBuilder app) { // For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=316888 //app.CreatePerOwinContext(ApplicationDbContext.Create); app.CreatePerOwinContext <AppUserManager>(AppUserManager.Create); app.CreatePerOwinContext <AppRoleManager>(AppRoleManager.Create); app.CreatePerOwinContext <AppSignInManager>(AppSignInManager.Create); app.UseCookieAuthentication(new CookieAuthenticationOptions { AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie, LoginPath = new PathString("/Account/Login"), Provider = new CookieAuthenticationProvider { // Enables the application to validate the security stamp when the AppMember logs in. // This is a security feature which is used when you change a password or add an external login to your account. OnValidateIdentity = SecurityStampValidator.OnValidateIdentity <AppUserManager, AppMember, int>( validateInterval: TimeSpan.FromMinutes(30), regenerateIdentityCallback: (manager, AppMember) => AppMember.GenerateUserIdentityAsync(manager), getUserIdCallback: (id) => (Int32.Parse(id.GetUserId()))) } }); app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie); // Enables the application to temporarily store AppMember information when they are verifying the second factor in the two-factor authentication process. app.UseTwoFactorSignInCookie(DefaultAuthenticationTypes.TwoFactorCookie, TimeSpan.FromMinutes(5)); // Enables the application to remember the second login verification factor such as phone or email. // 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. // This is similar to the RememberMe option when you log in. app.UseTwoFactorRememberBrowserCookie(DefaultAuthenticationTypes.TwoFactorRememberBrowserCookie); }
// 如需設定驗證的詳細資訊,請瀏覽 https://go.microsoft.com/fwlink/?LinkId=301864 public void ConfigureAuth(IAppBuilder app) { // 設定資料庫內容、使用者管理員和登入管理員,以針對每個要求使用單一執行個體 //app.CreatePerOwinContext(ApplicationDbContext.Create); app.CreatePerOwinContext(ApplicationDbContext.Create); app.CreatePerOwinContext <ApplicationUserManager>(ApplicationUserManager.Create); app.CreatePerOwinContext <ApplicationSignInManager>(ApplicationSignInManager.Create); //app.CreatePerOwinContext<AppUserManager>(AppUserManager.Create); //app.CreatePerOwinContext<AppRoleManager>(AppRoleManager.Create); // 讓應用程式使用 Cookie 儲存已登入使用者的資訊 // 並使用 Cookie 暫時儲存使用者利用協力廠商登入提供者登入的相關資訊; // 在 Cookie 中設定簽章 app.UseCookieAuthentication(new CookieAuthenticationOptions { AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie, LoginPath = new PathString("/Account/Login"), Provider = new CookieAuthenticationProvider { // 讓應用程式在使用者登入時驗證安全性戳記。 // 這是您變更密碼或將外部登入新增至帳戶時所使用的安全性功能。 OnValidateIdentity = SecurityStampValidator.OnValidateIdentity <ApplicationUserManager, AppMember, int>( validateInterval: TimeSpan.FromMinutes(30), regenerateIdentityCallback: (manager, AppMember) => AppMember.GenerateUserIdentityAsync(manager), getUserIdCallback: (id) => (Int32.Parse(id.GetUserId()))) } }); app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie); // 讓應用程式在雙因素驗證程序中驗證第二個因素時暫時儲存使用者資訊。 app.UseTwoFactorSignInCookie(DefaultAuthenticationTypes.TwoFactorCookie, TimeSpan.FromMinutes(5)); // 讓應用程式記住第二個登入驗證因素 (例如電話或電子郵件)。 // 核取此選項之後,將會在用來登入的裝置上記住登入程序期間的第二個驗證步驟。 // 這類似於登入時的 RememberMe 選項。 app.UseTwoFactorRememberBrowserCookie(DefaultAuthenticationTypes.TwoFactorRememberBrowserCookie); // 註銷下列各行以啟用利用協力廠商登入提供者登入 //app.UseMicrosoftAccountAuthentication( // clientId: "", // clientSecret: ""); //app.UseTwitterAuthentication( // consumerKey: "", // consumerSecret: ""); //app.UseFacebookAuthentication( // appId: "", // appSecret: ""); //app.UseGoogleAuthentication(new GoogleOAuth2AuthenticationOptions() //{ // ClientId = "", // ClientSecret = "" //}); }
// For more information on configuring authentication, please visit http://go.microsoft.com/fwlink/?LinkId=301864 public void ConfigureAuth(IAppBuilder app) { // Configure the db context, AppMember manager and signin manager to use a single instance per request app.CreatePerOwinContext(ApplicationDbContext.Create); app.CreatePerOwinContext <ApplicationUserManager>(ApplicationUserManager.Create); app.CreatePerOwinContext <ApplicationSignInManager>(ApplicationSignInManager.Create); // Enable the application to use a cookie to store information for the signed in AppMember // and to use a cookie to temporarily store information about a AppMember logging in with a third party login provider // Configure the sign in cookie app.UseCookieAuthentication(new CookieAuthenticationOptions { AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie, LoginPath = new PathString("/Account/Login"), Provider = new CookieAuthenticationProvider { // Enables the application to validate the security stamp when the AppMember logs in. // This is a security feature which is used when you change a password or add an external login to your account. OnValidateIdentity = SecurityStampValidator.OnValidateIdentity <ApplicationUserManager, AppMember, int>( validateInterval: TimeSpan.FromMinutes(30), regenerateIdentityCallback: (manager, AppMember) => AppMember.GenerateUserIdentityAsync(manager), getUserIdCallback: (id) => (Int32.Parse(id.GetUserId()))) } }); app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie); // Enables the application to temporarily store AppMember information when they are verifying the second factor in the two-factor authentication process. app.UseTwoFactorSignInCookie(DefaultAuthenticationTypes.TwoFactorCookie, TimeSpan.FromMinutes(5)); // Enables the application to remember the second login verification factor such as phone or email. // 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. // This is similar to the RememberMe option when you log in. app.UseTwoFactorRememberBrowserCookie(DefaultAuthenticationTypes.TwoFactorRememberBrowserCookie); // Uncomment the following lines to enable logging in with third party login providers //app.UseMicrosoftAccountAuthentication( // clientId: "", // clientSecret: ""); //app.UseTwitterAuthentication( // consumerKey: "", // consumerSecret: ""); //app.UseFacebookAuthentication( // appId: "", // appSecret: ""); //app.UseGoogleAuthentication(new GoogleOAuth2AuthenticationOptions() //{ // ClientId = "", // ClientSecret = "" //}); }