Skip to content
Agentmart
Submit a tool

authentication-authorization

Use when implementing auth — login, registration, session management, JWT, OAuth, password hashing, RBAC, API keys, MFA, and security headers.

Skill by UgochukwuChidera

IndexedGPL-3.0
Write a review

Install

Works with Claude Code, Claude apps, Codex, Cursor, Gemini CLI, GitHub Copilot, VS Code, OpenCode, Goose, Windsurf. Read the repository before you give any tool access to your data.

npx agentmarket install skill/ugochukwuchidera-authentication-authorization

Asks which of your tools to add it to (Claude Code, Codex, Cursor, VS Code, Windsurf, Gemini CLI, Claude Desktop) and shows the change first. See https://agentmart.dev/cli.

Get the weekly diff

The weekly diff: one email a week with new agent tools, notable updates and grade changes, plus security alerts for tools you follow. Double opt-in, one-click unsubscribe.

We use your email only for this newsletter. Privacy

About

Use when implementing auth — login, registration, session management, JWT, OAuth, password hashing, RBAC, API keys, MFA, and security headers. Covers both stateless (JWT) and stateful (session) patterns, social login, permission models, and auth testing.

Use cases: backend, testing, security

No reviews yet. Installed it? Reviews come from verified installers only. How reviews work

Permissions

What this skill can do and what it asks for, from its SKILL.md. Checked Oct 25, 2026.

Tools
No tools found
Secrets
None asked for
Install scripts
None found

Network hosts it talks to 1

  • codeload.github.com · found in install command

Files it touches

  • ~/.claude/skills/authentication-authorization

What's inside

Skill name
authentication-authorization
Description
Use when implementing auth — login, registration, session management, JWT, OAuth, password hashing, RBAC, API keys, MFA, and security headers. Covers both stateless (JWT) and stateful (session) patterns, social login, permission models, and auth testing.
License
GPL-3.0
Instructions
244 lines in SKILL.md · view on GitHub

Files (1)

  • SKILL.md

SKILL.md (first lines)

# Authentication & Authorization

## First Decision: Stateless vs Stateful

| | JWT (Stateless) | Sessions (Stateful) |
|---|---|---|
| **Storage** | Client (token) | Server (DB/Redis) |
| **Scale** | No server state — easy horizontal scale | Need shared session store (Redis) |
| **Revoke** | Hard — wait for expiry or maintain blocklist | Instant — delete session |
| **Payload** | Visible to client (don't put secrets) | Opaque to client |
| **Best for** | APIs, mobile, SPAs, microservices | Server-rendered apps, high-security |
| **Library** | `jsonwebtoken`, `jose` | `express-session`, `iron-session` |

**Default for Meta-Architect projects:** JWT with refresh tokens (stateless API + stateful refresh).

## JWT Pattern (Default)

### Token Structure

```typescript
interface JwtPayload {
  sub: string;        // user id — never email (emails change)
  role: string;       // for quick authz checks
  iat: number;        // issued at
  exp: number;        // expiry
  jti?: string;       // token id (for revocation)
}
```

### Implementation

```typescript
// auth.service.ts
import jwt from 'jsonwebtoken';

const ACCESS_SECRET = process.env.JWT_ACCESS_SECRET!;
const REFRESH_SECRET = process.env.JWT_REFRESH_SECRET!;
const ACCESS_EXPIRY = '15m';
const REFRESH_EXPIRY = '7d';

export function generateTokens(user: { id: string; role: string }) {
  const accessToken = jwt.sign(
    { sub: user.id, role: user.role },
    ACCESS_SECRET,
    { expiresIn: ACCESS_EXPIRY }
  );
  const refreshToken = jwt.sign(
    { sub: user.id, jti: crypto.randomUUID() },
    REFRESH_SECRET,
    { expiresIn: REFRESH_EXPIRY }
  );
  return { accessToken, refreshToken, expiresIn: 900 };
}

export function verifyAccessToken(token: string): JwtPayload {
  return jwt.verify(token, ACCESS_SECRET) as JwtPayload;
}

export function verifyRefreshToken(token: string): { sub: string; jti: string } {
  return jwt.verify(token, REFRESH_SECRET) as { sub: string; jti: string };
}
```

### Refresh Token Rotation

```typescript
// On every refresh: issue new pair, invalidate old refresh token
export async function refreshTokens(oldRefreshToken: string, prisma: PrismaClient) {
  const payload = verifyRefreshToken(oldRefreshToken);

  // Check if token was already used (rotation prevents replay)
  const stored = await prisma.refreshToken.findUnique({ where: { jti: payload.jti } });
  if (!stored) throw new Error('Token revoked — possible theft');

  // Delete old token, issue new pair
  await prisma.refreshToken.delete({ where: { jti: payload.jti } });

  const user = await prisma.user.findUniqueOrThrow({ where: { id: payload.sub } });
  const tokens = generateTokens(user);

  await prisma.refreshToken.create({
    data: { jti: jwt.decode(tokens.refreshToken)!.jti, userId: user.id, expiresAt: new Date(Date.now() + 7 * 86400000) },
  });

  return tokens;
}
```

### Auth Middleware

```typescript
// auth.middleware.ts
export function authenticate(req: Request, res: Response, next: NextFunction) {
  const header = req.headers.authorization;
  if (!header?.startsWith('Bearer ')) return res.status(401).json({ error: 'unauthorized' });

  try {
    const payload = verifyAccessToken(header.split(' ')[1]);
    req.user = { id: payload.sub, role: payload.role };
    next();
  } catch {
    return res.status(401).json({ error: 'token_expired' });
  }
}
```

## Password Hashing

```typescript
import bcrypt from 'bcryptjs';

const SALT_ROUNDS = 12;  // ~250ms — balance security vs speed

export async function hashPassword(password: string): Promise<string> {
  return bcrypt.hash(password, SALT_ROUNDS);
}

export async function verifyPassword(password: string, hash: string): Promise<boolean> {
  return bcrypt.compare(password, hash);

From UgochukwuChidera/Opencode-Agents, GPL-3.0.

More from UgochukwuChidera/Opencode-Agents

Signals

Stars
0
Forks
0
Open issues
0
Last commit (this folder)
Jun 22, 2026 (4 months ago)

From GitHub (fetched Oct 24, 2026).

Details

License
GPL-3.0
First seen
Oct 24, 2026
Last checked
Oct 24, 2026

More from UgochukwuChidera

Cite this page

authentication-authorization skill. Agent Mart. https://agentmart.dev/skills/ugochukwuchidera-authentication-authorization (last updated 2026-10-24)