Auth Provider

Generate Authorisation Token to call Affinidi Services.

Install Dependency

Package: @affinidi-tdk/auth-provider

npm install @affinidi-tdk/auth-provider --save

Check the latest version on the npm registry or view the source on GitHub.

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

Generates the Project Scoped Token required for calling Affinidi services.

When instantiating the AuthProvider class, provide the Personal Access Token (PAT) information including the private key to generate the authorisation token.

Constructor parameters

tokenId string Required
ID of the Personal Access Token (PAT).
privateKey string Required
Private key string used to sign the token.
passphrase string Optional
Passphrase of the private key, if configured.
projectId string Required
Project ID to generate the token for.

Example

import { AuthProvider } from '@affinidi-tdk/auth-provider'

const authProvider = new AuthProvider({
  privateKey: '<PAT_PRIVATE_KEY_STRING>',
  passphrase: '<PAT_KEY_PAIR_PASSPHRASE>',
  tokenId: '<PAT_ID>',
  projectId: '<PROJECT_ID>',
})

fetchProjectScopedToken

Returns the Project Scoped Token used to call Affinidi Services.

No parameters required.

Example

import { AuthProvider } from '@affinidi-tdk/auth-provider'

const authProvider = new AuthProvider({
  privateKey: '<PAT_PRIVATE_KEY_STRING>',
  passphrase: '<PAT_KEY_PAIR_PASSPHRASE>',
  tokenId: '<PAT_ID>',
  projectId: '<PROJECT_ID>',
})

const projectScopedToken = await authProvider.fetchProjectScopedToken()

createIotaToken

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

Parameters

iotaConfigId string Required
ID of the Iota configuration.
did string Required
DID of the logged-in user, obtained from the ID Token provided by Affinidi Login.
iotaSessionId string Optional
ID of the initialised Iota session.

Example

import { AuthProvider } from '@affinidi-tdk/auth-provider'

const authProvider = new AuthProvider({
  privateKey: '<PAT_PRIVATE_KEY_STRING>',
  passphrase: '<PAT_KEY_PAIR_PASSPHRASE>',
  tokenId: '<PAT_ID>',
  projectId: '<PROJECT_ID>',
})

const iotaToken = await authProvider.createIotaToken('<IOTA_CONFIGURATION_ID>', '<LOGGED_IN_USER_DID>')