前言
flask_jwt_extended 插件使用,当token过期的时候,默认返回401 UNAUTHORIZED {"msg": "Token has expired"}
@jwt.expired_token_loader
设置一个回调函数,以便在过期时返回自定义响应令牌尝试访问受保护的路由。这个特定的回调函数
将jwt_header和jwt_payload作为参数,并且必须返回 Flask 响应。查看API文档以查看其他回调函数所需的参数和返回值。
官方文档使用示例
from flask import Flask
from flask import jsonify
from flask_jwt_extended import create_access_token
from flask_jwt_extended import jwt_required
from flask_jwt_extended import JWTManager
app = Flask(__name__)
app.config["JWT_SECRET_KEY"] = "super-secret" # Change this!
jwt = JWTManager(app)
# Set a callback function to return a custom response whenever an expired
# token attempts to access a protected route. This particular callback function
# takes the jwt_header and jwt_payload as arguments, and must return a Flask
# response. Check the API do