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

Cache miss #6931

Open
vkt-kmd opened this issue Mar 1, 2024 · 5 comments
Open

Cache miss #6931

vkt-kmd opened this issue Mar 1, 2024 · 5 comments
Assignees
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. tracked-internally Bugs that are tracked by Msft internally

Comments

@vkt-kmd
Copy link

vkt-kmd commented Mar 1, 2024

Core Library

MSAL.js (@azure/msal-browser)

Core Library Version

3.0.9

Wrapper Library

MSAL Angular (@azure/msal-angular)

Wrapper Library Version

3.6.0

Public or Confidential Client?

Public

Description

Method getTenantFromAuthorityString (used to read cache) returns different value than Authority.tenant (used to store cache) results in missing cache. Those methods are used when token doesn't have tif or tfp or acr claims.

Error Message

No response

MSAL Logs

No response

MSAL Configuration

{ not relevant }

Relevant Code Snippets

not relevant

Reproduction Steps

  1. Token without tif, tfp, acr claims

Expected Behavior

Cache is hit when using fallback.

Identity Provider

Azure B2C Custom Policy

Browsers Affected (Select all that apply)

Chrome, Edge

Regression

No response

Source

External (Customer)

@vkt-kmd vkt-kmd 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 Mar 1, 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 Mar 1, 2024
@microsoft-github-policy-service microsoft-github-policy-service bot added the Needs: Attention 👋 Awaiting response from the MSAL.js team label Mar 1, 2024
@akyllus
Copy link

akyllus commented Mar 2, 2024

To fix this issue, you can either downgrade your MSAL.js library to version 3.0.9 or update your code to handle the new Authority.tenant property. Here's an example of how you can update your code to handle the new property:

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

const msalConfig: Configuration = {
auth: {
clientId: 'your-client-id',
authority: 'https://your-authority-url',
knownAuthorities: ['your-authority-url'],
redirectUri: 'your-redirect-uri',
},
cache: {
cacheLocation: 'localStorage',
storeAuthStateInCookie: false,
},
};

const msalInstance = new PublicClientApplication(msalConfig);

// Check if the authority URL has a tenant ID
if (msalConfig.auth.authority.includes('your-tenant-id')) {
// Use the tenant ID from the authority URL
const tenantId = msalConfig.auth.authority.split('/')[3];
} else {
// Use the tenant ID from the Authority.tenant property
const tenantId = msalConfig.auth.authority.tenant;
}

By checking if the authority URL contains a tenant ID, you can use the appropriate tenant ID for your cache. This will ensure that your cache is hit when using the fallback method.

@vkt-kmd
Copy link
Author

vkt-kmd commented Mar 4, 2024

I am not sure what should we do with that tenantid. Cache is handled by library itself.

Also version 3.0.9 of @azure/msal-browser doesn't exists
image

@sameerag sameerag self-assigned this Mar 28, 2024
@PetrasJaug
Copy link

I tested overwriting Authority.tenant the [0] with .at(-1):

    public get tenant(): string {
        return this.canonicalAuthorityUrlComponents.PathSegments.at(-1)!;
    }

Works for me, however, I am not sure if there could be consequences.

@seawave23
Copy link

Any updates on this?

@sameerag
Copy link
Member

sameerag commented May 7, 2024

Thanks for raising this, looks like a potential bug on our end. Marked to track internally. cc @hectormmg

@microsoft-github-policy-service microsoft-github-policy-service bot added Needs: Author Feedback Awaiting response from issue author and removed Needs: Attention 👋 Awaiting response from the MSAL.js team labels May 7, 2024
@sameerag sameerag added Needs: Attention 👋 Awaiting response from the MSAL.js team tracked-internally Bugs that are tracked by Msft internally labels May 7, 2024
@microsoft-github-policy-service microsoft-github-policy-service bot removed the Needs: Author Feedback Awaiting response from issue author label May 7, 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. tracked-internally Bugs that are tracked by Msft internally
Projects
None yet
Development

No branches or pull requests

5 participants