LoRemmit Shared Library
$ dotnet add package LoRemmit.Shared.LibraryTODO: Give a short introduction of your project. Let this section explain the objectives or the motivation behind this project.
TODO: Guide users through getting your code up and running on their own system. In this section you can talk about:
TODO: Describe and show how to build your code and run the tests.
TODO: Explain how other users and developers can contribute to make your code better If you want to learn more about creating good readme files then refer the following guidelines. You can also seek inspiration from the below readme files:
A comprehensive .NET 8 shared library providing authentication, JWT token blacklisting, Redis caching, HTTP client services, and common utilities for LoRemmit applications.
cd LoRemmit-Shared/LoRemmit-Shared.Library dotnet build
// Program.cs using LoRemmit_Shared.Library.ServiceCollectionExtensions.AuthenticationExtension; using LoRemmit_Shared.Library.Validation.Authentication;
var builder = WebApplication.CreateBuilder(args);
// Register authentication services builder.Services.AddSharedAuthenticationServices(builder.Configuration);
var app = builder.Build();
// Configure middleware pipeline app.UseAuthentication(); app.UseTokenBlacklist(); // JWT blacklist middleware app.UseAuthorization();
app.MapControllers(); app.Run();
{ "ConnectionStrings": { "Redis": "your-redis-connection-string" }, "Redis": { "ConnectionString": "your-redis-connection-string", "InstanceName": "URP-Central" }, "JwtSettings": { "Issuer": "your-issuer", "Audience": "your-audience", "SecretKey": "your-secret-key" } }
[ApiController] [Route("api/[controller]")] public class TestController : ControllerBase { private readonly ICurrentUser _currentUser; private readonly ITokenBlacklistService _blacklistService; private readonly IRedisService _redisService;
public TestController(
ICurrentUser currentUser,
ITokenBlacklistService blacklistService,
IRedisService redisService)
{
_currentUser = currentUser;
_blacklistService = blacklistService;
_redisService = redisService;
}
[HttpGet("protected")]
[Authorize]
public IActionResult GetProtectedData()
{
var userId = _currentUser.GetUserId();
var email = _currentUser.GetEmail();
return Ok(new { UserId = userId, Email = email });
}
[HttpPost("logout")]
[Authorize]
public async Task<IActionResult> Logout()
{
var jti = _currentUser.GetJwtId();
var expClaim = _currentUser.GetClaimValue("exp");
var expiration = DateTimeOffset.UtcNow.AddDays(1);
if (!string.IsNullOrEmpty(expClaim) && long.TryParse(expClaim, out var exp))
{
expiration = DateTimeOffset.FromUnixTimeSeconds(exp);
}
await _blacklistService.BlacklistTokenAsync(jti, expiration);
return Ok(new { Message = "Logged out successfully" });
}
}
SetAsync, GetAsync, RemoveAsync, ExistsAsync[RequiresRole("Administrator")] public IActionResult AdminEndpoint() => Ok();
[RequiresPermission("UserManagement", "Create")] public IActionResult CreateUser() => Ok();
await _redisService.SetAsync("user:123", userData, 3600); // 1 hour
// Get cached data var userData = await _redisService.GetAsync("user:123");
// Check existence var exists = await _redisService.ExistsAsync("user:123");
The Redis service automatically prefixes all keys with the current environment:
Development_user:123Staging_user:123Production_user:123This ensures complete data isolation between environments.
dotnet build
dotnet test
dotnet pack
dotnet pack dotnet nuget push LoRemmit.Shared.Library.{version}.nupkg --api-key {your-api-key} --source https://api.nuget.org/v3/index.json
MIT License - see LICENSE file for details.
For issues and questions, please create an issue in the repository or contact the development team.
Version: 1.2.89
Authors: EminenceTobi
Company: mcAdware Solutions