Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I cant use more than one configuration for MSAL #7421

Open
2 tasks
cdiazp-sacyr opened this issue Nov 15, 2024 · 0 comments
Open
2 tasks

I cant use more than one configuration for MSAL #7421

cdiazp-sacyr opened this issue Nov 15, 2024 · 0 comments
Labels
b2c Related to Azure B2C library-specific issues bug-unconfirmed A reported bug that needs to be investigated and confirmed msal-angular Related to @azure/msal-angular package msal-browser Related to msal-browser package Needs: Attention 👋 Awaiting response from the MSAL.js team public-client Issues regarding PublicClientApplications question Customer is asking for a clarification, use case or information.

Comments

@cdiazp-sacyr
Copy link

Core Library

MSAL.js (@azure/msal-browser)

Core Library Version

3.24.0

Wrapper Library

MSAL Angular (@azure/msal-angular)

Wrapper Library Version

3.0.23

Public or Confidential Client?

Public

Description

I have two different configurations in my environment file, from diferents tenants
image

On a specific page, the user chooses whether to access one tenant or another

My problem is that, in my app.module, I inject the configuration for msal this way

MsalModule.forRoot(new PublicClientApplication({
            auth: {
                clientId: environment.authConfig.clientId,
                authority: environment.authConfig.authority,
                redirectUri: environment.authConfig.redirectUri,
                postLogoutRedirectUri: environment.authConfig.postLogoutRedirectUri,
            },
            cache: {
                cacheLocation: 'localStorage',
                storeAuthStateInCookie: true,
            }
        }), {
            interactionType: InteractionType.Redirect, // Tipo de interacción para el guard (redirección)
            authRequest: {
                scopes: environment.authConfig.consentScopes,
            },
        }, {
            interactionType: InteractionType.Redirect, // Tipo de interacción para la solicitud de token
            protectedResourceMap: new Map<string, Array<string>>(environment.authConfig.protectedResourceMap.map((entry: [
                string,
                string[]
            ]) => [entry[0], entry[1]])),
        })

But there, I have to choose between one configuration and another.
And same way in the function for MSAL interceptor

function MSALInterceptorConfigFactory(): MsalInterceptorConfiguration {
    const protectedResourceMap = new Map<string, Array<string>>();
    if (Array.isArray(environment.authConfig.protectedResourceMap)) {
        environment.authConfig.protectedResourceMap.forEach((value: any) => {
            protectedResourceMap.set(value[0] as string, value[1] as Array<string>);
        });
    }
    return {
        interactionType: InteractionType.Redirect,
        protectedResourceMap,
    };
  }

And now, in another page, to use the other configuration, I'm trying to change the authService instance this way:


  public async onAzureAdFreeSignin(): Promise<void> {

        this.authService.instance = new PublicClientApplication({
      auth: {
          clientId: environment.authConfig.clientId,
          authority: environment.authConfig.authority,
          redirectUri: environment.authConfig.redirectUri,
          postLogoutRedirectUri: environment.authConfig.postLogoutRedirectUri,
      },
      cache: {
          cacheLocation: 'localStorage',
          storeAuthStateInCookie: true,
      }
  }), {
      interactionType: InteractionType.Redirect, // Tipo de interacción para el guard (redirección)
      authRequest: {
          scopes: environment.authConfig.consentScopes,
      },
  }, {
      interactionType: InteractionType.Redirect, // Tipo de interacción para la solicitud de token
      protectedResourceMap: new Map<string, Array<string>>(environment.authConfig.protectedResourceMap.map((entry: [
          string,
          string[]
      ]) => [entry[0], entry[1]])),
  }

But It doesnt work

Could you help me, please?
Thank you very much

Error Message

No response

MSAL Logs

No response

Network Trace (Preferrably Fiddler)

  • Sent
  • Pending

MSAL Configuration

authConfig: {
    clientId: "XXXX",
    tenantId: "XXXX",
    authority:"https://login.microsoftonline.com/XXXX",
    knownAuthorities: [""],
    redirectUri: "http://localhost:3000",
    postLogoutRedirectUri: "http://localhost:3000",
    scopes: ["XXXX", "user.read", "offline_access", "openid"],
    consentScopes: [
      "User.Read",
      "offline_access",
      "openid",
      "XXXX",
    ],
    protectedResourceMap: [
      [
        "XXXX",
        ["XXXX"],
      ],
    ],
  },
  authConfigAdFree:  {
    clientId: "XXXX",
    tenantId: "XXXX",
    authority:"https://login.microsoftonline.com/XXXX",
    knownAuthorities: [""],
    redirectUri: "http://localhost:3000",
    postLogoutRedirectUri: "http://localhost:3000",
    scopes: ["XXXX", "user.read", "offline_access", "openid"],
    consentScopes: [
      "User.Read",
      "offline_access",
      "openid",
      "XXXX"
    ],
    protectedResourceMap: [
      [
        "XXXX",
        ["XXXX"],
      ],
    ],
  }

Relevant Code Snippets

I cant use the authConfigAdFree, because the other one is injected in app module

Reproduction Steps

  1. I open my app
  2. In my app.module, i'm using the first configuration
  3. In one point, in my app I need to use the other configuration
  4. App doesnt work

Expected Behavior

should dynamically change settings for msal

Identity Provider

Azure B2C Custom Policy

Browsers Affected (Select all that apply)

Chrome

Regression

No response

@cdiazp-sacyr cdiazp-sacyr added bug-unconfirmed A reported bug that needs to be investigated and confirmed question Customer is asking for a clarification, use case or information. labels Nov 15, 2024
@microsoft-github-policy-service microsoft-github-policy-service bot added the Needs: Attention 👋 Awaiting response from the MSAL.js team label Nov 15, 2024
@github-actions github-actions bot added b2c Related to Azure B2C library-specific issues msal-angular Related to @azure/msal-angular package msal-browser Related to msal-browser package public-client Issues regarding PublicClientApplications labels Nov 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
b2c Related to Azure B2C library-specific issues bug-unconfirmed A reported bug that needs to be investigated and confirmed msal-angular Related to @azure/msal-angular package msal-browser Related to msal-browser package Needs: Attention 👋 Awaiting response from the MSAL.js team public-client Issues regarding PublicClientApplications question Customer is asking for a clarification, use case or information.
Projects
None yet
Development

No branches or pull requests

1 participant