PHP code example of jincor / auth-php-client

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

    

jincor / auth-php-client example snippets


$authClient = new AuthClient(new Client([
    'base_uri' => 'auth:3000',
    'headers' => [
        'Accept' => 'application/json',
        'Content-Type' => 'application/json',
    ]
]));

$tenant = $authClient->registerTenant('[email protected]', 'Passwpord');
echo $tenant->getId();
// 'af8b13ea-02a9-4e73-b8d9-58c8215757b9'
$tenantToken = $authClient->loginTenant('[email protected]', 'Passwpord');
$result = $authClient->verifyTenantToken($tenantToken);
echo $result->getAud();
// 'jincor.com'
$authClient->logoutTenant($tenantToken);

$userData = [
    'email' => '[email protected]',
    'password' => 'Password1',
    'login' => 'emp_dev',
    'sub' => '123',
    'scope' => [
        'admin',
        'settings' => 'setting',
    ]
];
$user = $authClient->createUser($userData, $tenantToken);
echo $user->getId();
// '55096b7d-0f14-446a-b50d-ee6bc8431e39'

$userData = [
    'login' => 'emp_dev',
    'password' => 'Password1',
    'deviceId' => '123',
];
$userToken = $authClient->loginUser($userData, $tenantToken);
$result = $authClient->verifyUserToken($userToken, $tenantToken);
$authClient->logoutUser($userToken, $tenantToken);

$authClient->deleteUser($userData['login'], $tenantToken);