ASP.NET IdentityServer3 的身份插件 UI (IdentityManager) 在部署到 Azure (WebApp) 后无法正常工作

ASP.NET Identity plugin UI (IdentityManager) for IdentityServer3 not working after deploying to Azure (WebApp)

我使用提供的示例设置 IdentityServer3 以使用 ASP.NET 身份。在本地一切正常,我可以通过“/admin”访问 Identity Manager UI 并且可以 add/remove users/roles.

但是,当我将它部署到 Azure 并尝试访问它时,什么也没有发生,并将我带到如下所示的 URL: https://IdentityServer3/admin/authorize?state=11373557769572288&client_id=idmgr&response_type=token

无论我使用本地还是远程 (Azure SQL) 数据库,它在本地都可以正常工作。

IdentityManager 在首次访问时自动登录本地用户,我怀疑这在访问远程服务器时可能是个问题,但我不确定如何customize/change。

我使用的样本在这里:https://github.com/IdentityServer/IdentityServer3.Samples/tree/master/source/AspNetIdentity

好的,以防其他人偶然发现这个问题,解决方案是将 IdentityManager 的 SecurityConfiguration 更改为 HostSecurityConfiguration,然后:

  1. 手动实现一个简单的身份验证机制,如下所示:https://vimeo.com/125427106

  2. 像配置任何其他 OIDC 客户端一样配置 IdentityManager。此处有更多详细信息:https://www.scottbrady91.com/ASPNET-Identity/Identity-Manager-using-ASPNET-Identity

以上都是必要的,因为默认情况下 IdentityManager 使用 LocalhostSecurityConfiguration,它只允许通过 localhost.

进行身份验证

对于第二个选项,IdentityManager 的 SecurityConfiguration 最终将如下所示:

managerApp.UseIdentityManager(new IdentityManagerOptions()
                {                            
                    SecurityConfiguration = new HostSecurityConfiguration
                    {
                        HostAuthenticationType = "cookies",
                        AdditionalSignOutType = "oidc",
                        NameClaimType = Constants.ClaimTypes.Name,
                        RoleClaimType = Constants.ClaimTypes.Role,
                        AdminRoleName = "IdentityManagerAdministrator" //default role name for IdentityManager
                    }
                });

提示,如果您 运行 IdentityManager 在与 IdentityServer 本身相同的 Web 应用程序中,请确保将 IdentityManager 的身份验证逻辑放在 IdentityServer 映射之后和 IdentityManager 的映射之前:

app.Map("/identity", idsrvApp =>

//this sets IdentityManager to use IdentityServer as Idp
ConfigureIdentityManagerAuthentication(app);

app.Map("/manager", managerApp =>

如果您将它放在 IdentityServer 的映射之前,那么您将在 IdentityServer 登录页面中看到一个额外的外部 'OpenId' 提供程序。如果将它放在 IdentityManager 映射之后,则身份验证将不起作用。