Identity Server 3 AzureAd声明未返回

时间:2017-03-13 11:40:54

标签: azure-active-directory identityserver3 openid-connect

我有一个有效的Identity Server应用程序,我将其设置为与Azure AD一起使用。我已经注册了Azure Ad App,我可以正确地进行身份验证。

查看this并尝试执行类似操作以存储与用户关联的第三方用户ID,但我未收到subnameIdentifier声明来自AAD。

我是否需要以某种方式从AzureAD请求这些? - 他们的文档似乎是在说" sub"声明是(或至少可以)返回:https://docs.microsoft.com/en-us/azure/active-directory/develop/active-directory-token-and-claims#_subjectThis文章似乎表示不会返回,但它适用于多租户应用,因此我不太确定这是否相关。

我确定我遗漏了一些简单的内容,但无法在Google上找到任何相关内容。

干杯, 亚历

1 个答案:

答案 0 :(得分:0)

文章Work with claims-based identities太旧了,这篇Azure AD token reference文章对于Azure AD发布的令牌中的令牌声明应该是正确的。

根据测试,我可以从Azure AD获取sub声明,它也由IdentityServer3发布,如下图所示: enter image description here

以下是我为IdentityServer3配置的代码供您参考:

var webApp = WebApp.Start("https://localhost:44333", app =>
{
    app.UseIdentityServer(new IdentityServerOptions
    {
        SiteName = "NDC Demo",
        SigningCertificate = cert,
        Factory = factory,
        AuthenticationOptions = new AuthenticationOptions
        {
            IdentityProviders = ConfigureAdditionalIdentityProviders,
            EnableAutoCallbackForFederatedSignout = true
        }
    });
});

public static void ConfigureAdditionalIdentityProviders(IAppBuilder app, string signInAsType)
{
    app.UseOpenIdConnectAuthentication(new OpenIdConnectAuthenticationOptions
    {
        AuthenticationType = "aad",
        Caption = "Azure AD",
        SignInAsAuthenticationType = signInAsType,

        Authority = "https://login.microsoftonline.com/{tenantId}",
        ClientId = "{clientIdFromAzurePortal}",
        RedirectUri = "{redirectUri}",
    });
}

如果您仍然遇到问题,您是否介意将请求共享给Azure AD,您可以使用Fiddler捕获它。