APIKeyMiddleware validates API key for protected endpoints. Swagger documentation endpoints (/swagger/*) are exempt from authentication to allow users to browse and test the API documentation freely.
(apiKey string)
| 119 | // Swagger documentation endpoints (/swagger/*) are exempt from authentication |
| 120 | // to allow users to browse and test the API documentation freely. |
| 121 | func APIKeyMiddleware(apiKey string) gin.HandlerFunc { |
| 122 | return apiKeyMiddleware(apiKey, newAuthFailureLimiter()) |
| 123 | } |
| 124 | |
| 125 | func apiKeyMiddleware(apiKey string, limiter *authFailureLimiter) gin.HandlerFunc { |
| 126 | // Hash the configured key so the comparison avoids leaking its length through timing. |