Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow custom JSON encoder for converting claims dict #214

Open
chbndrhnns opened this issue Mar 3, 2021 · 4 comments
Open

Allow custom JSON encoder for converting claims dict #214

chbndrhnns opened this issue Mar 3, 2021 · 4 comments

Comments

@chbndrhnns
Copy link

chbndrhnns commented Mar 3, 2021

I am using this snippet to allow a custom JSON encoder to be used (which is patching parts of python-jose):

from jose import jws, jwt
from jose.utils import base64url_encode
from my_encoder import MyEncoder

def _encode_with_my_encoder(payload):
    """Encode the payload with custom JSON encoder which knows how
    to handle the custom types
    """
    if isinstance(payload, Mapping):
        try:
            payload = json.dumps(
                payload,
                separators=(',', ':'),
                cls=MyEncoder
            ).encode('utf-8')
        except ValueError:
            pass

    return base64url_encode(payload)


jws._encode_payload = _encode_with_juice_encoder

Would it be feasible to support passing in a custom encoder class into the encode method?

@chbndrhnns
Copy link
Author

Is this kind of change unwanted? I would love some feedback.

@MarkParker5
Copy link

I need it

@Leithal3
Copy link

Leithal3 commented Nov 8, 2023

IMO would also be good to add the option to jwt.encode()

@iQiexie
Copy link

iQiexie commented Aug 30, 2024

is it gonna be added?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants