Ozcorps.Ozt
9.0.0
dotnet add package Ozcorps.Ozt --version 9.0.0
NuGet\Install-Package Ozcorps.Ozt -Version 9.0.0
<PackageReference Include="Ozcorps.Ozt" Version="9.0.0" />
<PackageVersion Include="Ozcorps.Ozt" Version="9.0.0" />
<PackageReference Include="Ozcorps.Ozt" />
paket add Ozcorps.Ozt --version 9.0.0
#r "nuget: Ozcorps.Ozt, 9.0.0"
#:package Ozcorps.Ozt@9.0.0
#addin nuget:?package=Ozcorps.Ozt&version=9.0.0
#tool nuget:?package=Ozcorps.Ozt&version=9.0.0
Ozcorps.Ozt
A lightweight token-based authentication and authorization library for ASP.NET Core applications.
Features
- Token Generation & Validation — Generate encrypted, compressed tokens containing user information
- Role & Permission Based Authorization — Use
[OztActionFilter]attribute with role/permission checks (supports OR with,and AND with&) - Redis Permission Store — Offload permissions to Redis to keep tokens small (optional)
- gRPC Session Validator — Single-session management via external gRPC validator service (optional)
- Swagger Integration — Automatic OZT header parameter in Swagger UI
Installation
dotnet add package Ozcorps.Ozt
Configuration
Add to your appsettings.json:
{
"Ozt": {
"Key": "your-secret-key",
"Expire": 1440
}
}
Optional: Redis Permission Store
When users have many permissions, the token can exceed HTTP header size limits. Enable Redis to store permissions externally and keep tokens small:
{
"Ozt": {
"Key": "your-secret-key",
"Expire": 1440,
"RedisConnectionString": "localhost:6379"
}
}
When RedisConnectionString is set, permissions, roles, role IDs, and company IDs are stored in Redis instead of the token. The Redis key TTL matches the Expire value.
When RedisConnectionString is not set, the library behaves as before — all user data is embedded in the token.
Optional: gRPC Session Validator
For single-session management (new login invalidates old token):
{
"Ozt": {
"Key": "your-secret-key",
"Expire": 1440,
"GrpcUrl": "https://localhost:5001"
}
}
Usage
Register Services
builder.Services.AddOzt();
Generate Token
var oztTool = serviceProvider.GetService<OztTool>();
var user = new OztUser
{
UserId = 1,
Username = "john",
Email = "john@example.com",
Roles = new List<string> { "admin" },
Permissions = new List<string> { "read", "write" },
RoleIds = new List<long> { 1, 2 },
CompanyIds = new List<long> { 100 }
};
string token = oztTool.GenerateToken(user);
Validate Token Manually
var result = oztTool.ValidateToken(token);
if (result.IsValidated)
{
var user = result.OztUser;
}
Use as Action Filter
// No role/permission check — just validates the token
[OztActionFilter]
public IActionResult MyAction() { }
// OR check — user needs "admin" OR "editor" role
[OztActionFilter(Roles = "admin,editor")]
public IActionResult MyAction() { }
// AND check — user needs both "admin" AND "editor" roles
[OztActionFilter(Roles = "admin&editor")]
public IActionResult MyAction() { }
// Permission check
[OztActionFilter(Permissions = "read,write")]
public IActionResult MyAction() { }
Read User Info from HttpContext
var user = HttpContext.GetOztUser();
var userId = HttpContext.GetUserId();
var isAdmin = HttpContext.IsAdmin();
var companyIds = HttpContext.GetCompanyIds();
Configuration Options
| Property | Type | Description |
|---|---|---|
Key |
string |
Secret key for token encryption |
Expire |
int |
Token expiration time in minutes (0 = no expiry) |
RedisConnectionString |
string |
Redis connection string for external permission storage (optional) |
GrpcUrl |
string |
gRPC validator service URL for single-session management (optional) |
| 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
- Google.Protobuf (>= 3.29.3)
- Grpc.Net.Client (>= 2.67.0)
- Ozcorps.Core (>= 3.0.1)
- StackExchange.Redis (>= 2.13.1)
- Swashbuckle.AspNetCore (>= 6.4.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 |
|---|---|---|
| 9.0.0 | 3,021 | 5/14/2026 |
| 8.3.0 | 492 | 1/15/2026 |
| 8.2.1 | 12,490 | 7/29/2025 |
| 8.2.0 | 441 | 7/29/2025 |
| 8.1.0 | 4,315 | 2/6/2025 |
| 8.0.0 | 1,699 | 11/26/2024 |
| 2.2.0 | 1,006 | 2/6/2025 |
| 2.1.0 | 4,561 | 6/25/2024 |
| 2.0.3 | 1,131 | 3/25/2024 |
| 2.0.2 | 286 | 3/15/2024 |
| 2.0.1 | 293 | 1/23/2024 |
| 2.0.0 | 1,419 | 6/12/2023 |
| 1.1.2 | 288 | 8/29/2023 |
| 1.1.1 | 1,081 | 8/23/2023 |
| 1.1.0 | 285 | 8/23/2023 |
| 1.0.3 | 727 | 11/29/2024 |
| 1.0.2 | 882 | 12/14/2023 |
| 1.0.1 | 1,367 | 11/24/2022 |
| 1.0.0 | 511 | 10/27/2022 |