问题
I am working with an application that authenticate in azure ad. I use adal.js to acquire access token. But the access token is only valid for 1 hour. So how can I acquire new token behind the scene using my refresh token in Adal js?
Appreciate if you can provide sample code.
回答1:
As long as the user have an active session with Azure AD, ADAL JS does it automatically for you. ADAL JS examines the projected expiration of the existing token (in the cache) and if the token is about to expire, it uses an invisible iFrame to send a new token (renewal) request to Azure AD.
This is discussed in detail here (with sample code) by Vittorio and the mechanics of silent renewal is discussed here.
回答2:
If you are using angular wrapper, then adal will take care of renewing tokens automatically as Karthik mentioned above.
If you are not using angular wrapper, then you can call acquireToken method to renew token. This might help: https://github.com/Azure-Samples/active-directory-javascript-singlepageapp-dotnet-webapi
来源:https://stackoverflow.com/questions/37535366/acquiring-new-access-token-using-refresh-token-adal-js