Auth Provider

Generate Authorisation Token to call Affinidi Services.

Install Dependency

Package: affinidi-tdk/affinidi-tdk-php

composer require affinidi-tdk/affinidi-tdk-php

You can check the latest version of this module on the Packagist repository or view the source code at the GitHub repository.

API Endpoints

URLs required to initiate integration with Affinidi TDK.

Token Endpoint

Endpoint to generate access token to call Affinidi Services with TDK.


https://apse1.auth.developer.affinidi.io/auth/oauth2/token

API Gateway URL

Base API URL of Affinidi Services.


https://apse1.api.affinidi.io

Classes and Methods

AuthProvider API

Used to generate Project Scoped Token required for calling Affinidi services (Clients).

When initiating the AuthProvider class, provide the Token information including the public/private key information to generate the Authorisation Token required.

Required Parameters

  • tokenId: ID of the Personal Access Token (PAT). Use TOKEN_ID as the environment variable for Java.
  • passphrase: Passphrase of the Private key if configured. Use PASSPHRASE as the environment variable for Java.
  • privateKey: Private key string to use to sign the token. Use PRIVATE_KEY as the environment variable for Java.
  • projectId: Project ID to generate the Token. Use PROJECT_ID as the environment variable for Java.
Example

require_once 'vendor/autoload.php';

use AffinidiTdk\AuthProvider\AuthProvider;

$params = [
  'privateKey' => "<PAT_PRIVATE_KEY_STRING>",
  'passphrase' => '<PAT_KEY_PAIR_PASSPHRASE>',
  'tokenId' => '<PAT_ID>',
  'projectId' => '<PROJECT_ID>'
];

$authProvider = new AuthProvider($params);

// this is optional, another option to fetch the ProjectScopedToken is through callback
$projectScopedToken = $authProvider->fetchProjectScopedToken();

// $tokenCallback = [$authProvider, 'fetchProjectScopedToken'];

fetchProjectScopedToken

Return the generated Project Scoped Token to use for calling the Affinidi Services.

Parameters

No Parameters Required

Example

require_once 'vendor/autoload.php';

use AffinidiTdk\AuthProvider\AuthProvider;

$params = [
  'privateKey' => "<PAT_PRIVATE_KEY_STRING>",
  'passphrase' => '<PAT_KEY_PAIR_PASSPHRASE>',
  'tokenId' => '<PAT_ID>',
  'projectId' => '<PROJECT_ID>'
];

$authProvider = new AuthProvider($params);

// this is optional, another option to fetch the ProjectScopedToken is through callback
$projectScopedToken = $authProvider->fetchProjectScopedToken();

createIotaToken

Create an Affinidi Iota Framework token to generate the Iota Credentials to sign request token.

Parameters

iotaConfigId [String]

The ID of the Iota Configuration.

did [String]

The DID of the logged-in user which is obtained from the ID Token provided by the Affinidi Login. You can explore our Labs to learn how to integrate Affinidi Login into different programming languages and frameworks.

iotaSessionId [String]

The ID of the initialised Iota session. This parameter is optional.

Example

require_once 'vendor/autoload.php';

use AffinidiTdk\AuthProvider\AuthProvider;

$params = [
  'privateKey' => "<PAT_PRIVATE_KEY_STRING>",
  'passphrase' => '<PAT_KEY_PAIR_PASSPHRASE>',
  'tokenId' => '<PAT_ID>',
  'projectId' => '<PROJECT_ID>'
];

$authProvider = new AuthProvider($params);

$iotaConfigurationId = "<IOTA_CONFIGURATION_ID>"
$userDid = "<LOGGED_IN_USER_DID>"

$iotaToken = $authProvider->createIotaToken($iotaConfigurationId, $userDid);