API auth with API key management - generate secure keys, hash at rest, scope and rate-limit them, and rotate keys without downtime.
Agentic Workflow: Read -> Reason -> Act (api-auth-keys)
You are Api Auth Keys (security) — a sub-agent that Reads, Reasons, and Acts via allowed-tools.
1. Read — security context for api-auth-keys
- Domain: API auth with API key management - generate secure keys, hash at rest, scope and rate-limit them, and rotate keys without downtime.
- api-key-mgmt: Generate, hash, scope, and rotate API keys —
openssl rand -hex 32
- Check
knowledge and prerequisites: node.js, python, jsonwebtoken
2. Reason — think for api-auth-keys
- For
api-key-mgmt: Generate, hash, scope, and rotate API keys — decide which checks to run
- Evaluate trust/policy:
kdesk trust + kdesk doctor patterns for your inputs
3. Act — execute with api-auth-keys tools
- Tools:
Glob, Grep, Read, Openssl, Bash (see frontmatter tools/allowed-tools)
- Use
safe_path for any write; record evidence (paths, checksums)
- Fingerprint:
api-auth-keys:b2c2e48e
API Auth (API Keys)
What this skill does
Manage API keys for third-party access: generate cryptographically secure keys, store only hashes, attach scopes and expiry, support rotation and revocation.
When to use
- Issuing keys to external partners
- Replacing shared static secrets
- Enforcing per-key limits and scopes
Real commands
# Generate a strong key
openssl rand -hex 32
node -e "const c=require('crypto');console.log(c.randomBytes(32).toString('hex'))"
# Hash for storage (never store the raw key)
node -e "const c=require('crypto');console.log(c.createHash('sha256').update(process.argv[1]).digest('hex'))" $KEY
# Create a scoped key
curl -s -X POST http://localhost:8080/api/keys \
-H 'X-Admin-Key: $ADMIN' -H 'Content-Type: application/json' \
-d '{"name":"billing","scopes":["read:invoices"],"expires_at":"2025-01-01T00:00:00Z"}' | jq '{key, id}'
# List keys
curl -s http://localhost:8080/api/keys | jq '.keys[] | {id, name, last_used_at}'
# Rotate
curl -s -X POST http://localhost:8080/api/keys/$ID/rotate -H 'X-Admin-Key: $ADMIN' | jq '{new_key, old_expires}'
# Revoke
curl -s -X DELETE http://localhost:8080/api/keys/$ID -H 'X-Admin-Key: $ADMIN' | jq '.revoked'
# Use it
curl -s http://localhost:8080/api/orders -H 'X-API-Key: $KEY' -o /dev/null -w '%{http_code}'
Key formats
sk_live_ prefix + 32+ random bytes (industry standard)
- Show the raw key exactly once at creation
Best practices
- Hash with SHA-256 before storing (plus optional HMAC pepper)
- Require scopes; default to least privilege
- Set expiry on all keys; auto-rotate yearly
- On rotation, accept the old key for a grace window
Testing
curl -s http://localhost:8080/api/orders -H 'X-API-Key: bad-key' -o /dev/null -w '%{http_code}\n'
curl -s http://localhost:8080/api/keys/$ID/rotate -X POST -H 'X-Admin-Key: $ADMIN' | jq
Capabilities
api-key-mgmt
Generate, hash, scope, and rotate API keys
Parameters:
name (string): Human-readable key name
scopes (array): Permissions granted to the key
expires_at (string): Expiry timestamp for the key
Commands:
openssl rand -hex 32
node -e "const c=require('crypto');console.log(c.randomBytes(32).toString('hex'))"
node -e "const c=require('crypto');console.log(c.createHash('sha256').update(process.argv[1]).digest('hex'))" $KEY
curl -s -X POST http://localhost:8080/api/keys -H 'X-Admin-Key: $ADMIN' -H 'Content-Type: application/json' -d '{"name":"billing","scopes":["read:invoices"],"expires_at":"2025-01-01T00:00:00Z"}' | jq '{key, id}'
curl -s http://localhost:8080/api/keys | jq '.keys[] | {id, name, last_used_at}'
Examples:
References
1---2name: "api-auth-keys"3description: "API auth with API key management - generate secure keys, hash at rest, scope and rate-limit them, and rotate keys without downtime. Use when working with api key mgmt or when the user mentions api key mgmt."4license: "MIT"5compatibility: "Requires node.js, python, jsonwebtoken, passport, keycloak. Needs network access."6metadata:7 source: https://skillmd.com/skills/opknock/api-auth-keys8 author: Kdesk9 version: 2.0.010 category: security11allowed-tools: "Glob Grep Read Bash(curl:*) Bash(node:*) Bash(openssl:*)"12---1314API auth with API key management - generate secure keys, hash at rest, scope and rate-limit them, and rotate keys without downtime.1516## Agentic Workflow: Read -> Reason -> Act (api-auth-keys)1718You are **Api Auth Keys** (security) — a sub-agent that **Reads, Reasons, and Acts** via `allowed-tools`.1920### 1. Read — security context for `api-auth-keys`21- Domain: API auth with API key management - generate secure keys, hash at rest, scope and rate-limit them, and rotate keys without downtime.22- **api-key-mgmt**: Generate, hash, scope, and rotate API keys — `openssl rand -hex 32`23- Check `knowledge` and `prerequisites: node.js, python, jsonwebtoken`2425### 2. Reason — think for `api-auth-keys`26- For `api-key-mgmt`: Generate, hash, scope, and rotate API keys — decide which checks to run27- Evaluate trust/policy: `kdesk trust` + `kdesk doctor` patterns for your inputs2829### 3. Act — execute with `api-auth-keys` tools30- Tools: `Glob`, `Grep`, `Read`, `Openssl`, `Bash` (see frontmatter `tools`/`allowed-tools`)31- Use `safe_path` for any write; record evidence (paths, checksums)32- Fingerprint: `api-auth-keys:b2c2e48e`3334# API Auth (API Keys)3536## What this skill does37Manage API keys for third-party access: generate cryptographically secure keys, store only hashes, attach scopes and expiry, support rotation and revocation.3839## When to use40- Issuing keys to external partners41- Replacing shared static secrets42- Enforcing per-key limits and scopes4344## Real commands45```bash46# Generate a strong key47openssl rand -hex 3248node -e "const c=require('crypto');console.log(c.randomBytes(32).toString('hex'))"4950# Hash for storage (never store the raw key)51node -e "const c=require('crypto');console.log(c.createHash('sha256').update(process.argv[1]).digest('hex'))" $KEY5253# Create a scoped key54curl -s -X POST http://localhost:8080/api/keys \55 -H 'X-Admin-Key: $ADMIN' -H 'Content-Type: application/json' \56 -d '{"name":"billing","scopes":["read:invoices"],"expires_at":"2025-01-01T00:00:00Z"}' | jq '{key, id}'5758# List keys59curl -s http://localhost:8080/api/keys | jq '.keys[] | {id, name, last_used_at}'6061# Rotate62curl -s -X POST http://localhost:8080/api/keys/$ID/rotate -H 'X-Admin-Key: $ADMIN' | jq '{new_key, old_expires}'6364# Revoke65curl -s -X DELETE http://localhost:8080/api/keys/$ID -H 'X-Admin-Key: $ADMIN' | jq '.revoked'6667# Use it68curl -s http://localhost:8080/api/orders -H 'X-API-Key: $KEY' -o /dev/null -w '%{http_code}'69```7071## Key formats72- `sk_live_` prefix + 32+ random bytes (industry standard)73- Show the raw key exactly once at creation7475## Best practices76- Hash with SHA-256 before storing (plus optional HMAC pepper)77- Require scopes; default to least privilege78- Set expiry on all keys; auto-rotate yearly79- On rotation, accept the old key for a grace window8081## Testing82```bash83curl -s http://localhost:8080/api/orders -H 'X-API-Key: bad-key' -o /dev/null -w '%{http_code}\n'84curl -s http://localhost:8080/api/keys/$ID/rotate -X POST -H 'X-Admin-Key: $ADMIN' | jq85```8687## Capabilities8889### api-key-mgmt90Generate, hash, scope, and rotate API keys9192**Parameters:**93- `name` (string): Human-readable key name94- `scopes` (array): Permissions granted to the key95- `expires_at` (string): Expiry timestamp for the key9697**Commands:**98- `openssl rand -hex 32`99- `node -e "const c=require('crypto');console.log(c.randomBytes(32).toString('hex'))"`100- `node -e "const c=require('crypto');console.log(c.createHash('sha256').update(process.argv[1]).digest('hex'))" $KEY`101- `curl -s -X POST http://localhost:8080/api/keys -H 'X-Admin-Key: $ADMIN' -H 'Content-Type: application/json' -d '{"name":"billing","scopes":["read:invoices"],"expires_at":"2025-01-01T00:00:00Z"}' | jq '{key, id}'`102- `curl -s http://localhost:8080/api/keys | jq '.keys[] | {id, name, last_used_at}'`103104**Examples:**105- curl -s -X DELETE http://localhost:8080/api/keys/$ID -H 'X-Admin-Key: $ADMIN' | jq '.revoked'106- curl -s http://localhost:8080/api/keys/$ID/rotate -X POST -H 'X-Admin-Key: $ADMIN' | jq '{new_key, old_expires}'107- curl -s http://localhost:8080/api/orders -H 'X-API-Key: $KEY' -o /dev/null -w '%{http_code}'108109## References110- [Stripe API Key Best Practices](https://docs.stripe.com/keys)111- [API Key in OpenAPI](https://swagger.io/docs/specification/authentication/api-keys/)