Integrate Autheona using C#

Server-side C# integration guide for Autheona Trust Verification API with copy-paste ready code using System.Net.Http standard library.

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 JsonDocument containing the validation result and email intelligence data.

using System;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;

public class AutheonaClient
{
    private static readonly HttpClient _httpClient = new HttpClient();

    public static async Task<JsonDocument> ValidateEmailAsync(
        string email,
        string apiKey,
        JsonDocument customPolicy = null)
    {
        var normalizedEmail = email.Trim().ToLower();
        
        var payload = new { email_address = normalizedEmail };
        var jsonPayload = JsonSerializer.Serialize(payload);
        
        if (customPolicy != null)
        {
            var customPolicyElement = customPolicy.RootElement;
            var payloadWithPolicy = $"{{\"email_address\":\"{normalizedEmail}\",\"custom_policy\":{customPolicyElement}}}";
            jsonPayload = payloadWithPolicy;
        }
        
        var content = new StringContent(jsonPayload, Encoding.UTF8, "application/json");
        content.Headers.Add("x-api-key", apiKey);
        
        var response = await _httpClient.PostAsync(
            "https://api.autheona.com/v1/intelligence",
            content);
        
        response.EnsureSuccessStatusCode();
        
        var responseBody = await response.Content.ReadAsStringAsync();
        return JsonDocument.Parse(responseBody);
    }
}

Usage

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

using System;
using System.Text.Json;
using System.Threading.Tasks;

class Program
{
    static async Task Main(string[] args)
    {
        var apiKey = Environment.GetEnvironmentVariable("AUTHEONA_API_KEY");
        
        // Basic validation
        var result = await AutheonaClient.ValidateEmailAsync("user@example.com", apiKey);
        Console.WriteLine(result.RootElement.GetProperty("action").GetString());
        
        // With custom policy for testing
        var customPolicyJson = @"{
            ""parent_rules"": [
                { ""action"": ""block"", ""field"": ""domain_disposable"", ""operator"": ""=="", ""target"": { ""bool"": true } }
            ],
            ""stop_on_block"": true,
            ""version"": ""1.0""
        }";
        
        var customPolicy = JsonDocument.Parse(customPolicyJson);
        var testResult = await AutheonaClient.ValidateEmailAsync(
            "user@tempmail.com", 
            apiKey, 
            customPolicy);
        Console.WriteLine(testResult.RootElement.GetProperty("action").GetString());
    }
}

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:

var customPolicyJson = @"{
    ""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: