Open
Conversation
|
@dohoudaniel Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
…middleware - Wired globalLimiter, sensitiveLimiter, and authenticateToken in src/index.js - Fixed authenticateToken vs sensitiveLimiter execution order - Re-architected index.test.js, auth.test.js, and rateLimit.test.js to send valid invoice bodies and pass generated JWT tokens - Restored src/index.test.js to passing state - Global coverage improved to 98.9%
Contributor
|
Resolve the conflicts & revert the changes in package-lock.json |
Author
|
@mikewheeleer I have resolved all conflicts. |
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
Adds optional API key authentication for trusted machine-to-machine (service-to-service) clients. Keys are scoped to specific permissions and support instant revocation — all without requiring a database.
Closes #41
Motivation
The existing
authenticateJWTmiddleware is designed for user-facing sessions. Service clients (e.g. a billing pipeline, a data-ingestion worker) do not hold user sessions — they need a simpler, long-lived credential with tightly scoped permissions. API keys fill this gap while remaining fully compatible with the existing JWT path.What Changed
src/config/apiKeys.js (new)
API_KEYSenvironment variable — a semicolon-separated list of JSON objects.lf_prefix, minimum key length (10 chars), non-emptyclientId, non-emptyscopesarray drawn from the allowlist, optional booleanrevokedflag.Map<key → entry>for O(1) lookup and detects duplicate keys at startup.src/middleware/apiKeyAuth.js (new)
401ifX-API-Keyheader is missing or blank.401if key is unknown or revoked.403ifrequiredScopeis set but the key does not hold it.req.apiClient = { clientId, scopes }for downstream handlers.tests/unit/apiKeyAuth.test.js (new)
42 tests across 14
describeblocks covering:API_KEYSenvREADME.md (updated)
New API Key Authentication section covering: header name,
API_KEYSschema table, scope table, error-response table, zero-downtime key rotation steps, and a usage code example.Updated Project structure diagram to include all new files.
.env.example (updated)
Documents
API_KEYSformat, per-field schema, a copy-paste example with one active and one revoked entry, key rotation notes, andJWT_SECRET..gitignore (updated)
Added
coverageto prevent the Jest coverage report from being tracked.Available Scopes
invoices:readGET /api/invoices— list active invoicesinvoices:writePOST /api/invoices— create / modify invoicesescrow:readGET /api/escrow/:id— read escrow stateKey Rotation (zero-downtime)
API_KEYS."revoked": truein its entry and redeploy.Security Notes
lf_prefix and be at least 10 characters — prevents accidental short / generic strings from being accepted.req.apiClientexposes onlyclientIdandscopes, never the raw key.security/detect-object-injectionfalse-positive on the constant-keyed header access (req.headers[API_KEY_HEADER]) is suppressed with an inlineeslint-disablecomment, consistent with the pattern already used in src/index.js.process.envbut can be overridden in tests — this keeps tests fully isolated without module-level mocking.Test Output
Usage Example
req.apiClienton a successful request:{ "clientId": "billing-service", "scopes": ["invoices:read", "invoices:write"] }Checklist
eslint-plugin-jsdocnpm run lintpasses with zero errors on new filescoverage/added to .gitignore