Browser is continously looping after signing in ADB2C

Rekell Caraan 21 Reputation points

A web app built in .Net Core 3.1 calling a protected custom web API built in .Net Core 3.1 too. Both web app and web api is using the one registered app in ADB2C tenant. That registered app has scope and redirect URIs. Access token and ID token is enabled too. Sign-in user flow is created and configured for local identity and MS identity. Using the default UI page for sign-in but plans to customize it later. Both web api and web app is also using azure key vault for some confidential values.

The issue is that after signing in from the Sign-in page using either local identity or MS identity, the browser is just looping continuously. Sometimes the error is something like "the resource you are looking for has been removed or changed".

Below are my configurations and codes:

Azure App Settings and appsettings.json of Web App or client
"AzureAdB2C": {
"Scopes": "user_access",
"Instance": "https://{tenant}",
"ClientId": "{the registered app client ID}",
"Domain": "{tenant}",
"SignedOutCallbackPath": "/{signin policy}/oauth2/v2.0/logout/",
"SignUpSignInPolicyId": "{signin policy}",
"ClientSecret": "{the registered app client secret}"

Web App Startup >> ConfigureServices

        services.Configure<CookiePolicyOptions>(options =>  
            // This lambda determines whether user consent for non-essential cookies is needed for a given request.  
            options.CheckConsentNeeded = context => true;  
            options.MinimumSameSitePolicy = SameSiteMode.None;  
            // Handling SameSite cookie according to  

            .AddMicrosoftIdentityWebAppAuthentication(Configuration, Constants.AzureAdB2C)  
            .EnableTokenAcquisitionToCallDownstreamApi(new string[] { "user_access" })  

        services.AddAuthorization(options =>  
            var groups = new Groups(Configuration);  
            options.AddPolicy("IsAdmin", policy =>  
                policy.RequireClaim(Groups.ClaimName, groups.Admin));  
            options.AddPolicy("IsUser", policy =>  
                policy.RequireClaim(Groups.ClaimName, groups.User));  

            options.AddPolicy("GeneralAccess", policy =>  
                policy.RequireClaim(Groups.ClaimName, groups.User, groups.Admin));  
            options.FallbackPolicy = options.GetPolicy("GeneralAccess");  



        //Deployment Mode  
        var deploymentMode = Configuration.GetSection("DeploymentMode");  
        //Set Session Timeout. Default is 20 minutes.  
        services.AddSession(options =>  
            options.IdleTimeout = TimeSpan.FromMinutes(30);  
        //services.AddSession(options =>  
        //    options.Cookie.HttpOnly = true;  
        //    options.Cookie.IsEssential = true;  

        //Configuring appsettings section AzureAdB2C, into IOptions  

Web App Controller(s)
//[Authorize(Policy = "GeneralAccess")]
//[RequiredScope(RequiredScopesConfigurationKey = "AzureAdB2C:Scopes")]
public class HomeController : Controller {

Web App Service for token acquisition
HttpResponseMessage response = null;
string accessToken = await _tokenAcquisition.GetAccessTokenForUserAsync(requiredScopes);
_client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);

Microsoft Entra External ID
Microsoft Entra External ID
A modern identity solution for securing access to customer, citizen and partner-facing apps and services. It is the converged platform of Azure AD External Identities B2B and B2C. Replaces Azure Active Directory External Identities.
2,756 questions
{count} votes

Accepted answer
  1. Shweta Mathur 29,531 Reputation points Microsoft Employee

    Hi @ RekellCaraan-3504,

    Thanks for the update.

    I have tried to replicate the issue by registering web app and web api and expose the scope of API in web app and able to call the web API successfully from web APP in .NET core.

    I tried multiple combinations to reproduce the error at my end, but I am able to sign in the B2C application and calling web API successfully after providing credentials.
    The error you are getting might be due to incorrect configurations in the application.

    I am trying to understand the use case where web App is calling itself for webAPI. The scope of webAPI need to expose for which client applications can obtain access tokens and call webAPI from web app. In case of single registered application, webapp calling the application itself.

    Are you also facing this issue when you are registering the two applications separately for both web application and web API?

    The scope you are passing in configuration file does not seem to be correct. It should be redirected to API scope with its address. Below is the configuration file I am using for which i am able to call web API successfully.

    "AzureAdB2C": {

    "Instance": "",
    "ClientId": "xxxx-xxx-xx-xx-xx",
    "Domain": "",
    "SignedOutCallbackPath": "/B2C_1_signupsignin//oauth2/v2.0/logout/",
    "SignUpSignInPolicyId": "B2C_1_signupsignin",
    "ClientSecret": "xxx"

    "API": {

    "APIScope": "",
    "APIBaseAddress": "https://localhost:44332"


    In startup. cs

    services.AddMicrosoftIdentityWebAppAuthentication(Configuration, Constants.AzureAdB2C)
    .EnableTokenAcquisitionToCallDownstreamApi(new string[] { Configuration["API:APIScope"] })

    I refer to call webApp from webAPI.

    Note: Posting it as answer as comment has limit restriction.

0 additional answers

Sort by: Most helpful