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

After implementation of the partition manager, the account is not removed from the cache anymore @azure/msal-node #7324

Open
2 tasks
LuccaRebelloToledo opened this issue Sep 19, 2024 · 8 comments
Labels
bug-unconfirmed A reported bug that needs to be investigated and confirmed confidential-client Issues regarding ConfidentialClientApplications msal-node Related to msal-node package Needs: Attention 👋 Awaiting response from the MSAL.js team question Customer is asking for a clarification, use case or information.

Comments

@LuccaRebelloToledo
Copy link

LuccaRebelloToledo commented Sep 19, 2024

Core Library

MSAL Node (@azure/msal-node)

Core Library Version

2.13.1

Wrapper Library

Not Applicable

Wrapper Library Version

0.0.0

Public or Confidential Client?

Confidential

Description

After implementing the partition manager, the remove Account method no longer works, the storage token is not removed or becomes empty data.

CacheClient Implementation
{F79797B4-398E-48A2-B85A-D056471B0402}

Partition Manager Implementation
{8550F8EA-2D06-46EF-BF93-DC0EE09F46E4}

RemoveAccount Implementation
{52E3F2EB-F325-4FD7-B712-275D71258B4D}

Error Message

Nothing Error Messages.

MSAL Logs

2024-09-20T12:32:02.167Z 824ae031-e9d2-474e-b4a4-a3bef1feed3b INFO Level: 2 Message: [Fri, 20 Sep 2024 12:32:02 GMT] : [] : @azure/msal-node@2.13.1 : Info - getTokenCache called

2024-09-20T12:32:02.167Z 824ae031-e9d2-474e-b4a4-a3bef1feed3b INFO Level: 4 Message: [Fri, 20 Sep 2024 12:32:02 GMT] : [] : @azure/msal-node@2.13.1 : Trace - getAllAccounts called

2024-09-20T12:32:02.428Z 824ae031-e9d2-474e-b4a4-a3bef1feed3b INFO Level: 4 Message: [Fri, 20 Sep 2024 12:32:02 GMT] : [] : @azure/msal-node@2.13.1 : Trace - Deserializing JSON to in-memory cache

2024-09-20T12:32:02.428Z 824ae031-e9d2-474e-b4a4-a3bef1feed3b INFO Level: 4 Message: [Fri, 20 Sep 2024 12:32:02 GMT] : [] : @azure/msal-node@2.13.1 : Trace - Reading cache snapshot from disk

2024-09-20T12:32:02.428Z 824ae031-e9d2-474e-b4a4-a3bef1feed3b INFO Level: 4 Message: [Fri, 20 Sep 2024 12:32:02 GMT] : [] : @azure/msal-node@2.13.1 : Trace - Overlaying input cache with the default cache

2024-09-20T12:32:02.428Z 824ae031-e9d2-474e-b4a4-a3bef1feed3b INFO Level: 4 Message: [Fri, 20 Sep 2024 12:32:02 GMT] : [] : @azure/msal-node@2.13.1 : Trace - Setting in-memory cache

2024-09-20T12:32:02.428Z 824ae031-e9d2-474e-b4a4-a3bef1feed3b INFO Level: 4 Message: [Fri, 20 Sep 2024 12:32:02 GMT] : [] : @azure/msal-node@2.13.1 : Trace - Getting cache key-value store

2024-09-20T12:32:02.428Z 824ae031-e9d2-474e-b4a4-a3bef1feed3b INFO Level: 4 Message: [Fri, 20 Sep 2024 12:32:02 GMT] : [] : @azure/msal-node@2.13.1 : Trace - Setting cache key value store

2024-09-20T12:32:02.428Z 824ae031-e9d2-474e-b4a4-a3bef1feed3b INFO Level: 4 Message: [Fri, 20 Sep 2024 12:32:02 GMT] : [] : @azure/msal-node@2.13.1 : Trace - Getting in-memory cache

2024-09-20T12:32:02.428Z 824ae031-e9d2-474e-b4a4-a3bef1feed3b INFO Level: 4 Message: [Fri, 20 Sep 2024 12:32:02 GMT] : [] : @azure/msal-node@2.13.1 : Trace - Getting cache key-value store

2024-09-20T12:32:02.428Z 824ae031-e9d2-474e-b4a4-a3bef1feed3b INFO Level: 4 Message: [Fri, 20 Sep 2024 12:32:02 GMT] : [] : @azure/msal-node@2.13.1 : Trace - Getting cache key-value store

