我正在使用flask-jwt-extended并尝试发送一个 cookie。不幸的是,我没有存储在浏览器中,但我可以在标题中找到它:
Set-Cookie: refresh_token_cookie=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE1OTM0NjUwNDgsIm5iZiI6MTU5MzQ2NTA0OCwianRpIjoiMjk3ZmQ2NTgtZDBmMi00ZjNlLWI0MGItNWViZDEzYzFjYWFhIiwiZXhwIjoxNTk2MDU3MDQ4LCJpZGVudGl0eSI6eyJpZCI6MSwicm9sbGUiOiJhZG1pbmlzdHJhdG9yIn0sInR5cGUiOiJyZWZyZXNoIiwiY3NyZiI6IjlmM2EzNGU2LTFjYzYtNDI4MC04NzEzLThkYmRiYTUyNzg2ZiJ9.Dcow66aWcChwvYHorP1Tk57bTT25ZP3k2Dlvuo9Vngs; Secure; HttpOnly; Path=/auth/refresh
它在我看来格式不正确:例如,“安全”应该是“真”,我怀疑这就是它没有被存储的原因(这个问题正在解决同样的问题,但我没有设法解决它那里提供的答案)。
init .py(相关部分):
from flask_jwt_extended import JWTManager
from flask_cors import CORS
from config import Config
jwt = JWTManager()
def create_app(config_class=Config):
app = Flask(__name__)
app.config.from_object(config_class)
app.config['JWT_TOKEN_LOCATION'] = ['cookies']
app.config['JWT_COOKIE_SECURE'] = True
app.config['JWT_ACCESS_COOKIE_PATH'] = '/auth'
app.config['JWT_REFRESH_COOKIE_PATH'] = '/auth/refresh'
app.config['JWT_COOKIE_CSRF_PROTECT'] = True
app.config['JWT_COOKIE_SECURE'] = True
app.config['JWT_CSRF_CHECK_FORM'] = True
app.config['JWT_SECRET_KEY'] = "change this"
CORS(app, supports_credentials=True)
jwt.init_app(app)
routes.py(相关部分):
@bp.route('/login', methods=['POST'])
def login():
...
resp = jsonify(access_token=access_token,
refresh_token=refresh_token)
set_access_cookies(resp, access_token)
set_refresh_cookies(resp, refresh_token)
return resp, 200
我以扩展的官方 repo 中的例子作为灵感。我在这里做错了什么?