api-authentication · secondsky — Claude Code skill: JWT, OAuth 2.0, API keys
A skill that helps your coding agent write API authentication: JWT, OAuth 2.0, API keys, sessions and security headers.
npx skills add secondsky/claude-skills --skill api-authentication -a claude-codeWhat api-authentication does
The skill hands your agent ready-made patterns and rules for API authentication. Inside you get a method comparison table, a Node.js JWT implementation with access and refresh tokens, middleware that validates the Authorization header, a list of security requirements and an example of security headers. A separate file, references/python-flask.md, covers Flask: JWT with role-based access decorators, OAuth 2.0 through Authlib and API key auth with hashing.
Reach for it when the agent builds a login flow, wires up a third-party provider or chases errors in an auth flow. It also flags the usual mistakes: plain-text passwords, weak JWT secrets, ignored token expiration, HTTPS turned off in production and tokens written to logs.
The Node.js examples need the jsonwebtoken package, and the Flask variant needs Python with Authlib. Secrets belong in environment variables — the sample reads JWT_SECRET and REFRESH_SECRET from there, so the code will not run without them.
What it helps with
- generate an access and refresh token pair for login
- write middleware that validates the
Authorizationheader - add Google sign-in over OAuth 2.0
- restrict endpoints by role with decorators
- set security headers such as
Strict-Transport-Security
Example prompts for the agent
- Add JWT authentication with access and refresh tokens to my project
- Review my middleware for the
Authorizationheader - Set up Google sign-in over OAuth 2.0 in Flask
How to install api-authentication
1Skills CLI (Vercel)
npx skills add secondsky/claude-skills --skill api-authentication -a claude-code2Manually: put the files in place
~/.claude/skills/api-authentication/SKILL.mdCopy the whole skill folder; for one project use .claude/skills/api-authentication/
1Skills CLI (Vercel)
npx skills add secondsky/claude-skills --skill api-authentication -a codex2Manually: put the files in place
.agents/skills/api-authentication/SKILL.mdFor all projects use ~/.agents/skills/
1Skills CLI (Vercel)
npx skills add secondsky/claude-skills --skill api-authentication -a cursor2Manually: put the files in place
.cursor/skills/api-authentication/SKILL.mdCursor also reads .agents/skills/ and .claude/skills/
1GitHub CLI
gh skill install secondsky/claude-skills api-authentication2Manually: put the files in place
.github/skills/api-authentication/SKILL.md1Skills CLI (Vercel)
npx skills add secondsky/claude-skills --skill api-authentication -a gemini-cli2Platform CLI
gemini skills install https://github.com/secondsky/claude-skills --path plugins/api-authentication/skills/api-authenticationManually: put the files in place
.devin/skills/api-authentication/SKILL.mdThe legacy .windsurf/skills/ path still works
Skills CLI (Vercel)
npx skills add secondsky/claude-skills --skill api-authentication -a opencodeClaude.ai
Zip the folder and upload it in Settings → Capabilities → Skills
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 secondsky/claude-skills --skill api-authentication -a claude-code. The skill lands in ~/.claude/skills/api-authentication/SKILL.md.
What does api-authentication do?
It gives the agent patterns and rules for API authentication: JWT, OAuth 2.0, API keys, sessions, security headers and a list of common mistakes.
What dependencies do the examples need?
The Node.js code needs the jsonwebtoken package; the Flask variant needs Python with Authlib. Secrets are read from the JWT_SECRET and REFRESH_SECRET environment variables.
Source text
SKILL.md · MIT
---
name: api-authentication
description: Secure API authentication with JWT, OAuth 2.0, API keys. Use for authentication systems, third-party integrations, service-to-service communication, or encountering token management, security headers, auth flow errors.
license: MIT
---
# API Authentication
Implement secure authentication mechanisms for APIs using modern standards and best practices.
## Authentication Methods
| Method | Use Case | Security Level |
|--------|----------|----------------|
| JWT | Stateless auth, SPAs | High |
| OAuth 2.0 | Third-party integration | High |
| API Keys | Service-to-service | Medium |
| Session | Traditional web apps | High |
## JWT Implementation (Node.js)
```javascript
const jwt = require('jsonwebtoken');
const generateTokens = (user) => ({
accessToken: jwt.sign(
{ userId: user.id, role: user.role },
process.env.JWT_SECRET,
{ expiresIn: '15m' }
),
refreshToken: jwt.sign(
{ userId: user.id, type: 'refresh' },
process.env.REFRESH_SECRET,
{ expiresIn: '7d' }
)
});
const authMiddleware = (req, res, next) => {
const authHeader = req.headers.authorization;
// Validate authorization header format
if (!authHeader || !authHeader.startsWith('Bearer ')) {
return res.status(401).json({ error: 'Malformed authorization header' });
}
const parts = authHeader.split(' ');
if (parts.length !== 2) {
return res.status(401).json({ error: 'Malformed authorization header' });
}
const token = parts[1];
if (!token) {
return res.status(401).json({ error: 'No token provided' });
}
try {
req.user = jwt.verify(token, process.env.JWT_SECRET);
next();
} catch (err) {
res.status(401).json({ error: 'Invalid token' });
}
};
```
## Security Requirements
- Always use HTTPS
- Store tokens in HttpOnly cookies (not localStorage)
- Hash passwords with bcrypt (cost factor 12+)
- Implement rate limiting on auth endpoints
- Rotate secrets regularly
- Never transmit tokens in URLs
## Security Headers
```javascript
app.use((req, res, next) => {
res.setHeader('X-Content-Type-Options', 'nosniff');
res.setHeader('X-Frame-Options', 'DENY');
res.setHeader('Strict-Transport-Security', 'max-age=31536000');
next();
});
```
## Additional Implementations
See [references/python-flask.md](references/python-flask.md) for:
- Flask JWT with role-based access control decorators
- OAuth 2.0 Google integration with Authlib
- API key authentication with secure hashing
## Common Mistakes to Avoid
- Storing plain-text passwords
- Using weak JWT secrets
- Ignoring token expiration
- Disabling HTTPS in production
- Logging sensitive tokens
© secondsky · MIT · secondsky/claude-skills
Similar skills
Everything for Security →api-authentication by other authors comes first.