Skip to content

feat: add get_jwks_url helper to UserManagement#644

Merged
gjtorikian merged 1 commit intomainfrom
feat/get-jwks-url
May 1, 2026
Merged

feat: add get_jwks_url helper to UserManagement#644
gjtorikian merged 1 commit intomainfrom
feat/get-jwks-url

Conversation

@gjtorikian
Copy link
Copy Markdown
Contributor

@gjtorikian gjtorikian commented May 1, 2026

Summary

Adds user_management.get_jwks_url(client_id=None) to both sync and async clients — a small helper that constructs the JWKS URL for a given client.

Why

v6 exposed user_management.get_jwks_url(), which customers used to integrate with JWT libraries that take a URL and handle fetching/caching themselves (e.g. PyJWT's PyJWKClient(url)). v7's generated get_jwks(client_id) returns the JWKS document, not the URL — so customers integrating with URL-based JWT libraries have been hand-constructing the URL with f"{client.base_url}sso/jwks/{client_id}", duplicating what session.py does internally.

Implementation

  • Adds get_jwks_url to UserManagement and AsyncUserManagement inside the existing @oagen-ignore-start / @oagen-ignore-end fences in src/workos/user_management/_resource.py. Verified the methods survive npm run sdk:generate -- --lang python.
  • Parameter is Optional[str] with fallback to the client's configured client_id via _require_client_id() — matches v6 ergonomics where the method took no arguments.
  • URL construction mirrors session.py:195 / session.py:373 exactly.

Test plan

  • uv run pytest tests/test_inline_helpers.py -k "JwksUrl" — 5 new tests pass (default lookup, explicit override, ConfigurationError when no client_id; sync + async)
  • uv run pytest tests/test_inline_helpers.py tests/test_user_management.py tests/test_session.py — 184 tests pass
  • uv run ruff format --check and uv run ruff check — clean
  • uv run pyright — 0 errors
  • Verified get_jwks_url survives a full npm run sdk:generate run

🤖 Generated with Claude Code


Open in Devin Review

v6 exposed `user_management.get_jwks_url()` as a small helper for
constructing the JWKS URL — useful when integrating with JWT libraries
(e.g. `PyJWKClient`) that fetch and cache the JWKS themselves given a
URL. The v7 generator emits `get_jwks()` which fetches the JWKS document,
but no equivalent URL builder, so users had to hand-construct the URL.

Adds `get_jwks_url(client_id=None)` to both `UserManagement` and
`AsyncUserManagement` inside the existing `@oagen-ignore` fences. The
parameter is optional and falls back to the client's configured
`client_id`, matching v6 ergonomics. URL construction mirrors the
internal `session.py` pattern exactly.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@gjtorikian gjtorikian requested review from a team as code owners May 1, 2026 16:03
@gjtorikian gjtorikian requested a review from nicknisi May 1, 2026 16:03
Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 1 additional finding.

Open in Devin Review

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented May 1, 2026

Greptile Summary

Adds a get_jwks_url(client_id=None) helper to both UserManagement and AsyncUserManagement, restoring the v6 ergonomic that customers were hand-rolling with f"{client.base_url}sso/jwks/{client_id}". The URL construction and client_id fallback via _require_client_id() are consistent with session.py and sso/_resource.py.

Confidence Score: 5/5

Safe to merge; the change is small, correct, and follows established codebase patterns.

Implementation mirrors the existing URL-construction pattern from session.py and the client_id fallback pattern from sso/_resource.py exactly. The only gap is a missing ConfigurationError test for the async class (P2), which does not affect correctness.

No files require special attention.

Important Files Changed

Filename Overview
src/workos/user_management/_resource.py Adds get_jwks_url to both UserManagement and AsyncUserManagement inside @oagen-ignore fences; URL construction mirrors session.py and client_id fallback matches the pattern used in sso/_resource.py.
tests/test_inline_helpers.py Adds 5 tests covering default client_id, explicit override, and ConfigurationError for the sync path; the async class is missing the test_raises_when_no_client_id_configured equivalent.

Sequence Diagram

sequenceDiagram
    participant Caller
    participant UserManagement
    participant BaseClient

    Caller->>UserManagement: get_jwks_url(client_id=None)
    alt client_id provided
        UserManagement->>UserManagement: use provided client_id
    else no client_id
        UserManagement->>BaseClient: _require_client_id()
        BaseClient-->>UserManagement: configured client_id (or raises ConfigurationError)
    end
    UserManagement-->>Caller: f"{base_url}sso/jwks/{resolved_client_id}"
Loading

Reviews (1): Last reviewed commit: "feat: add get_jwks_url helper to UserMan..." | Re-trigger Greptile

Comment on lines +298 to +305
class TestAsyncGetJwksUrl:
async def test_uses_configured_client_id(self, async_workos):
url = async_workos.user_management.get_jwks_url()
assert url == "https://api.workos.com/sso/jwks/client_test"

async def test_explicit_client_id_overrides_default(self, async_workos):
url = async_workos.user_management.get_jwks_url("client_other")
assert url == "https://api.workos.com/sso/jwks/client_other"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Missing ConfigurationError test for async path

The sync TestGetJwksUrl has test_raises_when_no_client_id_configured but TestAsyncGetJwksUrl does not. Since both implementations are identical, parity is worth adding to confirm the error path works through async_workos as well.

@gjtorikian gjtorikian changed the title feat: add get_jwks_url helper to UserManagement feat: add get_jwks_url helper to UserManagement May 1, 2026
@gjtorikian gjtorikian merged commit 53134d3 into main May 1, 2026
13 checks passed
@gjtorikian gjtorikian deleted the feat/get-jwks-url branch May 1, 2026 17:29
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