2024-09-20T12:32:02.428Z 824ae031-e9d2-474e-b4a4-a3bef1feed3b INFO Level: 4 Message: [Fri, 20 Sep 2024 12:32:02 GMT] : [] : @azure/msal-node@2.13.1 : Trace - Getting cache key-value store

2024-09-20T12:32:02.428Z 824ae031-e9d2-474e-b4a4-a3bef1feed3b INFO Level: 4 Message: [Fri, 20 Sep 2024 12:32:02 GMT] : [] : @azure/msal-node@2.13.1 : Trace - Getting in-memory cache

2024-09-20T12:32:02.428Z 824ae031-e9d2-474e-b4a4-a3bef1feed3b INFO Level: 4 Message: [Fri, 20 Sep 2024 12:32:02 GMT] : [] : @azure/msal-node@2.13.1 : Trace - Getting cache key-value store

2024-09-20T12:32:02.428Z 824ae031-e9d2-474e-b4a4-a3bef1feed3b INFO Level: 4 Message: [Fri, 20 Sep 2024 12:32:02 GMT] : [] : @azure/msal-common@14.14.2 : Trace - CacheManager - getIdToken called

2024-09-20T12:32:02.428Z 824ae031-e9d2-474e-b4a4-a3bef1feed3b INFO Level: 4 Message: [Fri, 20 Sep 2024 12:32:02 GMT] : [] : @azure/msal-node@2.13.1 : Trace - Getting cache key-value store

2024-09-20T12:32:02.429Z 824ae031-e9d2-474e-b4a4-a3bef1feed3b INFO Level: 4 Message: [Fri, 20 Sep 2024 12:32:02 GMT] : [] : @azure/msal-common@14.14.2 : Trace - getAliasesFromMetadata called with source: config

2024-09-20T12:32:02.429Z 824ae031-e9d2-474e-b4a4-a3bef1feed3b INFO Level: 4 Message: [Fri, 20 Sep 2024 12:32:02 GMT] : [] : @azure/msal-common@14.14.2 : Trace - getAliasesFromMetadata called with source: hardcoded_values

2024-09-20T12:32:02.429Z 824ae031-e9d2-474e-b4a4-a3bef1feed3b INFO Level: 4 Message: [Fri, 20 Sep 2024 12:32:02 GMT] : [] : @azure/msal-common@14.14.2 : Trace - getAliasesFromMetadata: found cloud discovery metadata in hardcoded_values, returning aliases

2024-09-20T12:32:02.429Z 824ae031-e9d2-474e-b4a4-a3bef1feed3b INFO Level: 2 Message: [Fri, 20 Sep 2024 12:32:02 GMT] : [] : @azure/msal-common@14.14.2 : Info - CacheManager:getIdToken - Returning ID token

2024-09-20T12:32:02.429Z 824ae031-e9d2-474e-b4a4-a3bef1feed3b INFO Level: 4 Message: [Fri, 20 Sep 2024 12:32:02 GMT] : [] : @azure/msal-node@2.13.1 : Trace - Getting cache key-value store

2024-09-20T12:32:02.429Z 824ae031-e9d2-474e-b4a4-a3bef1feed3b INFO Level: 4 Message: [Fri, 20 Sep 2024 12:32:02 GMT] : [] : @azure/msal-node@2.13.1 : Trace - Serializing in-memory cache

2024-09-20T12:32:02.429Z 824ae031-e9d2-474e-b4a4-a3bef1feed3b INFO Level: 4 Message: [Fri, 20 Sep 2024 12:32:02 GMT] : [] : @azure/msal-node@2.13.1 : Trace - Getting in-memory cache

2024-09-20T12:32:02.429Z 824ae031-e9d2-474e-b4a4-a3bef1feed3b INFO Level: 4 Message: [Fri, 20 Sep 2024 12:32:02 GMT] : [] : @azure/msal-node@2.13.1 : Trace - Getting cache key-value store

2024-09-20T12:32:02.429Z 824ae031-e9d2-474e-b4a4-a3bef1feed3b INFO Level: 4 Message: [Fri, 20 Sep 2024 12:32:02 GMT] : [] : @azure/msal-node@2.13.1 : Trace - Reading cache snapshot from disk

