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

查看:80
本文介绍了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,所以我不再具有Controller了.

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?

推荐答案

在以下位置查看源代码:

Check out the source at: 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硬编码到您网站的根目录.实现您自己的控制器方法,该方法接受重定向路径,并在内置控制器上使用新的控制器.

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天全站免登陆