Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change Azure AD B2C SignOut URL (Change AzureADB2C/Account/SignedOut to custom URL)

I'm currently building a C# Net Core 2.2 app that is using Azure B2C OIDC for login/authentication. I've customized the login page and know how to customize the edit/forgot password screens with CSS and code hosted on my site using custom page layouts.

The problem I'm running into is that on signout, I'm being redirected to /AzureADB2C/Account/SignOut. I'd like to either modify the CSS like I can with the login page, or change that URL to go to a custom controller action hosted on my site.

Does anyone know how/what the process is to manage that? It seems weird they would have custom layouts available for everything "but" the sign out process.

As a workaround, I found I could add a "Rewrite Option" for handling the SignOut URL and rewriting it to a controller I have on my site. However, I'm not sure if this is the optimal way to accomplish this task, it was on a very obscure MSDN page, but it does work. See below:

// Inside Startup.cs
// Workaround for SignedOut URL error in MSFT code 
RewriteOptions rewrite = new RewriteOptions().AddRedirect("AzureADB2C/Account/SignedOut","Account/SignedOut"); 
app.UseRewriter(rewrite);
like image 965
Ian Nielson Avatar asked Feb 03 '23 18:02

Ian Nielson


1 Answers

If you look at the source code of the AccountController in the Microsoft.AspNetCore.Authentication.AzureADB2C.UI nuget package, you can see that the callbackUrl is hard-coded to (/AzureADB2C)/Account/SignedOut.

But there is no requirement to use that controller. Just call your own SignOut action on your own controller. Copy-paste the code from the AzureADB2C SignOut action and change the callbackUrl to your own.

Edit _LoginPartial.cshtml: remove asp-area="AzureADB2C" and use your own for asp-controller and asp-action.

like image 80
Marcel W Avatar answered Feb 06 '23 08:02

Marcel W