Auth Middleware
The Auth Middleware, defined in auth.go
, is responsible for extracting authentication tokens from incoming requests. It supports multiple authentication methods to provide flexibility in how clients can authenticate.
Key Features
- Checks multiple sources for authentication tokens
- Supports different authentication methods
- Sets extracted token information in the request context
Token Extraction Process
- Check the
Authorization
header - If not found, check the
X-API-Key
header - If still not found, check the
access_token
query parameter
Usage in Routes
protected := r.Group("/api/v1")
protected.Use(middleware.AuthMiddleware())
This middleware sets the stage for token validation, which is handled by the Token Middleware.