pythonflaskjwtflask-jwtflask-jwt-extended

Get other user jti for flask-jwt-extended


How to get 'jti', not mine but by the "username" ? On registration/login jti for access and refresh were assigned to 'username'. All instructions and docs note only how to get my own jti to logout with smth. like this code:

class UserLogoutRefresh(Resource):
    @jwt_refresh_token_required
    def post(self):
        jti = get_raw_jwt()['jti']
        try:
            revoked_token = RevokedTokenModel(jti = jti)
            revoked_token.add()
            return {'message': 'Refresh token has been revoked'},200
        except:
            return {'message': 'Something went wrong'}, 500

How to get jti for another user. I suppose smth like:

jti = get_raw_jwt(identity='someusername')['jti']

has to exist for this, who knows ???


Solution

  • Each token will have a unique jti, it’s not scoped per username. If the same user creates 3 tokens, all of them will have a different jti for example. If you want to have access to these jti then you will use the decode_token function when you create your token and save it in a datastore somewhere you can look it up later