Csilk 0.2.1
A lightweight, high-performance C HTTP web framework
Loading...
Searching...
No Matches
auth.c File Reference

Token-based authentication middleware implementation. More...

#include <string.h>
#include "csilk/core/internal.h"
#include "csilk/csilk.h"
Include dependency graph for auth.c:

Functions

void csilk_auth_middleware (csilk_ctx_t *c, csilk_auth_validator_t validator)
 Token-based authentication middleware.
 

Detailed Description

Token-based authentication middleware implementation.

Function Documentation

◆ csilk_auth_middleware()

void csilk_auth_middleware ( csilk_ctx_t *  c,
csilk_auth_validator_t  validator 
)

Token-based authentication middleware.

Simple token-based authentication middleware.

Extracts the Bearer token from the Authorization header and validates it using the caller-provided validator callback. If validation fails, a 401 Unauthorized response is sent with a WWW-Authenticate header, and the request pipeline is aborted.

Parameters
cThe request context.
validatorCallback that receives the token string and returns non-zero if the token is valid, zero otherwise.
Note
This middleware does NOT handle token parsing beyond stripping the "Bearer " prefix — use the JWT middleware for structured token verification. Should be registered early in the pipeline (after request_id and session, before route handlers).
Warning
The validator must be stateless or thread-safe, as it may be invoked from multiple worker threads concurrently.