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

AuthenticationResult created with NativeBrokerPlugin has invalid expiresOn value #7086

Open
2 tasks
TheBlueRage opened this issue May 8, 2024 · 1 comment
Open
2 tasks
Labels
bug-unconfirmed A reported bug that needs to be investigated and confirmed msal-node Related to msal-node package msal-node-extensions Related to msal-node-extensions 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

@TheBlueRage
Copy link

Core Library

MSAL Node (@azure/msal-node)

Core Library Version

2.7.0

Wrapper Library

MSAL Node Extensions (@azure/msal-node-extensions)

Wrapper Library Version

1.0.15

Public or Confidential Client?

Public

Description

Please note, this only occurs with the NativeBrokerPlugin.
The AuthenticationResult returned by the NativeBrokerPlugin has an invalid expiresOn value.

The code is creating a Date object from a timestamp based in seconds but Date objects are based on the milliseconds since January 1, 1970.

This causes evaluation of the expiresOn in relation to Date.now() to always appear as though the result has expired.

Simply multiplying the expiresOn by 1000 resolves the issue.

Error Message

None

MSAL Logs

None

Network Trace (Preferrably Fiddler)

  • Sent
  • Pending

MSAL Configuration

{
    auth: {
      clientId: <client id>,
      authority: <authority>
    },
    broker: {
      nativeBrokerPlugin: new NativeBrokerPlugin()
    }
}

Relevant Code Snippets

**For this code to work, you must be logged in to a domain**
const msalApp = new PublicClientApplication(
  {
    auth: {
      clientId: <client id>,
      authority: <authority>
    },
    broker: {
      nativeBrokerPlugin: new NativeBrokerPlugin()
    }
  }
 );
    
const accounts =
  await this.m_cApplication.getAllAccounts();

const  result =
   await msalApp.acquireTokenSilent(
     {
       account: accounts[0],
       scopes: <scopes>
     }
);

/* Basically if the expiration time they sent us is < now it's bogus */
if ( result.expiresOn.valueOf() < Date.now().valueOf() ) {
     /* This resolves the issue and adjusts the date object to the right time */
      result.expiresOn =
          new Date( result.expiresOn.valueOf() * 1000 );
      }
}

Reproduction Steps

Create a NativeBrokerPlugin
Get an AuthenticationResult
Check the AuthenticationResult.expiresOn property

Expected Behavior

Result should be a proper date object in the future not the past.

Identity Provider

Entra ID (formerly Azure AD) / MSA

Browsers Affected (Select all that apply)

Other

Regression

No response

Source

External (Customer)

@TheBlueRage TheBlueRage 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 May 8, 2024
@microsoft-github-policy-service microsoft-github-policy-service bot added the Needs: Attention 👋 Awaiting response from the MSAL.js team label May 8, 2024
@github-actions github-actions bot added msal-node Related to msal-node package msal-node-extensions Related to msal-node-extensions package public-client Issues regarding PublicClientApplications labels May 8, 2024
@TheBlueRage
Copy link
Author

Apologies:
This line of code:
const accounts = await this.m_cApplication.getAllAccounts();
Should be:
const accounts = await msalApp.getAllAccounts();

@TheBlueRage TheBlueRage changed the title AuthenticationResult create with NativeBrokerPlugin has invalid expiresOn value AuthenticationResult created with NativeBrokerPlugin has invalid expiresOn value May 9, 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 msal-node Related to msal-node package msal-node-extensions Related to msal-node-extensions 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