2024-09-20T12:32:02.429Z 824ae031-e9d2-474e-b4a4-a3bef1feed3b INFO Level: 4 Message: [Fri, 20 Sep 2024 12:32:02 GMT] : [] : @azure/msal-node@2.13.1 : Trace - Merging in-memory cache with cache snapshot

2024-09-20T12:32:02.429Z 824ae031-e9d2-474e-b4a4-a3bef1feed3b INFO Level: 4 Message: [Fri, 20 Sep 2024 12:32:02 GMT] : [] : @azure/msal-node@2.13.1 : Trace - Remove updated entries in cache

2024-09-20T12:32:02.608Z 824ae031-e9d2-474e-b4a4-a3bef1feed3b INFO Level: 2 Message: [Fri, 20 Sep 2024 12:32:02 GMT] : [] : @azure/msal-node@2.13.1 : Info - getTokenCache called

2024-09-20T12:32:02.608Z 824ae031-e9d2-474e-b4a4-a3bef1feed3b INFO Level: 4 Message: [Fri, 20 Sep 2024 12:32:02 GMT] : [] : @azure/msal-node@2.13.1 : Trace - removeAccount called

2024-09-20T12:32:02.708Z 824ae031-e9d2-474e-b4a4-a3bef1feed3b INFO Level: 4 Message: [Fri, 20 Sep 2024 12:32:02 GMT] : [] : @azure/msal-node@2.13.1 : Trace - Deserializing JSON to in-memory cache

2024-09-20T12:32:02.708Z 824ae031-e9d2-474e-b4a4-a3bef1feed3b INFO Level: 4 Message: [Fri, 20 Sep 2024 12:32:02 GMT] : [] : @azure/msal-node@2.13.1 : Trace - Reading cache snapshot from disk

2024-09-20T12:32:02.708Z 824ae031-e9d2-474e-b4a4-a3bef1feed3b INFO Level: 4 Message: [Fri, 20 Sep 2024 12:32:02 GMT] : [] : @azure/msal-node@2.13.1 : Trace - Overlaying input cache with the default cache

2024-09-20T12:32:02.708Z 824ae031-e9d2-474e-b4a4-a3bef1feed3b INFO Level: 4 Message: [Fri, 20 Sep 2024 12:32:02 GMT] : [] : @azure/msal-node@2.13.1 : Trace - Setting in-memory cache

2024-09-20T12:32:02.708Z 824ae031-e9d2-474e-b4a4-a3bef1feed3b INFO Level: 4 Message: [Fri, 20 Sep 2024 12:32:02 GMT] : [] : @azure/msal-node@2.13.1 : Trace - Getting cache key-value store

2024-09-20T12:32:02.708Z 824ae031-e9d2-474e-b4a4-a3bef1feed3b INFO Level: 4 Message: [Fri, 20 Sep 2024 12:32:02 GMT] : [] : @azure/msal-node@2.13.1 : Trace - Setting cache key value store

2024-09-20T12:32:02.708Z 824ae031-e9d2-474e-b4a4-a3bef1feed3b INFO Level: 4 Message: [Fri, 20 Sep 2024 12:32:02 GMT] : [] : @azure/msal-node@2.13.1 : Trace - Getting cache key-value store

2024-09-20T12:32:02.708Z 824ae031-e9d2-474e-b4a4-a3bef1feed3b INFO Level: 4 Message: [Fri, 20 Sep 2024 12:32:02 GMT] : [] : @azure/msal-node@2.13.1 : Trace - Getting cache key-value store

2024-09-20T12:32:02.708Z 824ae031-e9d2-474e-b4a4-a3bef1feed3b INFO Level: 4 Message: [Fri, 20 Sep 2024 12:32:02 GMT] : [] : @azure/msal-node@2.13.1 : Trace - Getting in-memory cache

2024-09-20T12:32:02.708Z 824ae031-e9d2-474e-b4a4-a3bef1feed3b INFO Level: 4 Message: [Fri, 20 Sep 2024 12:32:02 GMT] : [] : @azure/msal-node@2.13.1 : Trace - Getting cache key-value store

2024-09-20T12:32:02.709Z 824ae031-e9d2-474e-b4a4-a3bef1feed3b INFO Level: 4 Message: [Fri, 20 Sep 2024 12:32:02 GMT] : [] : @azure/msal-node@2.13.1 : Trace - Getting cache key-value store

2024-09-20T12:32:02.709Z 824ae031-e9d2-474e-b4a4-a3bef1feed3b INFO Level: 4 Message: [Fri, 20 Sep 2024 12:32:02 GMT] : [] : @azure/msal-node@2.13.1 : Trace - Setting cache key value store

