okta-jwt-verifier-python icon indicating copy to clipboard operation
okta-jwt-verifier-python copied to clipboard

Feature request: Support for synchronous applications

Open jshields opened this issue 2 years ago • 2 comments

Feature request to add new method verify_sync or verify_blocking to AccessTokenVerifier and IDTokenVerifier that will have the same behavior as verify but not be async. I see the README has some instructions on how to make sync calls but does not address how to get the JWK synchronously.

We are an Okta customer with a synchronous Python application written in Django. The async implementation for AccessTokenVerifier.verify and IDTokenVerifier.verify is causing issues for us. Our application is not written with coroutines and due to other implementation issues, we don't want to use run_until_complete. We can't rewrite our entire application to be async at this time.

This change would involve a lot of duplicated code to make async methods sync / blocking, but it would allow support for Python code that doesn't use coroutines.

jshields avatar Jul 06 '22 17:07 jshields

Is there any update on this?

dee-corr avatar May 23 '24 18:05 dee-corr

Workaround, making sure to use a new loop if there could already be a running event loop for the Python process:

loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
loop.run_until_complete(jwt_verifier.verify(token))
loop.close()

It would still be better if the code looked like this for example:

jwt_verifier.verify_synchronous(token)

jshields avatar Aug 27 '24 21:08 jshields