File contents API Authentication
Table of Contents
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:
// 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
JWT Authentication
OAuth 2.0 Implementation
OAuth 2.0 Implementation
API Key Authentication
API Key Authentication
Python Authentication Implementation
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
Converted and distributed by TomeVault — claim your Tome and manage your conversions.
1 --- 2 name: aj-geddes-useful-ai-prompts-api-authentication 3 description: API Authentication 4 --- 5 6 # API Authentication 7 8 ## Table of Contents 9 10 - [Overview](#overview) 11 - [When to Use](#when-to-use) 12 - [Quick Start](#quick-start) 13 - [Reference Guides](#reference-guides) 14 - [Best Practices](#best-practices) 15 16 ## Overview 17 18 Implement comprehensive authentication strategies for APIs including JWT tokens, OAuth 2.0, API keys, and session management with proper security practices. 19 20 ## When to Use 21 22 - Securing API endpoints 23 - Implementing user login/logout flows 24 - Managing access tokens and refresh tokens 25 - Integrating OAuth 2.0 providers 26 - Protecting sensitive data 27 - Implementing API key authentication 28 29 ## Quick Start 30 31 Minimal working example: 32 33 ```javascript 34 // Node.js JWT Implementation 35 const express = require('express'); 36 const jwt = require('jsonwebtoken'); 37 const bcrypt = require('bcrypt'); 38 39 const app = express(); 40 const SECRET_KEY = process.env.JWT_SECRET || 'your-secret-key'; 41 const REFRESH_SECRET = process.env.REFRESH_SECRET || 'your-refresh-secret'; 42 43 // User login endpoint 44 app.post('/api/auth/login', async (req, res) => { 45 try { 46 const { email, password } = req.body; 47 48 // Find user in database 49 const user = await User.findOne({ email }); 50 if (!user) { 51 return res.status(401).json({ error: 'Invalid credentials' }); 52 } 53 54 // Verify password 55 const isValid = await bcrypt.compare(password, user.password); 56 if (!isValid) { 57 return res.status(401).json({ error: 'Invalid credentials' }); 58 } 59 // ... (see reference guides for full implementation) 60 ``` 61 62 ## Reference Guides 63 64 Detailed implementations in the `references/` directory: 65 66 | Guide | Contents | 67 |---|---| 68 | [JWT Authentication](references/jwt-authentication.md) | JWT Authentication | 69 | [OAuth 2.0 Implementation](references/oauth-20-implementation.md) | OAuth 2.0 Implementation | 70 | [API Key Authentication](references/api-key-authentication.md) | API Key Authentication | 71 | [Python Authentication Implementation](references/python-authentication-implementation.md) | Python Authentication Implementation | 72 73 ## Best Practices 74 75 ### ✅ DO 76 77 - Use HTTPS for all authentication 78 - Store tokens securely (HttpOnly cookies) 79 - Implement token refresh mechanism 80 - Set appropriate token expiration times 81 - Hash and salt passwords 82 - Use strong secret keys 83 - Validate tokens on every request 84 - Implement rate limiting on auth endpoints 85 - Log authentication attempts 86 - Rotate secrets regularly 87 88 ### ❌ DON'T 89 90 - Store passwords in plain text 91 - Send tokens in URL parameters 92 - Use weak secret keys 93 - Store sensitive data in JWT payload 94 - Ignore token expiration 95 - Disable HTTPS in production 96 - Log sensitive tokens 97 - Reuse API keys across services 98 - Store credentials in code 99 100 --- 101 > Converted and distributed by [TomeVault](https://tomevault.io/claim/aj-geddes) — claim your Tome and manage your conversions. 102 <!-- tomevault:4.0:skill_md:2026-04-11 -->
tomevault-io/skills-registry/tree/main/aj-geddes--useful-ai-prompts--api-authentication commit f9476a273d
Frequently asked questions How do I install the Aj Geddes Useful AI Prompts API Authentication skill? Run npx skillmds@latest add tomevault-io/aj-geddes-useful-ai-prompts-api-authentication in your terminal (requires Node.js), paste this page's agent-chat prompt into Claude, Cursor, or any MCP-connected agent, or download the SKILL.md file and copy it into your agent's skills directory.
What does the Aj Geddes Useful AI Prompts API Authentication skill do? API Authentication It is listed under Integrations & APIs on SkillMD.
Is Aj Geddes Useful AI Prompts API Authentication safe to use? This skill has not completed SkillMD's automated safety review yet. Independent scanners report: SkillSpector: PASS, Skill Scanner: PASS. SkillMD never runs a skill's scripts for you; review the SKILL.md before installing.
Which AI agents work with Aj Geddes Useful AI Prompts API Authentication? This skill is tagged as working with Claude Code, Claude.ai, OpenAI Codex. SKILL.md is an open format, so most agents that read a skills directory can load it too.
Is Aj Geddes Useful AI Prompts API Authentication free to use? Yes. Installing skills from SkillMD is free, and the skill stays under its author's original license.
Who published Aj Geddes Useful AI Prompts API Authentication? tomevault-io (@tomevault-io) published this skill. Their other Agent Skills are listed on their SkillMD profile.