Tatum.ClientSecretFetcher
1.0.1
dotnet add package Tatum.ClientSecretFetcher --version 1.0.1
NuGet\Install-Package Tatum.ClientSecretFetcher -Version 1.0.1
<PackageReference Include="Tatum.ClientSecretFetcher" Version="1.0.1" />
<PackageVersion Include="Tatum.ClientSecretFetcher" Version="1.0.1" />
<PackageReference Include="Tatum.ClientSecretFetcher" />
paket add Tatum.ClientSecretFetcher --version 1.0.1
#r "nuget: Tatum.ClientSecretFetcher, 1.0.1"
#:package Tatum.ClientSecretFetcher@1.0.1
#addin nuget:?package=Tatum.ClientSecretFetcher&version=1.0.1
#tool nuget:?package=Tatum.ClientSecretFetcher&version=1.0.1
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
- Checks if the client secret is cached.
- If found, returns the cached value.
- If not found, queries the database.
- If retrieved successfully, caches it for 24 hours.
- If any error occurs, returns an appropriate response.
Product | Versions 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. |
-
net8.0
- Dapper (>= 2.1.66)
- Microsoft.Data.SqlClient (>= 6.0.1)
- Microsoft.Extensions.Caching.Memory (>= 8.0.1)
- System.Runtime.Caching (>= 9.0.2)
- Tatum.ResponseLibrary (>= 1.0.2)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
For installation and usage instructions, see the README.md file.