如何在 Flask-JWT 中设置自定义授权响应?
How to set a custom authorization response in Flask-JWT?
Flask-JWT 本身可以工作,但我需要向 http 响应添加一些值,我尝试这样做:
@jwt.auth_response_callback
def custom_auth_response_handler(access_token, identity):
response = Response({
'accessToken': access_token.decode('utf-8')
})
response.headers['Access-Control-Allow-Origin'] = '*'
return response
添加此代码后,启动 Flask 时出现错误:
Traceback (most recent call last):
File "wsgi.py", line 1, in <module>
from app import create_app
File "D:\Dev\api-general\app\__init__.py", line 40, in <module>
def customized_response_handler(access_token, identity):
TypeError: _default_auth_response_handler() missing 1 required positional argument: 'identity'
如我所说,没有此代码一切正常。看起来函数应该 return 装饰器的东西,但是除了 HTTP 响应之外我应该 return 什么?
P.S。我尝试从函数中删除 identity
参数 - 它根本没有改变任何东西。
库已经5年没有支持了,所以我用了Flask-JWT-Extended
。原始问题可能有解决方案,但我认为这没有意义。
Flask-JWT 本身可以工作,但我需要向 http 响应添加一些值,我尝试这样做:
@jwt.auth_response_callback
def custom_auth_response_handler(access_token, identity):
response = Response({
'accessToken': access_token.decode('utf-8')
})
response.headers['Access-Control-Allow-Origin'] = '*'
return response
添加此代码后,启动 Flask 时出现错误:
Traceback (most recent call last):
File "wsgi.py", line 1, in <module>
from app import create_app
File "D:\Dev\api-general\app\__init__.py", line 40, in <module>
def customized_response_handler(access_token, identity):
TypeError: _default_auth_response_handler() missing 1 required positional argument: 'identity'
如我所说,没有此代码一切正常。看起来函数应该 return 装饰器的东西,但是除了 HTTP 响应之外我应该 return 什么?
P.S。我尝试从函数中删除 identity
参数 - 它根本没有改变任何东西。
库已经5年没有支持了,所以我用了Flask-JWT-Extended
。原始问题可能有解决方案,但我认为这没有意义。