grumar / adal-angular5

Angular 5 ADAL Wrapper
MIT License
12 stars 19 forks source link

Adal5Service.acquireToken falls with "Token renewal operation failed due to timeout", but there are successful requests in network #14

Open AlexeyBoiko opened 6 years ago

AlexeyBoiko commented 6 years ago

Please help me with Adal5Service.acquireToken method. I my case it is always falls with "Token renewal operation failed due to timeout".

Full online demo source code

Here is app.component.ts:

import { Component, OnInit } from '@angular/core';
import { Adal5Service } from 'adal-angular5';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit {
  constructor(private adalSvc: Adal5Service) {
    let config: adal.Config = {
      tenant: 'XXX.onmicrosoft.com',
      clientId: '21efffd5-29fc-XXX',
      postLogoutRedirectUri: window.location.origin,
      endpoints: {
        graphApiUri: "https://graph.microsoft.com",
      },
      cacheLocation: "localStorage",
      redirectUri: ''
    };

    this.adalSvc.init(config);
  }

  ngOnInit(): void {
    this.adalSvc.handleWindowCallback();

    if (!this.adalSvc.userInfo.authenticated) {
      this.adalSvc.login();
      return;
    }

    // work correct
    console.log(this.adalSvc.userInfo.username);

    this.adalSvc.acquireToken("https://graph.microsoft.com")
      .subscribe(
        token => console.log(token), // never comes
        error => console.log(error)); // error: Token renewal operation failed due to timeout
  }
}

There are correct acquired token In network: image

Error on page image

AlexeyBoiko commented 6 years ago

Finally get it working, but without this library. Here is full example of

Angular routs is working. Also, there are no double requests when renewing token.

kov-hans commented 6 years ago

I had the same problem but when I reverted adal-angular (adal-angular5 is dependent on adal-angular) from 1.0.16 to 1.0.15 it all worked fine. I have found the bug in 1.0.16 and will report it.

wally666 commented 6 years ago

1.0.36 still does not work

remisture commented 6 years ago

What was the bug? @kov-hans

nyn3x commented 6 years ago

I've hit the same problem - I guess. Any hint on how to resolve this (and maybe sticking with adal-angular5)?

kov-hans commented 6 years ago

I'm new to front end programming and type script so I'm not sure where the problem is but I found that adal-angular5 is working fine with version 1.0.15 of adal-angular and fails with version 1.0.16. I also found the problem that I described in an issue on adal-angular ( https://github.com/AzureAD/azure-activedirectory-library-for-js/issues/712 ), but they just closed the issue saying that adal-angular5 needs to be updated with the latest version of adal-angular. If adal-angular5 needs to be updated between 1.0.15 and 1.0.16 that seems like a breaking change in a patch release to me, but I might be wrong.

grumar commented 6 years ago

published as beta npm install adal-angular5@2.1.1