-
Notifications
You must be signed in to change notification settings - Fork 491
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
tokenNotExpired() always return false #334
Comments
the token is valid, so isTokenExpired should return false. It's certainly confusing. |
I update the post thx guy ! |
so return !isTokenExpired() |
I think I found the solution, as I was fighting with a similar error:
So there are two possible fixes: -Use The third, impossible and stupid solution would be changing the default token name in JWT again. |
Had the same issue. @qmsq's fix worked for me. Thank you. |
A big thank you @qmsq! The second solution looks better to me, since it's not very consistent to write localStorage.setItem('token', authResult.idToken) but this is a pure matter of preference. Big up again, I was stuck on this for the last couple hours (grrr). |
Yes, @qmsq's fix worked for me as well, thanks so much! |
@qmsq made my day! Thank you! |
same problem, the function is return from localStorage but is not using the factory options of tokenGetter The implementation with google chrome debugger is: function tokenNotExpired(tokenName, jwt) {
if (tokenName === void 0) { tokenName = AuthConfigConsts.DEFAULT_TOKEN_NAME; }
var token = jwt || localStorage.getItem(tokenName);// here is force to get from localStorage but not tokenGetter options of AuthConfig
var jwtHelper = new JwtHelper();
return token != null && !jwtHelper.isTokenExpired(token);
} So another options is to pass the token in second parameters. tokenNotExpired(null, sessionStorage.getItem("id_token")) Thank... |
Changing default token name was a tiny but breaking change in minor version update are unexpected. It happens... Looks like I need to constraint my lib versions to exact ones... |
@qmsq |
@qmsq |
I know this is closed, but can you update the README, as its confusing because the steps doesn't say that you now have to provide a parameter in |
In case anyone is still a little confused I needed to do a little more detective work to understand the issue. Because I'm thinking wait isn't this supposed to be a self contained package? The token used to be access-token and then it was changed to token AuthConfigConsts.DEFAULT_TOKEN_NAME = 'token'; So I'm thinking how the #$ does changing it to id_token make it work? Why aren't we changing it to access-token. I see in my auth.service.ts file it says id_token. So how did it ever work when the default token was access-token. Turns out when looking at the history on April 11th the default token name was changed TWICE in one day. https://github.com/auth0/angular2-jwt/commits/a6984d1df9315cc52b22b9c57b8badc4b6d1f479/angular2-jwt.ts id_token > access_token > token So if like me you haven't touched your project since before April 11th then you'll change from id_token > token when you update the package. I feel like tokenNotExpired('id_token') isn't the best solution, and changing the 'localstorage' property is better. |
Alternative solution : Modify your auth.service.ts file: import { AuthConfigConsts } from 'angular2-jwt'; Search and replace all "id_token" to AuthConfigConsts.DEFAULT_TOKEN_NAME |
@simeyla id_token and access_token are not the same, and they have changed it not so long ago. id_token is authentication (who you are) and access_token is authorization (it's sent as a Bearer token to the API). in the latest version the Auth0Lock by default returns only access_token, but not the id_token. I suppose you can change your auth.service.ts to check for access-token in authenticated() method or make Auth0Lock return id_token using options. What I did in auth.service.ts is:
and then:
hope it helps. |
Thanks. So the double check in on April 11th was just a misunderstanding of
this distinction.
…On Fri, May 19, 2017 at 21:15 Valerii Sosliuk ***@***.***> wrote:
@simeyla <https://github.com/simeyla> id_token and access_token are not
the same, and they have changed it not so long ago. id_token is
authentication (who you are) and access_token is authorization (it's sent
as a Bearer token to API). in the latest version the Auth0Lock by default,
returns only access_token, and not the id_token. I suppose you can change
your auth.service.ts to check for access-token in authenticated method or
make Auth0Lock return id_token using options. What I in auth.service.ts is:
var options = {
auth: {
params: {scope: 'openid email user_metadata app_metadata picture',
responseType: 'id_token token'},
}
};
....
lock = new Auth0Lock(myConfig.clientID, myConfig.domain, options);
and then:
this.lock.on('authenticated', (authResult) => {
localStorage.setItem('token', authResult.idToken);
localStorage.setItem('accessToken', authResult.accessToken);
hope it helps.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#334 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ADfKVqhj-0FnfYA9tqoIEYFKPlgMA2j4ks5r7mj9gaJpZM4M8mdi>
.
|
You can try |
we love you @qmsq |
Thank you @qmsq ! |
Oh you saved my day ! Thx @qmsq |
@qmsq thank you for the piece of mind after 2 hours of retracing steps to find out what I did wrong!!! |
@qmsq thanks a lot dude, i use tokenNotExpired('id_token') and everything work very well. |
@qmsq tnx man |
Hi all of you, It happen to me the same but I realize my token was expired, so I was getting the correct response from You can find the token's expiration date with,
|
I was using tokenNotExpired and it was always returning false, but instead I used JwtHelper.isTokenExpired and not it is working. |
Solution : For ex:
and use Following is the working code snippet:
|
Thanks, @rhtpandeyIN its works |
@qmsq you saved my soul today. God bless you sir |
i have face the same problem that tokenNotExpired() is always returning false. in the auth.service.ts change:
}` to:
}` 'tokenid' refers to the var name for the token in the local storage |
Thanks a whole lot
…On Sun, Jun 24, 2018 at 11:51 PM, Sanju maheeshan ***@***.***> wrote:
i have face the same problem that tokenNotExpired() is always returning
false.
this solution fixed the error
in the auth.service.ts
change:
`loggedIn() {
return tokenNotExpired();
}`
to:
`loggedIn() {
return tokenNotExpired('tokenid');
}`
'tokenid' refers to the var name for the token in the local storage
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#334 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/Ak7Hi9wwWQaYqKe7v32fevdOL4w3EcMCks5uAIiJgaJpZM4M8mdi>
.
|
Hi, I use your library without Ionic (native Angular 2) and all time tokenNotExpired() method return false.
When this code is exectued :
I use this code for angular routing canActivate: [AuthGuard].
But tokenNotExpired() always return false.
I don't understand why !
The text was updated successfully, but these errors were encountered: