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'
正如我所说,没有此代码一切正常。看起来这个函数应该为装饰器返回一些东西,但是除了 HTTP 响应我应该返回什么?
PS我尝试identity
从函数中删除参数 - 它根本没有改变任何东西。