Do you have any idea if there is a way to check if token has expired in Msal (in order to know if should get the acquireTokenSilent or not) Thanks
You don't need to check this by yourself. In MSAL, you will call acquireTokenSilent
method to make a silent request(without prompting the user) to Azure AD to obtain an access token. MSAL will automatically refresh your access token after expiration when calling.
If the silent token acquisition fails for some reasons such as an expired token or password change, you will need to invoke an interactive method to acquire tokens such as acquireTokenPopup or acquireTokenRedirect.
var graphScopes = ["user.read", "mail.send"];
userAgentApplication.loginPopup(graphScopes).then(function (idToken) {
//Login Success
userAgentApplication.acquireTokenSilent(graphScopes).then(function (accessToken) {
//AcquireTokenSilent Success
}, function (error) {
//AcquireTokenSilent Failure, send an interactive request.
userAgentApplication.acquireTokenPopup(graphScopes).then(function (accessToken) {
updateUI();
}, function (error) {
console.log(error);
});
})
}, function (error) {
//login failure
console.log(error);
});
You can refer to this article for more details.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With