Tatum.ClientSecretFetcher 1.0.1

dotnet add package Tatum.ClientSecretFetcher --version 1.0.1
                    
NuGet\Install-Package Tatum.ClientSecretFetcher -Version 1.0.1
                    
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="Tatum.ClientSecretFetcher" Version="1.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Tatum.ClientSecretFetcher" Version="1.0.1" />
                    
Directory.Packages.props
<PackageReference Include="Tatum.ClientSecretFetcher" />
                    
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 Tatum.ClientSecretFetcher --version 1.0.1
                    
#r "nuget: Tatum.ClientSecretFetcher, 1.0.1"
                    
#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 Tatum.ClientSecretFetcher@1.0.1
                    
#: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=Tatum.ClientSecretFetcher&version=1.0.1
                    
Install as a Cake Addin
#tool nuget:?package=Tatum.ClientSecretFetcher&version=1.0.1
                    
Install as a Cake Tool

ClientSecretService

##Overview ClientSecretService is a service designed to securely retrieve client secrets from a database and cache them for optimized performance. It leverages Dapper for efficient database queries and MemoryCache for in-memory caching to reduce database load.

##Features Retrieves client secrets from the Vendors table. Caches secrets in-memory for 24 hours to minimize database queries. Implements robust error handling for timeouts, SQL errors, and system failures.

Installation

You can install this package using NuGet Package Manager:

dotnet add package Tatum.ClientSecretFetcher

Or in the NuGet Package Manager Console:

Install-Package Tatum.ClientSecretFetcher

##Usage

#For ASP.NET Core applications, register ClientSecretService as a singleton in the dependency injection container:

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddSingleton<IClientSecretService>(sp =>
	new ClientSecretService("Server=myServer;Database=myDB;User Id=myUser;Password=myPass;"));

var app = builder.Build();

#Injecting ClientSecretService in Controllers or Services E.g Using ClientSecretService in an API Controller public class AuthController : ControllerBase { private readonly IClientSecretService _clientSecretService;

	public AuthController(IClientSecretService clientSecretService)
	{
		_clientSecretService = clientSecretService;
	}

	[HttpGet("/get-secret/{clientId}")]
	public async Task<IActionResult> GetSecret(string clientId)
	{
		var response = await _clientSecretService.GetClientSecretAsync(clientId);
		return Ok(response);
	}
}

#If you prefer not to use dependency injection, initialize ClientSecretService manually:

var clientSecretService = new ClientSecretService("Server=myServer;Database=myDB;User Id=myUser;Password=myPass;");
var secret = await clientSecretService.GetClientSecretAsync("someClientId");

API Reference

# `Task<Response> GetClientSecretAsync(string clientId)`

# Parameters:
	`clientId` *(string)*: The unique identifier for the client.

# Returns:
	 Response` object containing:
	`Code` (string): Status code (Success, ResourceNotFound, or Error codes).
	`Message` (string): Description of the response.
	`Data` (string): The client secret if found.

# Example Response:
json
{
  "Code": "00",
  "Message": "Success",
  "Data": "SomeSecretKey"
}
```

Error Handling

The service gracefully handles the following errors:

  • Database Connection Issues: Returns an error message if the database is unreachable.
  • SQL Timeout: Handles timeouts and advises users to retry later.
  • Resource Not Found: Returns an appropriate response if the client secret does not exist.
  • General Exceptions: Captures unexpected errors and returns a system malfunction message.

How It Works

  1. Checks if the client secret is cached.
  2. If found, returns the cached value.
  3. If not found, queries the database.
  4. If retrieved successfully, caches it for 24 hours.
  5. If any error occurs, returns an appropriate response.
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.1 173 3/12/2025
1.0.0 110 2/28/2025
0.9.0 144 4/4/2025

For installation and usage instructions, see the README.md file.