我目前正在尝试使用在基本级别扩展的 Flask-JWT。我从用户表单中获得了经过身份验证的用户和密码。我创建了一个访问令牌,将其包含在响应中并路由到另一个受保护的路由。请找到以下代码的较短版本...
from flask import Flask, jsonify, request
from flask_jwt_extended import,JWTManager, jwt_required, create_access_token,get_jwt_identity)
app.config['JWT_SECRET_KEY'] = 'super-secret'
jwt = JWTManager(app)
app.config['JWT_TOKEN_LOCATION'] = ['headers']
app.config['JWT_BLACKLIST_ENABLED'] = True
jwt = JWTManager(app)
app.config['PROPAGATE_EXCEPTIONS'] = True
@log_blueprint.route('/', methods=['GET', 'POST'])
def login():
form = LoginForm()
if request.method == 'POST':
if error is None and username = form.request['user'] and pwd = form.request['pwd'] :
access_token = create_access_token(identity=user)
resp = redirect(url_for('log_blueprint.protected'),access_token)
resp.headers = {'Authorization': 'Bearer {}'.format(access_token)}
return resp
@log_blueprint.route('/protected', methods=["POST","GET"])
@jwt_required
def protected():
current_user = get_jwt_identity()
return jsonify(logged_in_as=current_user), 200
它给了我如下错误...
{"msg":"Missing Authorization Header"}
我尝试了此页面上的答案... https://stackoverflow.com/questions/52087743/flask-restful-noauthorizationerror-missing-authorization-header 但无法变得更好。请让我知道此问题的任何解决方案。抱歉,如果有任何拼写错误。
谢谢和问候, Abhinay JK