auth0 / auth0-python

Auth0 SDK for Python
https://auth0-python.readthedocs.io
MIT License
499 stars 161 forks source link

Async All the Way #621

Open padrepitufo opened 2 months ago

padrepitufo commented 2 months ago

Changes

I am probably using this wrong and need guidance.

I want to use auth0-python asynchronously. My set up is close to this tutorial. I noticed it depends on PyJWT and I realized the library blocks. I have made an accompanying PR (that this PR points to) but I doubt I'm the first one to use this - I'm probably just using it wrong.

Main change in usage would be (using the tutorial example as my sample):

try:
    signing_key = self.jwks_client.get_signing_key_from_jwt(  # šŸ‘ˆ this lines changes
        token.credentials
    ).key
except jwt.exceptions.PyJWKClientError as error:
    raise UnauthorizedException(str(error))
except jwt.exceptions.DecodeError as error:
    raise UnauthorizedException(str(error))

becomes

try:
    payload  = await self.jwks_client.get_signing_key_from_jwt(  # šŸ‘ˆ this lines changes
        token.credentials
    )
    signing_key = payload.key
except jwt.exceptions.PyJWKClientError as error:
    raise UnauthorizedException(str(error))
except jwt.exceptions.DecodeError as error:
    raise UnauthorizedException(str(error))

References

... None

Testing

Please describe how this can be tested by reviewers. Be specific about anything not tested and reasons why. If this library has unit and/or integration testing, tests should be added for new functionality and existing tests should complete without errors.

Checklist

padrepitufo commented 1 month ago

Any guidance that @evansims @jpadilla @adamjmcgrath could lend would be much appreciated