PHP code example of vanta / esia-gateway-client

1. Go to this page and download the library: Download vanta/esia-gateway-client 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/ */

    

vanta / esia-gateway-client example snippets


use GuzzleHttp\Psr7\HttpFactory;
use Symfony\Component\HttpClient\CurlHttpClient;
use Symfony\Component\HttpClient\Psr18Client;
use Vanta\Integration\EsiaGateway\RestClientBuilder;
use Vanta\Integration\EsiaGateway\Infrastructure\HttpClient\ConfigurationClient;

$builder = RestClientBuilder::create(
    new Psr18Client(new CurlHttpClient(), new HttpFactory(), new HttpFactory()),
    new ConfigurationClient(
        clientId: 'YOUR_CLIENT_ID',
        clientSecret: 'YOUR_CLIENT_SECRET',
        url: 'YOUR_URL_GATEWAY',
        redirectUri: 'https://auth.vanta.ru'
    )
);

$client = $builder->createEsiaGatewayClient('https://demo.gate.esia.pro', 'https://pos-credit.ru');

$authorizationUrl = $builder->createAuthorizationUrlBuilder()
    ->withPermission(ScopePermission::DRIVERS_LICENSE_DOC)
    ->withoutPermission(ScopePermission::MOBILE)
    ->build()
;

$accessToken = $client->getPairKeyByAuthorizationCode($code);

$accessToken = $client->getPairKeyByRefreshToken($refreshToken);

$userInfo = $client->getUserInfo($accessToken);