View Consent Logs from your Application
When the consent logging is enabled on the Affinidi Iota Configuration, the Affinidi TDK provides a client to get the consent logs stored on your project and parse them from your application.
To do this, we will use the DefaultApi
of the Affinidi Iota Framework client. Follow the sample code below to learn how to integrate this.
- Install the required libraries (in our example, we will use Affinidi Iota Framework Service).
npm install -S @affinidi-tdk/auth-provider @affinidi-tdk/iota-client
pip install affinidi_tdk_auth_provider affinidi_tdk_iota_client
composer require affinidi-tdk/affinidi-tdk-php
- Import the libraries into the code. We are importing the Iota client (Affinidi Iota Framework Service) to get the list of consents and the Auth Provider to generate the Project Scoped Token for the Authorisation header.
import { DefaultApi, Configuration as AuthConfiguration } from '@affinidi-tdk/iota-client'
import { AuthProvider } from '@affinidi-tdk/auth-provider'
import affinidi_tdk_auth_provider
import affinidi_tdk_iota_client
require_once 'vendor/autoload.php';
use AffinidiTdk\AuthProvider\AuthProvider;
use AffinidiTdk\Clients\IotaClient;
- Generate an Authorisation token to call the client using the Personal Access Token for the specific project.
Use the Affinidi CLI Token command to generate the Personal Access Token (PAT) required by the auth-provider
module.
If you have created the Personal Access Token (PAT) with the
--key-id
flag in Affinidi CLI, you must also set thekeyId
with the supplied value in the AuthProvider class.
// NOTE: set your variables for PAT
const privateKey = '<PRIVATE_KEY_STRING>'
const passphrase = '<KEY_PAIR_PASSPHRASE>'
const tokenId = '<PAT_ID>'
const projectId = '<PROJECT_ID>'
const authProvider = new AuthProvider({
privateKey,
passphrase,
tokenId,
projectId
})
const authConfiguration = new AuthConfiguration({
apiKey: authProvider.fetchProjectScopedToken.bind(authProvider)
})
stats = {
'privateKey': '<PRIVATE_KEY_STRING>',
'passphrase': '<KEY_PAIR_PASSPHRASE>',
'tokenId': '<PAT_ID>',
'projectId': '<PROJECT_ID>'
}
authProvider = affinidi_tdk_auth_provider.AuthProvider(stats)
projectScopedToken = authProvider.fetch_project_scoped_token()
configuration = affinidi_tdk_credential_verification_client.Configuration()
# Configure API key authorization: ProjectTokenAuth
configuration.api_key['ProjectTokenAuth'] = projectScopedToken
$params = [
'privateKey' => "<PAT_PRIVATE_KEY_STRING>",
'passphrase' => '<PAT_KEY_PAIR_PASSPHRASE>',
'tokenId' => '<PAT_ID>',
'projectId' => '<PROJECT_ID>'
];
$authProvider = new AuthProvider($params);
$tokenCallback = [$authProvider, 'fetchProjectScopedToken'];
- Initialise the Iota client module with the authorisation header and call the client method.
const api = new DefaultApi(authConfiguration)
const { data } = await api.listLoggedConsents()
with affinidi_tdk_iota_client.ApiClient(configuration) as api_client:
api_instance = affinidi_tdk_iota_client.DefaultApi(api_client)
api_response = api_instance.list_logged_consents()
// Configure API key authorization: ProjectTokenAuth
$config = IotaClient\Configuration::getDefaultConfiguration()->setApiKey('authorization', '', $tokenCallback);
$apiInstance = new IotaClient\Api\DefaultApi(
new GuzzleHttp\Client(),
$config
);
try {
$result = $apiInstance->listLoggedConsents();
print_r($result);
} catch (Exception $e) {
echo 'Exception when calling method: ', $e->getMessage(), PHP_EOL;
}
The Iota client call to get list of consent will return the following JSON response:
{
"consents": [
{
"projectId": "af338c39-2201-49a6-90d2-106c6cbbbcb7",
"id": "4e0cb4cb-e7fc-4a06-bc1e-8724dffff4db",
"userId": "did:key:zQ3shnYYaYpKHEEsE8HirxBM3MFFR6Ubpjixdm5EET4ihug6l",
"vcType": "Membership",
"status": "GIVEN",
"modifiedAt": "2024-07-02T05:12:22.000Z",
"modifiedBy": "",
"createdAt": "2024-07-02T05:12:22.000Z",
"createdBy": ""
}
],
"lastEvaluatedKey": ""
}
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.