post_logout_redirect_uri ASP NET Core 2.2 AzureAD Razor类库RCL

时间:2018-12-21 19:41:30

标签: razor asp.net-core azure-active-directory openid-connect

我们尝试使用示例 https://github.com/Azure-Samples/active-directory-aspnetcore-webapp-openidconnect-v2/ 浏览了样本和所有作品。 退出过程后,我们无法使其重定向。另外,似乎帐户控制器不存在,但在_layout.chtml中被调用,这一定是新的东西。

2 个答案:

答案 0 :(得分:3)

  
    

是的,它确实重定向到了应用程序-我想要它执行的操作是重定向到另一个页面。

  

您可以在退出后通过设置OnSignedOutCallbackRedirect事件将用户重定向到另一个页面:

  1. Startup.cs中添加using System.Threading.Tasks;
  2. OnSignedOutCallbackRedirect事件中配置新的重定向URL:

    services.Configure<OpenIdConnectOptions>(AzureADDefaults.OpenIdScheme, options =>
    {
        options.Authority = options.Authority + "/v2.0/";
    
        options.TokenValidationParameters.ValidateIssuer = false;
    
        options.Events.OnSignedOutCallbackRedirect = (context) =>
        {
    
            context.Response.Redirect("/Home/About");
            context.HandleResponse();
    
            return Task.CompletedTask;
        };
    });
    

答案 1 :(得分:1)

帐户控制器代码现已内置到框架中。您可以在Microsoft.AspNetCore.Authentication.AzureAD.UI.AzureAD.Controllers.Internal中看到它(请参见https://github.com/aspnet/AADIntegration/blob/0efa96de73e3235fbfc55cfe51d9547a693010cc/src/Microsoft.AspNetCore.Authentication.AzureAD.UI/Areas/AzureAD/Controllers/AccountController.cs):

namespace Microsoft.AspNetCore.Authentication.AzureAD.UI.AzureAD.Controllers.Internal
{
    [AllowAnonymous]
    [Area("AzureAD")]
    [NonController]
    [Route("[area]/[controller]/[action]")]
    internal class AccountController : Controller
    {
        public IOptionsMonitor<AzureADOptions> Options
        {
            get;
        }

        public AccountController(IOptionsMonitor<AzureADOptions> options)
        {
            this.Options = options;
        }

        [HttpGet("{scheme?}")]
        public IActionResult SignIn([FromRoute] string scheme)
        {
            scheme = scheme ?? AzureADDefaults.AuthenticationScheme;
            string str = base.Url.Content("~/");
            return this.Challenge(new AuthenticationProperties()
            {
                RedirectUri = str
            }, new String[] { scheme });
        }

        [HttpGet("{scheme?}")]
        public IActionResult SignOut([FromRoute] string scheme)
        {
            scheme = scheme ?? AzureADDefaults.AuthenticationScheme;
            AzureADOptions azureADOption = this.Options.Get(scheme);
            string str = base.Url.Page("/Account/SignedOut", null, null, base.Request.Scheme);
            return this.SignOut(new AuthenticationProperties()
            {
                RedirectUri = str
            }, new String[] { azureADOption.CookieSchemeName, azureADOption.OpenIdConnectSchemeName });
        }
    }
}

不幸的是,我无法在注销后强制重定向。而是,我看到一个页面,上面写着“您已成功注销”。我想知道如何将用户重定向回“索引”页面。