AzureADB2C.UI - 登录后将用户重定向到页面 [英] AzureADB2C.UI - Redirect user to page after sign in

查看:26
本文介绍了AzureADB2C.UI - 登录后将用户重定向到页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm using AzureADB2C.UI on a .NET Core web application but I'm not sure how I can redirect a user to a custom page ej /Customers/Index after he signs in.

这基本上是我之前使用 SessionController 时的情况,但由于我使用的是 AzureADB2C.UI,所以我不再有控制器了.

This is basically what I had previously when using a SessionController but I don't have a Controller anymore since I'm using AzureADB2C.UI.

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 登录后重定向吗?

Does anybody knows how to redirect a user after he signs in using AzureADB2C.UI?

推荐答案

查看源代码: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);
    }

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

You can see how they are hardcoding the redirect Url to the root of your site. Implement your own controller method that accepts the redirect path and use your new controller over the built in controller.

支持传入重定向的简单实现

    [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);
    }

这篇关于AzureADB2C.UI - 登录后将用户重定向到页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