Search code examples
angularadal

How to stay authenticated with ms-adal-angular6?


I have an AuthService as wrapper for MsAdalAngular6Service. A method checks if current user is authenticated:

   export class AuthService {
      constructor(private adal: MsAdalAngular6Service) {}
    
   isAuthenticated() {
    return this.adal.isAuthenticated;
   }

If current user is inactive for some (short) time adal.isAuthenticated returns false. But I want it to return true.

I don't have access to azure to change the token expiration time. So I want this application to renew the token continuously after the user has logged in at some point such that this.adal.isAuthenticated returns true:

Can you help me?


Solution

  • From the ADAL we can't configure the expiration time of the token what you can do is When the adal toke is going to expiry make a acquiretoken request and refresh the token. Even after refreshing the token if adal.isAuthenticated is not changed to ture then you need to manually set it to true for but its not the recomended way.

    We would recommend you to migrate to MSAL over ADAL as ADAL is Deprecrated Starting June 30th, 2020, we will no longer add new features to ADAL. We'll continue adding critical security fixes to ADAL until June 30th, 2022. After this date, your apps using ADAL will continue to work, but we recommend upgrading to MSAL to take advantage of the latest features and to stay secure.

    Please choose MSAL over ADAL and here is the sample for angular using MSAL

    Please refer the link for migration of ADAL to MSAL