Primeros pasos
SDK de PHP
identvia/identvia-php 1.1.1 inicia sesión de usuarios con OpenID Connect. PHP 8.1+ puro, sin framework, funciona en hosting compartido.
Copia el prompt para tu agente de IA
¿Usas un agente de programación? Este prompt lo dirige a esta documentación y enumera las reglas que debe seguir. Revisa lo que escriba como cualquier otro código.
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.
You are helping me add "Sign in with Identvia" to my app (Laravel). 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: Laravel. Use the official SDK identvia/identvia-php (framework-agnostic) from a small service class bound in a service provider, not a hand-written OAuth client. Add GET /auth/identvia/redirect and GET /auth/identvia/callback routes in the web middleware group. After the callback, find-or-create the user by the Identvia sub (not by email), call Auth::login() and $request->session()->regenerate(). Put the client secret in .env and config/services.php.
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.
You are helping me add "Sign in with Identvia" to my app (Symfony). 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: Symfony. Use the official SDK identvia/identvia-php wrapped in a service, plus a custom authenticator (AbstractAuthenticator) on the callback route. Map users by the Identvia sub, not email. Keep the client secret in Symfony secrets or env vars, never in committed config.
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.
You are helping me add "Sign in with Identvia" to my app (Node.js). 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: Node.js. There is no Identvia JavaScript SDK; use a certified OpenID Connect relying-party library (for example openid-client) with discovery from the issuer. Use the authorization code flow with PKCE (S256), state and nonce, keep tokens server-side in the session store, and regenerate the session id after sign-in.
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.
You are helping me add "Sign in with Identvia" to my app (Python). 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: Python. There is no Identvia Python SDK; use a maintained OpenID Connect client library (for example Authlib) with discovery from the issuer. Use the authorization code flow with PKCE (S256), state and nonce, and keep tokens server-side.
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.
Requisitos
- PHP 8.1 o más reciente con openssl y json (estándar en todas partes).
- Opcional: curl (si no, se usan streams de PHP) y apcu (si no, la caché de claves usa archivos).
- Una dependencia: firebase/php-jwt para comprobar firmas. El SDK nunca implementa criptografía por sí mismo.
Instalar
composer require identvia/identvia-phpO suba el zip con el Administrador de archivos de cPanel e incluya vendor/autoload.php.
Configuración
$identvia = new Identvia\Sdk\Identvia([
'issuer' => 'https://id.identvia.com', // obligatorio
'client_id' => 'oid_…', // obligatorio
'client_secret' => 'ivs_…', // solo apps confidenciales
'redirect_uri' => 'https://example.com/callback.php', // debe coincidir exactamente
'scopes' => ['email', 'profile'], // openid siempre se añade
'cache_dir' => __DIR__ . '/../storage/identvia', // opcional; predeterminado: directorio temporal del sistema
'leeway' => 60, // desfase de reloj permitido, segundos
'timeout' => 10, // Tiempo de espera HTTP, segundos
]);| Opción | Notas |
|---|---|
| token_auth | client_secret_basic (predeterminado) o client_secret_post |
| ca_bundle | Ruta a un archivo CA si el almacén de certificados de su host está desactualizado. La verificación TLS no se puede desactivar. |
| cache, http, state_store | Traiga su propia caché, cliente HTTP o almacén de estado (interfaces en src/). |
Mantenga el secreto fuera del repositorio: use variables de entorno, o un config.php fuera de la raíz web.
Iniciar sesión
// login.php: envía al usuario a Identvia (state, nonce y PKCE se gestionan por usted)
$identvia->redirectToSignIn([
'return_to' => '/account', // opcional; solo se aceptan rutas same-site
// 'prompt' => 'login', // forzar un inicio de sesión fresco
// 'max_age' => 300, // exigir un inicio de sesión en los últimos 5 minutos
]);
// callback.php: lo completa
$signIn = $identvia->handleCallback($_GET);
$signIn->sub(); // the user's ID for your app
$signIn->email(); // null si no se comparte
$signIn->emailVerified();
$signIn->name();
$signIn->amr(); // e.g. ['hwk', 'user'] for a passkey
$signIn->tokens; // TokenSet: accessToken, refreshToken, idToken, expiresAt
$signIn->returnTo;Errores
| Excepción | Cuándo | Qué hacer |
|---|---|---|
| AuthorizationException | El usuario pulsó Cancelar (userCancelled()) o Identvia devolvió un error | Mostrar un mensaje amable |
| InvalidStateException | Callback caducado, reutilizado o falsificado; emisor incorrecto | Volver a iniciar sesión |
| TokenException | Falló el intercambio de código (invalid_grant, invalid_client) | Compruebe su secreto; empiece de nuevo |
| ValidationException | El ID token falló una comprobación | Nunca inicie sesión al usuario; regístrelo |
| HttpException | Fallo de red o TLS | Reintentar más tarde |
Todas extienden Identvia\Sdk\Exception\IdentviaException.
Userinfo, refresh, revoke, logout
$claims = $identvia->userinfo($tokens->accessToken, $signIn->sub());
// Necesita el ámbito offline_access. Identvia rota los refresh tokens: guarde siempre el nuevo.
$tokens = $identvia->refresh($tokens->refreshToken, $signIn->sub());
$identvia->revoke($tokens->refreshToken); // al cerrar sesión
// Opcional: también terminar la sesión de Identvia
header('Location: ' . $identvia->logoutUrl($tokens->idToken, 'https://example.com/'));Qué comprueba el SDK
- state: aleatorio, de un solo uso, caduca a los 10 minutos; varias pestañas pueden iniciar sesión a la vez.
- PKCE (S256) en cada solicitud, también para apps confidenciales.
- iss en el callback (RFC 9207), que defiende contra la confusión de proveedores de identidad.
- Firma del ID token con las claves publicadas de Identvia (solo RS256/ES256, nunca none ni HMAC); las claves se almacenan en caché una hora y se vuelven a obtener una vez cuando Identvia las rota.
- iss, aud, azp, exp, iat, nonce, auth_time frente a max_age, y at_hash.
- HTTPS con verificación de certificado en cada llamada; http:// solo se acepta para localhost.
Sesiones
El SDK guarda inicios de sesión pendientes en la sesión PHP y arranca una si hace falta. La cookie de sesión debe enviarse cuando Identvia redirige de vuelta, así que use SameSite=Lax (no Strict). Llame a session_regenerate_id(true) tras un inicio correcto.
App de ejemplo: Identvia Notes
Una app completa con CSP estricta, el botón, inicio/cierre de sesión y notas por usuario. Está en el zip en examples/notes-app.
cd identvia-php/examples/notes-app
cp config.example.php config.php # pegue su client ID y secreto
php -S localhost:9999 -t public # luego abra http://localhost:9999