PHP SDK
The passkeybase/passkeybase-php package provides a PHP client for the PasskeyBase Management API. Manage users, credentials, apps, roles, and enrollment tokens from your PHP backend.
Installation
Install via Composer:
Terminal
composer require passkeybase/passkeybase-phpQuick Start
Initialize the client with your Management API key and tenant domain, then make your first API call.
index.php
<?php
require_once 'vendor/autoload.php';
use PasskeyBase\PasskeyBaseClient;
$client = new PasskeyBaseClient([
'api_key' => 'YOUR_MANAGEMENT_API_KEY',
'domain' => 'myapp.auth.ing',
]);
// List all users
$users = $client->users()->list();
foreach ($users->data as $user) {
echo "{$user->id}: {$user->display_name}\n";
}User Management
Create User
Create a user
$user = $client->users()->create([
'external_id' => 'user_123',
'display_name' => 'Jane Doe',
]);
echo "Created user: {$user->id}\n";List Users
List users with pagination
// List with pagination
$users = $client->users()->list([
'page' => 1,
'per_page' => 20,
]);
foreach ($users->data as $user) {
echo "{$user->id}: {$user->display_name}\n";
}
echo "Total: {$users->pagination->total}\n";Get User
Get a user by ID
$user = $client->users()->get('usr_abc123');
echo "Name: {$user->display_name}\n";
echo "Passkeys: {$user->passkey_count}\n";
echo "Last login: {$user->last_login_at}\n";Update User
Update a user
$user = $client->users()->update('usr_abc123', [
'display_name' => 'Jane Smith',
]);
echo "Updated: {$user->display_name}\n";Delete User
Deletes a user and all their associated passkeys.
Delete a user
$client->users()->delete('usr_abc123');Block / Unblock User
Block and unblock
// Block a user (prevents authentication)
$client->users()->block('usr_abc123');
// Unblock a user
$client->users()->unblock('usr_abc123');Credential Management
List Credentials
List all passkey credentials for a specific user.
List credentials
$credentials = $client->credentials()->list('usr_abc123');
foreach ($credentials->data as $cred) {
echo "{$cred->id}: {$cred->device_name} ({$cred->authenticator_type})\n";
}Delete Credential
Revoke a specific passkey credential.
Delete a credential
$client->credentials()->delete('usr_abc123', 'pk_xyz789');Client / App Management
Create App
Create an OAuth app
$app = $client->apps()->create([
'name' => 'My Mobile App',
'redirect_uris' => ['myapp://callback'],
]);
echo "Client ID: {$app->id}\n";Rotate Secret
Rotate client secret
$secret = $client->apps()->rotateSecret('pk_live_abc123');
echo "New secret: {$secret->client_secret}\n";Role Management
Create Role
Create a role
$role = $client->roles()->create([
'name' => 'admin',
'description' => 'Administrator role',
]);
echo "Role ID: {$role->id}\n";Assign Users
Assign users to a role
$client->roles()->assignUser('role_abc123', 'usr_abc123');
// List users in a role
$users = $client->roles()->listUsers('role_abc123');
foreach ($users->data as $user) {
echo "{$user->id}: {$user->display_name}\n";
}Enrollment Tokens
Generate a one-time token for enrolling a passkey for an existing user. See the Enrollment guide for the full flow.
Create enrollment token
$token = $client->enrollmentTokens()->create([
'external_id' => 'user_123',
'display_name' => 'Jane Doe',
'expires_in' => 3600,
]);
echo "Token: {$token->token}\n";
echo "Expires: {$token->expires_at}\n";
// Return this token to your frontend for passkey enrollmentError Handling
API errors throw a PasskeyBaseExceptionwith structured error information.
Error handling
<?php
use PasskeyBase\PasskeyBaseClient;
use PasskeyBase\Exceptions\PasskeyBaseException;
$client = new PasskeyBaseClient([
'api_key' => 'YOUR_MANAGEMENT_API_KEY',
'domain' => 'myapp.auth.ing',
]);
try {
$user = $client->users()->get('usr_nonexistent');
} catch (PasskeyBaseException $e) {
echo "Error: {$e->getError()}\n"; // "not_found"
echo "Message: {$e->getMessage()}\n"; // "User not found"
echo "Status: {$e->getStatus()}\n"; // 404
}Configuration Options
Configuration
$client = new PasskeyBaseClient([
'api_key' => 'YOUR_MANAGEMENT_API_KEY', // Required. Management API key.
'domain' => 'myapp.auth.ing', // Required. Your tenant domain.
'timeout' => 30, // Optional. Request timeout in seconds. Default: 10.
'max_retries' => 3, // Optional. Max retry attempts. Default: 2.
'base_url' => 'https://custom.url', // Optional. Override API base URL.
]);| Option | Type | Required | Description |
|---|---|---|---|
api_key | string | Yes | Your Management API key from the dashboard. |
domain | string | Yes | Your tenant domain (e.g., myapp.auth.ing). |
timeout | int | No | Request timeout in seconds. Default: 10. |
max_retries | int | No | Maximum retry attempts. Default: 2. |
base_url | string | No | Override the API base URL. |