2024-09-20T12:32:02.709Z 824ae031-e9d2-474e-b4a4-a3bef1feed3b INFO Level: 4 Message: [Fri, 20 Sep 2024 12:32:02 GMT] : [] : @azure/msal-node@2.13.1 : Trace - Getting cache key-value store

2024-09-20T12:32:02.709Z 824ae031-e9d2-474e-b4a4-a3bef1feed3b INFO Level: 4 Message: [Fri, 20 Sep 2024 12:32:02 GMT] : [] : @azure/msal-node@2.13.1 : Trace - Getting cache key-value store

2024-09-20T12:32:02.709Z 824ae031-e9d2-474e-b4a4-a3bef1feed3b INFO Level: 4 Message: [Fri, 20 Sep 2024 12:32:02 GMT] : [] : @azure/msal-node@2.13.1 : Trace - Setting cache key value store

2024-09-20T12:32:02.709Z 824ae031-e9d2-474e-b4a4-a3bef1feed3b INFO Level: 4 Message: [Fri, 20 Sep 2024 12:32:02 GMT] : [] : @azure/msal-node@2.13.1 : Trace - Getting cache key-value store

2024-09-20T12:32:02.709Z 824ae031-e9d2-474e-b4a4-a3bef1feed3b INFO Level: 4 Message: [Fri, 20 Sep 2024 12:32:02 GMT] : [] : @azure/msal-node@2.13.1 : Trace - Setting cache key value store

2024-09-20T12:32:02.709Z 824ae031-e9d2-474e-b4a4-a3bef1feed3b INFO Level: 4 Message: [Fri, 20 Sep 2024 12:32:02 GMT] : [] : @azure/msal-node@2.13.1 : Trace - Getting cache key-value store

2024-09-20T12:32:02.709Z 824ae031-e9d2-474e-b4a4-a3bef1feed3b INFO Level: 4 Message: [Fri, 20 Sep 2024 12:32:02 GMT] : [] : @azure/msal-node@2.13.1 : Trace - Setting cache key value store

2024-09-20T12:32:02.709Z 824ae031-e9d2-474e-b4a4-a3bef1feed3b INFO Level: 4 Message: [Fri, 20 Sep 2024 12:32:02 GMT] : [] : @azure/msal-node@2.13.1 : Trace - Getting cache key-value store

Network Trace (Preferrably Fiddler)

  • Sent
  • Pending

MSAL Configuration

{
    auth: {
      clientId: OUTLOOK_CLIENT_ID,
      clientSecret: OUTLOOK_CLIENT_SECRET,
    },
    cache: {
      cachePlugin: new DistributedCachePlugin(
        new CacheClient(),
        new PartitionManager(homeAccountId || APP)
      ),
    },
    system: {
      loggerOptions: {
        loggerCallback: (level, message, containsPii) => {
          if (!containsPii) {
            log.log(`Level: ${level}`, `Message: ${message}`);
          }
        },
        piiLoggingEnabled: false,
      },
    },
    telemetry: {
      application: {
        appName: APP,
        appVersion: '1.0.0',
      },
    },
  }

Relevant Code Snippets

import { ICacheClient } from '@azure/msal-node';

import { DynamoDBDocument } from '@aws-sdk/lib-dynamodb';

import { getCacheStorageTableName, getDynamoDBClient } from './dynamo-db';

export default class CacheClient implements ICacheClient {
  private readonly client: DynamoDBDocument;
  private readonly tableName: string;

  constructor() {
    this.client = getDynamoDBClient();
    this.tableName = getCacheStorageTableName();
  }

  public async get(key: string): Promise<string> {
    const { Item } = await this.client.get({
      TableName: this.tableName,
      Key: { cache_identifier: key },
    });

    if (!Item) {
      return '';
    }

    const { serialized_token: serializedToken } = Item;

    return serializedToken;
  }

  public async set(key: string, value: string): Promise<string> {
    await this.client.put({
      TableName: this.tableName,
      Item: {
        cache_identifier: key,
        serialized_token: value,
      },
    });

    return 'OK';
  }
}

import { IPartitionManager } from '@azure/msal-node';

import { AccountEntity } from '@azure/msal-common';

import OutlookErrorMessages from './errors/outlook';

export default class PartitionManager implements IPartitionManager {
  private readonly homeAccountId: string;

