Integration Guide
.NET MVC C#
Complete guide for integrating .NET MVC applications with CAS SSO
10 min setup
Intermediate
.NET 6+
1. NuGet Installation
Package Manager Console
dotnet add package CasSystem.Client
dotnet add package Microsoft.AspNetCore.Authentication.JwtBearer
2. Configuration
appsettings.json
{
"CasSSO": {
"ServerUrl": "https://your-cas-server.com",
"ClientId": "your_client_id",
"ClientSecret": "your_client_secret",
"CallbackUrl": "https://your-app.com/cas/callback"
}
}
3. CAS Service
Services/CasAuthService.cs
public class CasAuthService
{
private readonly HttpClient _client;
private readonly CasSettings _settings;
public async Task<TokenResponse> ValidateToken(string token)
{
var payload = new {
token,
client_id = _settings.ClientId,
client_secret = _settings.ClientSecret
};
var response = await _client.PostAsJsonAsync(
$"{_settings.ServerUrl}/api/sso/validate", payload
);
return await response.Content
.ReadFromJsonAsync<TokenResponse>();
}
}
4. Controller & Middleware
Program.cs
builder.Services.AddSingleton<CasAuthService>();
builder.Services.AddAuthentication("CasSSO")
.AddScheme<CasAuthHandler, CasAuthOptions>("CasSSO", null);
app.UseAuthentication();
app.UseAuthorization();
Controllers/DashboardController.cs
[Authorize]
public class DashboardController : Controller
{
public IActionResult Index()
{
var user = HttpContext.Items["CasUser"];
return View(user);
}
}