> ## Documentation Index
> Fetch the complete documentation index at: https://www.canva.dev/docs/apps/llms.txt
> Use this file to discover all available pages before exploring further.
# JSON Web Tokens
How to verify a JSON Web Token (JWT).
For security reasons, Canva uses [JSON Web Tokens](https://datatracker.ietf.org/doc/html/rfc7519) (JWTs) to encode certain information, such as the ID of the user or the ID of a user's design. To access this information, apps must decode and verify the JWTs.
**Danger:** Apps must only verify JWTs through the app's backend — never through the frontend.
**For Node.js backends:** We recommend using the [`@canva/app-middleware`](https://www.npmjs.com/package/@canva/app-middleware) package, which provides built-in verification for both user tokens and design tokens, along with JWKS caching and error handling. This package simplifies the verification process and follows security best practices.
## Types of tokens
In the Canva Developers SDK, there are two types of tokens:
* **Design tokens** - Encode information about the current design, such as the ID of the design
* **User tokens** - Encode information about the current user, such as the ID of the user and their team
The steps for verifying each type of token are the same, but the tokens encode different information, and apps access them in different ways:
* An app can call the `getDesignToken` method. This method returns a design token, which the app can use to get the ID of a design and associate data with that design. To learn more, see [Using design IDs](https://www.canva.dev/docs/apps/using-design-ids/).
* An app can [start an authentication flow](https://www.canva.dev/docs/apps/authenticating-users/). This redirects the user to the app's **Redirect URL**. Canva appends a user token to the URL. The app's backend can use this token to authenticate the user using a third-party platform.
* An app can call the `auth.getCanvaUserToken` method. This method returns a user token, which the app can use to [verify HTTP requests](https://www.canva.dev/docs/apps/verifying-http-requests/) or identify users (for example, to check if they're authenticated).
## Verifying JWTs with @canva/app-middleware
For Node.js backends, the `@canva/app-middleware` package provides a simple and secure way to verify JWT tokens.
### Installation
```shell
npm install @canva/app-middleware
```
### Express.js middleware
For Express.js applications, use the built-in middleware:
### Framework-agnostic function
For other Node.js environments (Next.js, AWS Lambda, Cloudflare Workers, and so on):
## Manually verifying JWTs
If you're using a non-Node.js backend, you can manually verify JWTs. The following steps show how to implement JWT verification from scratch in TypeScript, which you can then adapt to your preferred language or framework.
### Step 4: Verify the token
Use the public key to verify the JWT:
```ts
const verified = jwt.verify("JWT_GOES_HERE", publicKey, {
audience: "YOUR_APP_ID",
});
```
The exact syntax will depend on the library you're using.
If the token is valid, the verified token will be a dictionary. The properties in this dictionary will depend on whether the token is a design token or a user token.
### Design tokens
If the token is a valid design token, the object will contain the following properties:
* `aud` - The ID of the app.
* `designId` - The ID of the current design.
If these properties aren't available, it means the token or public key are invalid:
```tsx
if (!verified.aud || !verified.designId) {
throw new Error("The design token is not valid");
}
```
### User tokens
If the token is a valid user token, the object will contain the following properties:
* `aud` - The ID of the app.
* `brandId` - The ID of the user's team.
* `userId` - The ID of the user.
If these properties aren't available, it means the token or public key are invalid:
```tsx
if (!verified.aud || !verified.brandId || !verified.userId) {
throw new Error("The user token is not valid");
}
```