AzureADB2C.UI-登录后将用户重定向到页面

时间:2019-04-24 18:09:27

标签: azure asp.net-core .net-core azure-ad-b2c

我在.NET Core Web应用程序上使用AzureADB2C.UI,但是我不确定在用户登录后如何将用户重定向到自定义页面ej /Customers/Index

这基本上是我以前使用SessionController时的内容,但是由于我正在使用AzureADB2C.UI,所以我不再有Controller。

var properties = new AuthenticationProperties { RedirectUri = redirectUrl };
properties.Items[AzureAdB2COptions.PolicyAuthenticationProperty] = AzureAdB2COptions.SignUpPolicy;
return Challenge(properties, OpenIdConnectDefaults.AuthenticationScheme);

这就是我在startup.cs上所拥有的

services.AddAuthentication(o => o.DefaultAuthenticateScheme = AzureADB2CDefaults.CookieScheme)
   .AddAzureADB2C(options => Configuration.Bind("AzureADB2C", options))
   .OnLogin(principal =>
       {
          services.BuildServiceProvider().GetRequiredService<LoginCommand>()
             .Execute(principal, principal.AzureID(), principal.Email(), principal.DisplayName());
       });

appsettings.json:

"AzureADB2C": {
    "Instance": "https://login.microsoftonline.com/tfp/",
    "ClientId": "............", // prod
    "CallbackPath": "/signin-oidc",
    "Domain": "something.onmicrosoft.com",
    "SignUpSignInPolicyId": "B2C_1_SiUpOrIn",
    "ResetPasswordPolicyId": "B2C_1_SSPR",
    "EditProfilePolicyId": "B2C_1_SiPe"
  }

在用户使用AzureADB2C.UI登录后,是否有人知道如何重定向用户?

2 个答案:

答案 0 :(得分:1)

在以下位置查看源代码:https://github.com/dotnet/aspnetcore/blob/master/src/Azure/AzureAD/Authentication.AzureADB2C.UI/src/Areas/AzureADB2C/Controllers/AccountController.cs

它们的默认实现

    [HttpGet("{scheme?}")]
    public IActionResult SignIn([FromRoute] string scheme)
    {
        scheme = scheme ?? AzureADB2CDefaults.AuthenticationScheme;
        var redirectUrl = Url.Content("~/");
        return Challenge(
            new AuthenticationProperties { RedirectUri = redirectUrl },
            scheme);
    }

您可以看到他们如何将重定向URL硬编码到您网站的根目录。实现自己的接受重定向路径的控制器方法,并在内置控制器上使用新控制器。

支持重定向传递的幼稚实现

    [HttpGet("login")]
    public IActionResult Login([FromQuery] string dest)
    {
        var scheme = "AzureADB2C";
        var redirectUrl = string.IsNullOrWhiteSpace(dest) ? Url.Content("~/") : Url.Content("~" + dest);
        return Challenge(
            new AuthenticationProperties { RedirectUri = redirectUrl },
            scheme);
    }

答案 1 :(得分:0)

回调路径应该是用户登录后登陆的路径,并且应该与在AD应用程序设置中注册的回调路径匹配。

现在,我从未尝试使用相对路径,例如您的/ customer / index。 我总是使用完整路径,如前所述,它确实起作用。