-
Notifications
You must be signed in to change notification settings - Fork 44
[v8] feat: add PKCE support for public clients; remove /client entry point #1435
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
Changes from 23 commits
fdf5908
4ea2ecc
acb9423
c7b3a19
7874e81
83f0c42
d1c579f
8e83244
448cdf9
ef1864b
c285a04
6419257
366a0e0
2087dbe
8fb0777
fb5e08b
d3e2f2f
9a757fb
a6ede43
8d3f693
8b9c16b
085a43d
753502e
6f16863
a3e370d
391feb4
c801272
436ec82
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -37,6 +37,54 @@ import { WorkOS } from '@workos-inc/node'; | |
| const workos = new WorkOS('sk_1234'); | ||
| ``` | ||
|
|
||
| ## Public Client Mode (Browser/Mobile/CLI) | ||
|
|
||
| For apps that can't securely store secrets, initialize with just a client ID: | ||
|
|
||
| ```ts | ||
| import { WorkOS } from '@workos-inc/node'; | ||
|
|
||
| const workos = new WorkOS({ clientId: 'client_...' }); // No API key needed | ||
|
|
||
| // Generate auth URL with automatic PKCE | ||
| const { url, codeVerifier } = await workos.userManagement.getAuthorizationUrlWithPKCE({ | ||
| provider: 'authkit', | ||
| redirectUri: 'myapp://callback', | ||
| clientId: 'client_...', | ||
| }); | ||
|
|
||
| // After user authenticates, exchange code for tokens | ||
| const { accessToken, refreshToken } = await workos.userManagement.authenticateWithCode({ | ||
| code: authorizationCode, | ||
| codeVerifier, | ||
| clientId: 'client_...', | ||
| }); | ||
| ``` | ||
|
|
||
| See the [AuthKit documentation](https://workos.com/docs/authkit) for details on PKCE authentication. | ||
|
|
||
| ### PKCE with Confidential Clients | ||
|
|
||
| Server-side apps can also use PKCE alongside the client secret for defense in depth (recommended by OAuth 2.1): | ||
|
|
||
| ```ts | ||
| const workos = new WorkOS('sk_...'); // With API key | ||
|
|
||
| // Use PKCE even with API key for additional security | ||
| const { url, codeVerifier } = await workos.userManagement.getAuthorizationUrlWithPKCE({ | ||
| provider: 'authkit', | ||
| redirectUri: 'https://example.com/callback', | ||
| clientId: 'client_...', | ||
|
||
| }); | ||
|
|
||
| // Both client_secret AND code_verifier will be sent | ||
| const { accessToken } = await workos.userManagement.authenticateWithCode({ | ||
| code: authorizationCode, | ||
| codeVerifier, | ||
| clientId: 'client_...', | ||
| }); | ||
| ``` | ||
|
|
||
| ## SDK Versioning | ||
|
|
||
| For our SDKs WorkOS follows a Semantic Versioning ([SemVer](https://semver.org/)) process where all releases will have a version X.Y.Z (like 1.0.0) pattern wherein Z would be a bug fix (e.g., 1.0.1), Y would be a minor release (1.1.0) and X would be a major release (2.0.0). We permit any breaking changes to only be released in major versions and strongly recommend reading changelogs before making any major version upgrades. | ||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
This file was deleted.
This file was deleted.
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we mention that the codeVerifier should be stored on-device (cookie, phone storage, etc.) for later? (it's somewhat clear since you need it for the authenticateWithCode call, but maybe not obvious to someone who has never done this before?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added the following to the README:
Important
Store
codeVerifiersecurely on-device between generating the auth URL and handling the callback. For mobile apps, use platform secure storage (iOS Keychain, Android Keystore). For CLI apps, consider OS credential storage. The verifier must survive app restarts during the auth flow.