Skip to main content

Get Started - 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.