Auth Provider

Generate Authorisation Token to call Affinidi Services.

Install Dependency

Package: pkg:maven/com.affinidi.tdk/auth.provider

<dependency>
    <groupId>com.affinidi.tdk</groupId>
    <artifactId>auth.provider</artifactId>
    <version><version_number></version>
</dependency>

You can check the latest version of this module on the Maven 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

import com.affinidi.tdk.authProvider.AuthProvider;

try{

  // Use this method by passing the values directly on initialisation
  // Initialise AuthProvider class to generate projectScopedToken
  AuthProvider authProviderWithPassedValues = new AuthProvider.Configurations()
                  .projectId("PROJECT_ID")
                  .privateKey("PRIVATE_KEY")
                  .passphrase("PASSPHRASE")
                  .tokenId("TOKEN_ID")
                  .build();
  String projectToken = authProviderWithPassedValues.fetchProjectScopedToken();

  // Alternatively, you can initialise the AuthProvider class by automatically reading known env variables from env file
  // Create an authprovider from the values configured in the environment file
  AuthProvider authProviderFromEnvFile = new AuthProvider.Configurations().buildWithEnv();
  String projectToken = authProviderFromEnvFile.fetchProjectScopedToken();

} catch(Exception e) {
  e.printStackTrace();
}

fetchProjectScopedToken

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

Parameters

No Parameters Required

Example

import com.affinidi.tdk.authProvider.AuthProvider;

try{

  // Use this method by passing the values directly on initialisation
  // Initialise AuthProvider class to generate projectScopedToken
  AuthProvider authProviderWithPassedValues = new AuthProvider.Configurations()
                  .projectId("PROJECT_ID")
                  .privateKey("PRIVATE_KEY")
                  .passphrase("PASSPHRASE")
                  .tokenId("TOKEN_ID")
                  .build();
  String projectToken = authProviderWithPassedValues.fetchProjectScopedToken();
  System.out.println(projectToken);

  // Alternatively, you can initialise the AuthProvider class by automatically reading known env variables from env file
  // Create an authprovider from the values configured in the environment file
  AuthProvider authProviderFromEnvFile = new AuthProvider.Configurations().buildWithEnv();
  String projectToken = authProviderFromEnvFile.fetchProjectScopedToken();
  System.out.println(projectToken);

} catch(Exception e) {
  e.printStackTrace();
}

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

import com.affinidi.tdk.authProvider.AuthProvider;
import com.affinidi.tdk.authProvider.types.IotaJwtOutput;

try {
  // Alternatively you can create an auth provider by explicitly passing the configurations 
  AuthProvider authProviderWithPassedValues = new AuthProvider.Configurations()
      .projectId(dotenv.get("PROJECT_ID"))
      .privateKey(dotenv.get("PRIVATE_KEY"))
      .passphrase(dotenv.get("PASSPHRASE"))
      .tokenId(dotenv.get("TOKEN_ID"))
      .build();

  String iotaConfigurationId = "<IOTA_CONFIGURATION_ID>";
  String userDid = "<LOGGED_IN_USER_DID>";
  String sessionId = "";

  IotaJwtOutput iotaToken = authProviderWithPassedValues.signIotaJwt(iotaConfigurationId, userDid, sessionId);

  System.out.println(iotaToken.getIotaJwt());
} catch (Exception e) {
  e.printStackTrace();
}