in my app.py I initialized flask-jwt-extended as follow:
# Setup the Flask-JWT-Extended extension
app.config['RESTPLUS_MASK_SWAGGER'] = False # remove default X-Fields field in swagger
app.config['JWT_SECRET_KEY'] = 'super-secret' # Change this!
app.config['JWT_BLACKLIST_ENABLED'] = True
app.config['JWT_BLACKLIST_TOKEN_CHECKS'] = ['access', 'refresh']
jwt = JWTManager(app)
then I create token in login with snippet:
expires = datetime.timedelta(minutes=10)
access_token = create_access_token(identity=payload['email'], fresh=True, expires_delta=expires)
refresh_token = create_refresh_token(identity=payload['email'])
strangely if I add decorator @jwt.token_in_blacklist_loader to a certain endpoint I always received "Token has been revoked" error message.
@jwt.token_in_blacklist_loader
@api.route('/')
class UserList(Resource):
@jwt_required
@api.doc('list_users')
@api.marshal_list_with(user)
def get(self):
'''Get all users'''
users = UserApi.query.all()
return users
As far as I know this decorator is to check whether or not the token is blacklisted and I just create a new token from login, what is the best practice to create a new token & check whether the token is blacklisted or not?