fix: Derive expected access token issuer from apiHostname - #85
Conversation
Make the issuer used to validate the access token `iss` claim
configurable via the new `issuer` option (WORKOS_ISSUER), defaulting to
https://${apiHostname} instead of a hardcoded https://api.workos.com.
Fixes #83
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
Original prompt from madison.packer
|
| // to jwtVerify here; doing so would reject every token. | ||
| const WORKOS_JWT_ISSUER = 'https://api.workos.com'; | ||
| function getExpectedIssuer(): string { | ||
| return getConfig('issuer') ?? `https://${getConfig('apiHostname')}`; |
There was a problem hiding this comment.
🟡 Custom API origins reject valid sessions
With apiHttps: false or apiPort set, getExpectedIssuer still uses HTTPS and omits the port. Valid tokens for that API origin fail verification, forcing repeated session refreshes.
Prompt for agents
Update src/session.ts getExpectedIssuer so its derived default reflects the complete configured API origin, including apiHttps and apiPort, while preserving an explicit issuer override. Add session tests covering HTTP and custom-port API configurations. Keep the default WorkOS configuration at https://api.workos.com.
Was this helpful? React with 👍 or 👎 to provide feedback.
Greptile SummaryThis PR makes access-token issuer verification follow the configured WorkOS environment instead of always requiring
Confidence Score: 5/5The PR appears safe to merge, with issuer configuration, precedence, tests, and documentation aligned. No actionable failure remains: explicit issuers resolve through the existing generic configuration system, the default preserves current production behavior, and the changed verification paths are covered by focused tests. Important Files Changed
|
Summary
Fixes #83.
verifyAccessTokenpinned the expectedissclaim to the literalhttps://api.workos.com, so any deployment with a non-defaultapiHostname(e.g.api.workos-test.com) failed verification on every request and silently fell into the refresh path inupdateSession— rotating the refresh token and emitting a newSet-Cookieon each loader run.The expected issuer is now configurable and defaults to the API host the JWKS URL already comes from:
New
AuthKitConfig.issuer?: stringoption (envWORKOS_ISSUER) for environments whose tokens carry a differentissthan the API host (the API can mintissfrom a custom auth domain, or with a/sso/<clientId>//convex/<clientId>path suffix), e.g.:Behavior with default config is unchanged (
https://api.workos.com).Test plan
session.spec.ts: default stayshttps://api.workos.com;WORKOS_API_HOSTNAME=api.workos-test.com→https://api.workos-test.com;WORKOS_ISSUERwins overapiHostname.npm test,npm run lint,npm run typecheck,npm run prettierpass locally.Link to Devin session: https://app.devin.ai/sessions/0ee38e859a9849658a7cdb2d215d89a6
Open in Devin Desktop: https://app.devin.ai/desktop/session/0ee38e859a9849658a7cdb2d215d89a6?variant=devin
Requested by: @m0tzy