LibraryService API uses JWT Bearer authentication. A signed token is issued atDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/marchena96/Paradigma-lab1/llms.txt
Use this file to discover all available pages before exploring further.
POST /login and must be attached to every request to a protected endpoint as an Authorization: Bearer <token> header. Requests that are missing or carry an invalid token receive a 401 Unauthorized response automatically — no extra handling is needed in individual controllers.
How it works
AuthController delegates to IAuthenticationService
AuthController.Login passes the credentials to IAuthenticationService.AuthenticateAsync. If the credentials are invalid the method returns null and the controller immediately returns 401 Unauthorized.TokenGenerator signs the JWT
When
AuthenticateAsync returns a valid User object, AuthController calls TokenGenerator.GenerateToken(validuser, jwtSettings). The generator builds a set of claims, creates a symmetric HMAC SHA-256 signing key from JwtSettings.SecretKey, and constructs a JwtSecurityToken.Claims are embedded in the token
Three standard claims are written into the JWT payload:
NameIdentifier (the user’s integer ID as a string), Email, and Role.Getting a token
Send aPOST request to /login with a JSON body containing the email and password fields:
200 OK) returns the TokenResponse record serialised as JSON:
401 Unauthorized with an empty body.
Using the token
Pass the token in theAuthorization header on every request to a protected endpoint:
<jwt-string> with the exact value of the token field returned by /login.
Token structure
The JWT payload contains three claims built from the authenticatedUser object:
| Claim | Type | Value |
|---|---|---|
NameIdentifier | ClaimTypes.NameIdentifier | User ID (integer serialised as a string) |
Email | ClaimTypes.Email | User’s email address |
Role | ClaimTypes.Role | User’s role (e.g. admin) |
Validation parameters
The JWT Bearer middleware is configured inStartup.ConfigureServices with the following TokenValidationParameters:
| Parameter | Setting |
|---|---|
| Algorithm | HS256 (HMAC SHA-256) |
| Issuer | MyApp (from JwtSettings.Issuer) |
| Audience | localhost:80 (from JwtSettings.Audience) |
| Signing key | Symmetric key derived from JwtSettings.SecretKey (UTF-8 bytes) |
| Clock skew | Zero (TimeSpan.Zero) — no grace period |
| Token lifetime | Validated (ValidateLifetime = true) |
ValidateIssuer = true, ValidateAudience = true), so a token issued with a different issuer or audience string will be rejected even if the signature is valid.
Protected endpoints
AuthController is the only controller with an access-control attribute. POST /login is decorated with [AllowAnonymous] and is always publicly accessible — no token is needed to obtain one. All other endpoints in the API do not carry an [Authorize] attribute and are accessible without a token at the controller level.
| Method | Route | Access |
|---|---|---|
POST | /login | Public — [AllowAnonymous] |
GET | /api/libraries/{libraryId}/books | No [Authorize] attribute |
POST | /api/libraries/{libraryId}/books | No [Authorize] attribute |
TokenGenerator source
The full implementation ofTokenGenerator.GenerateToken used to sign every token: