Documentation for EmAuth PHP SDK

Overview

The EmAuth PHP SDK provides a secure and efficient way to handle user verification and data retrieval in PHP-based applications. This library simplifies authentication and user data access.

Importing the Library

To use the EmAuth SDK, include the library in your PHP script:

include 'EmAuth.php';

Core Features

The SDK offers two primary functionalities:

  1. User Verification: Verify if a user successfully authenticates for an application.
  2. Data Retrieval: Fetch specific user data requested by the application.

Functions

1. verifyUser

Description

This function verifies whether the user has authenticated themselves for a given application.

Syntax

verifyUser($email_of_user, $requester)

Parameters

  • $email_of_user (string): The email address of the user.
  • $requester (string): The name of the application requesting verification.

Returns

  • TRUE (boolean): If the user successfully authenticates.
  • FALSE (boolean): If the user fails to authenticate.

Example

$isVerified = verifyUser("user@example.com", "MyApp");

if ($isVerified) {
    echo "User authenticated successfully.";
} else {
    echo "User authentication failed.";
}

2. getUserData

Description

This function retrieves specific user data requested by the application.

Syntax

getUserData($email_of_user, $requested_data, $requester)

Parameters

  • $email_of_user (string): The email address of the user.
  • $requested_data (array): An array of data fields to retrieve. 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 Image field, if requested, is represented in Base64 format.

Example

$requestedData = ["Name", "Image"];
$userData = getUserData("user@example.com", $requestedData, "MyApp");

echo $userData;
// Output Example:
// {
//   "Name": "John Doe",
//   "Image": "data:image/png;base64,iVBORw0KGgoAAAANS..."
// }

Notes

  • Ensure the application has the necessary permissions to request and handle sensitive user data.
  • Validate Base64-encoded image data before use.
  • Use secure communication protocols (e.g., HTTPS) to protect transmitted data.

Error Handling

It is recommended to handle potential errors using try-catch blocks when the functions throw exceptions.

Example

try {
    $isVerified = verifyUser("user@example.com", "MyApp");

    if (!$isVerified) {
        echo "Authentication failed.";
    }

    $userData = getUserData("user@example.com", ["Name"], "MyApp");
    echo $userData;
} catch (Exception $e) {
    echo "An error occurred: " . $e->getMessage();
}

Download

Download