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

mypy. Key can be cryptography.hazmat.backends.openssl.rsa._RSAPublicKey not only string #848

Closed
ievgennaida opened this issue Jan 8, 2023 · 5 comments
Labels
stale Issues without activity for more than 60 days

Comments

@ievgennaida
Copy link

ievgennaida commented Jan 8, 2023

Summary.
jwt.decode can accept cryptography.hazmat.backends.openssl.rsa._RSAPublicKey or private key or string.

Expected Result

Allow to pass not only string.

Actual Result

Warning from mypy while only string is expected but actually public key is expected.

Reproduction Steps

jwk_set = PyJWKSet.from_json(data)
jwt.decode("", key= jwk_set.keys[0].key);

System Information

$ python -m jwt.help
{
  "cryptography": {
    "version": "39.0.0"
  },
  "implementation": {
    "name": "CPython",
    "version": "3.8.10"
  },
  "platform": {
    "release": "10",
    "system": "Windows"
  },
  "pyjwt": {
    "version": "2.6.0"
  }
}
@Mark-Hetherington
Copy link

This tripped us up as well. MyPy suggested we pass a string, but the acceptable type depends on the algorithm, as algorith.prepare_key is called.

This appears to have been discussed in #605, #602 and the type annotation might have been changed to Any. There is more related work happening in #843 and #845

@Viicos
Copy link
Contributor

Viicos commented Jan 26, 2023

Indeed this is a duplicate of #602. Some additional context is available in #843, and the solution isn't trivial. pyjwt maintainers doesn't seem to be currently active on this project, so I'll get back on this when I'll get feedback on the #843 PR description

@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 Mar 28, 2023
@auvipy
Copy link
Collaborator

auvipy commented Mar 28, 2023

is it fixed now?

@Viicos
Copy link
Contributor

Viicos commented Mar 28, 2023

is it fixed now?

I'll probably try to find some time to work on it, but as I said here #848 (comment), it might be tricky

But this is a duplicate, so I think it can be closed

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

4 participants