1. Go to this page and download the library: Download authn-sh/sdk-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/ */
authn-sh / sdk-php example snippets
use Authn\Sdk\Client;
$client = new Client(secretKey: $_ENV['AUTHN_SECRET_KEY']);
$user = $client->users()->get('user_2x4yT…');
$session = $client->sessions()->revoke('sess_…');
$invite = $client->invitations()->create(['email_address' => '[email protected]']);
use Authn\Sdk\Client;
use GuzzleHttp\Client as Guzzle;
$client = new Client(
secretKey: $_ENV['AUTHN_SECRET_KEY'],
apiUrl: 'https://api.authn.sh',
http: new Guzzle(['timeout' => 5]),
logger: $psr3Logger,
);
use Authn\Sdk\Tokens\TokenVerifier;
use Authn\Sdk\Tokens\TokenInvalidException;
$verifier = new TokenVerifier(
publishableKey: $_ENV['AUTHN_PUBLISHABLE_KEY'], // pk_test_… / pk_live_…
cache: $psr16Cache, // optional PSR-16 cache for JWKS
);
try {
$claims = $verifier->verify($jwt); // throws TokenInvalidException
// or: $claims = $verifier->tryVerify($jwt); // returns null on failure
$userId = $claims->sub; // user_…
$sessionId = $claims->sid; // sess_…
} catch (TokenInvalidException $e) {
// 401 the request
}
// Optional: enforce origin binding via the azp claim.
$claims = $verifier->verify($jwt, expectedAzp: ['https://app.acme.com']);
use Authn\Sdk\Resources\SystemPermissions;
$claims = $verifier->verify($jwt);
if ($claims->organization !== null) {
$org = $claims->organization;
$org->id; // 'org_…'
$org->slug; // 'acme' or null
$org->role; // 'org:admin' or null
$org->permissions; // ['org:sys_profile:read', …]
$org->hasRole('org:admin');
$org->hasPermission(SystemPermissions::ORG_SYS_PROFILE_READ);
}
// Convenience shortcuts directly on VerifiedClaims:
$claims->hasRole('org:admin');
$claims->hasPermission(SystemPermissions::ORG_SYS_PROFILE_MANAGE);
$claims = $verifier->verify($jwt);
// Gate sensitive operations to passkey-authenticated sessions.
if (! $claims->wasVerifiedByPasskey()) {
abort(403, 'Sensitive operation
use Authn\Sdk\Webhooks\SignatureVerifier;
use Authn\Sdk\Webhooks\SignatureInvalidException;
// One signing secret, or many during a rotation overlap window.
$verifier = new SignatureVerifier($_ENV['AUTHN_WEBHOOK_SECRET']);
try {
$event = $verifier->verify($rawBody, $request->getHeaders()); // throws SignatureInvalidException
if ($event->type === 'user.created') {
// $event->data carries the resource payload
}
} catch (SignatureInvalidException $e) {
// 401 the request
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.