The Gestión Clínica API uses JSON Web Tokens (JWT) for stateless authentication. Token creation and validation are handled entirely by two classes in theDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/ttpullima/RomsoftBackEnd2021_v2/llms.txt
Use this file to discover all available pages before exploring further.
WebApi project: TokenGenerator (issues tokens at login) and TokenValidationHandler (validates tokens on every subsequent request). Both classes read their configuration from exactly four <appSettings> keys in Web.config — no code changes are needed to adjust the signing secret, issuer, audience, or session lifetime.
AppSettings Keys
The symmetric HMAC-SHA256 signing secret.
TokenGenerator uses this key to sign newly issued tokens; TokenValidationHandler uses the same key to verify incoming tokens. Any change to this value immediately invalidates all currently active sessions — all clients will receive 401 Unauthorized until they log in again and obtain a new token.Recommended format: a randomly generated UUID string (e.g., output of Guid.NewGuid().ToString()) or a 32-byte hex string.The expected
aud (audience) claim in every token. TokenGenerator sets this as the audience when creating a token; TokenValidationHandler rejects any token whose aud claim does not match this value exactly. In production, set this to the base URL of the API (e.g., https://api.romsoft.pe).The expected
iss (issuer) claim. Must match the value embedded in the token at creation time. Typically set to the same URL as JWT_AUDIENCE_TOKEN for single-server deployments.Token lifetime in minutes. The default value of
28800 equals 20 days (28800 ÷ 60 = 480 hours), which is a very long session window. After expiry, TokenValidationHandler returns 401 Unauthorized and the client must re-authenticate.To shorten sessions to 4 hours, set this to 240. To extend to 12 hours, use 720.TokenGenerator — Issuing Tokens
TokenGenerator is an internal static class in University.API.Controllers (the original namespace, retained from the template). It exposes a single method called at login time by AccountController:
header.payload.signature string. Clients store it (typically in memory or localStorage) and include it in every subsequent request as Authorization: Bearer <token>.
TokenValidationHandler — Validating Tokens
TokenValidationHandler extends DelegatingHandler and is registered globally in WebApiConfig.Register. It runs before any controller action:
Validation Checks Performed
| Check | Mechanism |
|---|---|
| Token present | TryRetrieveToken — looks for Authorization: Bearer <token> header |
| Audience matches | ValidAudience = JWT_AUDIENCE_TOKEN |
| Issuer matches | ValidIssuer = JWT_ISSUER_TOKEN |
| Signing key valid | IssuerSigningKey = HMAC-SHA256 key derived from JWT_SECRET_KEY |
| Not expired | Custom LifetimeValidator: DateTime.UtcNow < expires |
Authorization header is passed through to the controller. A request with a present but invalid token (wrong signature, wrong issuer, expired) returns 401 Unauthorized immediately without reaching the controller.
Changing the Token Expiry
To adjust session length, change only theJWT_EXPIRE_MINUTES value in Web.config:
Production Configuration Checklist
Generate a new JWT_SECRET_KEY
Run the following in a C# script or LINQPad:
Console.WriteLine(Guid.NewGuid().ToString()); and replace the value in Web.Release.config.Set JWT_AUDIENCE_TOKEN and JWT_ISSUER_TOKEN to your production URL
Replace
http://localhost:44390 with the actual HTTPS URL of the deployed API, e.g., https://api.romsoft.pe.Review JWT_EXPIRE_MINUTES for your clinic's shift schedule
The default 28800 minutes (20 days) is a very long session window. For a standard 8-hour clinical shift set this to
480; for 12-hour shifts use 720. Adjust based on your clinic’s security and compliance policy.