AzureAD / azure-activedirectory-library-for-js

The code for ADAL.js and ADAL Angular has been moved to the MSAL.js repo. Please open any issues or PRs at the link below.
https://github.com/AzureAD/microsoft-authentication-library-for-js/tree/dev/maintenance/adal-angular
Apache License 2.0
627 stars 374 forks source link

Can we find out, if a user is already signed in to O365 (angular)? #822

Closed bschaeublin closed 4 years ago

bschaeublin commented 5 years ago

Im using an Angular 4+ wrapper, which wrapps the adal-angular@1.0.15.

I'have been searching a long time for a way to find out, if a user can be silenty logged in, or if he would be prompted for credentials after i call login() but without any success so far.

This diagram should explain, what im trying to do (green-box):

image

My way to get to this information was, trying to get a token without login first. My expectation was, that it would return a token, if the user is signed in to O365 in this browser (like, having a valid login.microsoftonline.com cookie).

  public async isAbleToSilentLogin(): Promise<boolean> {
    let isLoggedIn = this._adal.userInfo.authenticated;
    if (isLoggedIn) {
      return true;
    }

    try {
      console.log('acquireToken with extraQueryParameter =', this._adal.config.extraQueryParameter);
     // would print  login_hint=test@email.com
      let token = await this._adal.acquireToken(this._adal.config.clientId).toPromise();
      console.log('token', token);
      return !!token;
    } catch (e) {
      console.log(e);
      return false;
    }
  }

But all i get is

User login is required

Even it should bypass this error, according to this line.

but nvm: I think it is a common scenario, Is there a way to get this information?

navyasric commented 5 years ago

@bschaeublin The feature to pass login_hint and then call acquireToken to get silent login is implemented in 1.0.16 release: https://github.com/AzureAD/azure-activedirectory-library-for-js/releases/tag/1.0.16

Please try with the above version.

bschaeublin commented 5 years ago

@navyasric thank you for responding. I'm using an angular2+ wrapper, which still has 1.0.15. And it seems it would not be updated in the next time.

Do you know any other angular-wrappers using a newer version of adaljs, which works with angular 7 and provides simple interceptor and service classes to use adal?

JACrazy commented 5 years ago

version 4 of adal-angular4 has now been released which supports adal-angular 1.0.17