You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: packages/backend/src/jwt/verifyJwt.ts
+4-1Lines changed: 4 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -94,6 +94,9 @@ export function decodeJwt(token: string): JwtReturnType<Jwt, TokenVerificationEr
94
94
return{ data };
95
95
}
96
96
97
+
/**
98
+
* @inline
99
+
*/
97
100
exporttypeVerifyJwtOptions={
98
101
/**
99
102
* A string or list of [audiences](https://datatracker.ietf.org/doc/html/rfc7519#section-4.1.3). If passed, it is checked against the `aud` claim in the token.
@@ -103,7 +106,7 @@ export type VerifyJwtOptions = {
103
106
* An allowlist of origins to verify against, to protect your application from the subdomain cookie leaking attack.
* > This is a lower-level method intended for more advanced use-cases. It's recommended to use [`authenticateRequest()`](https://clerk.com/docs/references/backend/authenticate-request), which fully authenticates a token passed from the `request` object.
24
+
*
25
+
* Verifies a Clerk-generated token signature. Networkless if the `jwtKey` is provided. Otherwise, performs a network call to retrieve the JWKS from the [Backend API](https://clerk.com/docs/reference/backend-api/tag/JWKS#operation/GetJWKS){{ target: '_blank' }}.
26
+
*
27
+
* @param token - The token to verify.
28
+
* @param options - Options for verifying the token.
29
+
*
30
+
* @example
31
+
*
32
+
* The following example demonstrates how to use the [JavaScript Backend SDK](https://clerk.com/docs/references/backend/overview) to verify the token signature.
33
+
*
34
+
* In the following example:
35
+
*
36
+
* 1. The **JWKS Public Key** from the Clerk Dashboard is set in the environment variable `CLERK_JWT_KEY`.
37
+
* 1. The session token is retrieved from the `__session` cookie or the Authorization header.
38
+
* 1. The token is verified in a networkless manner by passing the `jwtKey` prop.
39
+
* 1. The `authorizedParties` prop is passed to verify that the session token is generated from the expected frontend application.
40
+
* 1. If the token is valid, the response contains the verified token.
* The signing secret for the webhook. It's recommended to use the [`CLERK_WEBHOOK_SIGNING_SECRET` environment variable](https://clerk.com/docs/deployments/clerk-environment-variables#webhooks) instead.
* Verifies the authenticity of a webhook request using Svix.
26
+
* Verifies the authenticity of a webhook request using Svix. Returns a promise that resolves to the verified webhook event data.
21
27
*
22
-
* @param request - The incoming webhook request object
23
-
* @param options - Optional configuration object
24
-
* @param options.signingSecret - Custom signing secret. If not provided, falls back to CLERK_WEBHOOK_SIGNING_SECRET env variable
25
-
* @throws Will throw an error if the webhook signature verification fails
26
-
* @returns A promise that resolves to the verified webhook event data
28
+
* @param request - The request object.
29
+
* @param options - Optional configuration object.
27
30
*
28
31
* @example
29
-
* ```typescript
32
+
* See the [guide on syncing data](https://clerk.com/docs/webhooks/sync-data) for more comprehensive and framework-specific examples that you can copy and paste into your app.
33
+
*
34
+
* ```ts
30
35
* try {
31
-
* const evt = await verifyWebhook(request);
36
+
* const evt = await verifyWebhook(request)
32
37
*
33
38
* // Access the event data
34
-
* const { id } = evt.data;
35
-
* const eventType = evt.type;
39
+
* const { id } = evt.data
40
+
* const eventType = evt.type
36
41
*
37
42
* // Handle specific event types
38
43
* if (evt.type === 'user.created') {
39
-
* console.log('New user created:', evt.data.id);
44
+
* console.log('New user created:', evt.data.id)
40
45
* // Handle user creation
41
46
* }
42
47
*
43
-
* return new Response('Success', { status: 200 });
0 commit comments