簡體   English   中英

使用Owin OpenId身份驗證混合Owin Asp.Net身份Cookie身份驗證

[英]Mixing Owin Asp.Net Identity Cookie Authentication with Owin OpenId Authentication

有沒有人知道將Owin Asp.Net Identity Cookie身份驗證(本地數據庫)與Owin OpenId身份驗證(雲)混合的一個很好的例子? 然后,用戶可以選擇登錄/注冊,創建新用戶和通行證(存儲在本地數據庫中)或通過例如Office 365帳戶。 但是所有用戶都將使用asp.net Identity(本地數據庫)中的聲明和角色。

我這樣做了,但我有一些奇怪的問題。 這是我在Startup.Auth.cs中的ConfigureAuth方法

 public void ConfigureAuth(IAppBuilder app)
    {
        // Configure the db context and user manager to use a single instance per request
        app.CreatePerOwinContext(ApplicationDbContext.Create);
        app.CreatePerOwinContext<ApplicationUserManager>(ApplicationUserManager.Create);

         app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);
        //app.Properties["Microsoft.Owin.Security.Constants.DefaultSignInAsAuthenticationType"] = "ExternalCookie";

            // Enable the application to use a cookie to store information for the signed in user
        // and to use a cookie to temporarily store information about a user 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
            {
                OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, ApplicationUser>(
                    validateInterval: TimeSpan.FromMinutes(30),
                    regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager))
            }
        });

        app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);

        app.UseOpenIdConnectAuthentication(
          new OpenIdConnectAuthenticationOptions
          {
              ClientId = clientId,
              Authority = authority,
              PostLogoutRedirectUri = postLogoutRedirectUri
          });
    }

AccountController中的注銷方法

   public ActionResult LogOff()
    {
        //AuthenticationManager.SignOut();
        AuthenticationManager.SignOut( 
            DefaultAuthenticationTypes.ExternalCookie, 
            DefaultAuthenticationTypes.ApplicationCookie, 
            OpenIdConnectAuthenticationDefaults.AuthenticationType,
            CookieAuthenticationDefaults.AuthenticationType
        );
        return RedirectToAction("Login", "Account");
    }

這是問題,我試圖解釋另一個尚未得到任何響應的線程。

鏈接問題

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM