Installation & configuration
anikeen/id is the PHP client for the Anikeen ID API, shipped as a Laravel package. It covers OAuth login (a Socialite provider), an API token guard, the billing API and webhook verification.
Requirements: PHP 8.2+, Laravel 12 or 13.
Install
composer require anikeen/idThe service provider and the AnikeenId facade are registered automatically.
Configure
Register your app first, then add its credentials to .env:
ANIKEEN_ID_KEY=
ANIKEEN_ID_SECRET=
ANIKEEN_ID_CALLBACK_URL=http://localhost/auth/callback
ANIKEEN_ID_WEBHOOK_SECRET=To switch from production to staging:
ANIKEEN_ID_MODE=stagingAdd an entry to config/services.php, so the configuration is still available after php artisan config:cache:
'anikeen' => [
'mode' => env('ANIKEEN_ID_MODE'),
'client_id' => env('ANIKEEN_ID_KEY'),
'client_secret' => env('ANIKEEN_ID_SECRET'),
'redirect' => env('ANIKEEN_ID_CALLBACK_URL'),
'base_url' => env('ANIKEEN_ID_BASE_URL'),
'webhook_secret' => env('ANIKEEN_ID_WEBHOOK_SECRET'),
],| Key | |
|---|---|
mode | production (default) or staging; picks the base URL and the bundled public key |
client_id, client_secret | your OAuth client |
redirect | your callback URL (a registered redirect URI) |
base_url | overrides the base URL, e.g. for a local Anikeen ID instance |
webhook_secret | the signing secret whsec_… of your webhook endpoint |
The API token guard has more options under the same key.
The client
Anikeen\Id\AnikeenId is the API client, registered as a singleton:
$anikeenId = app(\Anikeen\Id\AnikeenId::class);
// or the facade
use Anikeen\Id\Facades\AnikeenId;Setters and immutable variants:
$anikeenId = new Anikeen\Id\AnikeenId();
$anikeenId->setClientId('abc123');
$anikeenId->setClientSecret('abc456');
$anikeenId->setToken('abcdef123456');
$anikeenId = $anikeenId->withClientId('abc123');
$anikeenId = $anikeenId->withClientSecret('abc123');
$anikeenId = $anikeenId->withToken('abcdef123456');
$user = $anikeenId->withToken('uvwxyz456789')->getAuthedUser()->shift();
AnikeenId::withToken('abcdef123456')->getAuthedUser();Methods of trusted apps (app*(), createChargeForUser(), findUserById(), …) fetch and cache the app's own token (client credentials) themselves; asApp() returns a copy of the client that uses it.
Results and resources
Low-level methods on AnikeenId (e.g. getAuthedUser(), createOrderPreview(), refreshToken()) return a Result. Check it before you use it:
$result = $anikeenId->getAuthedUser();
if (! $result->success()) {
die('Ooops: ' . $result->error());
}
$user = $result->shift(); // the object, or the first item of a listResource methods ($user->orders(), $anikeenId->sshKeysByUserId(), …) return objects and throw an ApiException instead, see Errors.