post_logout_redirect_uri ASP NET Core 2.2 AzureAD Razor Class Library RCL

瘦欲@ 提交于 2021-02-07 04:37:36

问题


We have tried using the sample https://github.com/Azure-Samples/active-directory-aspnetcore-webapp-openidconnect-v2/ Walked through the sample and all works. We can't get it to redirect after logout process. Also, it seems the account controller is not there but it is called in _layout.chtml this must be something new.


回答1:


Yes, it does redirect to the application - what I'd like it to do is redirect to a different page.

You can redirect user to another page after sign-out by setting the OnSignedOutCallbackRedirect event :

  1. In Startup.cs add using System.Threading.Tasks;
  2. Config your new redirect url in OnSignedOutCallbackRedirect event :

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



回答2:


The account controller code is built into the framework now. You can see it in Microsoft.AspNetCore.Authentication.AzureAD.UI.AzureAD.Controllers.Internal (see 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 });
        }
    }
}

Unfortunately, I have not be able to force a redirect after logout. Instead, I see a page that says "You have successfully signed out." I'd like to know how to redirect the user back to the Index page.



来源:https://stackoverflow.com/questions/53889990/post-logout-redirect-uri-asp-net-core-2-2-azuread-razor-class-library-rcl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!