  constructor(homeAccountId: string) {
    this.homeAccountId = homeAccountId;
  }

  public async getKey(): Promise<string> {
    return this.homeAccountId;
  }

  public async extractKey(accountEntity: AccountEntity): Promise<string> {
    const { homeAccountId } = accountEntity;

    if (!homeAccountId) {
      throw new Error(OutlookErrorMessages.accounts.cacheEntity.notFound);
    }

    return homeAccountId;
  }
}

export const removeAccount = async (homeAccountId: string) => {
  const msalClient = getMSALClient(homeAccountId);

  const account = await getAccountByHomeId({ msalClient, homeAccountId });

  // After implementation of the partition manager, the account is not removed from the cache anymore
  await msalClient.getTokenCache().removeAccount(account);
};

Reproduction Steps

  1. get auth code url
  2. acquire token by code ( in this moment, the token cache is stored. )
  3. call the remove account.

Expected Behavior

I hope of the stored cache is remove or data empty. Independent of the cache client i using.

My cache data after using the removeAccount method:
{1CD3D84E-4672-46A8-A211-5A525976748D}

Identity Provider

Entra ID (formerly Azure AD) / MSA

Browsers Affected (Select all that apply)

None (Server)

Regression

No response

Source

Internal (Microsoft)

@LuccaRebelloToledo LuccaRebelloToledo 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 Sep 19, 2024
@microsoft-github-policy-service microsoft-github-policy-service bot added the Needs: Attention 👋 Awaiting response from the MSAL.js team label Sep 19, 2024
@github-actions github-actions bot added confidential-client Issues regarding ConfidentialClientApplications msal-node Related to msal-node package labels Sep 19, 2024
@LuccaRebelloToledo
Copy link
Author

I forked the repository and create a new versions of msal-common and msal-node with more logs for better analyze. The removeAccount method is called correct but in the removeAccountContext method on "lib\msal-common\src\cache\CacheManager.ts", the keys is not removed.

removeAccountContext Method:
{0B13612E-42D8-496A-A1CA-DFEB1EDC8B97}

Logs:

2024-09-20T14:13:36.943Z 5ccde16d-ad8f-41be-80d3-82c873cb9c48 INFO Level: 4 Message: [Fri, 20 Sep 2024 14:13:36 GMT] : [] : @azure/msal-node@2.14.0 : Trace - Removing account from cache: 00000000-0000-0000-c2ad-4496109a7efd.9188040d-6c67-4c5b-b112-36a304b66dad-login.windows.net-9188040d-6c67-4c5b-b112-36a304b66dad --

2024-09-20T14:13:36.944Z 5ccde16d-ad8f-41be-80d3-82c873cb9c48 INFO Level: 4 Message: [Fri, 20 Sep 2024 14:13:36 GMT] : [] : @azure/msal-common@14.15.0 : Trace - CacheManager.removeAccount called with key: 00000000-0000-0000-c2ad-4496109a7efd.9188040d-6c67-4c5b-b112-36a304b66dad-login.windows.net-9188040d-6c67-4c5b-b112-36a304b66dad

2024-09-20T14:13:36.944Z 5ccde16d-ad8f-41be-80d3-82c873cb9c48 INFO Level: 4 Message: [Fri, 20 Sep 2024 14:13:36 GMT] : [] : @azure/msal-node@2.14.0 : Trace - Getting cache key-value store

2024-09-20T14:13:36.944Z 5ccde16d-ad8f-41be-80d3-82c873cb9c48 INFO Level: 4 Message: [Fri, 20 Sep 2024 14:13:36 GMT] : [] : @azure/msal-node@2.14.0 : Trace - Getting cache key-value store

2024-09-20T14:13:36.944Z 5ccde16d-ad8f-41be-80d3-82c873cb9c48 INFO Level: 4 Message: [Fri, 20 Sep 2024 14:13:36 GMT] : [] : @azure/msal-common@14.15.0 : Trace - CacheManager.removeAccount found account: 00000000-0000-0000-c2ad-4496109a7efd.9188040d-6c67-4c5b-b112-36a304b66dad

2024-09-20T14:13:36.944Z 5ccde16d-ad8f-41be-80d3-82c873cb9c48 INFO Level: 4 Message: [Fri, 20 Sep 2024 14:13:36 GMT] : [] : @azure/msal-node@2.14.0 : Trace - Getting in-memory cache

