PHP code example of identio / php-sdk

1. Go to this page and download the library: Download identio/php-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/ */

    

identio / php-sdk example snippets




use Identio\Sdk\Config\IdentioConfig;
use Identio\Sdk\IdentioClient;

$identio = new IdentioClient(new IdentioConfig(
    baseUrl: 'https://identio.ru',
    domainId: 42,
    apiToken: $_ENV['IDENTIO_API_TOKEN'],
    apiSecret: $_ENV['IDENTIO_API_SECRET'] ?? null,
));

$result = $identio->auth->register(
    email: '[email protected]',
    password: 'secret-password',
    values: [],
);

$result = $identio->auth->confirm($_GET['code']);

if ($result->isAuthenticated()) {
    $jwt = $result->token;
    $identioUser = $result->user;
}

$result = $identio->auth->login('[email protected]', 'secret-password');

if ($result->isAuthenticated()) {
    $jwt = $result->token;
    $identioUser = $result->user;
} elseif ($result->isRejected()) {
    // Wrong credentials and other expected login rejections are normal results.
    $reason = $result->rejection?->message;
    $code = $result->rejection?->code;
}

$identio->auth->resendVerification('[email protected]');
$identio->auth->forgotPassword('[email protected]');
$identio->auth->resetPassword($code, $newPassword);
$identio->auth->updateSelf($userJwt, password: $newPassword, values: []);
$identio->auth->deleteSelf($userJwt);

use Identio\Sdk\Dto\ProfileValue;

$values = [
    ProfileValue::string(fieldId: 10, name: 'name', value: 'Igor'),
    ProfileValue::numeric(fieldId: 11, name: 'age', value: 58),
    ProfileValue::date(fieldId: 12, name: 'birthday', value: '1968-01-01'),
];

$user = $identio->auth->getUser(7);
$updated = $identio->auth->updateUser(7, [
    ProfileValue::string(fieldId: 88, name: 'role', value: 'support'),
]);

use Identio\Sdk\Enum\SocialProvider;
use Identio\Sdk\Social\NativeSessionStore;
use Identio\Sdk\Social\SocialFlowManager;

session_start();

$flow = new SocialFlowManager(
    client: $identio->social,
    session: new NativeSessionStore(),
);

$start = $flow->start(SocialProvider::Facebook);
header('Location: ' . $start->authorizeUrl);
exit;

$result = $flow->complete(
    provider: SocialProvider::Facebook,
    code: $_GET['code'] ?? null,
    state: $_GET['state'] ?? null,
    vkDeviceId: $_GET['device_id'] ?? null,
    providerError: $_GET['error'] ?? null,
);

$result = $identio->social->completeRegistration(
    provider: SocialProvider::Facebook,
    registrationToken: $result->registrationToken,
    values: $values,
);

use Identio\Sdk\Config\IdentioConfig;
use Identio\Sdk\IdentioClient;

$this->app->singleton(IdentioClient::class, static fn (): IdentioClient => new IdentioClient(
    new IdentioConfig(
        baseUrl: (string) config('services.identio.base_url'),
        domainId: (int) config('services.identio.domain_id'),
        apiToken: (string) config('services.identio.api_token'),
        apiSecret: config('services.identio.api_secret'),
    ),
));

$valid = $identio->socialProviderUpdateVerifier->verify(
    apiTokenHeader: $_SERVER['HTTP_X_USERID_API_TOKEN'] ?? '',
    signatureHeader: $_SERVER['HTTP_X_USERID_API_SIGNATURE'] ?? '',
    payload: $providerConfig,
);
bash
composer