api-key-lifecycle-pattern

Implement API key issuance, verification, and revocation with salted hashing.

Updated Apr 4, 2026
One-click install
npx skills add https://github.com/saintgo7/claude-skills --skill api-key-lifecycle-pattern
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: api-key-lifecycle-pattern
Source: https://github.com/saintgo7/claude-skills/tree/main/api-key-lifecycle-pattern
Command: npx skills add https://github.com/saintgo7/claude-skills --skill api-key-lifecycle-pattern

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill solves the security and operational risk of poorly designed API-key handling by ensuring raw keys are exposed only once, while all subsequent verification uses prefix lookup plus salted hashing.

Core Features & Use Cases

  • API key lifecycle design: end-to-end flow covering issue (generate), verify (auth middleware), and revoke (disable without deleting), including rotation guidance.
  • Fast lookup + safe storage: stores only SHA256(salt + raw_key) in the database while using an indexed key_prefix (first 8 hex chars) to avoid full scans.
  • Operational tooling compatibility: defines a standard admin-cli command set (issue-key, list-keys, revoke-key, set-quota) with explicit rules about what data may be returned.

Quick Start

Ask your AI to implement an API key service that generates keys in the format gem_live_<32hex>, returns the raw key only at issuance time, verifies requests via prefix lookup plus salted SHA256, and revokes keys by setting revoked=true (never deleting rows).

Frequently Asked Questions about api-key-lifecycle-pattern

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How should I store and verify API keys securely in a database?▼

Securely storing and verifying API keys requires saving only salted SHA256 hashes in the database, never raw keys. You perform fast lookups using an indexed key_prefix, then validate the full key by comparing its salted hash against the stored value.

What is the best way to design API key revocation without deleting records?▼

API key revocation is best handled by setting a revoked boolean flag to true on the key record. This idempotent revoke semantic disables authentication immediately while preserving the database rows for audit trails and operational history.

How do I implement API key issuance that prevents raw key leakage?▼

Implement API key issuance by generating a formatted key and returning the raw key to the client exactly once at creation time. The system then stores only a salted hash and a short indexed key_prefix for all future verification operations.

How does prefix-based database lookup work for API key authentication?▼

Prefix-based database lookup for API key authentication works by indexing the first 8 hex characters of the key. The authentication middleware queries the database using this indexed key_prefix to avoid full table scans before applying salted hashing to verify the match.

Can I use this API key lifecycle pattern with FastAPI authentication middleware?▼

Yes, you can use this API key lifecycle pattern with FastAPI authentication middleware. It explicitly applies to REST or FastAPI-style gateways, utilizing prefix-based database lookups and salted hashing to verify requests efficiently.

Do I need an admin CLI to manage API key rotation and quotas?▼

You need an admin CLI to manage API key rotation and quotas operationally. The pattern defines a standard command set including issue-key, list-keys, revoke-key, and set-quota, ensuring secure operational tooling compatibility without exposing raw keys.