简体   繁体   中英

Expired JWT Token when trying to authenticate?

I am using JWT for the first time, I am finding a hard time to understand the way it works fully, every time I find a solution to simethong, an other thing pops out.

I was trying to authenticate before and when I send the correct username and password I get a token when using Postman.

I left the project few hours and came back and now when I try to authenticate I get this error :

{
    "code": 401,
    "message": "Expired JWT Token"
}

I don't know how to solve it, because I did not knwo I may face such problem.

Any help would be much appreciated.

It goes like this:

You make first api request, pass your credentials, get token and store it somewhere.

After that you should pass that token (trough "Bearer" header field) with every other request so server could identify you.

But that token won't be valid forever. After some time (TTL) it will expire and you'll get message like that. Then you have to repeat authentication to get new token.

So just repeat request you made at start, pass again credentials, collect and store again new token and keep using it as before.

If you're using LexikJWTAuthenticationBundle , you can set the TimeToLive for JWT in lexik_jwt_authentication.yaml in config/packages.

The token_ttl: attribute is for setting up the TimeToLive of a token in seconds (eg, 604800 is equal to 7 days).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM