-
Notifications
You must be signed in to change notification settings - Fork 546
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
feat: Machine Token Docs #1725
base: main
Are you sure you want to change the base?
feat: Machine Token Docs #1725
Conversation
Hey, here’s your docs preview: https://clerk.com/docs/pr/1725 |
f25d216
to
d6aa27f
Compare
ff5ca46
to
155ff57
Compare
running prettier removing redundant ids a "valid" id was in fact - not valid removing unneccessary "s" reverting adding pages back in different folder some minor changes machine_id has a 255 character limit Some Colin Notes
155ff57
to
cfb62cb
Compare
Hey, here’s your docs preview: https://clerk.com/docs/pr/1725 |
87e98ac
to
c43da27
Compare
editing session requests slightly
improving authenticateRequest docs page updating auth object type editing nextjs auth docs page Removing unnecessary preface
c43da27
to
ee56c1d
Compare
import { runCronJob } from './cronJob'; | ||
|
||
export const POST = async () => { | ||
const { isMachineAuthenticated } = await auth({ entity: 'machine' }); |
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.
const { isMachineAuthenticated } = await auth({ entity: 'machine' }); | |
const { machineId } = await auth({ entity: 'machine' }); |
this works the same way as user auth()
where you should check for machineId
export const POST = async () => { | ||
const { isMachineAuthenticated } = await auth({ entity: 'machine' }); | ||
|
||
if (!isMachineAuthenticated) { |
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.
if (!isMachineAuthenticated) { | |
if (!machineId) { |
to satisfy the change to machineId
|
||
#### Examples | ||
|
||
<Tabs items={['Next.js Middleware', 'Next.js API Route']}> |
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.
feels weird to me that the authenticateRequest()
example is in a whole different tab, but it makes sense because authenticateRequest()
is it's own thing, i might be too in the weeds / looking too deep into it
```tsx | ||
import jwt from 'jsonwebtoken' | ||
|
||
export default async function (req: Request, res: Response) { |
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 probably have a name on this function
|
||
## Creating Machine Requests | ||
|
||
You can create a machine token using the [clerk backend api](https://clerk.com/docs/reference/backend-api/tag/machine-tokens). Then use the created token in the `Authorization` header of outgoing request. |
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.
You can create a machine token using the [clerk backend api](https://clerk.com/docs/reference/backend-api/tag/machine-tokens). Then use the created token in the `Authorization` header of outgoing request. | |
You can create a machine token using the [Clerk Backend API](https://clerk.com/docs/reference/backend-api/tag/machine-tokens). Then use the created token in the `Authorization` header of outgoing requests. |
You can create a machine token using the [clerk backend api](https://clerk.com/docs/reference/backend-api/tag/machine-tokens). Then use the created token in the `Authorization` header of outgoing request. | ||
|
||
> [!WARNING] | ||
> Because creating machine tokens using [clerk backend api](https://clerk.com/docs/reference/backend-api/tag/machine-tokens), it is subject to the [Backend API rate limits](/docs/rate-limits). |
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.
> Because creating machine tokens using [clerk backend api](https://clerk.com/docs/reference/backend-api/tag/machine-tokens), it is subject to the [Backend API rate limits](/docs/rate-limits). | |
> Creating machine tokens uses the Clerk Backend API, and so it is subject to the [Backend API rate limits](/docs/rate-limits). |
You can verify machine tokens in two ways: | ||
|
||
1. Using Clerk's Backend SDKs (recommended) | ||
2. Manually verifying the machine token JWT using your instance's public key. |
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.
2. Manually verifying the machine token JWT using your instance's public key. | |
2. Manually verifying the machine token JWT using your instance's Public Key. |
|
||
## Verifying Machine Requests | ||
|
||
For a machine request to be valid, it must include a valid [machine token](/docs/machine-requests/machine-tokens) in the Bearer `Authorization` header. |
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.
Are we capitalizing Machine Request? Let's make a decision and make it consistent through. Same for Machine Token.
For a machine request to be valid, it must include a valid [machine token](/docs/machine-requests/machine-tokens) in the Bearer `Authorization` header. | |
For a Machine Request to be valid, it must include a valid [machine token](/docs/machine-requests/machine-tokens) in the Bearer `Authorization` header. |
|
||
### Using Clerk's Backend SDKs | ||
|
||
By default, authenticating requests, will default to authenticating user [session requests](/docs/session-requests/overview). |
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.
By default, authenticating requests, will default to authenticating user [session requests](/docs/session-requests/overview). | |
By default, authenticating requests will default to authenticating them as user [session requests](/docs/session-requests/overview). |
|
||
#### Examples | ||
|
||
<Tabs items={['Next.js Middleware', 'Next.js API Route']}> |
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.
I don't think we want to lead with middleware, auth should be done as close to the resource being protected as possible.
description: Learn how to manually verify Clerk-generated machine tokens (JWTs). | ||
--- | ||
|
||
Your Clerk-generated [machine tokens](/docs/machine-requests/machine-tokens) are essentially JWTs which are signed using your instance's private key and can be verified using your instance's public key. |
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.
Your Clerk-generated [machine tokens](/docs/machine-requests/machine-tokens) are essentially JWTs which are signed using your instance's private key and can be verified using your instance's public key. | |
Your Clerk-generated [machine tokens](/docs/machine-requests/machine-tokens) are JWTs which are signed using your instance's private key and can be verified using your instance's public key. |
|
||
Your Clerk-generated [machine tokens](/docs/machine-requests/machine-tokens) are essentially JWTs which are signed using your instance's private key and can be verified using your instance's public key. | ||
|
||
For every machine request, you must validate the token to ensure it hasn't expired or been tampered with (i.e., it's authentic and secure). Additionally, you likely want to differentiate between machine and user requests. If these validations succeed, then the machine is authenticated to your application. |
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.
For every machine request, you must validate the token to ensure it hasn't expired or been tampered with (i.e., it's authentic and secure). Additionally, you likely want to differentiate between machine and user requests. If these validations succeed, then the machine is authenticated to your application. | |
For every machine request, you must validate the token to ensure it hasn't expired or been tampered with (i.e., it's authentic and secure). Additionally, you might want to differentiate between machine and user requests within your application. If these validations succeed, then the machine is authenticated and granted access to your application. |
Currently all customer-facing tokens are session tokens. We are adding
machine tokens
which is another customer-facing token. This PR adds documentation on:Additionally because now, all backend requests may no longer have a user + session associated with them, I modified the structure of some of the docs pages, and slightly edited existing pages to help fit the concept of "machine authentication". Read below to see what I changed.
Created the following machine request pages:
/docs/machine-requests/overview
/docs/machine-requests/machine-tokens
/docs/machine-requests/manual-jwt
Moved most of the "Backend Requests" pages to "Session Requests"
Calling this section "backend request" is confusing because machine requests are also backend requests.
This caused most of the "files changed" in the PR because a lot of links were changed from @NWylynko's script.
Some pages that were in "Backend Requests" didn't fit under "Session Requests," so they were moved to their own section:
Modified the following pages to add the concept of machine authentication:
Slack thread:
https://clerkinc.slack.com/archives/C01QFRQNHSN/p1738141182851989
Checklist