簡體   English   中英

Azure AD B2C配置多個登錄策略

[英]Azure AD B2C Configure Multiple Sign on Policies

我想在Azure AD B2C中實現類似於此問題的多個注冊/登錄策略,但是我不知道如何在Visual Studio中配置我的解決方案以引用web.config文件中指定的不同注冊策略。 有人可以幫忙嗎?

您可以通過將請求的策略從控制器方法傳遞到身份驗證中間件來為不同類型的用戶調用不同的策略:

public IActionResult LogInForIndividualCustomer()
{
        return LogInFor(Constants.AuthenticationSchemes.B2COpenIdConnect, Constants.Policies.SignUpOrSignInWithPersonalAccount);
}

private IActionResult LogInFor(string authenticationScheme, string policy)
{
    if (!User.Identity.IsAuthenticated)
    {
        return new ChallengeResult(
            authenticationScheme,
            new AuthenticationProperties(
                new Dictionary<string, string>
                {
                    {Constants.AuthenticationProperties.Policy, policy}
                })
            {
                RedirectUri = Url.Action("LoggedIn", "Account", values: null, protocol: Request.Scheme)
            });
    }

    return RedirectToHome();
}

然后在身份驗證中間件中為請求的策略設置重定向URL

OnRedirectToIdentityProvider = async context =>
{
    var policy = context.Properties.Items.ContainsKey(Constants.AuthenticationProperties.Policy) ? context.Properties.Items[Constants.AuthenticationProperties.Policy] : Constants.Policies.SignUpOrSignInWithPersonalAccount;
    var configuration = await GetB2COpenIdConnectConfigurationAsync(context, policy);
    context.ProtocolMessage.IssuerAddress = configuration.AuthorizationEndpoint;
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM