api-auth-patterns

A reference guide for securing API authentication and access control. APIs are interfaces that let software communicate; the guide covers ways to verify users and decide what they may do.

In plain words
What is it for?
It helps implement OAuth 2.0 with PKCE, JSON Web Tokens, API keys, mutual TLS, and user sessions, including protections such as state and exact redirect checks.
Why use it?
Authentication mistakes can let attackers impersonate users or access more data than intended. This guide gives implementation patterns for choosing and applying common API security methods.

Skill for Claude CodeCodex

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add skills/hermeticormus/libresecops-claude-code/api-auth-patterns
Any agent
npx skills add HermeticOrmus/LibreSecOps-Claude-Code --skill api-auth-patterns
Clone the repo
git clone --depth 1 https://github.com/HermeticOrmus/LibreSecOps-Claude-Code

Made for: Claude Code, Codex.

Per session 0 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 2,405 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00000 $0.02405
Opus 5 $0.00000 $0.01203
Sonnet 5 $0.00000 $0.00481
Haiku 4.5 $0.00000 $0.00241

Measured 2d ago against content hash dbbac13a956c, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

api-auth-patterns scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 2d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

plugins/api-security-testing/skills/api-auth-patterns/SKILL.md · 223 lines

How it starts

The opening of the file, as written. The whole thing — 223 lines — stays where its author put it; the contents beside it link to each section on GitHub.

API Authentication Patterns

Secure authentication and authorization implementation patterns for APIs, covering OAuth 2.0, JWT, API keys, mTLS, and session management.

Knowledge Base

OAuth 2.0 Flows

Authorization Code with PKCE (Recommended for most applications)

The most secure flow for applications that interact with users. PKCE (Proof Key for Code Exchange, RFC 7636) prevents authorization code interception attacks and is required for public clients and recommended for all clients.

Flow:

  1. Client generates random code_verifier (43-128 characters, unreserved URI characters)
  2. Client computes code_challenge = BASE64URL(SHA256(code_verifier))
  3. Client redirects user to authorization endpoint with code_challenge and code_challenge_method=S256
  4. User authenticates and consents
  5. Authorization server redirects back with code
  6. Client exchanges code + code_verifier at token endpoint
  7. Authorization server verifies SHA256(code_verifier) == code_challenge and issues tokens

Security requirements:

  • State parameter: Cryptographically random, bound to user session, verified on callback
  • Redirect URI: Exact match validation (no wildcards, no path traversal)
  • PKCE: S256 method only (plain method provides no security)
  • Token endpoint: Authenticated with client_secret (confidential clients) or PKCE only (public clients)

Client Credentials (Machine-to-machine)

For service-to-service communication where no user is involved.

Security requirements:

  • Client secrets rotated regularly and stored securely (not in code)
  • Scope limited to minimum required permissions
  • Short token lifetimes (5-15 minutes)
  • mTLS client certificate binding for high-security environments

JWT Best Practices

Token Structure and Signing:

// Header
{
  "alg": "RS256",   // Use asymmetric algorithms for distributed validation
  "typ": "JWT",
  "kid": "key-2024-01"  // Key ID for rotation support
}

// Payload
{
  "iss": "https://auth.example.com",   // Issuer - validate this
  "sub": "user-uuid-here",             // Subject - the user identifier
  "aud": "https://api.example.com",    // Audience - validate this
  "exp": 1700000000,                   // Expiration - short-lived (15-60 min)
  "nbf": 1699999000,                   // Not before
  "iat": 1699999000,                   // Issued at
  "jti": "unique-token-id",            // JWT ID - for revocation tracking
  "scope": "read:users write:orders"   // Scopes/permissions
}

Read the full file on GitHub · 223 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 2d ago First seen · 223 lines · 0 tokens per session scan A dbbac13a956c

Subscribe to this mod's changes

api-auth-patterns is a skill published in the GitHub repository HermeticOrmus/LibreSecOps-Claude-Code (4 stars, last pushed 3mo ago), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 2,405 tokens. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.

Related

Other skills, from other repositories

implementing-devsecops-security-scanning

Integrates Static Application Security Testing (SAST), Dynamic Application Security Testing (DAST), and Software Composition Analysis (SCA) into CI/CD pipelines using open-source tools. Covers Semgrep for SAST, Trivy for SCA and container scanning, OWASP ZAP for DAST, and Gitleaks for secrets detection. Activates for…

xalgorix/xalgorix · 109 tokens

implementing-runtime-application-self-protection

Deploy Runtime Application Self-Protection (RASP) agents to detect and block attacks from within application runtime, covering OpenRASP integration, attack pattern detection, and security policy configuration for Java and Python web applications.

xalgorix/xalgorix · 51 tokens

building-devsecops-pipeline-with-gitlab-ci

Design and implement a comprehensive DevSecOps pipeline in GitLab CI/CD integrating SAST, DAST, container scanning, dependency scanning, and secret detection.

adriannoes/awesome-agentic-ai · 43 tokens

audit-production-readiness

Audit a repository or service for release-blocking bugs, security, data/privacy, AI-agent, supply-chain, operability, and scale risks. Use for deep code audits, threat models, pre-production reviews, vulnerability triage, incidents, defensive investigation, release gates, or evidence-based 10k-to-1M-user readiness.

kingggg5/shipproof · 72 tokens

engineer-production-systems

Design, write, refactor, or optimize production code so it is secure, correct, resource-bounded, observable, and maintainable. Use for full-stack features, APIs, databases, AI/RAG/MCP tools, CPU/RAM/latency work, 10k-to-1M-user planning, or authorized kernel, browser, parser, protocol, and defensive…

kingggg5/shipproof · 86 tokens

best-in-code

Run an adaptive, reusable software-delivery harness across AI models with project management, planning, research, design, frontend, backend, QA, durable scoped memory, capability fallbacks, bounded discovery, and human approval gates. Use when the user invokes Harness or asks for an end-to-end build, review, bug…

kingggg5/shipproof · 89 tokens