-
Notifications
You must be signed in to change notification settings - Fork 439
feat(backend,nextjs): Add support for M2M JWT creation and verification #7883
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
Merged
Merged
Changes from all commits
Commits
Show all changes
38 commits
Select commit
Hold shift + click to select a range
d282239
feat(backend): Add M2M JWT token verification support
wobsoriano bdf4613
add changeset
wobsoriano 32c1a7a
Merge branch 'release/core-2' into rob/USER-4704-m2m-jwts
wobsoriano 450ffdc
feat(backend): Add tokenFormat parameter to M2M token creation API
wobsoriano a7ff348
chore: update changeset
wobsoriano a85cd5e
test(backend): Update M2M JWT test tokens to match production format
wobsoriano 98b4733
Delete .changeset/cyan-wings-turn.md
wobsoriano b833f2b
chore: add default value to tokenFormat
wobsoriano 848e5d5
Merge branch 'release/core-2' into rob/USER-4704-m2m-jwts
wobsoriano 9740d2c
chore: improve jwt routing, prevent double decoding
wobsoriano c6d8547
Merge branch 'release/core-2' into rob/USER-4704-m2m-jwts
wobsoriano c92fe90
Merge branch 'release/core-2' into rob/USER-4704-m2m-jwts
wobsoriano 858a501
chore: clean up
wobsoriano 2f27712
refactor(backend): extract verifyDecodedJwtMachineToken to shared jwt…
wobsoriano 86383d4
feat(backend): support JWT format in m2m.verify()
wobsoriano ce5bcbe
test(integration): use m2m.verify() for JWT format M2M test
wobsoriano dbec863
fix(backend): restore createToken behavior and update internal export…
wobsoriano 6e96d46
chore: clean up verification functions
wobsoriano 5dff71b
delete unused file
wobsoriano 5fe771f
fix unit test
wobsoriano c00bec4
chore: clean up lint issues
wobsoriano 3aeafdb
Merge branch 'release/core-2' into rob/USER-4704-m2m-jwts
wobsoriano 7416624
fix: add missing jwtKey
wobsoriano 6363564
fix: use correct subject in integration
wobsoriano 3c8e1e3
chore: extend ClerkError
wobsoriano b5dacac
chore: use correct M2M ids
wobsoriano 1615d5b
fix: build error
wobsoriano 81c1a28
chore: update changeset
wobsoriano 3e6bef2
chore: unit test scopes
wobsoriano ca124f6
chore: fix nextjs jwt locking for machine auth
wobsoriano 3d8b68e
chore: add more tests
wobsoriano 2f01baf
chore: apply coderabbit suggestions
wobsoriano f884e95
chore: fix protect machine auth handling
wobsoriano 866d47b
fix e2e test
wobsoriano da9e999
chore: update changeset
wobsoriano f0522f3
Merge branch 'release/core-2' into rob/USER-4704-m2m-jwts
wobsoriano 38d60fe
chore: fix merge conflicts
wobsoriano 7888d87
fix tests
wobsoriano File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| --- | ||
| "@clerk/backend": minor | ||
| "@clerk/nextjs": minor | ||
| --- | ||
|
|
||
| Added support for JWT token format when creating and verifying machine-to-machine (M2M) tokens. This enables fully **networkless verification** when using the public JWT key. | ||
|
|
||
| **Creating a JWT-format M2M token** | ||
|
|
||
| ```ts | ||
| const clerkClient = createClerkClient({ | ||
| machineSecretKey: process.env.CLERK_MACHINE_SECRET_KEY | ||
| }) | ||
|
|
||
| const m2mToken = await clerkClient.m2m.createToken({ | ||
| tokenFormat: 'jwt', | ||
| }) | ||
|
|
||
| console.log('M2M token created:', m2mToken.token) | ||
| ``` | ||
|
|
||
| **Verifying a token** | ||
|
|
||
| ```ts | ||
| const clerkClient = createClerkClient({ | ||
| machineSecretKey: process.env.CLERK_MACHINE_SECRET_KEY | ||
| }) | ||
|
|
||
| const authHeader = req.headers.get('Authorization') | ||
| const token = authHeader.slice(7) | ||
|
|
||
| const verified = await clerkClient.m2m.verify(token) | ||
|
|
||
| console.log('Verified M2M token:', verified) | ||
| ``` | ||
|
|
||
| **Networkless verification** | ||
|
|
||
| ```ts | ||
| const clerkClient = createClerkClient({ | ||
| jwtKey: process.env.CLERK_JWT_KEY | ||
| }) | ||
|
|
||
| const authHeader = req.headers.get('Authorization') | ||
| const token = authHeader.slice(7) | ||
|
|
||
| const verified = await clerkClient.m2m.verify(token) | ||
|
|
||
| console.log('Verified M2M token:', verified) | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.