-
Notifications
You must be signed in to change notification settings - Fork 45
Feature: add api key auth #204
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
@0xfurai please review :) |
bf65290 to
f2dc1c7
Compare
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #204 +/- ##
==========================================
- Coverage 19.31% 18.61% -0.70%
==========================================
Files 170 181 +11
Lines 18144 18826 +682
==========================================
Hits 3504 3504
- Misses 14479 15161 +682
Partials 161 161 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Wow this is huge effort! Could you please remove dependency if possible. |
Yes, no problem. :) |
f2dc1c7 to
e56c516
Compare
|
Rebased on main of this repository. FYI @0xfurai |
0xfurai
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wow! this is huge PR, thanks again. I have left couple of comments, most of them minor but the api keys validation is important to address.
Waiting for updates 😉
|
@0xfurai the |
|
FYI I didn't test |
|
Not sure why the codecov checks are failing. Is it because of the line coverage decreasing? |
codecov only failing, thats fine |
|
@0xfurai FYI I can test and rebase onto main when the asdf PR is merged. |
done, go ahead |
- Add complete API key CRUD operations with validation - Implement unified AuthChain middleware for consistent authentication - Add API key management endpoints with proper error handling - Enhance database schema for API key storage and relationships - Add comprehensive validation for API key creation and updates - Implement multi-language localization support for API key management - Remove unused authentication methods and streamline middleware - Add proper field validation and required field enforcement This implementation provides a robust foundation for API key-based authentication across the Peekaping monitoring platform.
…ferences - Remove user_id from API key model and related database schema - Update API key service and repository methods to eliminate user_id dependency - Refactor controller methods to handle API key operations without user context
- Eliminate FindByKeyHash method from both MongoDB and SQL repository implementations - Update repository interfaces to reflect the removal of the FindByKeyHash method
- Update error responses in CreateAPIKey, GetAPIKeys, GetAPIKey, UpdateAPIKey, and DeleteAPIKey methods to return specific error messages instead of generic ones. - Log a warning when an API key is not found in the Delete method of the service layer.
- Implement validation in CreateAPIKey and UpdateAPIKey methods to ensure expiration date is not in the past and max usage count is greater than 0. - Remove redundant validation logic from the service layer, centralizing it in the controller for clean boundary separation.
- Eliminate the FindAll method from the SQLRepositoryImpl, streamlining the API key management logic. - This change simplifies the repository interface and focuses on essential operations.
- Update API key generation to include its unique ID for each key, improving traceability. - Refactor validation logic to parse the API key token, extracting the ID and actual key for verification. - Simplify the validation process by reducing the number of database queries needed to validate an API key. - Ensure that the actual key is securely hashed and stored, while the token includes the ID and key in a structured format.
- Update API key display key generation to use ApiKeyPrefix for consistency. - Modify middleware to check for ApiKeyPrefix instead of hardcoded values in authorization logic. - Enhance error handling in authentication methods to utilize http.StatusUnauthorized for clarity.
…ount - Update validation logic in the API key creation schema to ensure expiration date is a valid future date. - Refine max usage count validation to enforce that it is a positive integer. - Add additional validation checks before submission to provide immediate feedback on errors.
- Replace separate state variables for new token and newly created key ID with a single object to streamline state management. - Update related functions to utilize the new state structure for improved clarity and maintainability. - Ensure UI components reflect changes in the consolidated state.
- Introduce a new CreateAPIKeyModal component to streamline the API key creation process. - Replace the previous dialog implementation with a more modular approach, enhancing code readability and maintainability. - Update the APIKeys component to utilize the new modal, improving user experience by managing state and success callbacks more effectively.
- Introduce a DeleteConfirmationModal component to confirm API key deletions, enhancing user experience and preventing accidental deletions. - Update the APIKeys component to manage the delete confirmation state and handle deletion logic more effectively. - Refactor the handleDelete function to trigger the confirmation modal with the appropriate API key details.
- Remove JSON tags and validation constraints from CreateRequest and UpdateRequest types.
- Change the Alert component in the APIKeys to use a success variant for better visual feedback. - Modify the styling of the token display to enhance readability and user experience.
4e1115e to
09ac4cc
Compare
- Introduce translations for the delete confirmation dialog related to API keys in various languages, enhancing internationalization support. - Languages updated include Arabic, Belarusian, Bulgarian, Czech, Danish, German, Greek, English, Spanish, Estonian, Basque, Persian, Finnish, French, Irish, Hebrew, Croatian, Hungarian, Indonesian, Italian, Japanese, Georgian, Korean, Lithuanian, Norwegian, Dutch, Polish, Portuguese, Romanian, Slovenian, Serbian (Cyrillic and Latin), Swedish, Thai, Turkish, Ukrainian, Urdu, Uzbek, Vietnamese, Cantonese, Simplified Chinese, Traditional Chinese, and more.
- Refactor API key creation process to generate keys in three phases: initial record creation, key generation, and record update with key details. - Introduce new methods for updating key hash and display key in both MongoDB and SQL repositories. - Enhance the service layer to handle key generation and parsing, improving overall API key management. - Remove redundant utility functions related to key generation and hashing, consolidating logic within the service layer for better maintainability.
- Adjust the validation logic in isValidAPIKeyFormat to allow for a longer key length, accommodating base64 encoding requirements. - Ensure the prefix check uses the length of ApiKeyPrefix for improved accuracy.
- Change last_used and expires_at columns to TIMESTAMPTZ for better timezone handling. - Allow key_hash and display_key to be NULL initially to support two-phase creation process. - Update created_at and updated_at columns to TIMESTAMPTZ for consistency.
- Remove redundant JWT and API key authentication methods, consolidating logic into the AllAuth method. - Enhance logging for missing authorization headers and successful authentication attempts. - Introduce clear type and constructor comments for better code organization.
|
LGTM, thanks for contribution! |



Warning: this PR is based on top off #202 (I can remove that dependency though)
Solves #182
Screenshots:
Overview:

Create new API key modal (respects tanstack query):

Overview:


