feat: implement API key authentication for endpoints #3
No reviewers
Labels
No labels
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
jonasclaes/go-thermal-printer!3
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "dev/add-api-key-middleware"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.
Pull Request Overview
This PR implements API key authentication for all API endpoints to secure access to the thermal printer service. The authentication is implemented using a middleware approach with proper error handling and configuration support.
/apiroutes while keeping health endpoint publicReviewed Changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.
Show a summary per file
/apiroutes@ -0,0 +1,42 @@package middlewareConsider trimming whitespace from the API key header value to handle potential formatting issues in client requests that could cause authentication failures.
@ -0,0 +37,4 @@if apiKey != m.configService.GetServerConfig().ApiKey {return &common.InvalidAPIKeyError{}}The API key comparison should handle the case where the configured API key is empty. If no API key is configured, all requests would be accepted, which could be a security risk. Consider rejecting requests when the configured API key is empty.
@ -17,7 +20,20 @@ func (m *ErrorHandlerMiddleware) Add() gin.HandlerFunc {c.Next()This code will panic if the message string is empty. Add a length check before accessing message[0] and message[1:] to prevent runtime panics.
@ -0,0 +37,4 @@if apiKey != m.configService.GetServerConfig().ApiKey {return &common.InvalidAPIKeyError{}}It's a feature, not a bug. If people want to add no auth, that's fine. For example when it's only available on localhost...