feat: add api key authentication - #143
Merged
Dejmenek merged 7 commits intoSep 14, 2026
Merged
Conversation
Introduced a new `ApiKeyAuthenticationHandler` class in the `TournamentAPI.Authentication` namespace to enable API key-based authentication. - Implemented `HandleAuthenticateAsync` to: - Retrieve and validate the API key from request headers. - Compare API keys securely using `CryptographicOperations.FixedTimeEquals`. - Return appropriate `AuthenticateResult` for success or failure. - Created static claims (`Name` and `client_id`) for authenticated clients.
Introduce `CustomHttpResponseFormatter` to handle specific GraphQL error codes with custom HTTP status codes. Updated `GraphQLExtensions` to integrate the formatter into the GraphQL server configuration. The formatter returns `HttpStatusCode.Unauthorized` for errors with the code `AUTH_API_KEY_INVALID`, enhancing error handling for authentication-related issues.
The tests cover various scenarios, including: - Public queries without/with invalid API keys returning `AUTH_API_KEY_INVALID` errors. - Public queries with valid API keys succeeding without JWTs. - Protected queries with valid API keys but no JWTs returning `AUTH_NOT_AUTHENTICATED` errors. - Protected queries with valid API keys and JWTs succeeding. - Protected queries with valid JWTs but no API keys failing with `AUTH_API_KEY_INVALID` errors.
Added `ApiKey`, `ConnectionStrings`, `Jwt`, and `HealthCheck` sections to `appsettings.Development.json` with actual values for development purposes. Updated `appsettings.json` to include the same sections but with empty values to ensure sensitive data is not exposed in production.
Dejmenek
deleted the
feat/111-add-api-key-authentication-for-the-frontend-client
branch
September 14, 2026 08:48
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.
Summary
This pull request implements API key authentication, updates the
TestClientfor API key management, and adds integration tests to validate the new functionality. It also includes configuration updates and security enhancements.Changes
ApiKeyAuthenticationHandlerandApiKeyAuthenticationOptions: Added to handle API key authentication and define the scheme.HttpRequestInterceptor: Enforced API key validation for GraphQL requests, throwingAUTH_API_KEY_INVALIDerrors for invalid/missing keys.TestClientandBaseIntegrationTest: Enhanced to support API key management and dynamically set API keys from configuration.ApiKeyAuthenticationTests: Added tests for scenarios with valid, invalid, and missing API keys, as well as interactions with JWT.ApiKeyandJwtplaceholders inappsettings.jsonand development-specific values inappsettings.Development.json.