-
Notifications
You must be signed in to change notification settings - Fork 41
Description
Description
The Python SDK’s m2m.create_token() method does not currently expose a token_format parameter.
According to Clerk’s M2M token guide, M2M tokens can be created in two formats: opaque tokens (the default) and JWTs. The same guide also documents createToken({ tokenFormat: 'jwt' }) as the way to request a JWT-formatted token.
By contrast, the current Python SDK docs and generated source for m2m.create_token() only show support for seconds_until_expiration and claims, with no token_format parameter on either the sync or async method.
Steps to Reproduce
- Use the Python SDK’s M2M API.
- Call
m2m.create_token()orm2m.create_token_async(). - Try to request a JWT-format token.
Expected Behavior
create_token() should accept a token_format parameter with values such as "opaque" or "jwt", and pass that through to the POST /m2m_tokens request body.
Example:
token = sdk.m2m.create_token(
token_format="jwt",
seconds_until_expiration=1800,
)Actual Behavior
m2m.create_token() and m2m.create_token_async() currently only accept seconds_until_expiration and claims, so there does not appear to be a supported way to request a JWT-format M2M token from the Python SDK.
Workaround: call the REST API directly
resp = httpx.post(
"https://api.clerk.com/v1/m2m_tokens",
headers={"Authorization": f"Bearer {MACHINE_SECRET_KEY}"},
json={"token_format": "jwt", "claims": claims},
)
Reference
The JS SDK already exposes this as tokenFormat in createToken(), indicating the underlying POST /m2m_tokens endpoint supports this field, the Python SDK just doesn't pass it through.
https://clerk.com/docs/guides/development/machine-auth/m2m-tokens