View Consent Logs from your Application

Get the consent logs from the Affinidi Iota Framework stored on your project 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.

  1. 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
  1. 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
  1. 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 the keyId 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
  1. 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()

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": "UniversityDegree2024",
      "status": "GIVEN",
      "modifiedAt": "2024-07-02T05:12:22.000Z",
      "modifiedBy": "",
      "createdAt": "2024-07-02T05:12:22.000Z",
      "createdBy": ""
    }
  ],
  "lastEvaluatedKey": ""
}