pythonflaskflask-jwt

How to set a custom authorization response in Flask-JWT?


By itself, Flask-JWT works, but I need to add some values to the http response, I try to do it like this:

@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

As soon as I add this code I get an error when starting 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'

As I said, everything works without this code. It looks like the function should return something for the decorator, but what should I return besides the HTTP response?

P.S. I tried removing the identity parameter from the function - it doesn't change anything at all.


Solution

  • The library has not been supported for 5 years, so I used Flask-JWT-Extended. There may be a solution to the original problem, but I don't think that makes sense.