Implements authentication middleware: JWT verification with jsonwebtoken, Passport strategies, oauth2-proxy for edge auth, and token lifecycle checks.
Agentic Workflow: Read -> Reason -> Act (auth-middleware)
You are Auth Middleware (backend/general) — a sub-agent that Reads, Reasons, and Acts via allowed-tools.
1. Read — backend context for auth-middleware
- Domain: Implements authentication middleware: JWT verification with jsonwebtoken, Passport strategies, oauth2-proxy for edge auth, and token lifecycle checks.
- jwt-middleware: Verify JWTs in request middleware —
npm install jsonwebtoken express
- passport-oauth: Authenticate with Passport and oauth2-proxy —
npm install passport passport-jwt
- Check
knowledge and prerequisites: docker, node, npm
2. Reason — think for auth-middleware
- For
jwt-middleware: Verify JWTs in request middleware — decide which checks to run
- For
passport-oauth: Authenticate with Passport and oauth2-proxy — decide which checks to run
- Evaluate trust/policy:
kdesk trust + kdesk doctor patterns for your inputs
3. Act — execute with auth-middleware tools
- Tools:
Glob, Grep, Read, Bash (see frontmatter tools/allowed-tools)
- Use
safe_path for any write; record evidence (paths, checksums)
- Fingerprint:
auth-middleware:c0f73d40
Auth Middleware
Authentication middleware implementation.
What This Skill Does
- Verifies JWTs on requests
- Extracts user context from tokens
- Rejects missing/expired credentials
When to Use
- Protecting API routes
- Adding SSO with oauth2-proxy
- Standardizing auth across services
Real Commands
npm install jsonwebtoken express
node -e "const jwt=require('jsonwebtoken'); const t=jwt.sign({sub:'user-1'},'s3cret',{expiresIn:'1h'}); console.log(t)"
curl -s -o /dev/null -w '%{http_code}\n' -H "Authorization: Bearer $TOKEN" http://localhost:3000/api/me
Middleware Example
function requireAuth(req, res, next) {
const header = req.get('Authorization') || '';
const token = header.replace('Bearer ', '');
try {
req.user = jwt.verify(token, SECRET);
next();
} catch {
res.sendStatus(401);
}
}
Testing
- Test missing, invalid, and expired tokens
- Verify user context on protected routes
- Test role-based access paths
Best Practices
- Always verify expiry and signature
- Use RS256 for production issuance
- Return 401 uniformly for auth failures
Capabilities
jwt-middleware
Verify JWTs in request middleware
Parameters:
secret (string): JWT signing secret
expiresIn (string): Token lifetime
claims (object): Token claims
Commands:
npm install jsonwebtoken express
node -e "const jwt=require('jsonwebtoken'); const t=jwt.sign({sub:'user-1',role:'admin'},'s3cret',{expiresIn:'1h'}); console.log(t)"
node -e "const jwt=require('jsonwebtoken'); const t=jwt.sign({sub:'user-1'},'s3cret',{expiresIn:5}); setTimeout(()=>{try{jwt.verify(t,'s3cret')}catch(e){console.log('expired:',e.name)}},6000)"
curl -s -o /dev/null -w '%{http_code}\n' -H "Authorization: Bearer $TOKEN" http://localhost:3000/api/me
curl -s -o /dev/null -w '%{http_code}\n' http://localhost:3000/api/me
Examples:
- jwt.sign issues tokens with claims
- jwt.verify validates signature and expiry
- curl with/without tokens tests enforcement
passport-oauth
Authenticate with Passport and oauth2-proxy
Commands:
npm install passport passport-jwt
node -e "const p=require('passport'); console.log(typeof p.authenticate)"
docker run -d -p 4180:4180 bitnami/oauth2-proxy --provider github --upstream http://localhost:3000 --email-domain example.com --client-id $CLIENT_ID --client-secret $CLIENT_SECRET
curl -s -o /dev/null -w '%{http_code}\n' -H "Authorization: Bearer invalid" http://localhost:4180/oauth2/start
Examples:
- general-cli --help
- general-api --help
References
1---2name: "auth-middleware"3description: "Implements authentication middleware: JWT verification with jsonwebtoken, Passport strategies, oauth2-proxy for edge auth, and token lifecycle checks. Use when working with jwt middleware, passport oauth, backend or when the user mentions jwt middleware, passport oauth, backend."4license: "MIT"5compatibility: "Requires docker, node, npm. Needs network access."6metadata:7 source: https://skillmd.com/skills/opknock/auth-middleware8 author: Kdesk9 version: 2.0.010 category: backend11allowed-tools: "Glob Grep Read Bash(curl:*) Bash(docker:*) Bash(node:*) Bash(npm:*)"12---1314Implements authentication middleware: JWT verification with jsonwebtoken, Passport strategies, oauth2-proxy for edge auth, and token lifecycle checks.1516## Agentic Workflow: Read -> Reason -> Act (auth-middleware)1718You are **Auth Middleware** (backend/general) — a sub-agent that **Reads, Reasons, and Acts** via `allowed-tools`.1920### 1. Read — backend context for `auth-middleware`21- Domain: Implements authentication middleware: JWT verification with jsonwebtoken, Passport strategies, oauth2-proxy for edge auth, and token lifecycle checks.22- **jwt-middleware**: Verify JWTs in request middleware — `npm install jsonwebtoken express`23- **passport-oauth**: Authenticate with Passport and oauth2-proxy — `npm install passport passport-jwt`24- Check `knowledge` and `prerequisites: docker, node, npm`2526### 2. Reason — think for `auth-middleware`27- For `jwt-middleware`: Verify JWTs in request middleware — decide which checks to run28- For `passport-oauth`: Authenticate with Passport and oauth2-proxy — decide which checks to run29- Evaluate trust/policy: `kdesk trust` + `kdesk doctor` patterns for your inputs3031### 3. Act — execute with `auth-middleware` tools32- Tools: `Glob`, `Grep`, `Read`, `Bash` (see frontmatter `tools`/`allowed-tools`)33- Use `safe_path` for any write; record evidence (paths, checksums)34- Fingerprint: `auth-middleware:c0f73d40`3536# Auth Middleware3738Authentication middleware implementation.3940## What This Skill Does41- Verifies JWTs on requests42- Extracts user context from tokens43- Rejects missing/expired credentials4445## When to Use46- Protecting API routes47- Adding SSO with oauth2-proxy48- Standardizing auth across services4950## Real Commands5152```bash53npm install jsonwebtoken express54node -e "const jwt=require('jsonwebtoken'); const t=jwt.sign({sub:'user-1'},'s3cret',{expiresIn:'1h'}); console.log(t)"55curl -s -o /dev/null -w '%{http_code}\n' -H "Authorization: Bearer $TOKEN" http://localhost:3000/api/me56```5758## Middleware Example5960```js61function requireAuth(req, res, next) {62 const header = req.get('Authorization') || '';63 const token = header.replace('Bearer ', '');64 try {65 req.user = jwt.verify(token, SECRET);66 next();67 } catch {68 res.sendStatus(401);69 }70}71```7273## Testing74- Test missing, invalid, and expired tokens75- Verify user context on protected routes76- Test role-based access paths777879## Best Practices80- Always verify expiry and signature81- Use RS256 for production issuance82- Return 401 uniformly for auth failures8384## Capabilities8586### jwt-middleware87Verify JWTs in request middleware8889**Parameters:**90- `secret` (string): JWT signing secret91- `expiresIn` (string): Token lifetime92- `claims` (object): Token claims9394**Commands:**95- `npm install jsonwebtoken express`96- `node -e "const jwt=require('jsonwebtoken'); const t=jwt.sign({sub:'user-1',role:'admin'},'s3cret',{expiresIn:'1h'}); console.log(t)"`97- `node -e "const jwt=require('jsonwebtoken'); const t=jwt.sign({sub:'user-1'},'s3cret',{expiresIn:5}); setTimeout(()=>{try{jwt.verify(t,'s3cret')}catch(e){console.log('expired:',e.name)}},6000)"`98- `curl -s -o /dev/null -w '%{http_code}\n' -H "Authorization: Bearer $TOKEN" http://localhost:3000/api/me`99- `curl -s -o /dev/null -w '%{http_code}\n' http://localhost:3000/api/me`100101**Examples:**102- jwt.sign issues tokens with claims103- jwt.verify validates signature and expiry104- curl with/without tokens tests enforcement105106### passport-oauth107Authenticate with Passport and oauth2-proxy108109**Commands:**110- `npm install passport passport-jwt`111- `node -e "const p=require('passport'); console.log(typeof p.authenticate)"`112- `docker run -d -p 4180:4180 bitnami/oauth2-proxy --provider github --upstream http://localhost:3000 --email-domain example.com --client-id $CLIENT_ID --client-secret $CLIENT_SECRET`113- `curl -s -o /dev/null -w '%{http_code}\n' -H "Authorization: Bearer invalid" http://localhost:4180/oauth2/start`114115**Examples:**116- general-cli --help117- general-api --help118119## References120- [Passport.js Docs](https://www.passportjs.org/docs/)121- [oauth2-proxy Docs](https://oauth2-proxy.github.io/oauth2-proxy/)