首页 文章

使用Owin OpenId身份验证混合Owin Asp.Net身份Cookie身份验证

提问于
浏览
3

有没有人知道将Owin Asp.Net Identity Cookie身份验证(本地数据库)与Owin OpenId身份验证( Cloud )混合的一个很好的例子?然后,用户可以选择登录/注册,创建新用户和传递(存储在本地数据库中)或通过例如Office 365帐户 . 但是所有用户都将使用asp.net Identity(本地数据库)中的声明和角色 .

1 回答

  • 0

    我这样做了,但我有一些奇怪的问题 . 这是我在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");
        }
    

    这是问题,我试图解释另一个尚未得到任何响应的线程 .

    Link for the question

相关问题