Search code examples
javascriptvue.jsadaladal.js

acquireToken callback never called


I've made some progress after my initial post on integrating adal.js with Vue.js. I'm successfully logging in, and the properties I'd expect to be set are being set in localStorage.

However, calls to acquireToken never call the the callback I'm passing. The code looks like this:

let url = 'https://api.webserver.com/api/endpoint';

authContext.acquireToken(url, (err, token) => {
  console.log(`acquiring token for ${url}`);
  console.log(err, token);
});

Looking at the source for adal.js, the method signature for acquireToken is as follows:

AuthenticationContext.prototype.acquireToken(resource, callback)

The callback isn't called. Is the url value I'm passing what the method is expecting? I'm unclear about this.

Your help is appreciated. Thanks in advance!


Solution

  • According to your init post, you have completed the Azure AD application's configuration, you can try to replace the url to the client_id, under acquireToken() function.

    According to the source code of adal for js, the acquireToken() calls getCachedToken() at L515.

    And the function getCachedToken() will get the token in browser's session via var token = this._getItem(this.CONSTANTS.STORAGE.ACCESS_TOKEN_KEY + resource); You can check all the AD info in DEV TOOL of browser after you successfully login. We can find that the resource here is in the client_id format.

    enter image description here