@idpartner/trust-directory-api
TypeScript icon, indicating that this package has built-in type declarations

0.0.3 • Public • Published

@idpartner/trust-directory-api

@idpartner/trust-directory-api is an auto-generated Typescript HTTP client for interacting with the Trust Directory API.

Overview

This package provides a convenient way to integrate Trust Directory services, such as retrieving JWKS, OIDC client information, Trust packages, and creating verification events, into your OIDC Provider instance.

The package was generated using the openapi-generator/typescript-axios using the IDPartner Trust Directory OpenAPI spec. The UI for the OpenAPI spec can be found here.

To re-generate this library using the latest version of the openapi-generator/typescript-axios and the IDPartner Trust Directory OpenAPI spec run:

docker run --rm  --pull=always \
  -v ${PWD}:/trust-directory openapitools/openapi-generator-cli generate \
  -i https://api-docs.idpartner.com/trust-directory/raw.yml \
  -g typescript-axios \
  -o /trust-directory/ \
  --additional-properties withNodeImports=true \
  --additional-properties supportsES6=true \
  --additional-properties useSingleRequestParameter=true \
  --additional-properties apiPackage=api \
  --additional-properties modelPackage=models \
  --additional-properties withSeparateModelsAndApi=true

Installation

Install the package using npm:

npm install @idpartner/trust-directory-api

Or, if you prefer yarn, install the package running:

yarn add @idpartner/trust-directory-api

Usage

Import and initialize the client:

import { TrustDirectoryApi } from '@idpartner/trust-directory-api';

const trustDirectoryApi = TrustDirectoryApi();

If you already have an axios instance, you can specify it to avoid generating a new one:

import axios from 'axios';
import { TrustDirectoryApi } from '@idpartner/trust-directory-api';

const axiosClient = axios.create(customAxiosConfig);
const trustDirectoryApi = TrustDirectoryApi(undefined, undefined, axiosClient);

Examples

The initialization of some consts was ommited to make this shorter

import crypto from 'crypto';
import JOSEWrapper from '@idpartner/jose-wrapper';
import { VerificationEventRequestEventTypeEnum } from '@idpartner/trust-directory-api';

// These headers will be forwarded to the Trust Directory API
// as X-FAPI-Interaction-ID and X-Verification-ID. Log them on
// your end before sending them to IDPartner APIs.
const tracingHeaders = {
  xFAPIInteractionID,
  xVerificationID
};

// Generate a 1 minute valid auth token with all 
// claims required and the desired scope(s).
const authToken = await JOSEWrapper.createJWS({
  claims: {
    iss: oidcServiceURL,
    aud: trustDirectoryServiceURL,
    client_id: clientId,
    identity_provider_id: identityProviderId,
    idpartner_token: idpartnerToken,
    iat: Math.floor(Date.now() / 1000),
    exp: Math.floor((Date.now() / 1000) + 60),
    scope: 'clients:get trust_packages:get verification_events:create',
  }
}, jwks);

// Define custom axios config
const axiosConfig = {
  // Set request timeout to 30 seconds
  timeout: 30_000

  // Set custom headers
  headers: {
    'Content-Type': 'application/json',
    'Accept': 'application/json',
    'Authorization': authToken,
  },
};

// Retrieve JWKS (JSON Web Key Set)
await trustDirectoryApi.getJWKS(tracingHeaders, axiosConfig);

// Get Current OIDC Client
await trustDirectoryApi.getCurrentOidcClient(tracingHeaders, axiosConfig);

// Get Current Trust Package
await trustDirectoryApi.getCurrentTrustPackage(tracingHeaders, axiosConfig);

// Create a "Started" Verification Event
await trustDirectoryApi.createVerificationEvent({
  ...tracingHeaders
  verificationEventRequest: {
    verification_id: verificationId,
    event_type: VerificationEventRequestEventTypeEnum.Started,
    metadata: {
      'x-fapi-interaction-id': xFapiInteractionId,
      'x-verification-id': xVerificationID,
      'x-ip': userIP
    }
  }
}, axiosConfig);

// Create a "Failed" Verification Event
await trustDirectoryApi.createVerificationEvent({
  ...tracingHeaders
  verificationEventRequest: {
    verification_id: verificationId,
    event_type: VerificationEventRequestEventTypeEnum.Failed,
    metadata: {
      'x-fapi-interaction-id': xFapiInteractionId,
      'x-verification-id': xVerificationID
      'x-ip': userIP,
      error
    }
  }
}, axiosConfig);

// Create a "IdtokenIssued" Verification Event
await trustDirectoryApi.createVerificationEvent({
  ...tracingHeaders
  verificationEventRequest: {
    verification_id: verificationId,
    event_type: VerificationEventRequestEventTypeEnum.IdtokenIssued,
    footprint: crypto.createHash('sha256').update(userId).digest('hex'),
    metadata: {
      'x-fapi-interaction-id': xFapiInteractionId,
      'x-verification-id': xVerificationID,
      'x-ip': userIP
    }
  }
}, axiosConfig);

// Create an "UserinfoIssued" Verification Event
await trustDirectoryApi.createVerificationEvent({
  ...tracingHeaders
  verificationEventRequest: {
    verification_id: verificationId,
    event_type: VerificationEventRequestEventTypeEnum.UserinfoIssued,
    footprint: crypto.createHash('sha256').update(userId).digest('hex'),
    metadata: {
      'x-fapi-interaction-id': xFapiInteractionId,
      'x-verification-id': xVerificationID,
      'x-ip': userIP
    }
  }
}, axiosConfig);

Documentation for API Endpoints

For more detailed information about the API endpoints, models, and responses, refer to the provided OpenAPI specification hosted at https://api-docs.idpartner.com/trust-directory

Building

To build and compile the typescript sources to javascript use:

npm install
npm run build

Publishing

First build the package then run npm publish

Support

For support, please contact support@idpartner.com.

/@idpartner/trust-directory-api/

    Package Sidebar

    Install

    npm i @idpartner/trust-directory-api

    Weekly Downloads

    0

    Version

    0.0.3

    License

    none

    Unpacked Size

    346 kB

    Total Files

    169

    Last publish

    Collaborators

    • gioidpartner
    • francisco-idpartner
    • chrismccaw