Skip to content

Add Support for a JWT Leeway Parameter #430

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Conversation

Th3R3p0
Copy link

@Th3R3p0 Th3R3p0 commented Apr 12, 2025

Description

This PR adds support for configuring a JWT leeway parameter that helps address token validation timing issues. When authenticating with WorkOS, occasional errors like "The token is not yet valid (iat)" can occur due to clock skew between servers. The leeway parameter creates a time buffer around token validation, allowing slightly expired or not-yet-valid tokens to be accepted.

The implementation adds a jwt_leeway parameter (default: 0) to the client configuration that's passed through to the JWT validation operations. Users can now specify a custom leeway value when creating a WorkOS client, and the setting will be consistently applied to all token operations. This change is fully backward compatible and includes tests to verify the leeway functionality works as expected with both slightly and significantly expired tokens.

Documentation

Does this require changes to the WorkOS Docs? E.g. the API Reference or code snippets need updates.

[x] Yes

If yes, link a related docs PR and add a docs maintainer as a reviewer. Their approval is required.

Usage

You can now specify the jwt_leeway param on the WorkOSClient. It will default to 0 if it is not specified.

workos = WorkOSClient(
    api_key="", 
    client_id="", 
    jwt_leeway=30
)

@Th3R3p0 Th3R3p0 requested a review from a team as a code owner April 12, 2025 21:48
@Th3R3p0 Th3R3p0 requested a review from alisherry April 12, 2025 21:48
@nicknisi
Copy link
Contributor

@Th3R3p0 IMO the code looks good and this looks like a worthwhile feature to add, thank you! It looks like CI is failing on formatting. Would you mind running the following and pushing up the fixes?

pipx run black .

Thanks!

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

Successfully merging this pull request may close these issues.

2 participants