add api key auth for /api/v1 routes - #35
Merged
Merged
Conversation
add security scheme to docs
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR adds API key authentication for all /api/v1 routes to secure the public API endpoints. The implementation includes a complete authentication system with key generation, validation, rate limiting, and administrative management capabilities.
Key changes include:
- Implementation of API key authentication with Bearer token format using
lfc_prefixed keys - Addition of rate limiting and security validation middleware
- Creation of admin endpoints for API key management (create, list, update, revoke)
Reviewed Changes
Copilot reviewed 38 out of 39 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| swaggerSpec.ts | Added security scheme definition for API key authentication in OpenAPI documentation |
| src/server/services/auth.ts | New authentication service with API key creation, validation, and management capabilities |
| src/server/models/ApiKey.ts | New database model for storing API key metadata with proper column mapping |
| src/server/lib/auth/validate.ts | Authentication validation middleware for API routes with rate limiting checks |
| src/server/lib/auth/rateLimiter.ts | Redis-based rate limiting implementation using fixed window algorithm |
| src/server/lib/auth/keyGenerator.ts | Secure API key generation and validation utilities using bcrypt |
| src/server/db/migrations/003_add_api_keys.ts | Database migration to create api_keys table with proper indexes |
| src/pages/v1/docs.tsx | Updated API documentation to include security scheme definitions |
| src/pages/api/v1/**/*.ts | Added authentication validation to all v1 API endpoints |
| src/pages/api/v1/admin/api-keys/*.ts | New admin endpoints for API key CRUD operations |
| src/middleware.ts | Edge middleware for basic API key format validation before route processing |
| package.json | Added bcryptjs dependency for secure password hashing |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
You can also share your feedback on Copilot code review for a chance to win a $100 gift card. Take the survey.
vmelikyan
approved these changes
Aug 18, 2025
https enforcement handled at infrastrucure level
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Authorization: Bearer API_KEY