PHP code example of eko / authz-sdk

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

    

eko / authz-sdk example snippets



use Eko\AuthzSdk\Client;

$client = new Client('localhost:8081', '<client_id>', '<client_secret>');

[$response, $status] = $client->PrincipalCreate(new PrincipalCreateRequest([
    'id' => 'user-123',
    'attributes' => [
        new Attribute(['key' => 'email', 'value' => '[email protected]']),
    ],
]))->wait();

[$response, $status] = $client->ResourceCreate(new ResourceCreateRequest([
    'id' => 'post.123',
    'kind' => 'post',
    'value' => '123',
    'attributes' => [
        new Attribute(['key' => 'owner_email', 'value' => '[email protected]']),
    ],
]))->wait();

[$response, $status] = $client->PolicyCreate(new PolicyCreateRequest([
    'id' => 'post-owners',
    'resources' => ['post.*'],
    'actions' => ['edit', 'delete'],
    'attribute_rules' => [
        'principal.email == resource.owner_email',
    ],
]))->wait();

if ($client->IsAllowed('user-123', 'post', '123', 'edit')) {
    // Do something
}