Jwt Token renewal

How to renew jwt token through api’s?? Cause we see that the token expires frequently and we have to call the login rest api to generate a new jwt token.Is there any way to renew the jwt token. What would be the expiry time for this login rest api token. Also is it possible to generate two tokens , one for base and one for access in the rest api for long and short lifetime??

You can generate your own tokens, the format is described here: https://docs.loraserver.io/lora-app-server/integrate/auth/. When the expiration field is not set it will never expire.

We are generating token using /api/internal/login with values:
{
“username”: “user”
“password” “pass”
“iss”: “lora-app-server”,
“aud”: “lora-app-server”,
“sub”: “user”
}

still our token is expiring every day almost

Please check again with the previous documentation link. You should not post the token to /api/internal/login. Posting your username and password to /api/internal/login returns a token. However this token contains an expiration timestamp. To generate a token without expiration you have to construct your own JWT token based on the format in the previous link. You could use www.jwt.io for example.

We tried it using a decoder in jwt.io it says signature verified also…although when i call the api with That grpc Metadata it gives me error response,

“error”: “authentication failed: jwt parse error: signature is invalid”, “code”: 16.

Is This is correct??

Make sure you’re using the same secret as that you configured in the LoRa App Server configuration :wink:

Hi brocaar… I tried to use the JWT secret key in the decoder of jwt.io It also shows signature verified. but again as i hit it with the url it says invalid signature… Could you let me know the actual process of generating the token in a little more depth??.

https://scotch.io/tutorials/the-anatomy-of-a-json-web-token might be a good source to learn more about JWT tokens :slight_smile: