Documentation for EmAuth Dart SDK

Overview

The EmAuth Dart SDK provides tools to integrate user verification and data retrieval functionality into Dart or Flutter applications. The SDK is designed for secure and efficient authentication workflows.

Importing the Library

To use the EmAuth SDK in your Dart or Flutter project, include the following import statement:

import 'EmAuth.dart';

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 asynchronous function verifies whether a user has authenticated themselves for a given application.

Syntax

Future<bool> 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 verification.

Returns

  • true (bool): If the user successfully authenticates.
  • false (bool): If the user fails to authenticate.

Example

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

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

2. getUserData

Description

This asynchronous function retrieves specific user data requested by the application.

Syntax

Future<String> 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 Image field, if requested, is represented in Base64 format.

Example

List<String> requestedData = ["Name", "Image"];
String userData = await getUserData("user@example.com", requestedData, "MyApp");

print(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) for data transfer.

Error Handling

It is recommended to handle potential errors using try-catch blocks to ensure smooth operation and user feedback.

Example

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

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

  String userData = await getUserData("user@example.com", ["Name"], "MyApp");
  print(userData);
} catch (e) {
  print("An error occurred: $e");
}

Flutter Integration

This SDK can be easily integrated into a Flutter project. Below is an example usage in a Flutter application:

Example

import 'package:flutter/material.dart';
import 'EmAuth.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(title: Text("EmAuth Example")),
        body: UserAuthWidget(),
      ),
    );
  }
}

class UserAuthWidget extends StatefulWidget {
  @override
  _UserAuthWidgetState createState() => _UserAuthWidgetState();
}

class _UserAuthWidgetState extends State<UserAuthWidget> {
  String _status = "Not authenticated";

  Future<void> authenticateUser() async {
    try {
      bool isVerified = await verifyUser("user@example.com", "MyApp");
      if (isVerified) {
        setState(() {
          _status = "User authenticated successfully.";
        });

        String userData = await getUserData("user@example.com", ["Name"], "MyApp");
        print(userData);
      } else {
        setState(() {
          _status = "Authentication failed.";
        });
      }
    } catch (e) {
      setState(() {
        _status = "An error occurred: $e";
      });
    }
  }

  @override
  Widget build(BuildContext context) {
    return Column(
      mainAxisAlignment: MainAxisAlignment.center,
      children: [
        Text(_status),
        ElevatedButton(
          onPressed: authenticateUser,
          child: Text("Authenticate"),
        ),
      ],
    );
  }
}

Download

Download