Skip to content

Cache not used for getting token if scopes are empty #6969

Open
@ram-gupta

Description

@ram-gupta

Core Library

MSAL.js (@azure/msal-browser)

Core Library Version

2.30.0

Wrapper Library

MSAL React (@azure/msal-react)

Wrapper Library Version

1.4.9

Public or Confidential Client?

Public

Description

With code snippet belwo:

import { useAccount, useMsal } from '@azure/msal-react';

const { instance, accounts } = useMsal();
const account = useAccount(accounts[0]);

const loginRequest = {
  scopes: []
};

let response = await instance.acquireTokenSilent({
        ...loginRequest,
        account
});

If no scopes are specified while getting the token, cache is not looked up even though tokens are cached. This is due to scope validation error at ScopeSet.ts#L77.

If scopes are mandatory then its better to fail acquireTokenSilent then behave in an unexpected way and cause avoidable API requests to Azure AD. If scopes are not mandatory then cache should be used.

Error Message

No response

MSAL Logs

No response

Network Trace (Preferrably Fiddler)

  • Sent
  • Pending

MSAL Configuration

export const msalConfig = {
  auth: {
    clientId: <>
    authority: 'https://login.microsoftonline.com/<>',
    redirectUri: <>
  },
  cache: {
    cacheLocation: 'localStorage',
    storeAuthStateInCookie: false
  }
};

Relevant Code Snippets

import { useAccount, useMsal } from '@azure/msal-react';

const { instance, accounts } = useMsal();
const account = useAccount(accounts[0]);

const loginRequest = {
  scopes: []
};

let response = await instance.acquireTokenSilent({
        ...loginRequest,
        account
});

Reproduction Steps

  1. Use acquireTokenSilent to get token with empty scopes.

Expected Behavior

Cache should be used even with empty scopes.

Identity Provider

Entra ID (formerly Azure AD) / MSA

Browsers Affected (Select all that apply)

Edge

Regression

No response

Source

External (Customer)

Metadata

Metadata

Assignees

Labels

bugA problem that needs to be fixed for the feature to function as intended.msal-browserRelated to msal-browser packagemsal-reactRelated to @azure/msal-reactpublic-clientIssues regarding PublicClientApplications

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions