ZCloakNet 1.2.2
See the version list below for details.
dotnet add package ZCloakNet --version 1.2.2
NuGet\Install-Package ZCloakNet -Version 1.2.2
<PackageReference Include="ZCloakNet" Version="1.2.2" />
<PackageVersion Include="ZCloakNet" Version="1.2.2" />
<PackageReference Include="ZCloakNet" />
paket add ZCloakNet --version 1.2.2
#r "nuget: ZCloakNet, 1.2.2"
#:package ZCloakNet@1.2.2
#addin nuget:?package=ZCloakNet&version=1.2.2
#tool nuget:?package=ZCloakNet&version=1.2.2
π ZCloakNet β Authentication Library for .NET
ZCloakNet is a powerful and lightweight authentication library for .NET 8+ that integrates seamlessly with Keycloak, providing everything you need for user registration, activation, login, token refresh, password recovery, and email notifications β all in a few lines of code.
π Features
- β Plug-and-play integration with Keycloak using OAuth2/JWT
- π¬ Built-in email templates for account activation, welcome, and password reset
- π§© Extensible activation flow using
IActivationStore - βοΈ Ready-to-use endpoints (
/auth/register,/auth/login,/auth/activate, etc.) - π Minimal configuration and zero boilerplate
π¦ Installation
Add the NuGet package to your project:
dotnet add package ZCloakNet.Auth
βοΈ Configuration
Add the following configuration to your appsettings.json:
"ZCloakNet": {
"Auth": {
"BaseUrl": "http://localhost:8080",
"Realm": "myrealm",
"AdminClientId": "my-api-client",
"AdminClientSecret": "super-secret-value-123",
"PublicClientId": "my-app-client"
},
"Email": {
"Host": "smtp.mailserver.com",
"Port": 587,
"Username": "no-reply@myapp.com",
"Password": "email-password-123",
"From": "no-reply@myapp.com",
"EnableSsl": true,
"Templates": {
"Activation": {
"Subject": "Activate your MyApp account",
"BodyFilePath": "Templates/activation.html"
},
"Welcome": {
"Subject": "Welcome to MyApp",
"BodyFilePath": "Templates/welcome.html"
},
"ForgotPassword": {
"Subject": "Reset your password",
"BodyFilePath": "Templates/forgot-password.html"
}
}
}
}
π Explanation of settings:
| Key | Description |
|---|---|
Auth.BaseUrl |
URL of the Keycloak server |
Auth.Realm |
Realm name configured in Keycloak |
AdminClientId / AdminClientSecret |
Admin client credentials |
PublicClientId |
Client used by public applications |
Email.* |
SMTP configuration and template paths |
π οΈ Setup in Program.cs
To use the library, simply register it in your Program.cs:
var builder = WebApplication.CreateBuilder(args);
// π§ Register ZCloakNet
builder.Services.AddZCloakNet(builder.Configuration);
// π§© Register your activation store implementation
builder.Services.AddScoped<IActivationStore, UserIdentityService>();
var app = builder.Build();
// βοΈ Enable middleware and endpoints
app.UseZCloakNet();
app.MapZCloakNet();
app.Run();
β What each method does:
| Method | Purpose |
|---|---|
AddZCloakNet() |
Loads configuration and registers internal services |
AddScoped<IActivationStore, UserIdentityService>() |
Injects your custom activation logic |
UseZCloakNet() |
Adds internal middleware (error handling, etc.) |
MapZCloakNet() |
Maps all authentication endpoints automatically |
π IActivationStore Interface
The library exposes an interface so you can implement activation logic using your own database and domain model:
public interface IActivationStore
{
Task SaveAsync(IdentityUser user, CancellationToken ct);
Task<IdentityUser> FindByActivationCodeAsync(string code, CancellationToken ct);
Task ActivateAsync(string code, CancellationToken ct);
}
π§βπ» Example Implementation
Hereβs a simple implementation of IActivationStore using Entity Framework:
public class UserIdentityService : IActivationStore
{
private readonly UsersDbContext _context;
public UserIdentityService(UsersDbContext context)
{
_context = context;
}
public async Task SaveAsync(IdentityUser user, CancellationToken ct)
{
await _context.IdentityUsers.AddAsync(user, ct);
await _context.SaveChangesAsync(ct);
}
public async Task<IdentityUser> FindByActivationCodeAsync(string code, CancellationToken ct)
{
return await _context.IdentityUsers
.AsNoTracking()
.FirstOrDefaultAsync(u => u.ActivationCode == code, ct);
}
public async Task ActivateAsync(string code, CancellationToken ct)
{
var user = await _context.IdentityUsers.FirstOrDefaultAsync(u => u.ActivationCode == code, ct);
if (user is null) return;
user.IsActive = true;
user.ActivationCode = $"{user.ActivationCode}-activated-{DateTime.UtcNow:yyyyMMddHHmmss}";
await _context.SaveChangesAsync(ct);
}
}
π Example Usage in a Controller
[ApiController]
[Route("api/v1/activation")]
public class ActivationController : ControllerBase
{
private readonly IActivationStore _activationStore;
public ActivationController(IActivationStore activationStore)
{
_activationStore = activationStore;
}
[HttpPost("{code}")]
public async Task<IActionResult> Activate(string code, CancellationToken ct)
{
await _activationStore.ActivateAsync(code, ct);
return Ok(new { message = "Account successfully activated." });
}
}
π Available Endpoints
Once you call app.MapZCloakNet();, the following endpoints are available automatically:
| Endpoint | Method | Description |
|---|---|---|
/auth/register |
POST | Register a new user |
/auth/activate/{code} |
PATCH | Activate a user account |
/auth/login |
POST | Login with username and password |
/auth/refresh |
POST | Refresh access token |
/auth/logout |
DELETE | Logout and revoke tokens |
/auth/forgot-password |
POST | Send password reset email |
/auth/reset-password |
PATCH | Reset password with code |
β Quick Start
dotnet add package ZCloakNet.Auth
builder.Services.AddZCloakNet(builder.Configuration);
builder.Services.AddScoped<IActivationStore, UserIdentityService>();
app.UseZCloakNet();
app.MapZCloakNet();
π§βπΌ Recommended Project Structure
π src/
β£ π ZCloakNet.Auth/ # NuGet library
β£ π MyApp.API/ # Your API project
β£ π MyApp.Domain/ # Domain entities and interfaces
β£ π MyApp.Infrastructure/# EF Core + database logic
β π MyApp.Tests/ # Unit tests
π€ Contributing
Contributions, issues, and feature requests are welcome!
Feel free to open an issue or submit a pull request.
π License
This project is licensed under the MIT License.
| 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
- Microsoft.AspNetCore.Mvc.Versioning (>= 5.1.0)
- Microsoft.Extensions.Configuration.Abstractions (>= 8.0.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.0)
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 | |
|---|---|---|---|
| 2.0.2 | 218 | 1/1/2026 | |
| 2.0.1 | 156 | 1/1/2026 | |
| 2.0.0 | 161 | 1/1/2026 | |
| 1.3.1 | 479 | 11/18/2025 | |
| 1.3.0 | 453 | 11/18/2025 | |
| 1.2.9 | 363 | 11/17/2025 | |
| 1.2.8 | 245 | 10/28/2025 | |
| 1.2.7 | 242 | 10/28/2025 | |
| 1.2.6 | 229 | 10/26/2025 | |
| 1.2.5 | 158 | 10/25/2025 | |
| 1.2.4 | 163 | 10/25/2025 | |
| 1.2.3 | 207 | 10/24/2025 | |
| 1.2.2 | 230 | 10/20/2025 | |
| 1.2.1 | 224 | 10/16/2025 | |
| 1.2.0 | 228 | 10/14/2025 | |
| 1.1.0 | 236 | 10/9/2025 | |
| 1.0.10 | 236 | 10/6/2025 | |
| 1.0.9 | 312 | 10/6/2025 | |
| 1.0.8 | 310 | 10/6/2025 | |
| 1.0.7 | 231 | 10/6/2025 |