Skip to content

Commit

Permalink
running prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
Ben2W committed Nov 20, 2024
1 parent 8aadda9 commit fe66c06
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 40 deletions.
15 changes: 7 additions & 8 deletions docs/backend-requests/handling/manual-jwt.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -57,27 +57,26 @@ To authenticate machine requests using `authenticateRequest()`, specify the `ent

The following example uses the `authenticateRequest()` method with the [JavaScript Backend SDK](/docs/references/backend/overview) to verify that the token is a valid machine token generated by Clerk.


```tsx
import { createClerkClient } from '@clerk/backend';
import { createClerkClient } from '@clerk/backend'

export async function GET(req: Request) {
const clerkClient = createClerkClient({
secretKey: process.env.CLERK_SECRET_KEY,
publishableKey: process.env.CLERK_PUBLISHABLE_KEY,
});
})

const { isMachineAuthenticated, machinedId } = await clerkClient.authenticateRequest(req, {
entity: 'machine',
});
})

if (!authReq.isMachineAuthenticated) {
return Response.json({ status: 401 });
return Response.json({ status: 401 })
}

return Response.json({
return Response.json({
message: 'Machine is authenticated',
machineId
});
machineId,
})
}
```
17 changes: 8 additions & 9 deletions docs/backend-requests/making/machine.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,16 @@ The Node.js SDK has a `machineTokens` object that can be used to create machine
import { createClerkClient } from '@clerk/backend'

export default function machineFetch() {

const clerkClient = createClerkClient({ secretKey: process.env.CLERK_SECRET_KEY })

// creates a token with no additional claims.
const { token } = await clerkClient.machineTokens.create({
machineId: "mch_cron",
claims: {
permissions: ["read", "write"]
}, // custom claims customer's can add to their token
expiresInSeconds: 60
});
machineId: 'mch_cron',
claims: {
permissions: ['read', 'write'],
}, // custom claims customer's can add to their token
expiresInSeconds: 60,
})

const authenticatedFetch = async (...args) => {
return fetch(...args, {
Expand All @@ -40,6 +39,6 @@ export default function machineFetch() {

## Using the Backend API reference

You can also generate machine tokens by simply making a requests to Clerk's Backend API
You can also generate machine tokens by simply making a requests to Clerk's Backend API

Go to the Backend API reference to learn more. **The API reference for this endpoint doesn't exist yet**
Go to the Backend API reference to learn more. **The API reference for this endpoint doesn't exist yet**
29 changes: 14 additions & 15 deletions docs/backend-requests/resources/machine-tokens.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,25 @@ Every machine token you create needs to be associated with a `machine_id`. You c
> [!TIP]
> It is a good idea to have the `machine_id` correspond with the identity of the service generating the token. For example if you have a cron service, a `machine_id` of `mch_cron` would make sense.
#### Some valid machine_ids
#### Some valid machine\_ids

- mch_123
- mch_hi_there_jack
- mch_ooooooooooohhhhhhhhhhhhh_snaaaaaaaaaaap
- mch\_123
- mch\_hi\_there\_jack
- mch\_ooooooooooohhhhhhhhhhhhh\_snaaaaaaaaaaap

#### Some invalid machine_ids
#### Some invalid machine\_ids

- user_1234
- mch_OH_HI_MARK
- MCH_123
- user\_1234
- mch\_OH\_HI\_MARK
- MCH\_123
- mch-123

### Some **valid** machine_ids
### Some **valid** machine\_ids

- mch_cron
- mch_pub_sub
- mch_scheduler
- mch_device_ada3f8b7-d491-4fe4-b76e-99e4c00b56d1
- mch\_cron
- mch\_pub\_sub
- mch\_scheduler
- mch\_device\_ada3f8b7-d491-4fe4-b76e-99e4c00b56d1

### Claims

Expand All @@ -60,7 +60,6 @@ The `allowedClockSkew` parameter provides a leeway in seconds to account for clo

Adjusting the clock skew helps prevent token validation failures due to minor time discrepancies between the issuing server and the verifying server.


## Default machine claims

Every generated token has default claims that cannot be overridden by custom claims. Clerk's default claims include:
Expand All @@ -78,4 +77,4 @@ To start making machine requests, refer to [making machine requests](/docs/backe

## Validating Machine Tokens

To learn how to manually verify a machine token, refer to [validating machine tokens](/docs/backend-requests/handling/manual-jwt#machine-tokens).
To learn how to manually verify a machine token, refer to [validating machine tokens](/docs/backend-requests/handling/manual-jwt#machine-tokens).
16 changes: 8 additions & 8 deletions docs/references/backend/authenticate-request.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -238,25 +238,25 @@ export async function GET(req: Request) {
The following example uses the `authenticateRequest()` to verify a machine token.
```tsx
import { createClerkClient } from '@clerk/backend';
import { createClerkClient } from '@clerk/backend'

export async function GET(req: Request) {
const clerkClient = createClerkClient({
secretKey: process.env.CLERK_SECRET_KEY,
publishableKey: process.env.CLERK_PUBLISHABLE_KEY,
});
})

const { isMachineAuthenticated, machinedId } = await clerkClient.authenticateRequest(req, {
entity: 'machine',
});
})

if (!authReq.isMachineAuthenticated) {
return Response.json({ status: 401 });
return Response.json({ status: 401 })
}

return Response.json({
return Response.json({
message: 'Machine is authenticated',
machineId
});
machineId,
})
}
```
```

0 comments on commit fe66c06

Please sign in to comment.