Age Verification - 5 Minutes Tutorial - Java SDK BETA
⚠️ BETA Product: This product is currently in beta. Features and integrations are under active development.
Prerequisites
The following information is required to be able to integrate with Authologic:
- Developer portal credentials,
- API Keys.
Developer Portal Credentials
The developer portal address and credentials were provided during onboarding.
Passwords And API Keys
During the onboarding you have received the API keys:
- API key allowing communication with Authologic.
- The key used to verify the data sent by Authologic by the callback mechanism.
Integration Overview
The entire process is called conversation. The following diagram represents the process logical flow:
- Start of the age verification process. Your server calls the API method called: POST /api/conversations
- The response returns information about the address to which the user should be redirected
- Your system redirects the user's browser to the above URL
- The user verifies their age
- Authologic redirects the user's browser to a predefined page of your system
- Your server displays the return page
- Authologic calls a callback on your server's side with the result of the verification
One API for multiple online age verification methods written in Java.
Installation
The installation of the library is as simple as including it as one of the projects dependencies.
We encourage to use the newest version of the library as we are constantly expanding our product offering and the underlying functionalities.
Maven
Include the following dependency in your pom.xml file to use Authologic Java SDK:
<dependency>
<groupId>com.authologic.client</groupId>
<artifactId>authologic-client</artifactId>
<version>0.2.42</version>
</dependency>
Gradle
Include the following dependency in your build.gradle file to use Authologic Java SDK:
implementation("com.authologic.client:authologic-client:0.2.42")
Usage
The following example demonstrates how you can use the Java SDK to interact with the Authologic APIs for age verification.
Creating Conversation
To start a new conversation process for age verification, which is the main entry point for the age verification product, the following example can be used:
import com.authologic.client.api.*;
public class Main {
public static void main(String[] args) {
Client client = ClientBuilder.builder("username", "password").sandbox().build();
Conversation conversation = client.execute(
Requests.
createConversation(
"7dfb9ded-c38f-49ae-95e2-307283a0b1f6",
"https://system.acme.test/return/{conversationId}").
callbackUrl("some_callback_url").
strategy("public:sandbox").
addProduct(ProductQueries.ageVerification(18))
).get();
System.out.println(conversation.getUrl());
}
}
Creating the Client Instance
We start by creating the Client instance:
Client client = ClientBuilder.builder("username", "password").sandbox().build();
API credentials can be generated via OmniPanel.
Because the API is secured you need the provided credentials to be able to interact with it.
Once initialized the Client instance may be used to interact with the Authologic API.
Creating the Conversation
Next we can create the conversation and request age verification for a specific age threshold. For that purpose we use the Requests.createConversation()
using the following code snippet:
Requests.
createConversation().
callbackUrl("some_callback_url").
strategy("public:sandbox").
addProduct(ProductQueries.ageVerification(18))
We set:
- the user key
- the return URL
- the callback URL
- the strategy
- the product that we want to use
The user key is the field which you can use to provide your own user identification information. Authologic returns this field in the conversation results, but doesn't use the value of the field.
The return URL is the address to which the user will be redirected by Authologic after verifying the age. It may contain the fragment: {conversationId} - if it exists, it will be replaced with the conversation ID.
The callback URL is the URL that Authologic will call when the process, in our example case the age verification process, will be completed. You should set it to match return to your application or use a service like Webhook Site(opens in new tab) if you plan on testing the SDK.
The strategy is the information that tells Authologic how to perform the operation.
The field is optional, but you can explicitly provide the information to choose the strategy that
you want to use. In the above example we used the public:sandbox, a strategy which doesn't perform a
real verification, but allows to test the whole flow.
The product that we want to use is the Age Verification product, which allows us to verify if the user meets a specific age requirement. We use ProductQueries.ageVerification(18) to verify if the user is over 18 years old:
ProductQueries.ageVerification(18)
You can specify any age threshold (e.g., 18, 21, or any custom age requirement).
As the final step we print the URL of the created conversation to the standard output to be able to continue the process. If you are trying out the SDK head to the returned link to go through the age verification process.
Fetching Age Verification Results
After the user completes the age verification process, you can retrieve the results using the conversation ID. The result will contain the status of the verification and whether the user meets the specified age threshold.
import com.authologic.client.api.*;
public class Main {
public static void main(String[] args) {
Client client = ClientBuilder.builder("username", "password").sandbox().build();
String conversationId = "e0c0b3cc-8238-414f-9940-9f14bd1b8693";
Conversation conversation = client.execute(
Requests.getConversation(conversationId)
).get();
ConversationAgeVerificationResult ageVerificationResult =
conversation.getResult().getAgeVerification();
System.out.println("Status: " + ageVerificationResult.getStatus());
System.out.println("Age threshold: " + ageVerificationResult.getOver());
System.out.println("Verification result: " + ageVerificationResult.getResult());
}
}
The ConversationAgeVerificationResult object contains:
- status: The status of the age verification process (
IN_PROGRESS,FINISHED, orFAILED) - over: The age threshold that was verified (e.g., 18, 21)
- result: A boolean value indicating whether the user meets the age requirement (
trueif the user is over the specified age,falseotherwise, ornullif verification is not yet complete)