Skip to content

create_token() missing token_format parameter for JWT-format M2M tokens #217

@paul-ellis

Description

@paul-ellis

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

  1. Use the Python SDK’s M2M API.
  2. Call m2m.create_token() or m2m.create_token_async().
  3. 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

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