secondsky avatar

Api Authentication

Solid reference for implementing JWT, OAuth 2.0, and API key authentication across Node.js and Python Flask. You get working middleware examples, a comparison table of auth methods with their security tradeoffs, and the critical security requirements like HttpOnly cookies and bcrypt cost factors. The code actually validates authorization headers properly instead of the naive split you see in too many tutorials. Use this when you're setting up authentication from scratch or debugging why your auth flow is failing. The security headers and common mistakes section will save you from the usual footguns like storing tokens in localStorage or logging sensitive data.

skills.sh installs
549
GitHub stars
248
last updated
Aug 21, 2026

Install

$ npx -y skills add secondsky/claude-skills --skill api-authentication --agent claude-code

Installs into .claude/skills of the current project.

Files

API Authentication

Implement secure authentication mechanisms for APIs using modern standards and best practices.

Authentication Methods

MethodUse CaseSecurity Level
JWTStateless auth, SPAsHigh
OAuth 2.0Third-party integrationHigh
API KeysService-to-serviceMedium
SessionTraditional web appsHigh

JWT Implementation (Node.js)

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' });
  }

Sponsors

Details

Repository
github.com/secondsky/claude-skills
Categories
Backend & APIs, Security
First seen
Jun 3, 2026

More from secondsky/claude-skills

All 146
1aj-geddes avatarapi-gateway-configurationaj-geddes/useful-ai-promptsConfigure API gateways for routing, authentication, rate limiting, and request/response transformation. Use when deploying microservices, setting up reverse pro508skills.sh installs
2manutej avatargraphql-api-developmentmanutej/luxor-claude-marketplaceComprehensive guide for building GraphQL APIs including schema design, queries, mutations, subscriptions, resolvers, type system, error handling, authentication449skills.sh installs
3secondsky avatarapi-gateway-configurationsecondsky/claude-skillsConfigures API gateways for routing, authentication, rate limiting, and request transformation in microservice architectures. Use when setting up Kong, Nginx, A422skills.sh installs
4bobmatnyc avatarprisma-ormbobmatnyc/claude-mpm-skillsPrisma ORM for TypeScript - Type-safe database toolkit with schema-first development, auto-generated client, migrations, relations, and Prisma Studio341skills.sh installs
5nice-wolf-studio avatarsupabase-authnice-wolf-studio/claude-code-supabase-skillsManage authentication and user operations in Supabase. Use for sign up, sign in, sign out, password resets, and user management.318skills.sh installs
6cinience avataralicloud-database-rds-supabasecinience/alicloud-skillsManage Alibaba Cloud RDS Supabase (RDS AI Service 2025-05-07) via OpenAPI. Use for creating, starting/stopping/restarting instances, resetting passwords, queryi271skills.sh installs