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

Support returning Algorithm.to_jwk(key) as dict #880

Closed
fluxth opened this issue Apr 12, 2023 · 3 comments · Fixed by #881
Closed

Support returning Algorithm.to_jwk(key) as dict #880

fluxth opened this issue Apr 12, 2023 · 3 comments · Fixed by #881

Comments

@fluxth
Copy link
Contributor

fluxth commented Apr 12, 2023

Currently, the when generating a JWK, the only way to get a dict from PyJWT is to:

jwk_str = algo.to_jwk(key)
jwk = json.loads(jwk_str)

This is very unfortunate when you want to add more fields into the JWK:

modified_jwk = {
    **json.loads(jwk_str),
    "kid": "keyid",
}

There should be a way in the API to get the underlying dict from the Algorithm.to_jwk(key) functions.
My proposal is to add another variant Algorithm.to_jwk_dict(key) to not break API compatibility.

I'm planning to send PR implementing this, but I figured I should raise an issue first to see if there's any better way of doing this...

@Viicos
Copy link
Contributor

Viicos commented Apr 13, 2023

Maybe with a as_dict argument to to_jwk, with a default value of False for backwards compatibility?

@fluxth
Copy link
Contributor Author

fluxth commented Apr 14, 2023

Hmm, that might work...
I'm a bit concerned about the return type hint but with @overload it should work fine

@Viicos
Copy link
Contributor

Viicos commented Apr 14, 2023

I'm a bit concerned about the return type hint but with @overload it should work fine

yes using overloads is pretty common for this use case

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

Successfully merging a pull request may close this issue.

2 participants