Skip to content
This repository has been archived by the owner on Jun 26, 2021. It is now read-only.

1.0.16 issue #690

Closed
danpardo opened this issue Dec 20, 2017 · 11 comments
Closed

1.0.16 issue #690

danpardo opened this issue Dec 20, 2017 · 11 comments
Assignees

Comments

@danpardo
Copy link

Hi, I have project with angular2 and AAD since friday the method adalservice.acquiretoken has stoped working, it throws an Token renewal failed due to timeout error. This issue only occurs on my local environment and the issue seems to be with ng2-adal package more specifically with adal-angular version, all my coworkers has version 1.0.15 and it works for them but I have the new version 1.0.16.

Any ideas what can be causing the issue?

@rohitnarula7176
Copy link
Contributor

@danpardo We made a change in the new version to remove the renewStates property from window and adding it as a private property on the adal instance as _renewStates. This might be causing the issue. Can you share a code repro of this issue so I can investigate this further.

@danpardo
Copy link
Author

.acquireToken("resource")
.subscribe(token => {
this._store.dispatch({ type: "AUTHENTICATED", payload: token });

    window["$"].signalR.ajaxDefaults.headers = {
      Authorization: "Bearer " + token
    };
    var user = this.adalService.userInfo;

    this.conn.hub.logging = true;
    this.conn.hub.url = process.env.API_URL + "/SignalR";

    this.conn.hub
      .start({ transport: ["longPolling", "webSockets"] })
      .done(data => {
        console.log("=======================> SignalR connected");

        this._store.dispatch({ type: "REQUEST_STUDENT_PROGRESS" });
        this._store.dispatch({ type: "REQUEST_STUDENT_HISTORY" });
        this._store.dispatch({ type: "REQUEST_MY_FAVORITES" });

        start$.next(true);
        start$.complete();
      })
      .fail(error => {
        console.log("===============> SignalR could not connect");
        console.log(error);
        start$.next(false);
        start$.complete();
      });
  },
  err => {
    console.log("***************************************************************")
    console.log(err)
  });

The last console.log(err) contains the Token renewal operation failed due to time out this error comes from the acquireToken method.

@rohitnarula7176
Copy link
Contributor

@danpardo The code you pasted has no information about the internal implementation of acquireToken method of adal. I will need to see that or a working code repro of the issue which I can run to investigate this further.

@danpardo
Copy link
Author

@rohitnarula7176 Sorry, hope this helps:

public acquireToken(resource: string) {
let _this = this; // save outer this for inner function
let errorMessage: string;
return Observable.bindCallback(acquireTokenInternal, function (token: string) {
if (!token && errorMessage) {
throw (errorMessage);
}
return token;
})();

    function acquireTokenInternal(cb: any): string {
        let s: string = '';

        _this.adalContext.acquireToken(resource, (error: string, tokenOut: string) => {
            if (error) {
                _this.adalContext.error('Error when acquiring token for resource: ' + resource, error);
                errorMessage = error;
                cb(<string>null);
            } else {
                cb(tokenOut);
                s = tokenOut;
            }
        });
        return s;
    }
}

@rohitnarula7176
Copy link
Contributor

@danpardo I apologize for the misunderstanding but I need the source code of adal.js and adal-angular.js file (similar to what we have in the lib folder of our repo) you are using which has the implementation of the acquireToken method. I am guessing you are using an older version of the file.

@rohitnarula7176 rohitnarula7176 self-assigned this Dec 21, 2017
@ben-m-lucas
Copy link

This issue is affecting an application that we have as well. We're using ng2-adal and have endpoints specified with a client ID. The main authentication works, but we encounter failures to any endpoint specified and the javascript log starts reporting the following error:

ERROR Error: Uncaught (in promise): Token renewal operation failed due to timeout

@wvanderdeijl
Copy link

Looking at #690 (comment) the issue might indeed be related to removing renewStates from window and moving it to _renewStates on the adal instance. With that chance, the callBackMappedToRenewStates was also removed from window and moved to _callBackMappedToRenewStates on the adal instance. This is where ng2-adal fails as it is looking at window.parent.callBackMappedToRenewStates from the iframe code. See https://github.com/sureshchahal/angular2-adal/blob/266e93ef3bac374e005f814c0044dac67e6b5cb7/src/services/adal.service.ts#L72

@rohitnarula7176
Copy link
Contributor

@wvanderdeijl You are right. The issue is what I have mentioned above. ng-2 adal relies on the private properties of adal like _renewStates and _callBackMappedToRenewStates which were changed in the new version. The person who is maintaining the ng2-adal will have to update his code as per the latest version to fix the issue. Closing this as this is not an issue with the library.

@claudiuconstantin
Copy link

My understanding is that some breaking changes were introduced in the latest version, 1.0.16. This breaks the semver standard. A major version would be the right thing to do here

@rohitnarula7176
Copy link
Contributor

@claudiuconsttntin There were no changes made to the public API surface hence a major version was not released. We changed the internal properties and the developer should not be writing code using those properties. Please refer to my comment above. I can try to create a pull request for the ng2-Adal library to see if I can fix the issue.

@rohitnarula7176
Copy link
Contributor

@claudiuconstantin There were no changes made to the public API surface hence a major version was not released. We changed the internal properties and the developer should not be writing code using those properties. Please refer to my comment above. I can try to create a pull request for the ng2-Adal library to see if I can fix the issue.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants