Skip to content

M2M.authenticate_token() blocks event loop on JWKS fetch #312

Closed

Description

@vladislavkoz

Not 101% sure that this observation is correct, but please review 🙏 .

M2M.authenticate_token() lacks an async version and blocks the event loop when PyJWKClient fetches JWKS keys. The Sessions API correctly handles this with asyncio.to_thread(), but M2M does not.

The docstring for M2M.authenticate_token() states:
"Note: There is no async version of this since we make no network calls."

This blocks the async event loop, causing latency spikes in async applications.

M2M.authenticate_token() # stytch/consumer/api/m2m.py:111
→ jwt_helpers.authenticate_jwt_local() # stytch/shared/jwt_helpers.py:37
→ jwks_client.get_signing_key_from_jwt() # jwt/jwks_client.py:200
→ get_signing_key() # jwt/jwks_client.py:185
→ get_signing_keys() # jwt/jwks_client.py:160
→ get_jwk_set() # jwt/jwks_client.py:136
→ fetch_data() # jwt/jwks_client.py:107-111
→ urllib.request.urlopen() # ❌ BLOCKING

  • Stytch version: 15.0.0
  • Python version: 3.13

Activity

  1. changed the title [-]M2M.authenticate_token() to blocks event loop on JWKS fetch[/-] [+]M2M.authenticate_token() blocks event loop on JWKS fetch[/+] on Apr 23, 2026
  2. logan-stytch commented on Apr 23, 2026

    @logan-stytch
    Contributor

    Hey @vladislavkoz, you're totally right here. This was an oversight on our part. I've just put up #313 and once we land that, v15.1.0 should fix this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions