Skip to content

Authensure/authensure-dotnet

Repository files navigation

Authensure .NET SDK

NuGet Version .NET Version License: MIT

Official .NET SDK for Authensure - the electronic signature and document authentication platform.

Features

  • Full API Coverage - Access all Authensure API endpoints
  • .NET 8.0+ - Modern .NET with nullable reference types
  • Async/Await - Full async support with CancellationToken
  • Automatic Retries - Built-in exponential backoff for transient errors
  • Webhook Verification - Easy webhook signature verification
  • File Uploads - Simplified document upload handling
  • Strongly Typed - Full type safety with models

Installation

dotnet add package Authensure

Or via NuGet Package Manager:

Install-Package Authensure

Quick Start

using Authensure;

var client = AuthensureClient.WithApiKey("your_api_key");

// Create an envelope
var envelope = await client.Envelopes.CreateAsync(
    name: "Contract Agreement",
    message: "Please review and sign this document"
);

Console.WriteLine($"Created envelope: {envelope.Id}");

Configuration

// With API Key
var client = AuthensureClient.WithApiKey("your_api_key");

// With Access Token
var client = AuthensureClient.WithAccessToken("your_token");

// With custom options
var client = new AuthensureClient(new AuthensureClientOptions
{
    ApiKey = "your_api_key",
    BaseUrl = "https://api.authensure.app/api",
    Timeout = 30,
    RetryAttempts = 3
});

API Reference

Envelopes

// List envelopes
var envelopes = await client.Envelopes.ListAsync(status: "DRAFT");

// Get an envelope
var envelope = await client.Envelopes.GetAsync("envelope_id");

// Create an envelope
var envelope = await client.Envelopes.CreateAsync(
    name: "My Contract",
    message: "Please sign"
);

// Add a recipient
var recipient = await client.Envelopes.AddRecipientAsync(
    envelopeId: "envelope_id",
    email: "signer@example.com",
    name: "John Doe",
    role: "signer"
);

// Send for signing
await client.Envelopes.SendAsync("envelope_id");

// Void an envelope
await client.Envelopes.VoidAsync("envelope_id", "Contract cancelled");

Documents

// Upload a document
var fileContent = await File.ReadAllBytesAsync("contract.pdf");
var document = await client.Documents.UploadAsync("envelope_id", fileContent, "contract.pdf");

// Download a document
var content = await client.Documents.DownloadAsync("document_id");
await File.WriteAllBytesAsync("signed_contract.pdf", content);

Templates

// Use a template
var envelope = await client.Templates.UseAsync("template_id", new
{
    name = "New Contract",
    recipients = new[]
    {
        new { roleId = "role_1", email = "signer@example.com", name = "John Doe" }
    }
});

Webhooks

// Create a webhook
var webhook = await client.Webhooks.CreateAsync(
    url: "https://your-app.com/webhooks/authensure",
    events: new List<string> { "envelope.signed", "envelope.completed" }
);

// Verify webhook signature
var isValid = WebhooksResource.VerifySignature(payload, signature, "your_webhook_secret");

// Construct verified event
var webhookEvent = WebhooksResource.ConstructEvent(payload, signature, "your_webhook_secret");
Console.WriteLine($"Event type: {webhookEvent.Event}");

Error Handling

try
{
    var envelope = await client.Envelopes.GetAsync("invalid_id");
}
catch (NotFoundException)
{
    Console.WriteLine("Envelope not found");
}
catch (AuthenticationException)
{
    Console.WriteLine("Invalid API key");
}
catch (RateLimitException ex)
{
    Console.WriteLine($"Rate limited, retry after: {ex.RetryAfter} seconds");
}
catch (ValidationException ex)
{
    Console.WriteLine($"Validation errors: {ex.Details}");
}
catch (AuthensureException ex)
{
    Console.WriteLine($"API error: {ex.Message} (code: {ex.ErrorCode})");
}

ASP.NET Core Integration

Register in Program.cs:

builder.Services.AddSingleton<AuthensureClient>(sp =>
    AuthensureClient.WithApiKey(builder.Configuration["Authensure:ApiKey"]!));

Use in controllers:

public class EnvelopesController : ControllerBase
{
    private readonly AuthensureClient _authensure;

    public EnvelopesController(AuthensureClient authensure)
    {
        _authensure = authensure;
    }

    [HttpPost]
    public async Task<IActionResult> Create([FromBody] CreateEnvelopeRequest request)
    {
        var envelope = await _authensure.Envelopes.CreateAsync(
            name: request.Name,
            message: request.Message
        );
        return Ok(envelope);
    }
}

Development

# Build
dotnet build

# Run tests
dotnet test

# Pack
dotnet pack

Resources

License

This package is open-sourced software licensed under the MIT license.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages