0

Refresh token is not working as I expected in adal.js(@types - 1.0.8), When user is idle on screen for last 15 minutes (because I refresh token before 15 minutes of expiry of old token), and after that perform action, then my service call fail. because it gets old token(which expire) in header, but token refresh is also done after that. how I can handle this in angularJS and adal library? I used below code to get refresh token

this.authenticationContext.getCachedUser();
    this.authenticationContext.acquireToken(config.clientId, function (errorDesc, token) {
        if (errorDesc) {
            console.log("ErrorDesc", errorDesc);
        }
        if (token) {
            console.log("calling the Web API with the access token", token);
        }
    });

in angular.

S. Deshmukh
  • 314
  • 4
  • 19

2 Answers2

0
  1. Check to see that your reply urls and redirect uris are matching and are configured properly both in your app registration and in your config/app settings.
  2. Add a method var user = authContext.getCachedUser() right after you call authContext.handleWindowCallback in your index.js. This function sets the user property of adal and it needs to run on every page load.
  3. Set token lifetime. https://learn.microsoft.com/en-us/azure/active-directory/active-directory-configurable-token-lifetimes
Marilee Turscak - MSFT
  • 7,367
  • 3
  • 18
  • 28
0

Azure authentication token expires every 1 hour. you need to refresh the token before the token get expired. there are many angular wrappers over ADAL.js library for the purpose. See my answer in the below link to get an idea.

Adal Angular 4 - Refresh Token not working as expected

Harun
  • 5,109
  • 4
  • 38
  • 60