flask-jwt-extended icon indicating copy to clipboard operation
flask-jwt-extended copied to clipboard

Token becomes invalid after reload of service

Open mudrila opened this issue 8 years ago • 5 comments

Hi, I notice next issue:

If you serve flask app with uwsgi, and run your application with "service" command (create service file, put it to /etc/systemd/system), after service reload all tokens become invalid (e.g. for all requests with previously generated tokens returned response with 422 error).

If you need any examples(my configuration) - please, tell me.

mudrila avatar May 09 '18 11:05 mudrila

That shouldn’t be happening. What does your config look like? Are you generating a new secret key for your application every time it starts up, or do you have a key hard coded to a file or env variable somewhere?

vimalloc avatar May 09 '18 14:05 vimalloc

It is hard coded in config.py file, and then I apply config to app via app.config.from_object('config')

And hardest part: I can't reproduce it on my local environment. It's happend only on production.

mudrila avatar May 09 '18 14:05 mudrila

That is super strange. The only thing that causes 422’s by default is if the token has been tampered with, you try to use a refresh token to access an access token endpoint (or vice versa), or if the key/algorithm used to decode the JWT changes. If it’s happening to all of your endpoints with tokens that used to previously work, the secret key seems like the most likely suspect. I would start by looking there, and verifying that the key is in fact what you would expect it to be before and after a restart.

If you have any custom jwt callbacks as well (such as user loader or blacklisted tokens) it may be worth looking at those and see if they could be returning the 422 status code. I don’t think this is as likely, but if you are doing something like relying on a redis instance for blacklisting, and have the init script restarting the redis service at the same time as you application, it might be able to explain what’s going on.

Sorry I don’t have more concrete advice here, I Hope this helps point you in the right direction. If you can find a way to duplicate this issue with a minimum example project I would be happy to take that and help dig a bit more.

Good luck!

vimalloc avatar May 09 '18 14:05 vimalloc

Thank you for reply, I will try to reproduce it with some minimum example and let you know. Have a nice day :)

mudrila avatar May 10 '18 07:05 mudrila

Check if your SECRET_KEY had been changed. I was just doing this wrong.

mai1202 avatar Dec 16 '23 10:12 mai1202