Zum Inhalt springen

Erste Schritte

Schnellstart

Bauen Sie „Mit Identvia anmelden“ in etwa zehn Minuten in eine PHP-Website ein. Sie brauchen PHP 8.1+ mit OpenSSL, das jeder cPanel-Host bietet.

Prompt für Ihren KI-Agenten kopieren

Sie nutzen einen Coding-Agenten? Dieser Prompt verweist ihn auf diese Doku und listet die Regeln auf, die er befolgen muss. Prüfen Sie, was er schreibt, wie jeden anderen Code.

You are helping me add "Sign in with Identvia" to my app (PHP). Identvia is an OpenID Connect provider.

Read these first (they are plain Markdown and are the source of truth; prefer them over anything you remember):
- https://id.identvia.com/developers/docs/quickstart.md
- https://id.identvia.com/developers/docs/oidc.md
- https://id.identvia.com/developers/docs/security.md
- Discovery: https://id.identvia.com/.well-known/openid-configuration

Stack: plain PHP 8.1+ (no framework). Use the official SDK identvia/identvia-php (composer require identvia/identvia-php, or the zip with vendor/ from https://id.identvia.com/developers/docs/php for hosts without Composer). Create identvia.php (config), login.php (redirectToSignIn), callback.php (handleCallback, then session_regenerate_id(true) and store sub) and logout.php. Read secrets from environment variables or a config file outside the web root.

Requirements:
1. Authorization code flow with PKCE (S256 only), a random state and a nonce per sign-in. No implicit flow.
2. Validate the ID token: RS256 signature from the JWKS, iss = https://id.identvia.com, aud contains my client_id, exp/iat, and the nonce.
3. Identify users by sub (it is pairwise: different for every app). Treat email as optional, because the person may choose not to share it.
4. Redirect URIs must match exactly. Keep the client secret and refresh tokens server-side; never log tokens.
5. Ask only for the scopes I need (openid, plus email/profile if used). Handle the user canceling (error=access_denied) gracefully.

Optional, only if I ask for AI-agent access later:
- AgentPass (agents acting for a user with single-use, holder-bound passes): https://id.identvia.com/developers/docs/agentpass.md
- MCP server for agent clients: https://id.identvia.com/developers/docs/mcp.md
- Token exchange, rich authorization requests and CIBA: https://id.identvia.com/developers/docs/delegation.md

Before writing code, tell me which files you will add or change. Don't invent endpoints or options that aren't in the docs; if something is unclear, ask me.

1. App registrieren

Öffne die Entwicklerkonsole, melde dich mit deinem Identvia-Konto an und drücke Neue App. Wähle Web-App für eine serverseitige Seite (beinhält ein Client-Geheimnis) und füge deine Rückruf-URL als Umleitungs-URI hinzu, zum Beispiel http://localhost:8000/callback.php. Für eine Browser-SPA wähle Single-Page-App; für iOS, Android oder Desktop wähle Native & Desktop-App (private Schemata, App Links, Loopback).

Sie sehen die Client-ID und ein Client-Secret. Kopieren Sie das Secret sofort: Es wird nur einmal angezeigt, und Identvia speichert nur einen Hash davon.

Ihre erste Umgebung ist Development, die http://localhost erlaubt. Wenn Sie live gehen, fügen Sie eine Production-Umgebung mit Ihrem echten https://-Callback hinzu. Sie erhält eigene Client-ID und eigenes Secret.

2. SDK installieren

Mit Composer:

Terminal
composer require identvia/identvia-php

Andere Plattformen (JS, Mobil, .NET, WordPress): siehe SDKs & Bibliotheken.

Kein Composer und kein SSH? Laden Sie das ZIP herunter, das vendor/ enthält, entpacken Sie es im Dateimanager von cPanel neben Ihrer Website und nutzen Sie require 'identvia-php/vendor/autoload.php'.

3. Konfigurieren

identvia.phpPHP
<?php // identvia.php: von Ihren Login- und Callback-Seiten einbinden
require __DIR__ . '/vendor/autoload.php';

session_start();

$identvia = new Identvia\Sdk\Identvia([
    'issuer'        => 'https://id.identvia.com',
    'client_id'     => getenv('IDENTVIA_CLIENT_ID'),
    'client_secret' => getenv('IDENTVIA_CLIENT_SECRET'),
    'redirect_uri'  => 'http://localhost:8000/callback.php',
    'scopes'        => ['email', 'profile'],
]);

4. Schaltfläche einbauen

index.htmlHTML
<a class="identvia-btn" href="/login.php">Sign in with Identvia</a>
<script src="https://id.identvia.com/sdk/v1/button.js" async></script>
Mit Identvia anmelden← so sieht es aus

5. Anmeldung starten

login.phpPHP
<?php // login.php
require __DIR__ . '/identvia.php';

$identvia->redirectToSignIn(['return_to' => '/dashboard.php']);

6. Callback verarbeiten

callback.phpPHP
<?php // callback.php
require __DIR__ . '/identvia.php';

try {
    $signIn = $identvia->handleCallback($_GET);
} catch (Identvia\Sdk\Exception\AuthorizationException $e) {
    exit($e->userCancelled() ? 'You canceled sign-in.' : 'Sign-in failed.');
} catch (Identvia\Sdk\Exception\IdentviaException $e) {
    error_log($e->getMessage());
    exit('Sign-in failed. Please try again.');
}

session_regenerate_id(true);
$_SESSION['user_id'] = $signIn->sub();   // stabil, eindeutig für Ihre App
$_SESSION['email']   = $signIn->email(); // nur wenn der Nutzer sie geteilt hat

header('Location: ' . ($signIn->returnTo ?? '/'));

Das war’s. handleCallback() prüft den state, tauscht den Code mit PKCE ein, prüft die Signatur des ID-Tokens gegen die Schlüssel von Identvia und kontrolliert Aussteller, Audience, Ablauf und Nonce. Stimmt etwas nicht, wird eine Ausnahme ausgelöst und niemand wird angemeldet.

Verwenden Sie sub() als Nutzer-ID, nicht die E-Mail-Adresse. Nutzer können ihre E-Mail-Adresse ändern oder sie nicht teilen, und die sub ist bewusst für jede App unterschiedlich.

Nächste Schritte