简体   繁体   中英

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!

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.

在此处输入图片说明

In AdalJS version 1.0.13, If you want to have a callback, you can use the following code:

                authContext.acquireToken('https://api.webserver.com/api/endpoint').then(function (token) {
                    console.log(token)
                },function(error){
                    console.log('Failed to acquire token');  
                }
            );

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM