Primeiros passos
SDK PHP
identvia/identvia-php 1.1.1 autentica usuários com OpenID Connect. PHP 8.1+ puro, sem framework, funciona em hospedagem compartilhada.
Copie o prompt para o seu agente de IA
Usa um agente de programação? Este prompt o direciona para esta documentação e lista as regras que ele deve seguir. Revise o que ele escrever como qualquer outro 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 ou mais novo com openssl e json (padrão em todo lugar).
- Opcional: curl (senão usam-se streams do PHP) e apcu (senão o cache de chaves usa arquivos).
- Uma dependência: firebase/php-jwt para checagem de assinaturas. O SDK nunca implementa criptografia sozinho.
Instalar
composer require identvia/identvia-phpOu envie o zip pelo Gerenciador de arquivos do cPanel e inclua vendor/autoload.php.
Configuração
$identvia = new Identvia\Sdk\Identvia([
'issuer' => 'https://id.identvia.com', // obrigatório
'client_id' => 'oid_…', // obrigatório
'client_secret' => 'ivs_…', // somente apps confidenciais
'redirect_uri' => 'https://example.com/callback.php', // deve coincidir exatamente
'scopes' => ['email', 'profile'], // openid é sempre adicionado
'cache_dir' => __DIR__ . '/../storage/identvia', // opcional; padrão: diretório temp do sistema
'leeway' => 60, // diferença de relógio permitida, segundos
'timeout' => 10, // Timeout HTTP, segundos
]);| Opção | Notas |
|---|---|
| token_auth | client_secret_basic (padrão) ou client_secret_post |
| ca_bundle | Caminho para um arquivo CA se o estoque de certificados do host estiver desatualizado. A verificação TLS não pode ser desligada. |
| cache, http, state_store | Traga seu próprio cache, cliente HTTP ou armazenamento de estado (interfaces em src/). |
Mantenha o segredo fora do repositório: use variáveis de ambiente, ou um config.php fora da raiz web.
Entrar
// login.php: envia o usuário à Identvia (state, nonce e PKCE são tratados por você)
$identvia->redirectToSignIn([
'return_to' => '/account', // opcional; só caminhos same-site são aceitos
// 'prompt' => 'login', // forçar uma entrada nova
// 'max_age' => 300, // exigir uma entrada nos últimos 5 minutos
]);
// callback.php: completa
$signIn = $identvia->handleCallback($_GET);
$signIn->sub(); // the user's ID for your app
$signIn->email(); // null se não compartilhado
$signIn->emailVerified();
$signIn->name();
$signIn->amr(); // e.g. ['hwk', 'user'] for a passkey
$signIn->tokens; // TokenSet: accessToken, refreshToken, idToken, expiresAt
$signIn->returnTo;Erros
| Exceção | Quando | O que fazer |
|---|---|---|
| AuthorizationException | O usuário pressionou Cancelar (userCancelled()) ou a Identvia retornou um erro | Mostrar uma mensagem amigável |
| InvalidStateException | Callback expirado, reutilizado ou forjado; emissor errado | Recomeçar a entrada |
| TokenException | Falha na troca do código (invalid_grant, invalid_client) | Verifique seu segredo; comece de novo |
| ValidationException | O ID token falhou em uma verificação | Nunca autentique o usuário; registre |
| HttpException | Falha de rede ou TLS | Tentar de novo mais tarde |
Todos estendem Identvia\Sdk\Exception\IdentviaException.
Userinfo, refresh, revoke, logout
$claims = $identvia->userinfo($tokens->accessToken, $signIn->sub());
// Precisa do escopo offline_access. A Identvia rotaciona refresh tokens: sempre armazene o novo.
$tokens = $identvia->refresh($tokens->refreshToken, $signIn->sub());
$identvia->revoke($tokens->refreshToken); // ao sair
// Opcional: também encerrar a sessão da Identvia
header('Location: ' . $identvia->logoutUrl($tokens->idToken, 'https://example.com/'));O que o SDK verifica
- state: aleatório, uso único, expira após 10 minutos; várias abas podem entrar ao mesmo tempo.
- PKCE (S256) em cada solicitação, também para apps confidenciais.
- iss no callback (RFC 9207), que defende contra confusão de provedores de identidade.
- Assinatura do ID token com as chaves publicadas da Identvia (somente RS256/ES256, nunca none ou HMAC); as chaves ficam em cache por uma hora e são buscadas de novo uma vez quando a Identvia as rotaciona.
- iss, aud, azp, exp, iat, nonce, auth_time contra max_age, e at_hash.
- HTTPS com verificação de certificado em cada chamada; http:// só é aceito para localhost.
Sessões
O SDK guarda entradas pendentes na sessão PHP e inicia uma se preciso. O cookie de sessão deve ser enviado quando a Identvia redireciona de volta, então use SameSite=Lax (não Strict). Chame session_regenerate_id(true) após uma entrada bem-sucedida.
App de exemplo: Identvia Notes
Um app completo com CSP rigorosa, o botão, entrada/saída e notas por usuário. Está no zip em examples/notes-app.
cd identvia-php/examples/notes-app
cp config.example.php config.php # cole seu client ID e segredo
php -S localhost:9999 -t public # depois abra http://localhost:9999