Skip to main content
skill CX Codex

api-authentication · aj-geddes — Claude Code skill: JWT, OAuth 2.0, API keys

A skill for API authentication: JWT, OAuth 2.0, API keys and session handling. Useful when you lock down endpoints or build a login flow.

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add aj-geddes/useful-ai-prompts --skill api-authentication -a claude-code
Open on GitHub

What api-authentication does

The skill tells your agent how to put authentication into an API. It ships four reference guides under references/: JWT, OAuth 2.0, API keys, and a Python implementation. There is also a short Node.js example using express, jsonwebtoken and bcrypt — a login endpoint that looks up the user and checks the password.

A separate section lists practices. Under DO: HTTPS for all authentication, tokens in HttpOnly cookies, a refresh mechanism, sensible expiration times, salted password hashing, strong secret keys, token validation on every request, rate limiting on auth endpoints, secret rotation. Under DON'T: plain-text passwords, tokens in URL parameters, weak keys, sensitive data in the JWT payload, HTTPS off in production, logging tokens, reusing API keys across services.

The Quick Start example reads secrets from environment variables but keeps a fallback value in code. That fallback is a bad idea in production — it ends up in the repository, so check that JWT_SECRET and REFRESH_SECRET are actually set and the fallback is gone.

What it helps with

  • lock down API endpoints without leaving a hole in token validation
  • build login and logout with access and refresh tokens
  • wire an OAuth 2.0 provider into your service
  • add API key authentication for external clients
  • get rid of plain-text passwords and weak secret keys

Example prompts for the agent

  • Add JWT authentication to this project: login, validate the token on every request, refresh via a refresh token
  • Help me wire up an OAuth 2.0 provider and walk through the token exchange
  • Set up API key auth for external clients and rate limit the login endpoint

How to install api-authentication

1Skills CLI (Vercel)

npx skills add aj-geddes/useful-ai-prompts --skill api-authentication -a claude-code

2Manually: put the files in place

~/.claude/skills/api-authentication/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/api-authentication/

Step by step, with commands for each platform: How to install skills in Claude Code: five ways

Questions about api-authentication

How do I install api-authentication in Claude?

Run npx skills add aj-geddes/useful-ai-prompts --skill api-authentication -a claude-code. The skill file lands at ~/.claude/skills/api-authentication/SKILL.md.

What does api-authentication do?

It gives the agent instructions for API authentication: JWT, OAuth 2.0, API keys and session management. Reference guides live in references/, plus a Node.js example.

Which languages and libraries does the skill cover?

The Quick Start example is Node.js with express, jsonwebtoken and bcrypt. One reference guide covers a Python implementation.

Source text

SKILL.md · MIT
---
name: api-authentication
description: >
  Implement secure API authentication with JWT, OAuth 2.0, API keys, and session
  management. Use when securing APIs, managing tokens, or implementing user
  authentication flows.
---

# API Authentication

## Table of Contents

- [Overview](#overview)
- [When to Use](#when-to-use)
- [Quick Start](#quick-start)
- [Reference Guides](#reference-guides)
- [Best Practices](#best-practices)

## Overview

Implement comprehensive authentication strategies for APIs including JWT tokens, OAuth 2.0, API keys, and session management with proper security practices.

## When to Use

- Securing API endpoints
- Implementing user login/logout flows
- Managing access tokens and refresh tokens
- Integrating OAuth 2.0 providers
- Protecting sensitive data
- Implementing API key authentication

## Quick Start

Minimal working example:

```javascript
// Node.js JWT Implementation
const express = require('express');
const jwt = require('jsonwebtoken');
const bcrypt = require('bcrypt');

const app = express();
const SECRET_KEY = process.env.JWT_SECRET || 'your-secret-key';
const REFRESH_SECRET = process.env.REFRESH_SECRET || 'your-refresh-secret';

// User login endpoint
app.post('/api/auth/login', async (req, res) => {
  try {
    const { email, password } = req.body;

    // Find user in database
    const user = await User.findOne({ email });
    if (!user) {
      return res.status(401).json({ error: 'Invalid credentials' });
    }

    // Verify password
    const isValid = await bcrypt.compare(password, user.password);
    if (!isValid) {
      return res.status(401).json({ error: 'Invalid credentials' });
    }
// ... (see reference guides for full implementation)
```

## Reference Guides

Detailed implementations in the `references/` directory:

| Guide | Contents |
|---|---|
| [JWT Authentication](references/jwt-authentication.md) | JWT Authentication |
| [OAuth 2.0 Implementation](references/oauth-20-implementation.md) | OAuth 2.0 Implementation |
| [API Key Authentication](references/api-key-authentication.md) | API Key Authentication |
| [Python Authentication Implementation](references/python-authentication-implementation.md) | Python Authentication Implementation |

## Best Practices

### ✅ DO

- Use HTTPS for all authentication
- Store tokens securely (HttpOnly cookies)
- Implement token refresh mechanism
- Set appropriate token expiration times
- Hash and salt passwords
- Use strong secret keys
- Validate tokens on every request
- Implement rate limiting on auth endpoints
- Log authentication attempts
- Rotate secrets regularly

### ❌ DON'T

- Store passwords in plain text
- Send tokens in URL parameters
- Use weak secret keys
- Store sensitive data in JWT payload
- Ignore token expiration
- Disable HTTPS in production
- Log sensitive tokens
- Reuse API keys across services
- Store credentials in code

© aj-geddes · MIT · aj-geddes/useful-ai-prompts

Similar skills

Everything for Security →

api-authentication by other authors comes first.

From the same set118

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor