我有一个Flask REST API,它使用Flask Restx和JWT令牌身份验证,并且正在进行postman调用。但是,当我尝试使用swagger时,发送的令牌不是我通过接口输入的令牌。我的代码如下所示:
blueprint = Blueprint('api_bp', __name__, url_prefix='/api/1')
authorizations = {
'api_key' : {
'type' : 'apiKey',
'in' : 'header',
'name' : 'x-access-token'
}
}
api = Api(blueprint,
authorizations=authorizations,
title='My Title',
version='1.0',
security='api_key'
)
from timesheets.views.api_bp import api as ns1
np = api.namespace('index', description='Index API')
def token_required(f):
@wraps(f)
def decorated(*args, **kwargs):
...
@np.route('/users')
class Users(Resource):
@api.doc(security='api_key')
@token_required
def get(self, current_user):
...
return jsonify({'user' : output})
当我“试用”时,我可以看到正确的x-access-token被放置在curl调用中
但是,如果我查看我的请求头,每次我获得发送到服务器的相同x-access-token时:
那么,这个令牌是从哪里生成的呢?我如何确保我只使用通过接口传递的令牌
在检查返回的是同一个键之后,我发现在代码中输入的值被我之前引入的测试数据覆盖了
相关问题 更多 >
编程相关推荐