1. Go to this page and download the library: Download trustport/sdk 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/ */
trustport / sdk example snippets
Trustport\Client;
use Trustport\TrustportException;
$tp = new Client(['apiKey' => getenv('TRUSTPORT_API_KEY')]);
// In your login handler, after the password check passes:
$session = $tp->startSession(['subject' => $user->username]);
// Send $session->sid to your frontend, KEEP $session->claimToken on the server.
$_SESSION['tp_sid'] = $session->sid;
$_SESSION['tp_claim'] = $session->claimToken;
echo json_encode(['trustport_sid' => $session->sid]);
// Later (after the widget reports onApproved):
$result = $tp->verifySession([
'sid' => $_SESSION['tp_sid'],
'claimToken' => $_SESSION['tp_claim'],
]);
if ($result->ok) {
// $result->subject is the verified user. Now upgrade your PHP session.
$_SESSION['user_id'] = $userId;
}
$session->sid // string — give to the frontend / widget
$session->claimToken // string — SERVER ONLY
$session->verifyUrl // string
$session->qrUrl // string
$session->expiresAt // DateTimeImmutable