Adds synchronous verify_sync() methods to AccessTokenVerifier and IDTokenVerifier#93
Open
BinoyOza-okta wants to merge 1 commit intomasterfrom
Open
Adds synchronous verify_sync() methods to AccessTokenVerifier and IDTokenVerifier#93BinoyOza-okta wants to merge 1 commit intomasterfrom
verify_sync() methods to AccessTokenVerifier and IDTokenVerifier#93BinoyOza-okta wants to merge 1 commit intomasterfrom
Conversation
Add sync counterparts to all async verification and JWK retrieval methods, enabling use in Django, Flask, and other non-async frameworks without requiring asyncio.run() or run_until_complete() wrappers. Changes: - Add verify_sync() to AccessTokenVerifier and IDTokenVerifier - Add verify_access_token_sync(), verify_id_token_sync(), get_jwk_sync(), get_jwks_sync() to BaseJWTVerifier - Add fire_request_sync(), get_sync() to RequestExecutor using the requests library with simple dict-based caching - Extract _verify_token_common() to eliminate duplicated parse/alg-check/claims-check logic across 4 verify methods - Fix get_jwks() silently swallowing exceptions on HTTP failure - Fix _get_jwk_by_kid() unnecessary temp variable - Add 5 unit tests covering all sync code paths - Clean up docstrings: fix typos, add RFC references, correct return types Fully backward compatible — no changes to existing public API. All 27 tests pass (22 existing + 5 new).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds synchronous
verify_sync()methods toAccessTokenVerifierandIDTokenVerifier, allowing non-async Python applications (Django, Flask, etc.) to verify Okta JWTs without needingasyncio.run()orrun_until_complete().Closes #42
Motivation
Okta customers with synchronous Python applications (e.g. Django) cannot easily use the existing async-only
verify()API. Wrapping withasyncio.run()orrun_until_complete()causes issues in applications not built around coroutines. This PR adds first-class sync support.Changes
New Public API (additive, non-breaking)
AccessTokenVerifierverify_sync()verify()IDTokenVerifierverify_sync()verify()Usage
Internal Changes
request_executor.pyfire_request_sync()— sync HTTP viarequestslibrary with simple dict cacheget_sync()— sync GET with retry and throttling (mirrorsget())clear_cache()— now clears both async and sync cachesjwt_verifier.py_verify_token_common()— extracted shared parse → alg check → claims check logic (eliminates duplication across 4 verify methods)verify_access_token_sync(),verify_id_token_sync()— sync verification onBaseJWTVerifierget_jwk_sync(),get_jwks_sync()— sync JWK retrieval with cache-clear retry for key rotationBug Fixes
get_jwks()exception handling: Previously swallowed exceptions silently, leavingjwksundefined → would raiseUnboundLocalError. Now re-raises after cleanup._get_jwk_by_kid(): Removed unnecessary temp variable, uses early return.Code Quality
"acess"→"access"str→dictfor JWK methodsBackward Compatibility
✅ Fully backward compatible. All existing public methods retain identical signatures and behavior. New methods are purely additive. All 22 existing unit tests pass unchanged alongside 5 new tests.
Testing
pytest tests/unit/ -v # 27 tests passNew tests:
test_get_jwk_synctest_get_jwks_synctest_access_token_verifier_synctest_id_token_verifier_synctest_invalid_claims_fail_first_sync