---
title: "JWT-tokens | Tajo"
description: "JSON Web Tokens voor veilige API-authenticatie"
url: https://tajo.io/nl/docs/authentication/jwt-tokens/
markdown: https://tajo.io/nl/docs/authentication/jwt-tokens.md
lang: nl-NL
author: "Set Noa"
author_url: https://tajo.io/nl/set-noa/
robots: noindex
---

Vraag vroegtijdige toegang aan

Vul je voornaam en je zakelijke e-mailadres in. We sturen je een link om je aanvraag voor toegang tot Tajo te bevestigen.

# JWT-tokens

[Set Noa](https://tajo.io/nl/set-noa/)

JSON Web Tokens (JWT) bieden een veilige manier om informatie tussen partijen uit te wisselen als een JSON-object.

## Structuur van een JWT

Een JWT bestaat uit drie delen, gescheiden door punten:

```
header.payload.signature
```

### Header

```json
{
  "alg": "HS256",
  "typ": "JWT"
}
```

### Payload

```json
{
  "sub": "1234567890",
  "email": "user@example.com",
  "iat": 1516239022,
  "exp": 1516242622
}
```

### Handtekening

De handtekening wordt als volgt aangemaakt:

```
HMACSHA256(
  base64UrlEncode(header) + "." +
  base64UrlEncode(payload),
  secret
)
```

## JWT-tokens aanmaken

### Voorbeeld in Node.js

```javascript
const jwt = require('jsonwebtoken');

const payload = {
  userId: '12345',
  email: 'user@example.com',
  scope: ['email', 'contacts']
};

const token = jwt.sign(payload, process.env.JWT_SECRET, {
  expiresIn: '1h',
  issuer: 'your-app',
  audience: 'brevo-api'
});
```

### Voorbeeld in Python

```python
import jwt
import datetime

payload = {
    'user_id': '12345',
    'email': 'user@example.com',
    'exp': datetime.datetime.utcnow() + datetime.timedelta(hours=1),
    'iat': datetime.datetime.utcnow()
}

token = jwt.encode(payload, 'your-secret-key', algorithm='HS256')
```

## JWT gebruiken met de Brevo API

```bash
curl -X GET "https://api.brevo.com/v3/account" \
  -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..." \
  -H "Accept: application/json"
```

## Tokenvalidatie

```javascript
const validateToken = (token) => {
  try {
    const decoded = jwt.verify(token, process.env.JWT_SECRET);
    return { valid: true, payload: decoded };
  } catch (error) {
    return { valid: false, error: error.message };
  }
};
```

## Best practices

- Gebruik sterke, willekeurige secrets
- Stel passende vervaltijden in
- Valideer tokens bij elk verzoek
- Gebruik uitsluitend HTTPS
- Bewaar secrets op een veilige plek
- Bouw logica in om tokens te vernieuwen
