Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getAuthDataFromParams call in tryLoadAuthData does not work #382

Open
okodo opened this issue Dec 21, 2017 · 2 comments
Open

getAuthDataFromParams call in tryLoadAuthData does not work #382

okodo opened this issue Dec 21, 2017 · 2 comments
Labels

Comments

@okodo
Copy link

okodo commented Dec 21, 2017

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

@douglasward
Copy link

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

@colmben
Copy link
Contributor

colmben commented Apr 17, 2018

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.

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

No branches or pull requests

4 participants