【问题标题】:How to enable Azure integration in IdentityServer4 for Core 2.0?如何在 IdentityServer4 for Core 2.0 中启用 Azure 集成?
【发布时间】:2018-04-04 19:48:01
【问题描述】:

我有一个基于 IdentityServer4 core 1.0 的应用程序。它与 Azure AD 有效集成。但是,将项目迁移到 IdentityServer4 2.0.0-rc1 后,集成不再起作用。这与从 .NET Core 1.0 到 Core 2.0 的破坏性变化有关。我遵循https://docs.microsoft.com/en-us/aspnet/core/migration/1x-to-2x/identity-2x的建议

我尝试将 app.UseOpenIdConnectAuthentication 调用更改为

services.AddAuthentication() .AddMicrosoftAccount(...)

或到

services.AddAuthentication() .AddOpenIdConnect(...)

但所有这些仅在此查询中产生空列表: _httpContextAccessor.HttpContext.Authentication.GetAuthenticationSchemes(),用于构建外部认证服务。

有谁知道再次启用 Azure AD 集成的正确方法是什么?

【问题讨论】:

    标签: azure integration azure-active-directory identityserver4


    【解决方案1】:

    经过一番研究,我想通了。重要的是,您不应再依赖过时的调用:_httpContextAccessor.HttpContext.Authentication.GetAuthenticationSchemes()。相反,您应该调用await _schemaProvider.GetAllSchemesAsync(),其中_schemaProvider 是IAuthenticationSchemeProvider 的注入接口。另一个更改是在 Startup.cs ConfigureServices 中,您应该像这样构建外部身份验证提供程序:

    services.AddAuthentication(options => { options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme; options.DefaultChallengeScheme = "[custom name]" }) .AddCookie() .AddOpenIdConnect("[custom name]", options => { options.Authority = $"https://login.microsoftonline.com/[tenantid]"; options.ClientId = [client id]; });

    注意:我将名称作为第一个参数传递给 AddOpenIdConnect,它将为该实例提供自定义方案名称。这有助于在登录页面上显示外部提供程序,因为我还没有弄清楚如何传递 DisplayName。如果没有此更改,它将显示“openIdConnect”。如果我有很多 AAD 集成,我认为这太笼统和混乱了。由于此方案更改,您还需要确保 options.DefaultChallengeScheme 设置为您添加的方案名称。

    【讨论】:

      【解决方案2】:

      John Cheng 是正确的。 只是想在 AddOpenIdConnect 方法中添加第二个参数,该参数采用显示名称:

      .AddOpenIdConnect("azure", "AZURE AD", options => {})

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-03-06
        • 1970-01-01
        • 1970-01-01
        • 2018-09-29
        • 2019-07-19
        • 1970-01-01
        • 1970-01-01
        • 2018-11-22
        相关资源
        最近更新 更多