IAM
Install Dependency
Package: affinidi-tdk/affinidi-tdk-php
composer require affinidi-tdk/affinidi-tdk-phpCheck the latest version on the Packagist repository or view the source on GitHub.
Classes and Methods
Projects API
Use the Projects API to manage your projects including providing access to other users on your projects.
addPrincipalToProject
Adds a principal to the project to grant access.
Parameters
user or token).Example
require_once 'vendor/autoload.php';
use AffinidiTdk\Clients\IamClient;
$tokenCallback = [$authProvider, 'fetchProjectScopedToken'];
$config = IamClient\Configuration::getDefaultConfiguration()->setApiKey('authorization', '', $tokenCallback);
$apiInstance = new IamClient\Api\ProjectsApi(new GuzzleHttp\Client(), $config);
try {
$request = array(
'principalId' => '<PAT_ID>',
'principalType' => 'token',
);
$result = $apiInstance->addPrincipalToProject($request);
print_r($result);
} catch (Exception $e) {
echo 'Exception: ', $e->getMessage(), PHP_EOL;
}createProject
Creates a project for your account.
Parameters
Example
require_once 'vendor/autoload.php';
use AffinidiTdk\Clients\IamClient;
$tokenCallback = [$authProvider, 'fetchProjectScopedToken'];
$config = IamClient\Configuration::getDefaultConfiguration()->setApiKey('authorization', '', $tokenCallback);
$apiInstance = new IamClient\Api\ProjectsApi(new GuzzleHttp\Client(), $config);
try {
$request = array(
'name' => 'project_name',
'description' => 'project_description',
);
$result = $apiInstance->createProject($request);
print_r($result);
} catch (Exception $e) {
echo 'Exception: ', $e->getMessage(), PHP_EOL;
}deletePrincipalFromProject
Removes a principal (user or PAT) from the project to revoke access.
Parameters
principalId
string
RequiredprincipalType
string
Requireduser for a user or token for a PAT.Example
require_once 'vendor/autoload.php';
use AffinidiTdk\Clients\IamClient;
$tokenCallback = [$authProvider, 'fetchProjectScopedToken'];
$config = IamClient\Configuration::getDefaultConfiguration()->setApiKey('authorization', '', $tokenCallback);
$apiInstance = new IamClient\Api\ProjectsApi(new GuzzleHttp\Client(), $config);
try {
$result = $apiInstance->deletePrincipalFromProject('<PAT_ID>', 'token');
print_r($result);
} catch (Exception $e) {
echo 'Exception: ', $e->getMessage(), PHP_EOL;
}listPrincipalsOfProject
Returns the list of principals assigned to the project.
No parameters required.
Example
require_once 'vendor/autoload.php';
use AffinidiTdk\Clients\IamClient;
$tokenCallback = [$authProvider, 'fetchProjectScopedToken'];
$config = IamClient\Configuration::getDefaultConfiguration()->setApiKey('authorization', '', $tokenCallback);
$apiInstance = new IamClient\Api\ProjectsApi(new GuzzleHttp\Client(), $config);
try {
$result = $apiInstance->listPrincipalsOfProject();
print_r($result);
} catch (Exception $e) {
echo 'Exception: ', $e->getMessage(), PHP_EOL;
}listProject
Returns the list of projects.
No parameters required.
Example
require_once 'vendor/autoload.php';
use AffinidiTdk\Clients\IamClient;
$tokenCallback = [$authProvider, 'fetchProjectScopedToken'];
$config = IamClient\Configuration::getDefaultConfiguration()->setApiKey('authorization', '', $tokenCallback);
$apiInstance = new IamClient\Api\ProjectsApi(new GuzzleHttp\Client(), $config);
try {
$result = $apiInstance->listProject();
print_r($result);
} catch (Exception $e) {
echo 'Exception: ', $e->getMessage(), PHP_EOL;
}updateProject
Updates the project details.
Parameters
projectId
string
RequiredExample
require_once 'vendor/autoload.php';
use AffinidiTdk\Clients\IamClient;
$tokenCallback = [$authProvider, 'fetchProjectScopedToken'];
$config = IamClient\Configuration::getDefaultConfiguration()->setApiKey('authorization', '', $tokenCallback);
$apiInstance = new IamClient\Api\ProjectsApi(new GuzzleHttp\Client(), $config);
try {
$request = array(
'name' => 'project_name',
'description' => 'project_description',
);
$result = $apiInstance->updateProject('<PROJECT_ID>', $request);
print_r($result);
} catch (Exception $e) {
echo 'Exception: ', $e->getMessage(), PHP_EOL;
}Policies API
Use the Policies API to manage access to your projects and related resources for other users.
getPolicies
Retrieves the policy attached to a principal.
Parameters
principalId
string
RequiredprincipalType
string
Requireduser for a user or token for a PAT.Example
require_once 'vendor/autoload.php';
use AffinidiTdk\Clients\IamClient;
$tokenCallback = [$authProvider, 'fetchProjectScopedToken'];
$config = IamClient\Configuration::getDefaultConfiguration()->setApiKey('authorization', '', $tokenCallback);
$apiInstance = new IamClient\Api\PoliciesApi(new GuzzleHttp\Client(), $config);
try {
$result = $apiInstance->getPolicies('<PAT_ID>', 'token');
print_r($result);
} catch (Exception $e) {
echo 'Exception: ', $e->getMessage(), PHP_EOL;
}updatePolicies
Updates the policy for a principal.
Parameters
principalId
string
RequiredprincipalType
string
Requireduser for a user or token for a PAT.Example
require_once 'vendor/autoload.php';
use AffinidiTdk\Clients\IamClient;
$tokenCallback = [$authProvider, 'fetchProjectScopedToken'];
$config = IamClient\Configuration::getDefaultConfiguration()->setApiKey('authorization', '', $tokenCallback);
$apiInstance = new IamClient\Api\PoliciesApi(new GuzzleHttp\Client(), $config);
try {
$request = array(
'version' => '2022-12-15',
'statement' => array(
array(
'principal' => array('<PRINCIPAL_ID>'),
'action' => array(),
'resource' => array(),
'effect' => 'Allow',
),
),
);
$result = $apiInstance->updatePolicies('<PAT_ID>', 'token', $request);
print_r($result);
} catch (Exception $e) {
echo 'Exception: ', $e->getMessage(), PHP_EOL;
}Secure Token Exchange (STS) API
Use the STS (Secure Token Exchange) API to create a Project Scoped Token and get the current session information.
createProjectScopedToken
Creates a project scoped token to access resources in the project.
Parameters
Example
require_once 'vendor/autoload.php';
use AffinidiTdk\Clients\IamClient;
$tokenCallback = [$authProvider, 'fetchProjectScopedToken'];
$config = IamClient\Configuration::getDefaultConfiguration()->setApiKey('authorization', '', $tokenCallback);
$apiInstance = new IamClient\Api\StsApi(new GuzzleHttp\Client(), $config);
try {
$request = array(
'projectId' => '<PROJECT_ID>',
);
$result = $apiInstance->createProjectScopedToken($request);
print_r($result);
} catch (Exception $e) {
echo 'Exception: ', $e->getMessage(), PHP_EOL;
}whoami
Retrieves the principal information of the current user.
No parameters required.
Example
require_once 'vendor/autoload.php';
use AffinidiTdk\Clients\IamClient;
$tokenCallback = [$authProvider, 'fetchProjectScopedToken'];
$config = IamClient\Configuration::getDefaultConfiguration()->setApiKey('authorization', '', $tokenCallback);
$apiInstance = new IamClient\Api\StsApi(new GuzzleHttp\Client(), $config);
try {
$result = $apiInstance->whoami();
print_r($result);
} catch (Exception $e) {
echo 'Exception: ', $e->getMessage(), PHP_EOL;
}Tokens API
Use the Tokens API to create a Personal Access Token (PAT) to call Affinidi services on your behalf. Alternatively, use the Token command from Affinidi CLI.
createToken
Creates a Personal Access Token.
Parameters
Example
require_once 'vendor/autoload.php';
use AffinidiTdk\Clients\IamClient;
$tokenCallback = [$authProvider, 'fetchProjectScopedToken'];
$config = IamClient\Configuration::getDefaultConfiguration()->setApiKey('authorization', '', $tokenCallback);
$apiInstance = new IamClient\Api\TokensApi(new GuzzleHttp\Client(), $config);
try {
$jwks = array(
'keys' => array(
array(
'kty' => '<KEY_TYPE>',
'n' => '<KEY_N>',
'e' => '<KEY_E>',
'alg' => '<ALGORITHM>',
'kid' => '<KID>',
'use' => 'sig',
),
),
);
$request = array(
'name' => 'token_name',
'authenticationMethod' => array(
'type' => 'PRIVATE_KEY',
'signingAlgorithm' => '<ALGORITHM>',
'publicKeyInfo' => array(
'jwks' => $jwks,
),
),
);
$result = $apiInstance->createToken($request);
print_r($result);
} catch (Exception $e) {
echo 'Exception: ', $e->getMessage(), PHP_EOL;
}deleteToken
Deletes a Personal Access Token.
Parameters
tokenId
string
RequiredExample
require_once 'vendor/autoload.php';
use AffinidiTdk\Clients\IamClient;
$tokenCallback = [$authProvider, 'fetchProjectScopedToken'];
$config = IamClient\Configuration::getDefaultConfiguration()->setApiKey('authorization', '', $tokenCallback);
$apiInstance = new IamClient\Api\TokensApi(new GuzzleHttp\Client(), $config);
try {
$result = $apiInstance->deleteToken('<TOKEN_ID>');
print_r($result);
} catch (Exception $e) {
echo 'Exception: ', $e->getMessage(), PHP_EOL;
}getToken
Retrieves the Personal Access Token details.
Parameters
tokenId
string
RequiredExample
require_once 'vendor/autoload.php';
use AffinidiTdk\Clients\IamClient;
$tokenCallback = [$authProvider, 'fetchProjectScopedToken'];
$config = IamClient\Configuration::getDefaultConfiguration()->setApiKey('authorization', '', $tokenCallback);
$apiInstance = new IamClient\Api\TokensApi(new GuzzleHttp\Client(), $config);
try {
$result = $apiInstance->getToken('<TOKEN_ID>');
print_r($result);
} catch (Exception $e) {
echo 'Exception: ', $e->getMessage(), PHP_EOL;
}listToken
Returns the list of Personal Access Tokens.
No parameters required.
Example
require_once 'vendor/autoload.php';
use AffinidiTdk\Clients\IamClient;
$tokenCallback = [$authProvider, 'fetchProjectScopedToken'];
$config = IamClient\Configuration::getDefaultConfiguration()->setApiKey('authorization', '', $tokenCallback);
$apiInstance = new IamClient\Api\TokensApi(new GuzzleHttp\Client(), $config);
try {
$result = $apiInstance->listToken();
print_r($result);
} catch (Exception $e) {
echo 'Exception: ', $e->getMessage(), PHP_EOL;
}updateToken
Updates an existing Personal Access Token.
Parameters
tokenId
string
RequiredExample
require_once 'vendor/autoload.php';
use AffinidiTdk\Clients\IamClient;
$tokenCallback = [$authProvider, 'fetchProjectScopedToken'];
$config = IamClient\Configuration::getDefaultConfiguration()->setApiKey('authorization', '', $tokenCallback);
$apiInstance = new IamClient\Api\TokensApi(new GuzzleHttp\Client(), $config);
try {
$jwks = array(
'keys' => array(
array(
'kty' => '<KEY_TYPE>',
'n' => '<KEY_N>',
'e' => '<KEY_E>',
'alg' => '<ALGORITHM>',
'kid' => '<KID>',
'use' => 'sig',
),
),
);
$request = array(
'name' => 'token_name',
'authenticationMethod' => array(
'type' => 'PRIVATE_KEY',
'signingAlgorithm' => '<ALGORITHM>',
'publicKeyInfo' => array(
'jwks' => $jwks,
),
),
);
$result = $apiInstance->updateToken('<TOKEN_ID>', $request);
print_r($result);
} catch (Exception $e) {
echo 'Exception: ', $e->getMessage(), PHP_EOL;
}Glad to hear it! Please tell us how we can improve more.
Sorry to hear that. Please tell us how we can improve.
Thank you for sharing your feedback so we can improve your experience.