CasSystem.Client
2.0.0
dotnet add package CasSystem.Client --version 2.0.0
NuGet\Install-Package CasSystem.Client -Version 2.0.0
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="CasSystem.Client" Version="2.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="CasSystem.Client" Version="2.0.0" />
<PackageReference Include="CasSystem.Client" />
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 CasSystem.Client --version 2.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: CasSystem.Client, 2.0.0"
#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 CasSystem.Client@2.0.0
#: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=CasSystem.Client&version=2.0.0
#tool nuget:?package=CasSystem.Client&version=2.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
.NET CAS Client
A .NET library for seamless integration with One System CAS (Central Authentication Service) SSO servers. Targets .NET 8 and works with ASP.NET Core 8.
Features
- 🔐 Secure SSO Authentication — JWT token-based authentication
- 🛡️ HMAC Signature Validation — Request signing with SHA-256
- 👥 Role-Based Access Control — ASP.NET Core middleware for role protection
- ⚡ Async/Await — Fully asynchronous API
- 💉 Dependency Injection — Built-in service registration extensions
- 🔄 Thread-Safe Caching — ConcurrentDictionary token cache
Requirements
- .NET 8 SDK (the package targets
net8.0). - An ASP.NET Core (web) host — the package references the
Microsoft.AspNetCore.Appshared framework forHttpContext,IServiceCollection, and the middleware.
Installation
NuGet
dotnet add package CasSystem.Client
Package Manager
Install-Package CasSystem.Client
How it works
- Browser SSO — send the user to
GetLoginUrl(), which buildsGET {ServerUrl}/sso/login?client_id={ClientId}. The One System CAS server authenticates the user and 302-redirects the browser back to the registeredcallback_urlwith?token={JWT}appended. - Server-to-server validation — call
ValidateTokenAsync(token), which POSTs to{ServerUrl}/api/validate-tokenwith{ token, client_id, client_secret }. On success the server returns200 { valid: true, user: { id, username, email }, expires_at }. The token is single-use — validate it exactly once, then create your own session. - Service-to-service issuance —
GenerateSSOTokenAsync(username)POSTs to{ServerUrl}/api/sso/tokenwith{ client_id, client_secret, username }to mint a token for a user (the caller must be IP-whitelisted on the CAS server).
Quick Start
1. Configure in Program.cs
using CasSystem.Client;
var builder = WebApplication.CreateBuilder(args);
// Register CAS client
builder.Services.AddCasClient(new CasConfig
{
ServerUrl = "https://your-cas-server.com",
ClientId = "your_client_id",
ClientSecret = "your_client_secret",
CallbackUrl = "https://your-app.com/cas/callback",
});
builder.Services.AddSession();
var app = builder.Build();
app.UseSession();
app.UseMiddleware<CasAuthMiddleware>();
app.MapGet("/dashboard", (HttpContext ctx) =>
{
var user = ctx.Items["cas_user"] as Dictionary<string, object>;
return Results.Json(new { user });
});
app.Run();
2. Manual Authentication
using CasSystem.Client;
var config = new CasConfig
{
ServerUrl = "https://your-cas-server.com",
ClientId = "your_client_id",
ClientSecret = "your_client_secret",
};
var cas = new CasClient(config);
// Generate login URL
var loginUrl = cas.GetLoginUrl("https://your-app.com/dashboard");
// Validate token
var user = await cas.ValidateTokenAsync(token);
if (user != null)
{
var username = user["username"].ToString();
}
// Role checks
bool isAdmin = CasClient.UserHasRole(user, "admin");
// Logout
await cas.LogoutAsync(token);
3. Controller Usage
[ApiController]
[Route("api/[controller]")]
public class DashboardController : ControllerBase
{
private readonly CasClient _cas;
public DashboardController(CasClient cas) => _cas = cas;
[HttpGet]
public IActionResult Index()
{
var user = HttpContext.Items["cas_user"] as Dictionary<string, object>;
if (user == null) return Unauthorized();
return Ok(new { user });
}
}
API Reference
| Method | Description |
|---|---|
GetLoginUrl(returnUrl?) |
Generate CAS login URL |
GenerateSSOTokenAsync(username) |
Generate SSO token |
ValidateTokenAsync(token) |
Validate token, returns user dict |
GetUserFromToken(token) |
Get cached user data |
LogoutAsync(token?) |
Logout from CAS server |
UserHasRole(user, role) |
Check single role |
UserHasAnyRole(user, roles) |
Check any of roles |
UserHasAllRoles(user, roles) |
Check all roles |
License
MIT
| 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. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net8.0
- System.Text.Json (>= 8.0.5)
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.0 | 115 | 7/8/2026 |