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

Why token with kid should be decoded twice? #408

Closed
Reskov opened this issue Apr 22, 2019 · 3 comments
Closed

Why token with kid should be decoded twice? #408

Reskov opened this issue Apr 22, 2019 · 3 comments
Labels
stale Issues without activity for more than 60 days

Comments

@Reskov
Copy link

Reskov commented Apr 22, 2019

decoding and verifying JWT token with kid need token to be loaded and parsed twice. First to get headers and thereafter to verify signature.

headers = jwt.get_unverified_header(token) # parse token
kid = headers["kid"]
public_key = get_public_key(kid)

decoded = jwt.decode( # parse once more
    token,
    public_key,
    verify=True,
    algorithms=[self.alg],
    audience=valid_audiences,
    issuer=self.issuer,
)

Does it possible to eliminate unnecessary second parsing?

For example google-auth does not have such problem
https://github.com/googleapis/google-auth-library-python/blob/2c6ad78917e936f38f87c946209c8031166dc96e/google/auth/jwt.py#L197

@nigoroll
Copy link

nigoroll commented Feb 16, 2020

I would argue that in particular with public key crypto, the duplicate parsing overhead is insignificant, but you are right: decode() could support passing a dict with key ids.
I would suggest to allow a list or dict also as the key argument:

@jpadilla I would prepare a PR for this, would this sound like a viable interface to you?

@jpadilla
Copy link
Owner

jpadilla commented Apr 8, 2020

Have been working on v2 which includes some new primitives that aim to improve this. Feedback is welcome #470

@github-actions
Copy link

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 7 days

@github-actions github-actions bot added the stale Issues without activity for more than 60 days label Jun 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stale Issues without activity for more than 60 days
Projects
None yet
Development

No branches or pull requests

3 participants