PHP code example of ruwork / skolkovo-client

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

    

ruwork / skolkovo-client example snippets




declare(strict_types=1);

use Ruwork\SkolkovoClient\SkolkovoClient;
use Ruwork\SkolkovoClient\TokenStorage\FileTokenStorage;
use Ruwork\SkolkovoClient\Definition\SkolkovoDefinition;

$tokenStorage = new FileTokenStorage('path/to/token.json');

$client = new SkolkovoClient([
    'client_id' => 'client_id',
    'client_secret' => 'client_secret',
], [], new SkolkovoDefinition($tokenStorage));



declare(strict_types=1);

$url = $client->generateLoginUrl('your/redirect/url');



declare(strict_types=1);

use Ruwork\SkolkovoClient\TokenStorage\InstantTokenStorage;

$code = $_GET['code'];

$token = $client->oauthTokenCode()
    ->setCode($code)
    ->setRedirectUri('your/redirect/url')
    ->getResult();

$apiData = $client->info()
    ->setTokenStorage(new InstantTokenStorage($token))
    ->getResult();

var_dump($apiData['AccessingUser']);



declare(strict_types=1);

use Ruwork\SkolkovoClient\TokenStorage\InstantTokenStorage;

$client->request([
    'method' => 'GET',
    // адрес на стороне сервиса, обязательный параметр
    'endpoint' => '/oauth/token',
    // добавлять заголовки авторизации?
    'authenticate' => true,
    'data' => [
        'key' => 'value',
    ],
    'headers' => [
        'header' => 'value',
    ],
]);



declare(strict_types=1);

$token = $client
    ->oauthTokenPassword()
    ->setUsername('username')
    ->setPassword('password')
    ->getResult();

$tokenStorage->set($token);
bash
$ composer