Azure AD B2C AuthenticationResponseChallenge

时间:2016-02-08 04:34:10

标签: azure-web-sites azure-ad-b2c

我最近几天在Azure AD B2C上工作,得到了一个示例并使其运行。 我面临的问题与{3}点#3完全相同,但我可以在这个可能解决我问题的问题上得到任何有价值的评论。示例对我运行正常但是当我在我的解决方案中实现它时,在给出AAD B2C凭证之后我最终得到了:

   private async Task OnRedirectToIdentityProvider(RedirectToIdentityProviderNotification<OpenIdConnectMessage, OpenIdConnectAuthenticationOptions> notification)
    {
        PolicyConfigurationManager mgr = notification.Options.ConfigurationManager as PolicyConfigurationManager;
        if (notification.ProtocolMessage.RequestType == OpenIdConnectRequestType.LogoutRequest)
        {
            OpenIdConnectConfiguration config = await mgr.GetConfigurationByPolicyAsync(CancellationToken.None, notification.OwinContext.Authentication.AuthenticationResponseRevoke.Properties.Dictionary[Startup.PolicyKey]);
            notification.ProtocolMessage.IssuerAddress = config.EndSessionEndpoint;
        }
        else
        {
            OpenIdConnectConfiguration config = await mgr.GetConfigurationByPolicyAsync(CancellationToken.None, notification.OwinContext.Authentication.AuthenticationResponseChallenge.Properties.Dictionary[Startup.PolicyKey]);
            notification.ProtocolMessage.IssuerAddress = config.AuthorizationEndpoint;
        }
    }

在'else'部分,AuthenticationResponseChallenge始终为null,这会引发错误。任何人都可以给我一个详细的答复,原因是什么以及如何解决它?

1 个答案:

答案 0 :(得分:0)

我遇到了同样的问题,因为实际的PolicyKey没有正确启动,请确保您拥有&#34; PolicyAuthHelpers&#34; (由Microsoft提供,因为他们当前的库无法处理B2C)。将代码放入PolicyConfigurationManager.cs中,您可以找到它中断的原因。还要验证您是否在web.config中配置了正确的策略,例如:

<add key="ida:SignInPolicyId" value="B2C_1_signin" />

如果这没有帮助你当然可以硬编码:

 OpenIdConnectConfiguration config = await mgr.GetConfigurationByPolicyAsync(CancellationToken.None, notification.OwinContext.Authentication.AuthenticationResponseChallenge.Properties.Dictionary["b2cpolicy"]);