2024-09-20T14:13:36.944Z 5ccde16d-ad8f-41be-80d3-82c873cb9c48 INFO Level: 4 Message: [Fri, 20 Sep 2024 14:13:36 GMT] : [] : @azure/msal-node@2.14.0 : Trace - Getting cache key-value store

2024-09-20T14:13:36.944Z 5ccde16d-ad8f-41be-80d3-82c873cb9c48 INFO Level: 4 Message: [Fri, 20 Sep 2024 14:13:36 GMT] : [] : @azure/msal-common@14.15.0 : Trace - All token keys before: { "idToken": [ "00000000-0000-0000-c2ad-4496109a7efd.9188040d-6c67-4c5b-b112-36a304b66dad-login.windows.net-idtoken-4443f941-37fc-4834-8919-440a8d0a2ed0-9188040d-6c67-4c5b-b112-36a304b66dad---" ], "accessToken": [ "00000000-0000-0000-c2ad-4496109a7efd.9188040d-6c67-4c5b-b112-36a304b66dad-login.windows.net-accesstoken-4443f941-37fc-4834-8919-440a8d0a2ed0-9188040d-6c67-4c5b-b112-36a304b66dad-user.read calendars.readwrite openid profile--" ], "refreshToken": [ "00000000-0000-0000-c2ad-4496109a7efd.9188040d-6c67-4c5b-b112-36a304b66dad-login.windows.net-refreshtoken-4443f941-37fc-4834-8919-440a8d0a2ed0----" ] }

2024-09-20T14:13:36.944Z 5ccde16d-ad8f-41be-80d3-82c873cb9c48 INFO Level: 4 Message: [Fri, 20 Sep 2024 14:13:36 GMT] : [] : @azure/msal-node@2.14.0 : Trace - Getting cache key-value store

2024-09-20T14:13:36.944Z 5ccde16d-ad8f-41be-80d3-82c873cb9c48 INFO Level: 4 Message: [Fri, 20 Sep 2024 14:13:36 GMT] : [] : @azure/msal-node@2.14.0 : Trace - Setting cache key value store

2024-09-20T14:13:36.944Z 5ccde16d-ad8f-41be-80d3-82c873cb9c48 INFO Level: 4 Message: [Fri, 20 Sep 2024 14:13:36 GMT] : [] : @azure/msal-node@2.14.0 : Trace - Getting cache key-value store

2024-09-20T14:13:36.944Z 5ccde16d-ad8f-41be-80d3-82c873cb9c48 INFO Level: 4 Message: [Fri, 20 Sep 2024 14:13:36 GMT] : [] : @azure/msal-node@2.14.0 : Trace - Getting cache key-value store

2024-09-20T14:13:36.944Z 5ccde16d-ad8f-41be-80d3-82c873cb9c48 INFO Level: 4 Message: [Fri, 20 Sep 2024 14:13:36 GMT] : [] : @azure/msal-node@2.14.0 : Trace - Setting cache key value store

2024-09-20T14:13:36.944Z 5ccde16d-ad8f-41be-80d3-82c873cb9c48 INFO Level: 4 Message: [Fri, 20 Sep 2024 14:13:36 GMT] : [] : @azure/msal-node@2.14.0 : Trace - Getting cache key-value store

2024-09-20T14:13:36.944Z 5ccde16d-ad8f-41be-80d3-82c873cb9c48 INFO Level: 4 Message: [Fri, 20 Sep 2024 14:13:36 GMT] : [] : @azure/msal-node@2.14.0 : Trace - Setting cache key value store

2024-09-20T14:13:36.944Z 5ccde16d-ad8f-41be-80d3-82c873cb9c48 INFO Level: 4 Message: [Fri, 20 Sep 2024 14:13:36 GMT] : [] : @azure/msal-common@14.15.0 : Trace - All token keys after: { "idToken": [ "00000000-0000-0000-c2ad-4496109a7efd.9188040d-6c67-4c5b-b112-36a304b66dad-login.windows.net-idtoken-4443f941-37fc-4834-8919-440a8d0a2ed0-9188040d-6c67-4c5b-b112-36a304b66dad---" ], "accessToken": [ "00000000-0000-0000-c2ad-4496109a7efd.9188040d-6c67-4c5b-b112-36a304b66dad-login.windows.net-accesstoken-4443f941-37fc-4834-8919-440a8d0a2ed0-9188040d-6c67-4c5b-b112-36a304b66dad-user.read calendars.readwrite openid profile--" ], "refreshToken": [ "00000000-0000-0000-c2ad-4496109a7efd.9188040d-6c67-4c5b-b112-36a304b66dad-login.windows.net-refreshtoken-4443f941-37fc-4834-8919-440a8d0a2ed0----" ] }

