[英]Why doesn't Flask see JWT cookie while sending POST request
我正在嘗試在此 POST 路由上向我的 Flask 應用程序提交簡單的 HTML 表單,但出現未經授權的錯誤,因為 Flask/JWT(我不確定)在 cookies 中找不到它。它可以很好地處理相同的路線(它在 cookie 中找到 access_token)。 POST請求中的cookies是什么問題? 謝謝!
@app.route('/someRoute', methods=["GET", "POST"])
@jwt_required(locations=["cookies"])
def someRoute():
if request.method == "GET":
return render_template("page.html") **works fine**
elif request.method == "POST":
**there is the problem**
你如何發送你的 POST 請求? 如果您從瀏覽器發送請求,則需要隱式設置 withCredentials
例如:
axios.get(url, { withCredentials: true });
您看到的實際錯誤是什么? 我懷疑您沒有在請求中發送 CSRF 雙提交令牌,這是 POST 請求所必需的。 請參閱此處的文檔: https://flask-jwt-extended.readthedocs.io/en/stable/token_locations/#cookies
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.