0
votes

Azure AD B2C is setup for authentication in Asp.netCore web app. The authentication process works perfectly. After authentication, the user needs to be redirected back the page where the login was initiated at.

the way the current flow happens:

This is the button <a class="btn btn-primary" asp-area="AzureADB2C" asp-controller="Account" asp-action="SignIn">Sign in</a>

PublicPage (has an sign-in/register button) on part of page that user need be authenticated to interact with -> signin button clicked -> redirected to Azure AD B2C -> user returned to IndexPage.

the way the needs to be:

PublicPage (has an sign-in/register button) on part of page that user need be authenticated to interact with -> signin button clicked -> redirected to Azure AD B2C -> user returned to PublicPage.

EDIT @Jit_MSFT thanks for the suggestion, but I'm not exactly sure where to add those configurations.

services.AddAuthentication(AzureADB2CDefaults.AuthenticationScheme)
                   .AddAzureADB2C(options => { 
                       Configuration.Bind("AzureAdB2C", options);
                   });

The settings above don't have those options. Also there are several page need to have that dynamic ability.

context.Properties.RedirectUri = "/xxxx;

this seems like i wold be locked into one page on the returnUrl

1
Thanks @ChampChris. Could you please use authentication.navigateToLoginRequestUrl = false; and context.Properties.RedirectUri = "/xxxx; in your startup.cs file and let us know if it will not workJit_MSFT
@Jit_MSFT the problem with that approach is that, the redirect uri is dynamic. Or are saying the /xxxx literally should be put in the startup?ChampChris

1 Answers

0
votes

In your AccountController, please define the SignIn method as something like:

public async Task SignIn()
{
    var redirectUri = ... // your redirect URI
    await HttpContext.ChallengeAsync(AzureADB2CDefaults.AuthenticationScheme,
                               new AuthenticationProperties { RedirectUri = redirectUri });
}

You may also check other details and options in this answer

In addition, please check if, in Azure AD, you have to register your client app with a matching redirect URI (more details here) :)