Regira-Packages

Regira Security — Cookie Authentication

Cookie-based sessions from Regira.Security.Authentication, for a server-rendered app or a same-site SPA that prefers a cookie over a bearer token.


For server-rendered apps, Blazor Server, and same-site SPAs. No extra package — it is in the ASP.NET Core shared framework.

var services = new ServiceCollection();
IConfiguration configuration = new ConfigurationManager();

services.AddCookieAuthentication(o =>
{
    o.IsApi = true;                          // 401/403 instead of a 302 to LoginPath
    o.ExpireTimeSpan = TimeSpan.FromHours(8);
});

// or bind Authentication:Cookie
services.AddCookieAuthentication(configuration);

CookieAuthOptions

Property Type Default Description
AuthenticationScheme string "Cookies" The framework’s own name, so SignInAsync without a scheme resolves here
CookieName string ".Regira.Auth"  
IsApi bool false Answer 401/403 instead of redirecting
ExpireTimeSpan TimeSpan 8 h  
SlidingExpiration bool true Measured from the last request
LoginPath / LogoutPath / AccessDeniedPath string /login, /logout, /forbidden Ignored when IsApi
ReturnUrlParameter string "returnUrl"  
SameSite SameSiteMode Lax  
SecurePolicy CookieSecurePolicy Always  
Domain string? null  
Claims ClaimNormalizationOptions (defaults) Source claim types folded into the canonical set
Configure Action<CookieAuthenticationOptions>? null Applied last, for anything not exposed

HttpOnly is always on and not configurable.

Signing in and out

await HttpContext.SignInWithClaimsAsync(claims, isPersistent: true);   // normalizes first
await HttpContext.SignOutCookieAsync();

Normalization runs at sign-in, so the canonical claim spellings go into the ticket rather than being recomputed per request.


Overview

  1. Index — Overview, projects, and choosing a scheme
  2. Encryption & Hashing — Symmetric encryption, PBKDF2 and BCrypt password hashing
  3. JWT Authentication — Self-issued bearer tokens, claims, and refresh tokens
  4. API Key Authentication — Key-based auth for machine callers
  5. External Identity Providers — Validating external bearer tokens; OpenID Connect sign-in
  6. Cookie Authentication — Cookie-backed sessions
  7. Composing Multiple Schemes — Running several schemes side by side
  8. Pre-built Auth Controllers — Account, password and user endpoints
  9. Practical Examples — Complete implementation examples

License

Apache License 2.0 — this package contains no license validation and no runtime limits. See LICENSE. A few companion packages are commercially licensed with a free tier; see the licensing overview.