2024-09-20T14:13:36.944Z 5ccde16d-ad8f-41be-80d3-82c873cb9c48 INFO Level: 4 Message: [Fri, 20 Sep 2024 14:13:36 GMT] : [] : @azure/msal-node@2.14.0 : Trace - Getting cache key-value store

2024-09-20T14:13:36.944Z 5ccde16d-ad8f-41be-80d3-82c873cb9c48 INFO Level: 4 Message: [Fri, 20 Sep 2024 14:13:36 GMT] : [] : @azure/msal-node@2.14.0 : Trace - Setting cache key value store

2024-09-20T14:13:36.944Z 5ccde16d-ad8f-41be-80d3-82c873cb9c48 INFO Level: 4 Message: [Fri, 20 Sep 2024 14:13:36 GMT] : [] : @azure/msal-node@2.14.0 : Trace - Getting cache key-value store

@LuccaRebelloToledo
Copy link
Author

LuccaRebelloToledo commented Sep 20, 2024

In new tests, I added more logs inside the loops.

{D8B96FA5-EE89-4CE3-B161-C0035BB5E57C}

2024-09-20T14:32:09.586Z 9b77ce8b-458e-4ee8-aeda-791386b0c117 INFO Level: 4 Message: [Fri, 20 Sep 2024 14:32:09 GMT] : [] : @azure/msal-common@14.15.0 : Trace - Account ID: 00000000-0000-0000-c2ad-4496109a7efd.9188040d-6c67-4c5b-b112-36a304b66dad-login.windows.net --

2024-09-20T14:32:09.586Z 9b77ce8b-458e-4ee8-aeda-791386b0c117 INFO Level: 4 Message: [Fri, 20 Sep 2024 14:32:09 GMT] : [] : @azure/msal-common@14.15.0 : Trace - idToken - Checking key: 00000000-0000-0000-c2ad-4496109a7efd.9188040d-6c67-4c5b-b112-36a304b66dad-login.windows.net-idtoken-4443f941-37fc-4834-8919-440a8d0a2ed0-9188040d-6c67-4c5b-b112-36a304b66dad---

2024-09-20T14:32:09.586Z 9b77ce8b-458e-4ee8-aeda-791386b0c117 INFO Level: 4 Message: [Fri, 20 Sep 2024 14:32:09 GMT] : [] : @azure/msal-common@14.15.0 : Trace - Removing idToken key: 00000000-0000-0000-c2ad-4496109a7efd.9188040d-6c67-4c5b-b112-36a304b66dad-login.windows.net-idtoken-4443f941-37fc-4834-8919-440a8d0a2ed0-9188040d-6c67-4c5b-b112-36a304b66dad---

@LuccaRebelloToledo
Copy link
Author

2024-09-20T14:59:16.062Z 6dcfe0e2-2658-48d3-870a-ff75914238b2 INFO Level: 4 Message: [Fri, 20 Sep 2024 14:59:16 GMT] : [] : @azure/msal-node@2.14.0 : Trace - Removing cache item with key: 00000000-0000-0000-c2ad-4496109a7efd.9188040d-6c67-4c5b-b112-36a304b66dad-login.windows.net-9188040d-6c67-4c5b-b112-36a304b66dad --

2024-09-20T14:59:16.062Z 6dcfe0e2-2658-48d3-870a-ff75914238b2 INFO Level: 4 Message: [Fri, 20 Sep 2024 14:59:16 GMT] : [] : @azure/msal-node@2.14.0 : Trace - Successfully removed cache item with key: 00000000-0000-0000-c2ad-4496109a7efd.9188040d-6c67-4c5b-b112-36a304b66dad-login.windows.net-9188040d-6c67-4c5b-b112-36a304b66dad

2024-09-20T14:59:16.062Z 6dcfe0e2-2658-48d3-870a-ff75914238b2 INFO Level: 4 Message: [Fri, 20 Sep 2024 14:59:16 GMT] : [] : @azure/msal-node@2.14.0 : Trace - Cache after removal: {}

