---
title: "sdk/php"
description: "PHP-8.1+-Server-SDK für netzwerklose JWT-Prüfung,PSR-7-Anfrage-Authentifizierung und Webhook-Signaturvalidierung."
locale: "de"
---

> Documentation Index
> Fetch the locale documentation index at: https://xid.dev/de/llms.txt
> Use this file to discover all available pages before exploring further.

# sdk/php

## Zustand

Implementiert und lokal verifiziert. Die echteIdP-Round-Trip-Verifizierung (JWKS-Abruf, Token-Signierung/Prüfung gegeneine Live-XID-Instanz) wurde noch nicht durchgeführt und muss vor demProduktionseinsatz abgeschlossen werden.

## Installieren

PHP 8.1+ erforderlich. Kern-Abhängigkeiten werden automatisch von Composerbezogen.

```shell
composer require xid/xid
```

## Schnellstart

```php
use Xid\XidClient;
use Xid\Exception\TokenException;
use Xid\Exception\JwksException;

$xid = new XidClient([
'issuer'   => 'https://xid.dev',
'audience' => 'your-client-id',
'cache'    => $psrSimpleCacheImpl, // PSR-16; null disables JWKS cache
]);

try {
$claims = $xid->verifyToken($jwtString);
echo $claims->sub();    // user ID
echo $claims->scope();  // "openid profile email"
echo implode(',', $claims->amr()); // "phr" / "otp"
} catch (TokenException $e) {
http_response_code(401);
} catch (JwksException $e) {
http_response_code(503);
}
```

## PSR-7-Anfrage authentifizieren

```php
$result = $xid->authenticateRequest($psrRequest);

if ($result->isAuthenticated()) {
$userId = $result->claims()->sub();
} else {
// $result->reason() for server-side logs only
http_response_code(401);
}
```

## Webhook prüfen

```php
use Xid\Exception\WebhookException;

try {
$payload = $xid->verifyWebhook($psrRequest, 'whsec_...');
$type = $payload->type();  // "user.created"
$data = $payload->data();
} catch (WebhookException $e) {
http_response_code(400);
}
```

## XidClient-Optionen

| Schlüssel | Standard | Beschreibung |
| --- | --- | --- |
| `issuer` | erforderlich | XID-Issuer-URI |
| `audience` | `null` | Erwartetes audience; null überspringt die Validierung |
| `cache` | `null` | PSR-16-CacheInterface für JWKS-Caching |
| `jwks_ttl` | `3600` | JWKS-Cache-TTL in Sekunden |
| `clock_leeway` | `0` | JWT-Taktversatztoleranz in Sekunden |
| `cookie_name` | `__xid_session` | Session-Cookie-Schlüssel für die Token-Extraktion |

## XidClient-Methoden

| Methode | Gibt zurück | Beschreibung |
| --- | --- | --- |
| `verifyToken(string $token)` | `Claims` | JWT-String prüfen; wirft bei Fehler Exception |
| `authenticateRequest(ServerRequestInterface $request)` | `AuthResult` | PSR-7-Anfrage authentifizieren; wirft keine Exception |
| `verifyWebhook(ServerRequestInterface $request, string $secret)` | `WebhookPayload` | Webhook-Signatur validieren; wirft bei Fehler Exception |
| `refreshJwks()` | `void` | JWKS-Cache erzwungen aktualisieren |

## Plattformhinweise

- Verwendet `firebase/php-jwt` für ES256/RS256-Prüfung. HS256 und`none`-Algorithmus werden abgelehnt.
- Erfordert ein PSR-7-Anfrageobjekt für `authenticateRequest` und`verifyWebhook`. Framework-native Anfragen bei Bedarf mit einerPSR-7-Bridge konvertieren.
- Ausnahmehierarchie: `XidException` -&gt; `TokenException`,`JwksException`, `WebhookException`.

Source: https://xid.dev/de/sdks/php/index.mdx
