diff --git a/docs/backend-requests/handling/manual-jwt.mdx b/docs/backend-requests/handling/manual-jwt.mdx index 88827ba577..80e59077d6 100644 --- a/docs/backend-requests/handling/manual-jwt.mdx +++ b/docs/backend-requests/handling/manual-jwt.mdx @@ -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, + }) } ``` diff --git a/docs/backend-requests/making/machine.mdx b/docs/backend-requests/making/machine.mdx index 5261fa2115..5aadfa66f7 100644 --- a/docs/backend-requests/making/machine.mdx +++ b/docs/backend-requests/making/machine.mdx @@ -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, { @@ -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** \ No newline at end of file +Go to the Backend API reference to learn more. **The API reference for this endpoint doesn't exist yet** diff --git a/docs/backend-requests/resources/machine-tokens.mdx b/docs/backend-requests/resources/machine-tokens.mdx index e018d9c624..83d92cfc71 100644 --- a/docs/backend-requests/resources/machine-tokens.mdx +++ b/docs/backend-requests/resources/machine-tokens.mdx @@ -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 @@ -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: @@ -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). \ No newline at end of file +To learn how to manually verify a machine token, refer to [validating machine tokens](/docs/backend-requests/handling/manual-jwt#machine-tokens). diff --git a/docs/references/backend/authenticate-request.mdx b/docs/references/backend/authenticate-request.mdx index a40d141739..8388e68b43 100644 --- a/docs/references/backend/authenticate-request.mdx +++ b/docs/references/backend/authenticate-request.mdx @@ -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, + }) } -``` \ No newline at end of file +```