Azure / ms-rest-nodeauth

node.js based authentication library for Azure with type definitions
MIT License
33 stars 33 forks source link

interactiveLoginWithAuthResponse fails the second time it's used with tokenCache #119

Closed sadasant closed 3 years ago

sadasant commented 3 years ago

Using the following snippet:

const tokenCache = new adal.MemoryCache();
let authResponse = await msRestNodeAuth.interactiveLoginWithAuthResponse({ tokenCache });
console.log({ authResponse });
authResponse = await msRestNodeAuth.interactiveLoginWithAuthResponse({ tokenCache });
// We won't reach this console.log, since the previous call will throw.
console.log({ authResponse });

We can see that the second call to interactiveLoginWithAuthResponse will throw the error: Error: Entry not found in cache.

Other login methods, like loginWithUsernamePasswordWithAuthResponse, do not have this issue. For example, the following code will authenticate both times (and the second time it will do so using the cache, as it can be verified by debugging):

const username = process.env.AZURE_USERNAME || "";
const password = process.env.AZURE_PASSWORD || "";
const tokenCache = new adal.MemoryCache();
let authResponse = await msRestNodeAuth.loginWithUsernamePasswordWithAuthResponse(
  username,
  password,
  { tokenCache }
);
console.log({ authResponse });
authResponse = await msRestNodeAuth.loginWithUsernamePasswordWithAuthResponse(
  username,
  password,
  { tokenCache }
);
console.log({ authResponse });

interactiveLoginWithAuthResponse should be able to authenticate silently after a first successful interactive authentication.

sadasant commented 3 years ago

Based on previous experiences, I believe this is likely an issue with adal. Since adal is not taking any more changes, and since we’re moving to deprecate this package soon on favor of https://www.npmjs.com/package/@azure/identity, at this time we’ve decided to close this issue.