benbaran / adal-angular4

Angular 4/5/6/7 ADAL Wrapper
MIT License
86 stars 104 forks source link

How to access the callback after login? #45

Closed rodneyjoyce closed 6 years ago

rodneyjoyce commented 6 years ago

Hi,

After login I want to show a message if it is successful or an error if not, however it is a void method which means I have no way of knowing when it completes - should it not return a promise or callback?

HighSoftWare96 commented 6 years ago

If you're using the window mode redirect and you have set in the adalService configuration the postLogoutRedirectUri then in the component called by routing into postLogoutRedirectUri in the OnInit function you can handle the callback of the login process with the function handleWindowCallback() that saves all the parameters in the cache. Then if you need the token you can use acquireToken (that finds out the token from the cache) and subscribe to its retriving as in this code:

    this.adalService.handleWindowCallback();
    this.adalService.acquireToken(environment.tokenServiceId).subscribe({
      next: (token) => {
        localStorage.setItem('token', token);
        // redirect to home page
      }
    });

I thinks there is no way to know if the login is successful or not because in case of error you remain in the microsoft login form....

rodneyjoyce commented 6 years ago

Thank you, I've decided to use an HTTP Interceptor to check tokens every time as opposed to an event on login.