Integrate Autheona using Dart

Server-side Dart integration guide for Autheona Trust Verification API with copy-paste ready code using dart:io and dart:convert standard libraries.

Prerequisites

Before using this code, you need:

  1. An Autheona account: Sign up at https://app.autheona.com/sign-up
  2. A project (Sandbox or Production): See project creation guide
  3. An access token with API permissions: See access token documentation

Store your access token securely using environment variables. Never hardcode tokens in your source code.

Code

This function sends an HTTP POST request to the Autheona API with the email address to validate. It accepts an optional customPolicy parameter for testing validation rules. The function returns the API response as a map containing the validation result and email intelligence data.

import 'dart:convert';
import 'dart:io';

Future<Map<String, dynamic>> validateEmail(
  String email,
  String apiKey, {
  Map<String, dynamic>? customPolicy,
}) async {
  final normalizedEmail = email.trim().toLowerCase();

  final payload = <String, dynamic>{
    'email_address': normalizedEmail,
  };
  if (customPolicy != null) {
    payload['custom_policy'] = customPolicy;
  }

  final httpClient = HttpClient();
  final request = await httpClient.postUrl(
    Uri.parse('https://api.autheona.com/v1/intelligence'),
  );

  request.headers.set('Content-Type', 'application/json');
  request.headers.set('x-api-key', apiKey);

  final body = jsonEncode(payload);
  request.write(body);

  final response = await request.close();
  final responseBody = await response.transform(utf8.decoder).join();

  httpClient.close();

  if (response.statusCode != 200) {
    throw Exception('HTTP ${response.statusCode}');
  }

  return jsonDecode(responseBody) as Map<String, dynamic>;
}

Usage

Import the function, provide your API key via environment variable, and call validateEmail with an email address. The function returns a map with action field ('allow', 'block', or 'ignore') and detailed email analysis. For testing specific rules, pass a custom policy as the optional parameter.

import 'dart:io';

void main() async {
  final apiKey = Platform.environment['AUTHEONA_API_KEY'];

  // Basic validation
  final result = await validateEmail('user@example.com', apiKey);
  print(result['action']);

  // With custom policy for testing
  final customPolicy = {
    'parent_rules': [
      {
        'action': 'block',
        'field': 'domain_disposable',
        'operator': '==',
        'target': {'bool': true}
      }
    ],
    'stop_on_block': true,
    'version': '1.0'
  };

  final testResult = await validateEmail(
    'user@tempmail.com',
    apiKey,
    customPolicy: customPolicy,
  );
  print(testResult['action']);
}

Custom Policy Parameter

Warning

The custom_policy parameter is for testing only. In production, configure policies using the Policy Editor instead of sending them in requests.

Add custom_policy to your request body to test custom validation rules:

final customPolicy = {
  'parent_rules': [
    {'action': 'block', 'field': 'domain_disposable', 'operator': '==', 'target': {'bool': true}},
    {'action': 'block', 'field': 'email_deliverable', 'operator': '==', 'target': {'bool': false}},
    {'action': 'ignore', 'field': 'domain_free', 'operator': '==', 'target': {'bool': true}}
  ],
  'stop_on_block': true,
  'version': '1.0'
};

Available fields: domain_disposable, domain_free, email_deliverable, domain_has_website, email_has_fraud_pattern, and more from the API response.

Environment Variables

Set your API key as an environment variable to keep it out of your code:

export AUTHEONA_API_KEY="your-api-key"

Note

This is a minimal integration example. For production use cases, error handling, retry logic, rate limiting, and advanced response processing, refer to the API Reference Documentation.

Support

For issues with the API, refer to: