agentleFS
agentsdanceagentsdance/agentskills/skills/authentication-implementer/SKILL.md

authentication-implementer

Skill3 starsChanged 11 months agoApache-2.0View on GitHub

Implement authentication systems with best practices. Use when the user needs to add login, JWT tokens, OAuth, or session management.

  • Reads credentials

The file

Files
SKILL.md

Authentication Implementer

Implement secure authentication flows and patterns.

Authentication Methods

MethodUse CaseSecurity
SessionTraditional web appsHigh with HTTPS
JWTAPIs, microservicesMedium-High
OAuth2Third-party loginHigh
API KeysService-to-serviceMedium

JWT Implementation

Token Generation

import jwt from 'jsonwebtoken';

function generateTokens(user) {
  const accessToken = jwt.sign(
    { userId: user.id, role: user.role },
    process.env.JWT_SECRET,
    { expiresIn: '15m' }
  );

  const refreshToken = jwt.sign(
    { userId: user.id },
    process.env.JWT_REFRESH_SECRET,
    { expiresIn: '7d' }
  );

  return { accessToken, refreshToken };
}

Middleware

function authenticate(req, res, next) {
  const token = req.headers.authorization?.replace('Bearer ', '');

  if (!token) {
    return res.status(401).json({ error: 'No token provided' });
  }

  try {
    const decoded = jwt.verify(token, process.env.JWT_SECRET);
    req.user = decoded;
    next();
  } catch (error) {
    res.status(401).json({ error: 'Invalid token' });
  }
}

Password Hashing

import bcrypt from 'bcrypt';

async function hashPassword(password) {
  return bcrypt.hash(password, 12);
}

async function verifyPassword(password, hash) {
  return bcrypt.compare(password, hash);
}

OAuth2 Flow

// 1. Redirect to provider
app.get('/auth/google', (req, res) => {
  const url = `https://accounts.google.com/o/oauth2/v2/auth?
    client_id=${CLIENT_ID}&
    redirect_uri=${REDIRECT_URI}&
    response_type=code&
    scope=email profile`;
  res.redirect(url);
});

// 2. Handle callback
app.get('/auth/callback', async (req, res) => {
  const { code } = req.query;
  const tokens = await exchangeCodeForTokens(code);
  const user = await getUserInfo(tokens.access_token);
  // Create session or JWT
});

Security Checklist

  • Use HTTPS only
  • Hash passwords with bcrypt/argon2
  • Implement rate limiting
  • Use secure cookie flags
  • Validate and sanitize inputs

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.