Official .NET SDK for Authensure - Electronic signature and document authentication platform
$ dotnet add package AuthensureOfficial .NET SDK for Authensure - the electronic signature and document authentication platform.
dotnet add package Authensure
Or via NuGet Package Manager:
Install-Package Authensure
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}");
// 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
});
// 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");
// 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);
// 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" }
}
});
// 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}");
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})");
}
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);
}
}
# Build
dotnet build
# Run tests
dotnet test
# Pack
dotnet pack
This package is open-sourced software licensed under the MIT license.