Skip to main content

Java

Initial Setup

The LoginID Server SDK enables you to connect to LoginID APIs in a secure, robust and secure manner. Using the SDK simplifies integrations with LoginID so that your developers can concentrate on features that improve users experiences rather than having to deal with raw API calls. This page provides the initial steps that are required to retrieve credentials and register your application with LoginID.

Create an Application on the Dashboard

An application must be created on the LoginID Dashboard in order to correctly configure the Server SDK.

Once logged into the dashboard, navigate to the Applications tab in the sidebar, select “Add Application”. For the purpose of getting started select “Backend / API” which enables the usage of management APIs.

In the resulting form set a name for your application and a web site URL if desired. After clicking “Create” you will find a “Client ID” which is needed to configure the SDK! Click “Next Step”.

The next page “API Credentials” provides three options. In any case it refers to a private / public key pair which is used by the SDK. To get started select “Generate key pair for me”. If you are setting up an application for production systems upload your own public key. If you have previously created an API Credential you can reuse it.

After selecting “Generate key pair for me” set a name for this API Credential and hit “Generate Key”. The page generates a private key in PEM format. This private key is used by the SDK. Copy the key and paste it into a private, secured file. LoginID does not persist the private key, therefore, make sure not to lose it! Hit “Complete”.

Your application is now registered and the SDK can be configured!

note

All API calls made from a Management integration type require an API Service Token

Add the SDK to an existing Application

The SDK is open source, uses Maven and can be found on GitHub. Clone the repository and install it as shown below (https works too instead of ssh)!

git clone git@github.com:loginid1/java-server-side-sdk.git
cd java-server-side-sdk

mvn clean install

Create an SDK Instance

There are two types of APIs available and both have their dedicated java class to use:

import io.loginid.sdk.java.LoginId;
import io.loginid.sdk.java.LoginIdManagement;

LoginId loginId = LoginId(CLIENT_ID, PRIVATE_KEY, BASE_URL);
LoginIdManagement mgmt = LoginIdManagement(CLIENT_ID, PRIVATE_KEY, BASE_URL); // used with credentials created on this page

An easy way to store the credentials and initialize the SDK is so use a properties file. Here is an example (shown for Mac computers):

  1. Create a file at ~/.loginid/config

  2. Add this content (using your client_id and your private key):

    1. for the private key set \n to separate lines from each other!

      base_url=https://directweb.usw1.loginid.io
      client_id=Fnfga......QhjE3ZatQ==
      API_PRIVATE_KEY=-----BEGIN PRIVATE KEY-----\nMIGHAgEA......wkJ/7B\n-----END PRIVATE KEY-----
  3. Try this code snippet:

    Properties props = new Properties();
    props.load(new FileReader(String.format("%s/%s", System.getProperty("user.home"), ".loginid/config")));
    LoginIdManagement mgmt = new LoginIdManagement(props.getProperty("client_id"), props.getProperty("API_PRIVATE_KEY"), props.getProperty("base_url") );

The SDK is now ready for use. Checkout the API Reference documentation to get started!

note

If using a custom base_url, you can initialize the SDK with that base_url. Otherwise, it will default to the main LoginID production environment.

Application API Reference

LoginId Class

Constructor

This server SDK leverages either a web or mobile application and requires an API credential to be assigned to that integration.


Helper Functions

generateServiceToken

Generate a service token, to be used when making protected API calls. Not required when calling other methods with the server SDK.

verifyToken

Verify a JWT returned upon user authentication.


generateTxAuthToken

Generates the bearer token to be used in the transaction confirmation flow, as it has a specific format slightly different from the standard service tokens. This function generates that token. If calling the createTx method, this function does not need to be called first.

createTx

Create a transaction ID. This is typically the first step of the transaction confirmation flow.

verifyTransaction

Verify the jwt returned in the confirmTransaction flow.

Management API Reference

Overview

LoginIdManagement Constructor

This server SDK can be used with a management application and requires an API credential to be assigned to that integration. All calls made from this SDK are intended to be backend-to-backend calls, as the operations are sensitive.

Credential Management Functions

getCredentials

Get an exhaustive list of credentials for a given user.

renameCredential

Rename a given credential.

revokeCredential

Revoke a credential so it can longer be used.


generateCode

Generate a code, which can be used for a variety of purposes. Check out the guides section for how various ways these codes can be used.

authorizeCode

Authorize a code which was previously generated through the generateCode method.

waitCode

Submit a code and wait for it to be authorized. You can use this method when leveraging the code to authenticate a user.

invalidateAllCodes

Invalidate all codes of a given type for a specific user.


User Management Functions

getUserId

Get a user identifier for a given username.

deactivateUserById

Temporarily deactivate a user account.

activateUserById

Re-activate a previously deactivated user profile.

deleteUserById

Deletes a user profile based on a userId as the input. This operation cannot be undone.

deleteUserByUsername

Deletes a user profile based on a username as the input. This operation cannot be undone.

createUserWithoutCredentials

Adds a new user without credentials. The new user can create new credentials with recovery flow