Documentation for EmAuth Java SDK
Overview
The EmAuth Java SDK provides a straightforward and secure way to perform user verification and retrieve user data. This library is designed to be easily integrated into Java-based applications.
Importing the Library
To use the EmAuth SDK in your application, include the following import statement:
import EmAuth.*;
Core Features
The SDK provides two main functionalities:
- User Verification: Validate if a user has successfully authenticated for a specific application.
- Data Retrieval: Fetch specific user information requested by the application.
Methods
1. verifyUser
Description
This method verifies whether a user has authenticated themselves for a given application.
Syntax
boolean EmAuth.verifyUser(String email_of_user, String requester)
Parameters
email_of_user(String): The email address of the user.requester(String): The name of the application requesting the verification.
Returns
true(boolean): If the user successfully authenticates.false(boolean): If the user fails to authenticate.
Example
boolean isVerified = EmAuth.verifyUser("user@example.com", "MyApp");
if (isVerified) {
System.out.println("User authenticated successfully.");
} else {
System.out.println("User authentication failed.");
}
2. getUserData
Description
This method retrieves specific user data requested by the application.
Syntax
String EmAuth.getUserData(String email_of_user, List<String> requested_data, String requester)
Parameters
email_of_user(String): The email address of the user.requested_data(List) : A list of requested data fields. Possible values:"Name""Date-Of-Birth""Image"(in Base64 format)"IP"requester(String): The name of the application requesting the data.
Returns
- A JSON string containing the requested data. The
Imagefield, if requested, will be in Base64 format.
Example
import java.util.Arrays;
import java.util.List;
List<String> requestedData = Arrays.asList("Name", "Image");
String userData = EmAuth.getUserData("user@example.com", requestedData, "MyApp");
System.out.println(userData);
// Output Example:
// {
// "Name": "John Doe",
// "Image": "data:image/png;base64,iVBORw0KGgoAAAANS..."
// }
Notes
- Ensure that your application has the necessary permissions to access sensitive user data.
- Properly handle and validate the Base64-encoded image data before use.
- Use secure communication channels to protect sensitive information.
Error Handling
It is recommended to handle potential exceptions while using the methods. Use try-catch blocks to manage errors effectively.
Example
import java.util.Arrays;
try {
boolean isVerified = EmAuth.verifyUser("user@example.com", "MyApp");
if (!isVerified) {
System.out.println("Authentication failed.");
}
String userData = EmAuth.getUserData("user@example.com", Arrays.asList("Name"), "MyApp");
System.out.println(userData);
} catch (Exception e) {
System.err.println("An error occurred: " + e.getMessage());
}