# AlastackCas **Repository Path**: kyzala/AlastackCas ## Basic Information - **Project Name**: AlastackCas - **Description**: A .NET client supports Central Authentication Service (CAS). - **Primary Language**: C# - **License**: MIT - **Default Branch**: main - **Homepage**: https://github.com/kyzala/AlastackCas - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2024-02-25 - **Last Updated**: 2026-11-04 ## Categories & Tags **Categories**: Uncategorized **Tags**: Alastack, Authentication, auth, CAS ## README # Alastack Cas A .NET client supports Central Authentication Service ([CAS](https://apereo.github.io/cas/7.2.x/protocol/CAS-Protocol.html)). [![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/kyzala/AlastackCas/dotnet.yml?branch=main)](https://github.com/kyzala/AlastackCas/actions/workflows/dotnet.yml)[![GitHub](https://img.shields.io/github/license/kyzala/AlastackCas)](LICENSE)[![Nuget](https://img.shields.io/nuget/v/Alastack.Cas)](https://www.nuget.org/packages/Alastack.Cas) ## Getting started ### Install package from the .NET CLI ``` dotnet add package Alastack.Cas ``` ### Dependency Injection `AuthenticationBuilder` extension methods to configure CAS authentication. ```c# var builder = WebApplication.CreateBuilder(args); builder.Services.AddControllersWithViews(); builder.Services.AddAuthentication(options => { options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme; }) .AddCookie(options => { options.LoginPath = "/signin"; options.LogoutPath = "/signout"; options.SlidingExpiration = true; options.ExpireTimeSpan = TimeSpan.FromMinutes(3); options.Cookie.Name = ".app.cookies"; //options.Cookie.MaxAge = TimeSpan.FromMinutes(1); //options.Cookie.Expiration = TimeSpan.FromMinutes(1); }) .AddCas(options => { options.Service = builder.Configuration["CAS:Service"]!; options.Server = builder.Configuration["CAS:Server"]!; options.SaveTokens = true; //options.ProtocolVersion = builder.Configuration["ProtocolVersion"]; //options.LoginPath = builder.Configuration["CAS:LoginPath"]; //options.LogoutPath = builder.Configuration["CAS:LogoutPath"]; //options.ServiceValidatePath = builder.Configuration["CAS:ServiceValidatePath"]; //options.ProxyValidatePath = builder.Configuration["CAS:ProxyValidatePath"]; //options.SignInScheme = CookieAuthenticationDefaults.AuthenticationScheme; }); var app = builder.Build(); app.UseStaticFiles(); app.UseRouting(); app.UseCookiePolicy(); app.UseAuthentication(); app.UseAuthorization(); app.MapControllerRoute(name: "default", pattern: "{controller=Home}/{action=Index}/{id?}"); app.Run(); ``` ### Configuration Using json configuration. ```JSON { "CAS": { "Service": "[CAS integration app uri]", // https://casclientsite "Server": "[CAS service uri]", // https://casserver/cas "ProtocolVersion": "3.0", "LoginPath": "/login", "LogoutPath": "/logout", "ServiceValidatePath": "/serviceValidate", "ProxyValidatePath": "/proxyValidate" } } ``` ### Single logout Sign out of both the local cookie and the CAS single sign-on session: ```c# return SignOut(new AuthenticationProperties { RedirectUri = "/" }, CookieAuthenticationDefaults.AuthenticationScheme, CasDefaults.AuthenticationScheme); ``` The CAS handler redirects to `{Server}{LogoutPath}?service={app url}`. After the CAS session is destroyed, the CAS server redirects back to `RedirectUri` (requires the CAS server to allow service redirects). ### Authentication failures When the CAS server rejects a ticket, the failure code and description returned by the server (e.g. `INVALID_TICKET`) are surfaced through the standard `RemoteFailure` event and the authentication failure message. ## CasOptions The `CasOptions` object provides properties that connects to the CAS server. | Property | Description | Default | | --------------------- | ------------------------------------------------------------ | ----------------------------- | | `Service` | | `null` | | `Renew` | if this parameter is set, single sign-on will be bypassed. In this case, CAS will require the client to present credentials regardless of the existence of a single sign-on session with CAS. This parameter is not compatible with the `gateway` parameter. | `false` | | `Gateway` | if this parameter is set, CAS will not ask the client for credentials. If the client has a pre-existing single sign-on session with CAS, or if a single sign-on session can be established through non-interactive means (i.e. trust authentication), CAS MAY redirect the client to the URL specified by the `service` parameter, appending a valid service ticket. (CAS also MAY interpose an advisory page informing the client that a CAS authentication has taken place.) If the client does not have a single sign-on session with CAS, and a non-interactive authentication cannot be established, CAS MUST redirect the client to the URL specified by the `service` parameter with no “ticket” parameter appended to the URL. If the `service` parameter is not specified and `gateway` is set, the behavior of CAS is undefined. | `false` | | `Server` | CAS Server Uri. | `null` | | `ProtocolVersion` | CAS protocol version. | `2.0` | | `LoginPath` | Credential requestor / acceptor. | `/login` | | `LogoutPath` | Destroy CAS session (logout). | `/logout` | | `ServiceValidatePath` | Service ticket validation. | Depends on `ProtocolVersion`: `/validate` (1.0), `/serviceValidate` (2.0), `/p3/serviceValidate` (3.0) | | `ProxyValidatePath` | Service/proxy ticket validation. | Depends on `ProtocolVersion`: `/proxyValidate` (2.0), `/p3/proxyValidate` (3.0) | | `CallbackPath` | The path the CAS server redirects back to after login. | `/signin-cas` | | `ClaimsFilter` | Used to select values from the CAS validation response and create Claims. | `DefaultCasClaimsFilter` | | `TicketValidator` | Checks the validity of a service ticket and returns the AuthenticationTicket. | `CompositeCasTicketValidator` | | `StateDataFormat` | Gets or sets the type used to secure data handled by the middleware. | `PropertiesDataFormat` | More information: [CAS - CAS Protocol Specification](https://apereo.github.io/cas/7.2.x/protocol/CAS-Protocol-Specification.html) ## Samples Visit the [samples](https://github.com/kyzala/AlastackCas/tree/main/samples) folder.