WorkOS Knowledge Patch
Use this skill when implementing, upgrading, or reviewing a WorkOS integration.
Start with migration hazards, then load only the references relevant to the SDK,
framework, and WorkOS products in use.
Reference index
| Reference |
Topics |
| node-sdk-migrations.md |
Node runtime and v9/v10 migrations, events, errors, pagination, webhooks, Vault, Radar, Connect, Agents, retries |
| authkit-nextjs.md |
App Router, callbacks, cookies, proxy or middleware, response headers, caching, sessions, access tokens, PKCE |
| authkit-react.md |
Browser provider setup, redirects, auth state, organization switching, refresh hooks, token helpers |
| api-and-sdk-contracts.md |
Public-client PKCE, Python async client, Go v6 packages, OpenAPI contract |
| authentication-and-sessions.md |
Identity data, AuthKit customization, applications, sessions, invitations, email lifecycle, OAuth, Radar |
| authorization-and-features.md |
Roles, authorization resources, group assignments, permissions, multi-role provisioning, Feature Flags |
| sso-directory-and-widgets.md |
SSO lifecycle and providers, Directory Sync, identity-provider attributes, domains, embedded widgets |
| platform-products.md |
Connect, MCP, CLI, Pipes, Vault BYOK, Audit Logs, API keys, email delivery, analytics, Stripe |
Triage the integration
- Identify the SDK language and version, framework version, and WorkOS products.
- Apply breaking migrations before adding features.
- Load the topic references that match the integration surface.
- Preserve raw payloads, OAuth security state, and internal response headers as
required by the framework.
- Verify dashboard-side settings: redirect and logout URIs, allowed origins,
domains, providers, sign-in endpoints, cookie sharing, and OAuth scopes.
Breaking changes and deprecations
Migrate Node SDK v9
- Run Node.js 22.11 or newer; v9 no longer supports Node.js 20.
- Replace the removed legacy FGA package with authorization resources and role
APIs. FGA was deprecated in v8.4 and removed in v9.
- Rename client access from
portal to adminPortal.
- Keep the established Authorization method names. v9.1.1 reverted generated
renames and fixed the endpoint for
listEffectivePermissionsByExternalId.
Migrate Node SDK v10
- Treat
Group.createdAt and Group.updatedAt as Date, not strings.
- Construct webhooks from the WorkOS client:
new Webhooks(workos).
- Remove
search from listResources calls.
- Consume
vault.listObjects as an auto-paginatable collection of object
summaries; generated key and object response fields are camel-cased.
Update event handling
- Handle API-key deletion as
api_key.revoked, not api_key.deleted.
- Accept typed events for organization roles and permissions, feature flags,
Vault, groups, and domain-verification failures.
- Handle
vault.byok_key.verification_completed.
- Read
resourceTypeSlug from deserialized organization-role events.
Enforce AuthKit Next.js v3 state checks
- Remove
WORKOS_ENABLE_PKCE; PKCE and sealed OAuth state are always enabled.
- Preserve the short-lived
wos-auth-verifier cookie through the callback.
- Treat a missing verifier as
Auth cookie missing and a mismatch as
OAuth state mismatch; do not restore the removed URL-state-only fallback.
Select the Next.js request hook
- For Next.js 16 or newer, define root-level
proxy.ts with authkitProxy.
- For earlier Next.js versions, define
middleware.ts with authkitMiddleware.
- Exclude
/_next/static, /_next/image, and favicon.ico from broad matchers.
Recent Node SDK contracts
For SDK changes identified by batch 10.10.0:
- Action contexts expose the authentication method.
- Agents can link a claim attempt to an external user, read agent
registrations, and validate credentials; API-key validation returns the agent
registration ID.
- User API-key methods are available, and
ApiKey.owner includes a user variant
and organizationId.
CookieSession.refresh() distinguishes retryable transient failures from
terminal failures.
- Listed
AuthenticationFactor values may omit totp.
- The HTTP client supports configurable automatic retries.
- Pipes supports API-key installation and Data Integration operations and models.
- DELETE calls preserve query parameters supplied through
{ query: ... }.
AuthKit Next.js quick reference
Configure the App Router flow
Provide a client ID, API key, public redirect URI, and session-cookie password
of at least 32 characters. Create the callback as an App Router route handler:
// app/callback/route.ts
import { handleAuth } from '@workos-inc/authkit-nextjs';
export const GET = handleAuth({ returnPathname: '/dashboard' });
Set a default Logout URI in the WorkOS dashboard before relying on sign-out.
Use baseURL when an internal request host differs from the public host.
Preserve proxy response semantics
For custom proxy logic, call authkit(request) and pass every response through
handleAuthkitHeaders(request, headers, options). For rewrites, use
partitionAuthkitHeaders and applyResponseHeaders. Never expose or forward
injected x-workos-* request values.
Enable route protection with middlewareAuth.enabled; put public routes in
unauthenticatedPaths, and use signUpPaths for protected routes that should
show the sign-up screen.
Read and refresh authentication
- Use
withAuth() in server components.
- Import
AuthKitProvider and useAuth from
@workos-inc/authkit-nextjs/components in client components.
- Pass
ensureSignedIn: true where authentication is mandatory.
- Remove the access token from server
initialAuth before passing it to the
provider.
- Use
refreshSession on the server and
refreshAuth({ organizationId }) on the client.
- Use
useAccessToken for expiry-aware access, manual refresh, and refresh state.
Use eagerAuth: true only when the initial client render needs an access token.
It transfers the token in a 30-second initial-page-load-only cookie that client
JavaScript consumes and deletes, so maintain normal XSS defenses.
AuthKit React quick reference
Configure AuthKitProvider with the public client ID, dashboard redirect URI,
and allowed application origin. In production, set apiHostname to an owned
Authentication API domain. Treat devMode as local-development token storage;
it is automatic only on localhost and 127.0.0.1.
Use useAuth() for user and organization state, roles, permissions, feature
flags, impersonator, authentication method, token access, and organization
switching. Catch LoginRequiredError when getAccessToken() is called while
signed out.
Public-client PKCE quick reference
Construct the Node client with only a client ID for browser, mobile, or CLI
applications. Generate the URL and verifier together, retain the verifier in
secure platform storage across restarts, and submit it during code exchange:
const workos = new WorkOS({ clientId: 'client_...' });
const { url, codeVerifier } =
await workos.userManagement.getAuthorizationUrlWithPKCE({
provider: 'authkit',
redirectUri: 'myapp://callback',
clientId: 'client_...',
});
const tokens = await workos.userManagement.authenticateWithCode({
code: authorizationCode,
codeVerifier,
clientId: 'client_...',
});
Confidential clients may use the same flow with an API key; exchange then sends
both the client secret and verifier.
Authorization quick reference
- Model scoped access with authorization resources and resource-scoped custom
roles. Supply
resource_type_slug when creating an organization role.
- Pass
role_slug on invitations.
- Filter assignment lists with
resource and role_slug.
- Inspect assignment
source to distinguish direct grants from group grants.
- Expect memberships to hold multiple roles provisioned by AuthKit, SSO, or
Directory Sync.
- Use the Feature Flags runtime client for local evaluation when a network
request per evaluation is undesirable.
Webhook and data-integrity checklist
- Verify signatures against raw request bytes; do not decode, normalize, or
reserialize the payload first.
- Preserve SSO context on authentication events.
- Preserve
verification_prefix on organization domains.
- Expect server and authentication errors to retain typed data.
- Use exported
ConflictException.code and the complete
isAuthenticationErrorData guard.
- Treat the normalized identity-provider value as
GitHubOAuth, not
GithubOAuth.
Product selection quick reference
- Use AuthKit for hosted user authentication, including MCP authorization.
- Use Standalone OAuth for a server that retains its existing authentication.
- Use Connect for delegated application authorization and organization choice.
- Use Pipes for end-user third-party connections or a deployable MCP server with
time-limited connection access.
- Use Radar for signup risk controls and SMS challenges.
- Use Vault BYOK with AWS KMS or Azure Key Vault for customer-managed keys.
Final verification
Before shipping, verify runtime compatibility, dashboard configuration,
callback cookies and state, redirect behavior, session refresh, raw-body webhook
verification, pagination shapes, retry behavior, and exact event names.
1---2name: workos-knowledge-patch-23description: WorkOS4license: MIT5---678# WorkOS Knowledge Patch910Use this skill when implementing, upgrading, or reviewing a WorkOS integration.11Start with migration hazards, then load only the references relevant to the SDK,12framework, and WorkOS products in use.1314## Reference index1516| Reference | Topics |17| --- | --- |18| [node-sdk-migrations.md](references/node-sdk-migrations.md) | Node runtime and v9/v10 migrations, events, errors, pagination, webhooks, Vault, Radar, Connect, Agents, retries |19| [authkit-nextjs.md](references/authkit-nextjs.md) | App Router, callbacks, cookies, proxy or middleware, response headers, caching, sessions, access tokens, PKCE |20| [authkit-react.md](references/authkit-react.md) | Browser provider setup, redirects, auth state, organization switching, refresh hooks, token helpers |21| [api-and-sdk-contracts.md](references/api-and-sdk-contracts.md) | Public-client PKCE, Python async client, Go v6 packages, OpenAPI contract |22| [authentication-and-sessions.md](references/authentication-and-sessions.md) | Identity data, AuthKit customization, applications, sessions, invitations, email lifecycle, OAuth, Radar |23| [authorization-and-features.md](references/authorization-and-features.md) | Roles, authorization resources, group assignments, permissions, multi-role provisioning, Feature Flags |24| [sso-directory-and-widgets.md](references/sso-directory-and-widgets.md) | SSO lifecycle and providers, Directory Sync, identity-provider attributes, domains, embedded widgets |25| [platform-products.md](references/platform-products.md) | Connect, MCP, CLI, Pipes, Vault BYOK, Audit Logs, API keys, email delivery, analytics, Stripe |2627## Triage the integration28291. Identify the SDK language and version, framework version, and WorkOS products.302. Apply breaking migrations before adding features.313. Load the topic references that match the integration surface.324. Preserve raw payloads, OAuth security state, and internal response headers as33 required by the framework.345. Verify dashboard-side settings: redirect and logout URIs, allowed origins,35 domains, providers, sign-in endpoints, cookie sharing, and OAuth scopes.3637## Breaking changes and deprecations3839### Migrate Node SDK v94041- Run Node.js 22.11 or newer; v9 no longer supports Node.js 20.42- Replace the removed legacy FGA package with authorization resources and role43 APIs. FGA was deprecated in v8.4 and removed in v9.44- Rename client access from `portal` to `adminPortal`.45- Keep the established Authorization method names. v9.1.1 reverted generated46 renames and fixed the endpoint for `listEffectivePermissionsByExternalId`.4748### Migrate Node SDK v104950- Treat `Group.createdAt` and `Group.updatedAt` as `Date`, not strings.51- Construct webhooks from the WorkOS client: `new Webhooks(workos)`.52- Remove `search` from `listResources` calls.53- Consume `vault.listObjects` as an auto-paginatable collection of object54 summaries; generated key and object response fields are camel-cased.5556### Update event handling5758- Handle API-key deletion as `api_key.revoked`, not `api_key.deleted`.59- Accept typed events for organization roles and permissions, feature flags,60 Vault, groups, and domain-verification failures.61- Handle `vault.byok_key.verification_completed`.62- Read `resourceTypeSlug` from deserialized organization-role events.6364### Enforce AuthKit Next.js v3 state checks6566- Remove `WORKOS_ENABLE_PKCE`; PKCE and sealed OAuth state are always enabled.67- Preserve the short-lived `wos-auth-verifier` cookie through the callback.68- Treat a missing verifier as `Auth cookie missing` and a mismatch as69 `OAuth state mismatch`; do not restore the removed URL-state-only fallback.7071### Select the Next.js request hook7273- For Next.js 16 or newer, define root-level `proxy.ts` with `authkitProxy`.74- For earlier Next.js versions, define `middleware.ts` with `authkitMiddleware`.75- Exclude `/_next/static`, `/_next/image`, and `favicon.ico` from broad matchers.7677## Recent Node SDK contracts7879For SDK changes identified by batch `10.10.0`:8081- Action contexts expose the authentication method.82- Agents can link a claim attempt to an external user, read agent83 registrations, and validate credentials; API-key validation returns the agent84 registration ID.85- User API-key methods are available, and `ApiKey.owner` includes a user variant86 and `organizationId`.87- `CookieSession.refresh()` distinguishes retryable transient failures from88 terminal failures.89- Listed `AuthenticationFactor` values may omit `totp`.90- The HTTP client supports configurable automatic retries.91- Pipes supports API-key installation and Data Integration operations and models.92- DELETE calls preserve query parameters supplied through `{ query: ... }`.9394## AuthKit Next.js quick reference9596### Configure the App Router flow9798Provide a client ID, API key, public redirect URI, and session-cookie password99of at least 32 characters. Create the callback as an App Router route handler:100101```ts102// app/callback/route.ts103import { handleAuth } from '@workos-inc/authkit-nextjs';104105export const GET = handleAuth({ returnPathname: '/dashboard' });106```107108Set a default Logout URI in the WorkOS dashboard before relying on sign-out.109Use `baseURL` when an internal request host differs from the public host.110111### Preserve proxy response semantics112113For custom proxy logic, call `authkit(request)` and pass every response through114`handleAuthkitHeaders(request, headers, options)`. For rewrites, use115`partitionAuthkitHeaders` and `applyResponseHeaders`. Never expose or forward116injected `x-workos-*` request values.117118Enable route protection with `middlewareAuth.enabled`; put public routes in119`unauthenticatedPaths`, and use `signUpPaths` for protected routes that should120show the sign-up screen.121122### Read and refresh authentication123124- Use `withAuth()` in server components.125- Import `AuthKitProvider` and `useAuth` from126 `@workos-inc/authkit-nextjs/components` in client components.127- Pass `ensureSignedIn: true` where authentication is mandatory.128- Remove the access token from server `initialAuth` before passing it to the129 provider.130- Use `refreshSession` on the server and131 `refreshAuth({ organizationId })` on the client.132- Use `useAccessToken` for expiry-aware access, manual refresh, and refresh state.133134Use `eagerAuth: true` only when the initial client render needs an access token.135It transfers the token in a 30-second initial-page-load-only cookie that client136JavaScript consumes and deletes, so maintain normal XSS defenses.137138## AuthKit React quick reference139140Configure `AuthKitProvider` with the public client ID, dashboard redirect URI,141and allowed application origin. In production, set `apiHostname` to an owned142Authentication API domain. Treat `devMode` as local-development token storage;143it is automatic only on `localhost` and `127.0.0.1`.144145Use `useAuth()` for user and organization state, roles, permissions, feature146flags, impersonator, authentication method, token access, and organization147switching. Catch `LoginRequiredError` when `getAccessToken()` is called while148signed out.149150## Public-client PKCE quick reference151152Construct the Node client with only a client ID for browser, mobile, or CLI153applications. Generate the URL and verifier together, retain the verifier in154secure platform storage across restarts, and submit it during code exchange:155156```ts157const workos = new WorkOS({ clientId: 'client_...' });158const { url, codeVerifier } =159 await workos.userManagement.getAuthorizationUrlWithPKCE({160 provider: 'authkit',161 redirectUri: 'myapp://callback',162 clientId: 'client_...',163 });164165const tokens = await workos.userManagement.authenticateWithCode({166 code: authorizationCode,167 codeVerifier,168 clientId: 'client_...',169});170```171172Confidential clients may use the same flow with an API key; exchange then sends173both the client secret and verifier.174175## Authorization quick reference176177- Model scoped access with authorization resources and resource-scoped custom178 roles. Supply `resource_type_slug` when creating an organization role.179- Pass `role_slug` on invitations.180- Filter assignment lists with `resource` and `role_slug`.181- Inspect assignment `source` to distinguish direct grants from group grants.182- Expect memberships to hold multiple roles provisioned by AuthKit, SSO, or183 Directory Sync.184- Use the Feature Flags runtime client for local evaluation when a network185 request per evaluation is undesirable.186187## Webhook and data-integrity checklist188189- Verify signatures against raw request bytes; do not decode, normalize, or190 reserialize the payload first.191- Preserve SSO context on authentication events.192- Preserve `verification_prefix` on organization domains.193- Expect server and authentication errors to retain typed data.194- Use exported `ConflictException.code` and the complete195 `isAuthenticationErrorData` guard.196- Treat the normalized identity-provider value as `GitHubOAuth`, not197 `GithubOAuth`.198199## Product selection quick reference200201- Use AuthKit for hosted user authentication, including MCP authorization.202- Use Standalone OAuth for a server that retains its existing authentication.203- Use Connect for delegated application authorization and organization choice.204- Use Pipes for end-user third-party connections or a deployable MCP server with205 time-limited connection access.206- Use Radar for signup risk controls and SMS challenges.207- Use Vault BYOK with AWS KMS or Azure Key Vault for customer-managed keys.208209## Final verification210211Before shipping, verify runtime compatibility, dashboard configuration,212callback cookies and state, redirect behavior, session refresh, raw-body webhook213verification, pagination shapes, retry behavior, and exact event names.