İçeriğe geç

Başlarken

Hızlı başlangıç

Bir PHP sitesine yaklaşık on dakikada “Identvia ile oturum aç” ekleyin. OpenSSL'li PHP 8.1+ gerekir; her cPanel hostunda bulunur.

Yapay zekâ ajanınız için istemi kopyalayın

Kodlama ajanı mı kullanıyorsunuz? Bu istem onu bu belgelere yönlendirir ve uyması gereken kuralları listeler. Yazdıklarını diğer kodlar gibi inceleyin.

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. Uygulamanızı kaydedin

geliştirici konsolunu açın, Identvia hesabınızla oturum açın ve Yeni uygulama butonuna basın. Sunucu tarafı bir site için Web uygulaması seçin (bir istemci sırrını korur) ve geri dönüş URL'nizi bir yönlendirme URI'si olarak ekleyin, örneğin http://localhost:8000/callback.php. Bir tarayıcı SPA için Tek sayfa uygulaması seçin; iOS, Android veya masaüstü için Yerel & masaüstü uygulama seçin (özel kullanım şemaları, App Links, loopback).

client ID ve bir client secret göreceksiniz. Secret'ı hemen kopyalayın: yalnızca bir kez gösterilir ve Identvia yalnızca hash'ini saklar.

İlk ortamınız http://localhost adresine izin veren Development ortamıdır. Yayına geçtiğinizde gerçek https:// callback'inizle bir Production ortamı ekleyin. Kendi client ID'si ve secret'ı olur.

2. SDK'yı kurun

Composer ile:

Terminal
composer require identvia/identvia-php

Diğer platformlar (JS, mobil, .NET, WordPress): SDK’ler ve kitaplıklar’a bakın.

Composer veya SSH yok mu? vendor/ içeren zip dosyasını indirin, cPanel Dosya Yöneticisi ile sitenizin yanına açın ve require 'identvia-php/vendor/autoload.php' kullanın.

3. Yapılandırın

identvia.phpPHP
<?php // identvia.php: bunu oturum açma ve callback sayfalarınızdan dahil edin
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. Düğmeyi ekleyin

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>
Identvia ile oturum aç← görünümü böyle

5. Oturum açmayı başlatın

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

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

6. Callback'i işleyin

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();   // sabit, uygulamanıza özgü
$_SESSION['email']   = $signIn->email(); // yalnızca kullanıcı paylaştıysa

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

Hepsi bu. handleCallback() state'i kontrol eder, kodu PKCE ile takas eder, ID token imzasını Identvia anahtarlarıyla doğrular ve vereni, hedef kitleyi, süreyi ve nonce'u kontrol eder. Bir sorun varsa istisna fırlatır ve kimse oturum açmaz.

Kullanıcı kimliği olarak e-posta adresini değil sub() değerini kullanın. Kullanıcılar e-postalarını değiştirebilir veya paylaşmamayı seçebilir; sub ise tasarım gereği her uygulama için farklıdır.

Sonraki adımlar