2024-09-20T14:59:16.062Z 6dcfe0e2-2658-48d3-870a-ff75914238b2 INFO Level: 4 Message: [Fri, 20 Sep 2024 14:59:16 GMT] : [] : @azure/msal-node@2.14.0 : Trace - Setting cache key value store

2024-09-20T14:59:16.062Z 6dcfe0e2-2658-48d3-870a-ff75914238b2 INFO Level: 4 Message: [Fri, 20 Sep 2024 14:59:16 GMT] : [] : @azure/msal-node@2.14.0 : Trace - Getting cache key-value store

2024-09-20T14:59:16.062Z 6dcfe0e2-2658-48d3-870a-ff75914238b2 INFO kvStore: {}

2024-09-20T14:59:16.062Z 6dcfe0e2-2658-48d3-870a-ff75914238b2 INFO accountEntities: []

After another tests the functionality of the removeAccount is correct. But, after:

{A13BD7A7-DE71-481D-9D5B-3BC5C3966F63}

The afterCacheAccess in DistributedCachePlugin is called and the result of kvStore is {} and the accountEntities is []. So, in this moment i dont have my partition key to make the new input. I gonna this use the partitionManager.getKey() to make the the updated if !accountEntities.length

@LuccaRebelloToledo
Copy link
Author

I identified the problem. I'll write the pull request with the fix :)

@Robbie-Microsoft
Copy link
Collaborator

Robbie-Microsoft commented Oct 31, 2024

@LuccaRebelloToledo I'm unable to reproduce this so far.

I was tinkering with our auth-code sample. In index.js, I changed the redirect route to:

app.get("/redirect", async (req, res) => {
        const tokenRequest = { ...requestConfig.tokenRequest, code: req.query.code, state: req.query.state };
        const authCodeResponse = {
            nonce: req.session.nonce,
            code: req.query.code,
            state: req.session.state
        };

        let homeAccountId;
        try {
            const response = await clientApplication.acquireTokenByCode(tokenRequest, authCodeResponse);
            console.log("Successfully acquired token using Authorization Code.");
            homeAccountId = response.account.homeAccountId;
            console.log(homeAccountId);
            // res.sendStatus(200);
        } catch (error) {
            console.log(error);
            res.status(500).send(error);
        }

        await delay(5000);

        // get cache
        const tokenCache = clientApplication.getTokenCache();
        console.log(tokenCache);

        // get account
        const account = await tokenCache.getAccountByHomeId(homeAccountId);
        console.log(account);

        // remove account from cache
        await tokenCache.removeAccount(account);
        console.log(tokenCache);

        // will be null, since it was successfully removed from cache
        const account2 = await tokenCache.getAccountByHomeId(homeAccountId);
        console.log(account2);

        res.sendStatus(200);
    });

The account was successfully removed from the cache.

I'll give this another look early next week, and use a custom Partition Manager.

@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 Oct 31, 2024
@LuccaRebelloToledo
Copy link
Author

The account was successfully removed from the cache.

I'll give this another look early next week, and use a custom Partition Manager.

Hello Robbie, how are you?

The problem only happens when you're using the DistributedCachePlugin class, that is, with a custom CacheClient and a custom PartitionManager.

In your example, you are right, the account was successfully removed from the cache, but if you try to use the DistributedCachePlugin, the account will not be removed.

@microsoft-github-policy-service microsoft-github-policy-service bot added Needs: Attention 👋 Awaiting response from the MSAL.js team and removed Needs: Author Feedback Awaiting response from issue author labels Oct 31, 2024
@Robbie-Microsoft
Copy link
Collaborator

I'm great, thanks! I'm unable to look at this again today or tomorrow. I'll continue investigating on Monday. Thanks for the clarity.

@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 Oct 31, 2024
@LuccaRebelloToledo
Copy link
Author

I'm great, thanks! I'm unable to look at this again today or tomorrow. I'll continue investigating on Monday. Thanks for the clarity.

You're welcome!!

No problem, if you need help next week with something, I'm available to help you.

@microsoft-github-policy-service microsoft-github-policy-service bot added Needs: Attention 👋 Awaiting response from the MSAL.js team and removed Needs: Author Feedback Awaiting response from issue author labels Oct 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug-unconfirmed A reported bug that needs to be investigated and confirmed confidential-client Issues regarding ConfidentialClientApplications msal-node Related to msal-node package Needs: Attention 👋 Awaiting response from the MSAL.js team question Customer is asking for a clarification, use case or information.
Projects
None yet
Development

No branches or pull requests

2 participants