pallets-eco / flask-jwt

JWT (JSON Web Tokens) for Flask applications
MIT License
564 stars 177 forks source link

Add response_handler hook/decorator #13

Closed sloria closed 10 years ago

sloria commented 10 years ago

Adds a response_handler hook that allows for custom formatting of the output response for the auth endpoint.

Example

@jwt.response_handler
def handle_response(token):
    return jsonify({'mytoken': token})

# POST /auth  => {"mytoken": 'abc123...'}

This control over the response is absolutely necessary when using libraries that automatically JSONify the return value of your views. For example, Flask-API and Flask-RESTful extensions expect views to return dictionaries. The extensions handle the "jsonification".

Without a means for overriding flask-jwt's response behavior, your token payload gets jsonified twice!

coveralls commented 10 years ago

Coverage Status

Coverage remained the same when pulling 465a22822de66d4dc0b63d7c52f609087a352351 on sloria:response-handler into ba5652b8544068f8d7fcb391f8a3cbbbca4741c9 on mattupstate:master.

mattupstate commented 10 years ago

Thanks for this. Good idea.