jpadilla / pyjwt

JSON Web Token implementation in Python
https://pyjwt.readthedocs.io
MIT License
5.11k stars 684 forks source link

Add `as_dict` option to `Algorithm.to_jwk` #881

Closed fluxth closed 1 year ago

fluxth commented 1 year ago

Fixes #880

This patch adds an optional as_dict=False keyword argument to Algorithm.to_jwk() functions.

Library API is still backwards compatible with this change:

IPython 8.12.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: import jwt
In [2]: algo = jwt.get_algorithm_by_name('HS256')
In [3]: jwk_json = algo.to_jwk('test')

In [4]: type(jwk_json), jwk_json
Out[4]: (str, '{"k": "dGVzdA", "kty": "oct"}')

In [5]: jwk_dict = algo.to_jwk('test', as_dict=True)

In [6]: type(jwk_dict), jwk_dict
Out[6]: (dict, {'k': 'dGVzdA', 'kty': 'oct'})
fluxth commented 1 year ago

I think this is ready for review now, the only CI that is failing is codecov for typehint @overloads, mypy already checks for that.

Viicos commented 1 year ago

@fluxth Regarding failing CI, you can add more to exclude_lines: https://github.com/jpadilla/pyjwt/blob/97711b1a4fc322796092faa6bb18f8097b8eed62/pyproject.toml#L13-L15

That might be not working, if so maybe a # pragma: no cover could help

fluxth commented 1 year ago

CI test flaked, requesting re-run.

fluxth commented 1 year ago

Thanks for merging! 🚀 Sorry I wasn't able to update the changelog before release, it was nighttime in Japan.