A powerful and secure .NET client library for integrating VerifySpeed user verification services into your C# applications. Support for multiple verification methods including Telegram, WhatsApp, and SMS.
- Multiple Verification Methods: Support for Telegram, WhatsApp, and SMS verification
- Local Token Decryption: Decrypt verification tokens locally for enhanced security and performance
- Dependency Injection Ready: Seamless integration with .NET Core/5+ dependency injection
- Async/Await Support: Full async support for all operations
- Comprehensive Error Handling: Detailed exception types for better error management
- Cross-Platform: Works on Windows, macOS, and Linux
dotnet add package VerifySpeed.VSCSharpInstall-Package VerifySpeed.VSCSharpusing VSCSharp;
var builder = WebApplication.CreateBuilder(args);
// Register VerifySpeed services
builder.Services.AddVerifySpeed("YOUR_SERVER_KEY");
var app = builder.Build();
app.Run();using VSCSharp;
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
services.AddVerifySpeed("YOUR_SERVER_KEY");
}
}public class VerificationService
{
private readonly IVerifySpeedClient _verifySpeedClient;
public VerificationService(IVerifySpeedClient verifySpeedClient)
{
_verifySpeedClient = verifySpeedClient;
}
public async Task<DecryptTokenResult> VerifyUserAsync(string token)
{
try
{
// Decrypt token locally (recommended)
var result = _verifySpeedClient.DecryptToken(token);
// Or use API verification
// var result = await _verifySpeedClient.VerifyTokenAsync(token);
// The result contains the user's phone number, verification method, and date
// result.PhoneNumber - The verified user's phone number
// result.MethodName - The verification method used (e.g., "telegram-message")
// result.DateOfVerification - When the verification was completed
return result;
}
catch (InvalidVerificationTokenException ex)
{
// Handle invalid token
throw;
}
}
}π Full Documentation: http://doc.verifyspeed.com/docs/Integrations/backend/sdks/csharpdotnet
The complete documentation covers:
- Initializing the Client
- Creating Verifications
- Decrypting Verification Tokens
- API Examples
- Models and Exceptions
- Telegram Message: Send verification codes via Telegram
- Telegram OTP: Receiving OTP code via Telegram
- WhatsApp Message: Send verification codes via WhatsApp
- WhatsApp OTP: Receiving OTP code via WhatsApp
- SMS OTP: Receiving OTP code via SMS
- .NET 5.0 or later
- C# 9.0 or later
- VerifySpeed Account with server key
VERIFYSPEED_SERVER_KEY=your_server_key_here{
"VerifySpeed": {
"ServerKey": "your_server_key_here"
}
}public async Task InitializeVerificationAsync()
{
try
{
var clientIp = "192.168.1.1"; // Replace with actual client IP
var initializationResponse = await _verifySpeedClient.InitializeAsync(clientIp);
foreach (var method in initializationResponse.AvailableMethods)
{
Console.WriteLine($"- {method.DisplayName} ({method.MethodName})");
}
}
catch (FailedInitializationException ex)
{
Console.WriteLine($"Initialization failed: {ex.Message}");
}
}After creating an OTP verification, validate the code on your server when the user's app sends it to your backend:
public async Task<ValidateOtpResponse> ValidateOtpAsync(string code, string verificationKey)
{
try
{
var result = await _verifySpeedClient.ValidateOtpAsync(code, verificationKey);
if (!result.Succeed)
{
// Handle OTP_EXPIRED, OTP_INVALID, OTP_ALREADY_VERIFIED via result.ErrorCode
Console.WriteLine($"OTP validation failed: {result.ErrorMessage} ({result.ErrorCode})");
return result;
}
// result.Token and result.PhoneNumber are set on success
var details = _verifySpeedClient.DecryptToken(result.Token!);
return result;
}
catch (FailedValidateOtpException ex)
{
Console.WriteLine($"Validate OTP request failed: {ex.Message}");
throw;
}
}public async Task<CreatedVerificationResponse> CreateVerificationAsync()
{
try
{
var clientIp = "192.168.1.1"; // Replace with actual client IP
var verification = await _verifySpeedClient.CreateVerificationAsync(
methodName: "telegram-message",
clientIPv4Address: clientIp,
language: "en"
);
return verification;
}
catch (FailedCreateVerificationException ex)
{
Console.WriteLine($"Failed to create verification: {ex.Message}");
throw;
}
}The library provides specific exception types for better error handling:
try
{
var result = _verifySpeedClient.DecryptToken(token);
}
catch (InvalidVerificationTokenException ex)
{
// Token is null, empty, or has invalid format
Console.WriteLine($"Invalid token: {ex.Message}");
}
catch (FailedDecryptingVerificationTokenException ex)
{
// Cryptographic error during decryption
Console.WriteLine($"Decryption failed: {ex.Message}");
}
catch (FailedVerifyingTokenException ex)
{
// API verification failed
Console.WriteLine($"Verification failed: {ex.Message}");
}
catch (FailedValidateOtpException ex)
{
// validate-otp HTTP request failed
Console.WriteLine($"Validate OTP failed: {ex.Message}");
}This project is licensed under the MIT License - see the LICENSE file for details.
- Documentation: http://doc.verifyspeed.com/docs/Integrations/backend/sdks/csharpdotnet
- Issues: GitHub Issues
Made with β€οΈ by the VerifySpeed Team