PHP code example of globaltrustid / php

1. Go to this page and download the library: Download globaltrustid/php library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

globaltrustid / php example snippets


use GlobalTrustID\Client;

$gti = new Client(['client_id' => 'gtid_...', 'redirect_uri' => 'https://siteniz.com/callback']);

header('Location: ' . $gti->loginUrl());   // 1. kullanıcıyı yolla
$user = $gti->handleCallback();            // 2. callback'te profili al
echo $user['sub'];



use GlobalTrustID\Client;
use GlobalTrustID\Exception as GtiException;

$gti = new Client([
    'client_id'     => 'gtid_...',
    'redirect_uri'  => 'https://siteniz.com/gti-callback.php',
    'client_secret' => '...',   // yalnızca confidential istemcide
]);

// SCOPE_OPENID = yalnızca giriş; hiçbir kişisel veri paylaşılmaz.
header('Location: ' . $gti->loginUrl(Client::SCOPE_OPENID));
exit;

try {
    $user = $gti->handleCallback();
} catch (GtiException $e) {
    http_response_code(400);
    exit($e->getMessage());
}

// 'sub' kullanıcının DEĞİŞMEYEN kimliği. Kendi tablonuzda bunu saklayın,
// e-postayı değil — e-posta değişebilir, sub değişmez.
$gtiSub = $user['sub'];

$gti = new Client(['api_key' => 'sk_live_...']);

$session = $gti->verify(['identity.first_name', 'identity.last_name', 'identity.national_id']);

echo '<img src="' . htmlspecialchars($gti->qrUrl($session['session_id'])) . '">';

$result = $gti->result($session['session_id']);

if ($result['status'] === 'approved') {
    $ad = $result['identity']['identity.first_name'];
}

if ($gti->isIdentityVerified($result)) {
    // Kimlik BELGESİ NFC ile okundu.
}

$gti = new Client(['webhook_secret' => 'whsec_...']);

// HAM gövdeyi ÖNCE okuyun.
$raw = file_get_contents('php://input');

if (!$gti->verifyWebhook($raw)) {
    http_response_code(401);
    exit;
}

$payload = json_decode($raw, true);

class GtiController extends Controller
{
    public function __construct(private \GlobalTrustID\Client $gti) {}

    public function redirect()
    {
        return redirect()->away($this->gti->loginUrl());
    }

    public function callback(Request $request)
    {
        $profile = $this->gti->handleCallback($request->query());
        // ...
    }
}

use GlobalTrustID\Laravel\GlobalTrustIDFacade as GlobalTrustID;

return redirect()->away(GlobalTrustID::loginUrl(['email']));

$gti = service('gti');
return $this->response->redirect($gti->loginUrl());



$gti = new GlobalTrustID\Client([...]);