TwoFactorFBRIP 1.0.0

dotnet add package TwoFactorFBRIP --version 1.0.0
                    
NuGet\Install-Package TwoFactorFBRIP -Version 1.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="TwoFactorFBRIP" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="TwoFactorFBRIP" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="TwoFactorFBRIP" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add TwoFactorFBRIP --version 1.0.0
                    
#r "nuget: TwoFactorFBRIP, 1.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package TwoFactorFBRIP@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=TwoFactorFBRIP&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=TwoFactorFBRIP&version=1.0.0
                    
Install as a Cake Tool

TwoFactorFBRIP

A .NET 8 client library for interacting with the 2FA.fb.rip API to generate time-based one-time passwords (TOTP).

Installation

Install the package via NuGet Package Manager:

Install-Package TwoFactorFBRIP

Or via .NET CLI:

dotnet add package TwoFactorFBRIP

Usage

Basic Usage

using TwoFactorFBRIP;

// Create a client instance
using var client = new TwoFactorClient();

// Get OTP for a secret (async)
var response = await client.GetOtpAsync("TWOFACTORSECRET");

if (response.Ok && response.Data != null)
{
    Console.WriteLine($"OTP: {response.Data.Otp}");
    Console.WriteLine($"Time Remaining: {response.Data.TimeRemaining} seconds");
}

Synchronous Usage

using TwoFactorFBRIP;

// Create a client instance
using var client = new TwoFactorClient();

// Get OTP for a secret (sync)
var response = client.GetOtp("TWOFACTORSECRET");

if (response.Ok && response.Data != null)
{
    Console.WriteLine($"OTP: {response.Data.Otp}");
    Console.WriteLine($"Time Remaining: {response.Data.TimeRemaining} seconds");
}

Using with HttpClient Factory

using TwoFactorFBRIP;
using Microsoft.Extensions.DependencyInjection;

// Using dependency injection
var services = new ServiceCollection();
services.AddHttpClient();
var serviceProvider = services.BuildServiceProvider();

var httpClientFactory = serviceProvider.GetService<IHttpClientFactory>();
var httpClient = httpClientFactory.CreateClient();

// Create client with custom HttpClient
using var client = new TwoFactorClient(httpClient);

var response = await client.GetOtpAsync("TWOFACTORSECRET");

API Response

The API returns a response in the following format:

{
  "ok": true,
  "data": {
    "otp": "384866",
    "timeRemaining": 10
  }
}

This is mapped to the OtpResponse class:

  • Ok (bool): Indicates if the request was successful
  • Data (OtpData): Contains the OTP information
    • Otp (string): The generated 6-digit OTP code
    • TimeRemaining (int): Time in seconds until the OTP expires

Error Handling

The client throws the following exceptions:

  • ArgumentNullException: When the secret is null or empty
  • HttpRequestException: When the API request fails
  • JsonException: When the response cannot be parsed
try
{
    var response = await client.GetOtpAsync("INVALID_SECRET");
}
catch (ArgumentNullException ex)
{
    Console.WriteLine($"Invalid secret: {ex.Message}");
}
catch (HttpRequestException ex)
{
    Console.WriteLine($"API request failed: {ex.Message}");
}
catch (JsonException ex)
{
    Console.WriteLine($"Failed to parse response: {ex.Message}");
}

License

MIT License

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0 113 8/1/2025