angular-token icon indicating copy to clipboard operation
angular-token copied to clipboard

getAuthDataFromParams call in tryLoadAuthData does not work

Open okodo opened this issue 7 years ago • 2 comments

In

Angular2TokenService.prototype.tryLoadAuthData = function () {....

you have

if (this.activatedRoute)
    this.getAuthDataFromParams();
if (this.atCurrentAuthData)
    this.validateToken();

But the method "getAuthDataFromParams()" uses "this.activatedRoute.queryParams.subscribe...." (so observable)

And therefore the next condition "if (this.atCurrentAuthData)" in tryLoadAuthData is always "false"!

It is impossible to login the user within queryParams. But it is necessary!

Example: Reset password

  • Mailer sends me a link to backend
  • Backend redirects me to frontend with neccessary params like token, client_id etc

And now i have to signin the user within query params because i will signin the user after update password. And this is impossible.

I think the solution is to call "validateToken()" in getAuthDataFromParams not in tryLoadAuthData..e.g. so

// Try to get auth data from url parameters.
    Angular2TokenService.prototype.getAuthDataFromParams = function () {
        var _this = this;
        if (this.activatedRoute.queryParams)
            this.activatedRoute.queryParams.subscribe(function (queryParams) {
                var authData = {
                    accessToken: queryParams['token'] || queryParams['auth_token'],
                    client: queryParams['client_id'],
                    expiry: queryParams['expiry'],
                    tokenType: 'Bearer',
                    uid: queryParams['uid']
                };
                if (_this.checkAuthData(authData)) {
                    _this.atCurrentAuthData = authData;
                    _this.validateToken(); //  ---> this is my idea
                }
            });
    };

and tryLoadAuthData shows like so:

// Try to load auth data
    Angular2TokenService.prototype.tryLoadAuthData = function () {
        var userType = this.getUserTypeByName(localStorage.getItem('userType'));
        if (userType)
            this.atCurrentUserType = userType;
        this.getAuthDataFromStorage();
        if (this.activatedRoute)
            this.getAuthDataFromParams();
        // ---> next lines can be remove because never calls
        // if (this.atCurrentAuthData)
        //    this.validateToken();
    };

Furthermore it might resolve the previous issue #371

okodo avatar Dec 21 '17 20:12 okodo

Just ran into this as well. Any idea when this will be fixed?

douglasward avatar Jan 09 '18 14:01 douglasward

I may be misreading the code, but I think whatever issue you are facing is not related to the validateToken not being called because in fact validateToken is also an observable and without a subscribe the call this.validateToken does nothing!

Note also that from looking at the code, the tryLoadAuthData is only called once, on init, so it isn't doing whatever you think it should be doing.

colmben avatar Apr 17 '18 21:04 colmben