Getting CORS on Azure AD B2C with For a talent that configured under Microsoft Entra External ID

Sourav Karmakar 0 Reputation points
2025-05-23T12:29:13.79+00:00

Hello Team,

Getting CORS error when we configure Azure AD B2C in my angular app. The "Sign Up Sign In" user flow is not coming with MsalGuard.

I added Redirect URLs properly in App Registration.
User's image

Here I'm sharing my app-config and app-module, and the error screenshot.

User's image

User's image

User's image

Code of app-config

// src/app/app.config.ts

import { Configuration, InteractionType, LogLevel } from '@azure/msal-browser';
import { MsalInterceptorConfiguration, ProtectedResourceScopes } from '@azure/msal-angular';

// Replace these with your actual Azure AD B2C details
const b2cTenant = 'souravwebapp.onmicrosoft.com';
const b2cDomain = 'souravwebapp.ciamlogin.com';
const clientId = '02d5d6ed-3624-4cce-b886-0bee17e0b660';
const apiClientId = '4143217a-0a92-4eaa-baa8-0a87cc7acafb';
const signUpSignInPolicy = 'souravwebapp_signup_signin';  
const redirectUri = 'http://localhost:4200'; // or your production URL
const apiUri = 'https://localhost:44316';

export const msalConfig: Configuration = {
  auth: {
    clientId,
    authority: `https://${b2cDomain}/${b2cTenant}/${signUpSignInPolicy}`,
    knownAuthorities: [b2cDomain],
    redirectUri,
    postLogoutRedirectUri: redirectUri
  },
  cache: {
    cacheLocation: 'localStorage',
    storeAuthStateInCookie: false
  },
  system: {
    loggerOptions: {
      loggerCallback: (level, message, containsPii) => {
        if (!containsPii) {
          console.log(message);
        }
      },
      logLevel: LogLevel.Info
    }
  }
};

export const loginRequest = {
  scopes: ['openid', 'profile', `https://${b2cTenant}/${apiClientId}/access_as_user`]
};

export const protectedResourceMap = new Map<string, Array<string>>([
  [apiUri, [`https://${b2cTenant}/${apiClientId}/access_as_user`]]
]);

export const msalInterceptorConfig: MsalInterceptorConfiguration = {
  interactionType: InteractionType.Redirect,
  protectedResourceMap,
};

.NET Runtime
.NET Runtime
.NET: Microsoft Technologies based on the .NET software framework.Runtime: An environment required to run apps that aren't compiled to machine language.
1,265 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Sam Crowley 0 Reputation points
    2025-05-23T17:01:15.5066667+00:00

    // src/app/app.config.ts

    import { Configuration, InteractionType, LogLevel } from '@azure/msal-browser';

    import { MsalInterceptorConfiguration, ProtectedResourceScopes } from '@azure/msal-angular';

    // Replace these with your actual Azure AD B2C details

    const b2cTenant = 'souravwebapp.onmicrosoft.com';

    const b2cDomain = 'souravwebapp.ciamlogin.com';

    const clientId = '02d5d6ed-3624-4cce-b886-0bee17e0b660';

    const apiClientId = '4143217a-0a92-4eaa-baa8-0a87cc7acafb';

    const signUpSignInPolicy = 'souravwebapp_signup_signin';

    const redirectUri = 'http://localhost:4200'; // or your production URL

    const apiUri = 'https://localhost:44316';

    export const msalConfig: Configuration = {

    auth: {

    clientId,
    
    authority: `https://${b2cDomain}/${b2cTenant}/${signUpSignInPolicy}`,
    
    knownAuthorities: [b2cDomain],
    
    redirectUri,
    
    postLogoutRedirectUri: redirectUri
    

    },

    cache: {

    cacheLocation: 'localStorage',
    
    storeAuthStateInCookie: false
    

    },

    system: {

    loggerOptions: {
    
      loggerCallback: (level, message, containsPii) => {
    
        if (!containsPii) {
    
          console.log(message);
    
        }
    
      },
    
      logLevel: LogLevel.Info
    
    }
    

    }

    };

    export const loginRequest = {

    scopes: ['openid', 'profile', https://${b2cTenant}/${apiClientId}/access_as_user]

    };

    export const protectedResourceMap = new Map<string, Array<string>>([

    [apiUri, [https://${b2cTenant}/${apiClientId}/access_as_user]]

    ]);

    export const msalInterceptorConfig: MsalInterceptorConfiguration = {

    interactionType: InteractionType.Redirect,

    protectedResourceMap,

    };

    0 comments No comments

  2. Sam Crowley 0 Reputation points
    2025-05-23T17:01:57.4166667+00:00

    clientId,

    authority: https://${b2cDomain}/${b2cTenant}/${signUpSignInPolicy},

    knownAuthorities: [b2cDomain],

    redirectUri,

    postLogoutRedirectUri: redirectUricacheLocation: 'localStorage',

    storeAuthStateInCookie: falseloggerOptions: {

    loggerCallback: (level, message, containsPii) => {

    if (!containsPii) {
    
      console.log(message);
    
    }
    

    },

    logLevel: LogLevel.Info

    }


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.