我已经开始使用apidoc
来生成restapi文档。我试过用它。在
在我基于flask
的api应用程序中,我使用JWT
(尤其是flask jwt)进行身份验证。doc得到了正确的生成,但是来自doc的请求没有正确地发生。在
我在这里放置了生成doc的docsting
def authenticate(username, password):
"""
@api {post} /auth Authentication url
@apiName Authentication
@apiGroup Login
@apiParam {String} username Username of the user
@apiParam {String} password Password of the user
@apiSuccess {String} access_code JWT
@apiSuccessExample Success Response
HTTP/1.1 200 OK
{
"access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZGVudGl0eSI6IjM5MDA4MGExLWY0ZjctMTFlNS04NTRkLTI4ZDI0NDQyZDNlNyIsImlhdCI6MTQ1OTE3ODE0NSwibmJmIjoxNDU5MTc4MTQ1LCJleHAiOjE0NTkxNzg0NDV9.nx_1a4RmvJ7Vlf1CvnMzqoTfzChcuJnDb1Tjy1_FnXw"
}
@apiErrorExample Invalid Credentials
{
"description": "Invalid credentials",
"error": "Bad Request",
"status_code": 401
}
"""
user = session.query(User).filter_by(username=username).first()
if user and user.is_correct_password(password):
return user
return False
当我生成文档时,它得到了正确的生成
^{pr2}$''
(空)Content-Type
头,它也会失败。我在flask的请求中得到的请求数据是username=test@example.com&password=test123
我已经通过在Flask JWT的代码中添加调试点来确认上述内容
def _default_auth_request_handler():
data = request.get_json() # My debug poing
username = data.get(current_app.config.get('JWT_AUTH_USERNAME_KEY'), None)
password = data.get(current_app.config.get('JWT_AUTH_PASSWORD_KEY'), None)
但是当我使用postman
发出同样的请求时,它会正常地发生。在
我错过了什么?在
目前没有回答
相关问题 更多 >
编程相关推荐