我正在使用ASP.Net Core创建一个网站,并使用Azure AD B2C保护它。
我已经实施了登录,但一切正常,但现在我正在尝试设置注册,但似乎无法正常工作。
我的网站设置基于this sample。
在该示例中,他们不使用注册策略,因为他们使用共享注册和登录策略(我不愿意),但他们确实使用编辑配置文件和重置密码策略,可以看到API方法在SessionController。
我试图以同样的方式实现我的注册端点:
var properties = new AuthenticationProperties() { RedirectUri = "/" };
properties.Items[AzureAdB2COptions.PolicyAuthenticationProperty] = AzureAdB2COptions.SignUpPolicyId;
await HttpContext.Authentication.ChallengeAsync( OpenIdConnectDefaults.AuthenticationScheme, properties, ChallengeBehavior.Unauthorized);
然而,当我到这里时,我只是被重定向到登录页面而不是注册页面。
注册政策和B2C目录一般都是正确设置的,因为我在其他网站上使用它没有任何问题。
有人可以告知可能导致这种情况的原因吗?
答案 0 :(得分:1)
在我的OnRedirectToIdentityProvider方法中,我有:
context.ProtocolMessage.IssuerAddress = context.ProtocolMessage.IssuerAddress.Replace(defaultPolicy, policy);
由于此处的IssuerAddress为小写,因此无法查找和更改策略。
我将其更新为:
context.ProtocolMessage.IssuerAddress = context.ProtocolMessage.IssuerAddress.ToLower().Replace(defaultPolicy.ToLower(), policy.ToLower());
中一样