Repository navigation
Conversation
…stead of an API key Add a workloadIdentity client option. The SDK exchanges the platform's ID token for a short-lived WorkOS API access token (RFC 7523 jwt-bearer, no client secret), keeps it in memory, and exchanges again shortly before expiry and once on a 401. Concurrent requests share one exchange, and x-url-environment-id is sent when an environment ID is configured. Exchange failures surface as OauthException with the endpoint's error code and description. Neither token appears in errors or logs. The exchange uses fetch only, so the worker entry supports it too.
[High impact] The PR appears safe to merge; both previously reported failures are fixed. SummaryAdds
Both previous findings are fixed. No new actionable issues were found in the changes since the previous review.
|
…t methods and bound the token source Methods that send the API key as client_secret (authenticateWithPassword and the other non-PKCE authenticate methods) passed the API key check when only a workload identity was configured, so they exchanged a token and sent it to the authenticate endpoint. They now throw ApiKeyRequiredException as they do for a public client. The exchange timeout now covers tokenSource() too. A token source that never settles used to hold every later request on the shared in-flight exchange.
gjtorikian
left a comment
There was a problem hiding this comment.
This approach is a little different than the one I launched: https://github.com/workos/workos-node/commits/feat/workload-identity/
Ultimately I'm not precious about which change gets merged in. I am going to mark this review as blocking, though, because I think we should test it in prod against GCP/AWS/GHA before merging it into a release branch, and I don't want someone to accidentally do so.
|
Closing this in favour of I ran it against the server stack (workos/workos#79789 to workos/workos#79802) to check that they fit:
Two notes from the server side:
|
Description
Adds a
workloadIdentityclient option, so a workload that already has an identity from its platform (a GitHub Actions job, a GCP or AWS service account) can call the WorkOS API without an API key.jwt-bearer, no client secret), keeps it in memory, and exchanges again shortly before expiry and once after a 401. Concurrent requests share one exchange.environmentIdandscopeare optional.x-url-environment-idis sent when an environment ID is set.WORKOS_API_KEYis not read when it is set.client_secret(authenticateWithPasswordand the other non-PKCE authenticate methods) still throwApiKeyRequiredExceptionwithout an API key. The PKCE flows work as in public client mode and do not carry the workload token.tokenSource().OauthExceptionwith the endpoint'serroranderror_description. Neither token appears in errors or logs.fetchonly, so the worker entry supports it.The server side is in review as a stack starting at workos/workos#79789, so nothing can use this yet.
Open for discussion, not settled:
clientId), and whether this belongs in the core client or a separate package.createWorkOStypes a workload-identity-only client as a public client. Usenew WorkOS(...)for the full type.Checked: 35 new unit tests against a mocked token endpoint, the full suite (1,342 tests), typecheck, lint and prettier. Not checked: an exchange against a real token endpoint, and
npm run build.Documentation
Does this require changes to the WorkOS Docs? E.g. the API Reference or code snippets need updates.
No docs PR yet. Docs wait on the server side merging.