API Authentication

API Authentication

Guides an AI agent to implement secure API authentication with JWT, OAuth 2.0, API keys and session management, with Node.js and Python examples.

Skill files6 files

references/

scripts/

SKILL.md102 lines
1
---
2
name: api-authentication
3
description: >
4
Implement secure API authentication with JWT, OAuth 2.0, API keys, and session
5
management. Use when securing APIs, managing tokens, or implementing user
6
authentication flows.
7
---
8
9
# API Authentication
10
11
## Table of Contents
12
13
- [Overview](#overview)
14
- [When to Use](#when-to-use)
15
- [Quick Start](#quick-start)
16
- [Reference Guides](#reference-guides)
17
- [Best Practices](#best-practices)
18
19
## Overview
20
21
Implement comprehensive authentication strategies for APIs including JWT tokens, OAuth 2.0, API keys, and session management with proper security practices.
22
23
## When to Use
24
25
- Securing API endpoints
26
- Implementing user login/logout flows
27
- Managing access tokens and refresh tokens
28
- Integrating OAuth 2.0 providers
29
- Protecting sensitive data
30
- Implementing API key authentication
31
32
## Quick Start
33
34
Minimal working example:
35
36
```javascript
37
// Node.js JWT Implementation
38
const express = require('express');
39
const jwt = require('jsonwebtoken');
40
const bcrypt = require('bcrypt');
41
42
const app = express();
43
const SECRET_KEY = process.env.JWT_SECRET || 'your-secret-key';
44
const REFRESH_SECRET = process.env.REFRESH_SECRET || 'your-refresh-secret';
45
46
// User login endpoint
47
app.post('/api/auth/login', async (req, res) => {
48
try {
49
const { email, password } = req.body;
50
51
// Find user in database
52
const user = await User.findOne({ email });
53
if (!user) {
54
return res.status(401).json({ error: 'Invalid credentials' });
55
}
56
57
// Verify password
58
const isValid = await bcrypt.compare(password, user.password);
59
if (!isValid) {
60
return res.status(401).json({ error: 'Invalid credentials' });
61
}
62
// ... (see reference guides for full implementation)
63
```
64
65
## Reference Guides
66
67
Detailed implementations in the `references/` directory:
68
69
| Guide | Contents |
70
|---|---|
71
| [JWT Authentication](references/jwt-authentication.md) | JWT Authentication |
72
| [OAuth 2.0 Implementation](references/oauth-20-implementation.md) | OAuth 2.0 Implementation |
73
| [API Key Authentication](references/api-key-authentication.md) | API Key Authentication |
74
| [Python Authentication Implementation](references/python-authentication-implementation.md) | Python Authentication Implementation |
75
76
## Best Practices
77
78
### ✅ DO
79
80
- Use HTTPS for all authentication
81
- Store tokens securely (HttpOnly cookies)
82
- Implement token refresh mechanism
83
- Set appropriate token expiration times
84
- Hash and salt passwords
85
- Use strong secret keys
86
- Validate tokens on every request
87
- Implement rate limiting on auth endpoints
88
- Log authentication attempts
89
- Rotate secrets regularly
90
91
### ❌ DON'T
92
93
- Store passwords in plain text
94
- Send tokens in URL parameters
95
- Use weak secret keys
96
- Store sensitive data in JWT payload
97
- Ignore token expiration
98
- Disable HTTPS in production
99
- Log sensitive tokens
100
- Reuse API keys across services
101
- Store credentials in code
102

© AJ Geddes · MIT · source · posted by @OpenSourceBuffGuy on promptparty.com

@OpenSourceBuffGuy

I find openly licensed prompts and post them here.

0 followers · 14,621 prompts

More by @OpenSourceBuffGuy

See all
Sea turtle carrying floating film studio island prompt image

Sea turtle carrying floating film studio island

Draws a giant sea turtle carrying a floating island film studio through a starry sky, where fairies polish rough film strips into golden film.

image-prompt, nano-banana, 3d-render, cartoon, fantasy-world, creatures, animals, whimsical, dreamy, cinematic, dramatic-lighting, vibrant-colors, bokeh, miniature, widescreen, night-scene, illustration, concept-art, surreal, storytelling, clay-3d

Desert buggy escapes drones past industrial outpost prompt image

Desert buggy escapes drones past industrial outpost

Builds a 15-second desert chase video where a racer in an armored buggy escapes drones past an industrial outpost, using five reference images with set jobs.

video-prompt, hailuo, action, multi-shot, timed-beats, camera-movement, reference-image, character-consistency, negative-prompt, cinematic, sci-fi, cars, landscape, aerial-view, tracking-shot, photorealistic, sound-effects, structured-output, long-form, widescreen

1 view
Cozy Pixel Art Farm Island Village prompt image

Cozy Pixel Art Farm Island Village

Draws a cozy 16-bit pixel-art farming village across six small islands joined by bridges, with exact counts for buildings, animals and crops.

image-prompt, gpt-image, pixel-art, isometric, game-assets, concept-art, maps, worldbuilding, cozy, vibrant-colors, ocean, landscape, wide-shot, widescreen, game-development, video-games, structured-output, whimsical, summer, high-angle, aerial-view, animals, negative-prompt, cityscape

1 view

Reviews

Loading reviews…

Discussion

Loading comments…