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

PyJWT async #956

Draft
wants to merge 11 commits into
base: master
Choose a base branch
from
Draft

PyJWT async #956

wants to merge 11 commits into from

Conversation

padrepitufo
Copy link

@padrepitufo padrepitufo commented May 17, 2024

I am somewhat new to contributing to a python library, and I am not sure if the code I'm supplying is needed/wanted-by/appropriate-for this project. If there is already a suggested way to use PyJWT within an asynchronous context (like FastAPI) I would like guidance. If something like this could be useful I can add tests or make changes to align the code with the style of the project.

The purpose of this PR is to mitigate blocking code/calls such as represented in this tutorial (to get_signing_key_from_jwt):

class VerifyToken:
    """Does all the token verification using PyJWT"""
    # ...
    async def verify(self,
                     security_scopes: SecurityScopes,
                     token: Optional[HTTPAuthorizationCredentials] = Depends(HTTPBearer())
                     ):
        # ...
        try:
            signing_key = self.jwks_client.get_signing_key_from_jwt( # 👈 current behavior
                token.credentials
            ).key
        except jwt.exceptions.PyJWKClientError as error:
            # ...
        return payload
    # ...

I wish to call it like so

class VerifyToken:
    """Does all the token verification using PyJWT"""
    # ...
    async def verify(self,
                     security_scopes: SecurityScopes,
                     token: Optional[HTTPAuthorizationCredentials] = Depends(HTTPBearer())
                     ):
        # ...
        try:
            signing_key = await self.jwks_client.get_signing_key_from_jwt_async( # 👈 desired behavior
                token.credentials
            ).key
        except jwt.exceptions.PyJWKClientError as error:
            # ...
        return payload
    # ...

Thank you in advance for any guidance/direction you provide.

@padrepitufo
Copy link
Author

apologies on the pre-commit failure, it wasn't working on my end for some reason so I pushed with 🤞 . I'll fix that. And of course, there is no test coverage - but I didn't want to make a deeper investment until I got some feedback.

@padrepitufo padrepitufo marked this pull request as draft May 17, 2024 23:05
@padrepitufo
Copy link
Author

fixed (but still a lot of tests pending your response @jpadilla )

@yossivainshtein
Copy link

I'm not active on the project, I'm only here to say that YES, i'd love to have this change,
This method (get_signing_key_from_jwt ) is blocking and should be async.

I was looking for this functionality today and found this PR, would love to see this included.

@Omar12e44
Copy link

xD

@github-actions github-actions bot added the stale Issues without activity for more than 60 days label Aug 3, 2024
@Dazix
Copy link

Dazix commented Aug 9, 2024

Any update on this?
@jpadilla

@github-actions github-actions bot removed the stale Issues without activity for more than 60 days label Aug 10, 2024
@github-actions github-actions bot added the stale Issues without activity for more than 60 days label Oct 9, 2024
@marcstreetergu
Copy link

I could really use this too, I think @padrepitufo would make changes if/when there was any traction on this PR from @jpadilla

@github-actions github-actions bot removed the stale Issues without activity for more than 60 days label Oct 12, 2024
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 this pull request may close these issues.

5 participants