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>

Check the latest version on the Maven Central repository 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

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.

AuthProvider (constructor)

Initialises AuthProvider with the Personal Access Token credentials required to generate authorisation tokens.

Parameters

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

Example

import com.affinidi.tdk.authProvider.AuthProvider;

try {
    // Pass values directly
    AuthProvider authProvider = new AuthProvider.Configurations()
        .projectId("<PROJECT_ID>")
        .privateKey("<PAT_PRIVATE_KEY_STRING>")
        .passphrase("<PAT_KEY_PAIR_PASSPHRASE>")
        .tokenId("<PAT_ID>")
        .build();

    // Or read from environment variables
    AuthProvider authProviderFromEnv = new AuthProvider.Configurations().buildWithEnv();
} catch (Exception e) {
    e.printStackTrace();
}

fetchProjectScopedToken

Returns the generated project-scoped token for calling Affinidi services.

No parameters required.

Example

import com.affinidi.tdk.authProvider.AuthProvider;

try {
    AuthProvider authProvider = new AuthProvider.Configurations()
        .projectId("<PROJECT_ID>")
        .privateKey("<PAT_PRIVATE_KEY_STRING>")
        .passphrase("<PAT_KEY_PAIR_PASSPHRASE>")
        .tokenId("<PAT_ID>")
        .build();

    String projectToken = authProvider.fetchProjectScopedToken();
    System.out.println(projectToken);
} catch (Exception e) {
    e.printStackTrace();
}

createIotaToken

Creates an Affinidi Iota Framework token to generate Iota Credentials for signing 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 com.affinidi.tdk.authProvider.AuthProvider;
import com.affinidi.tdk.authProvider.types.IotaJwtOutput;

try {
    AuthProvider authProvider = new AuthProvider.Configurations()
        .projectId("<PROJECT_ID>")
        .privateKey("<PAT_PRIVATE_KEY_STRING>")
        .passphrase("<PAT_KEY_PAIR_PASSPHRASE>")
        .tokenId("<PAT_ID>")
        .build();

    IotaJwtOutput iotaToken = authProvider.signIotaJwt(
        "<IOTA_CONFIGURATION_ID>",
        "<LOGGED_IN_USER_DID>",
        ""
    );
    System.out.println(iotaToken.getIotaJwt());
} catch (Exception e) {
    e.printStackTrace();
}