# Authentifizierung

Die Chamilo API verwendet **JWT (JSON Web Tokens)** zur Authentifizierung, implementiert über `lexik/jwt-authentication-bundle`.

## Token erhalten

Senden Sie eine POST-Anfrage an den Authentifizierungsendpunkt:

```
POST /api/authentication_token
Content-Type: application/json

{
  "username": "admin",
  "password": "your-password"
}
```

Antwort:

```json
{
  "token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9..."
}
```

## Token verwenden

Fügen Sie den Token in den `Authorization`-Header nachfolgender Anfragen ein:

```
GET /api/users
Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9...
```

## Token-Lebenszyklus

* Tokens haben eine konfigurierbare Ablaufzeit
* Wenn ein Token abläuft, muss der Client einen neuen anfordern
* JWT-Schlüssel werden in `config/jwt/` gespeichert (private und öffentliche Schlüssel)

## JWT-Schlüssel generieren

```bash
php bin/console lexik:jwt:generate-keypair
```

Dies erstellt:

* `config/jwt/private.pem` — Privater Schlüssel zum Signieren von Tokens
* `config/jwt/public.pem` — Öffentlicher Schlüssel zum Verifizieren von Tokens

Konfigurieren Sie die Passphrase in `.env`:

```env
JWT_PASSPHRASE=your-passphrase
```

## API-Dokumentation

Wenn `APP_ENABLE_API_ENTRYPOINT=1` in der Umgebung gesetzt ist, ist die API-Dokumentation unter `/api` verfügbar. Dies bietet eine interaktive Swagger/OpenAPI-Schnittstelle zum Erkunden und Testen von Endpunkten.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.chamilo.org/2.x-de/entwicklerhandbuch/developer-guide/api/authentication.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
