asp.net - 将 Owin Asp.Net 身份 Cookie 身份验证与 Owin OpenId 身份验证混合使用

标签 asp.net asp.net-identity owin

有谁知道将 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");
    }

这是问题,我试图在另一个尚未得到任何回应的线程上进行解释。

Link for the question

关于asp.net - 将 Owin Asp.Net 身份 Cookie 身份验证与 Owin OpenId 身份验证混合使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23785177/

相关文章:

c# - 如何在其他asp.net 项目中使用用C# 编写的DLL?

c# - self 主机中的代码工作两次

c# - MVC 和 Web Api 中的 Owin 身份验证

c# - 在 Microsoft.Owin.Security.OpenIdConnect 中间件的响应中添加位置 header

c# - Unity DI 帐户 Controller 中的 IRepositories 为空

c# - ASP .NET Core Identity 自定义 ApiAuthorizationDbContext

asp.net - 托管 ASP.NET 应用程序的硬盘空间对网站的性能有影响吗?

c# - ASP.NET c# 中 System.Threading.Timer 和 Thread.Sleep() 的区别

c# - App_Code 类中的全局资源

entity-framework - 使用 Azure 表存储进行代码优先和身份验证