question

AmbigerMahantesh-7470 avatar image
0 Votes"
AmbigerMahantesh-7470 asked alfredorevilla-msft edited

Mulitple ADB2C policies for differenct users from Angular client

I have an angular for which the users are company employees and external users. There are two separate ADB2C policies defined for each type of users. I have followed the approach that Microsoft has provided (see the link below). With this approach I am able configure one type of authentication. Can you please suggest a good way to implement hot two end points based which button is clicked?


https://docs.microsoft.com/en-us/azure/active-directory-b2c/enable-authentication-angular-spa-app

azure-ad-b2c
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

alfredorevilla-msft avatar image
0 Votes"
alfredorevilla-msft answered alfredorevilla-msft edited

Hello @ambigermahantesh-7470. You might try to create your own Factory Provider so that it instantiate a different PublicClientApplication depending on the policy to use.

export function MSALInstanceFactory(policyService: PolicyService): IPublicClientApplication {
  return new PublicClientApplication({
    auth: {
      clientId:  "6226576d-37e9-49eb-b201-ec1eeb0029b6",
      authority: policyService.GetPolicyUrl(),
      redirectUri: "http://localhost:4200",
      postLogoutRedirectUri: "http://localhost:4200"
    },
    cache: {
      cacheLocation: BrowserCacheLocation.LocalStorage,
      storeAuthStateInCookie: isIE, // set to true for IE 11
    },
  });
}


The button clicked would set a value in an application wide state (Data stores, singleton service, etc) so that the factory can use the later and instantiate the appropiate PublicClientApplication.

// component.ts
// this.policyService is an injected dependency
policy1buttonClick(){
    this.policyService.setPolicy(1);
}
policy2buttonClick(){
    this.policyService.setPolicy(2);
}


Please let us know if you need additional assistance.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.