-
Notifications
You must be signed in to change notification settings - Fork 11
Add expiry and last-used tracking to API keys #75
Copy link
Copy link
Open
Labels
GRANTFOX OSSGrantFox open-source campaign taskGrantFox open-source campaign taskMAYBE REWARDEDMay be rewarded under the GrantFox campaignMay be rewarded under the GrantFox campaignOFFICIAL CAMPAIGNOfficial GrantFox campaign issueOfficial GrantFox campaign issuearea:api-keysapi keysapi keyspriority:mediumMedium priorityMedium prioritystack:expressstack:expressstack:expressstack:nodejsNode.jsNode.jsstack:typescriptTypeScriptTypeScripttype:enhancementImprovement to existing functionalityImprovement to existing functionality
Description
Metadata
Metadata
Assignees
Labels
GRANTFOX OSSGrantFox open-source campaign taskGrantFox open-source campaign taskMAYBE REWARDEDMay be rewarded under the GrantFox campaignMay be rewarded under the GrantFox campaignOFFICIAL CAMPAIGNOfficial GrantFox campaign issueOfficial GrantFox campaign issuearea:api-keysapi keysapi keyspriority:mediumMedium priorityMedium prioritystack:expressstack:expressstack:expressstack:nodejsNode.jsNode.jsstack:typescriptTypeScriptTypeScripttype:enhancementImprovement to existing functionalityImprovement to existing functionality
Type
Fields
Give feedbackNo fields configured for Feature.
Add API-key expiry and last-used tracking
Description
ApiKeyRecordinsrc/index.tsonly stores{ label, createdAt }. Keys minted viaPOST /api/v1/api-keysnever expire and there is no record of whether a key has ever been used, making operational rotation and stale-key cleanup impossible. This issue adds an optional expiry on creation andlastUsedAttracking, surfaced through the existing list endpoint.Requirements and context
expiresInSeconds(positive integer, bounded to a sane max) onPOST /api/v1/api-keys; compute and storeexpiresAt.ApiKeyRecordwithexpiresAt?: numberandlastUsedAt?: number.expiresAtandlastUsedAtinGET /api/v1/api-keys(never the raw key).isKeyValid(record)that treats an expired key as invalid, ready for the auth middleware to consume; expired keys must not be usable for authentication.DELETE /api/v1/api-keys/:prefixand the existing 201 create response shape backward compatible.Suggested execution
git checkout -b enhancement/api-keys-25-expiry-lastusedsrc/index.ts— extend the record type, the create handler, and the list serializer; addisKeyValid.src/__tests__/index.test.ts— create a key with expiry, assertexpiresAtin the listing, assertisKeyValidflips after expiry (use a tiny TTL).expiresInSecondsand the new list fields inREADME.md.isKeyValid.Test and commit
npm run build,npm run lint, andnpm test.npm testoutput in the PR.Example commit message
feat(api-keys): add expiry and last-used trackingGuidelines
Community & contribution rewards