Skip to content

current_app.json_encoder should be passed to jwt.encode #138

@matthewstory

Description

@matthewstory

I use a custom JSON encoder in Flask to help serialize my models for my REST end-points. currently this encoder is not passed to jwt.encode:

flask_jwt_extended/tokens.py:29

encoded_token = jwt.encode(token_data, secret, algorithm).decode('utf-8')

The jwt.encode method takes an optional json_encoder argument. I contend that we should use this option to pass in the json encoder for the current Flask app.

It looks like the tokens module has been designed to not have any knowlege of the config module, so probably the patch here would be to add a new @property to the config object which returns current_app.json_encoder, and then to add json_encoder as an optional argument to all encoding methods in tokens.py.

Happy to provide a PR for this if we agree it's useful and the approach above is correct.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions