# API Authentication Engineer

> Implements API authentication: JWT issuance and validation, OAuth 2.0 flows, API keys, and mTLS with rotation. Use when working with jwt implementation, oauth2 flows or when the user mentions jwt implementation, oauth2 flows.

- Skill: `opknock/api-authentication-engineer` (Agent Skill)
- Install (CLI): `npx get-skill add opknock/api-authentication-engineer`
- Raw SKILL.md: https://api.skillmd.com/api/skills/opknock/api-authentication-engineer/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Integrations & APIs
- License: MIT
- Author: OpKnock (https://skillmd.com/u/opknock)
- Updated: 2026-11-23
- Page: https://skillmd.com/skills/opknock/api-authentication-engineer

---


Implements API authentication: JWT issuance and validation, OAuth 2.0 flows, API keys, and mTLS with rotation.

## Agentic Workflow: Read -> Reason -> Act (api-authentication-engineer)

You are **api-authentication-engineer** (security) — a sub-agent that **Reads, Reasons, and Acts** via `allowed-tools`.

### 1. Read — security context for `api-authentication-engineer`
- Domain: Implements API authentication: JWT issuance and validation, OAuth 2.0 flows, API keys, and mTLS with rotation.
- **jwt-implementation**: Issue, validate, and rotate JWTs for API access — `npm install jsonwebtoken`
- **oauth2-flows**: Configure OAuth 2.0 authorization code and client credentials flows — `npm install openid-client`
- Check `knowledge` and `prerequisites: node.js, python, openssl, jwt-cli`

### 2. Reason — think for `api-authentication-engineer`
- For `jwt-implementation`: Issue, validate, and rotate JWTs for API access — decide which checks to run
- For `oauth2-flows`: Configure OAuth 2.0 authorization code and client credentials flows — decide which checks to run
- Evaluate trust/policy: `kdesk trust` + `kdesk doctor` patterns for your inputs

### 3. Act — execute with `api-authentication-engineer` tools
- Tools: `Glob`, `Grep`, `Read`, `Bash`, `Jwt` (see frontmatter `tools`/`allowed-tools`)
- Use `safe_path` for any write; record evidence (paths, checksums)
- Fingerprint: `api-authentication-engineer:4e92c03f`

# API Authentication Engineer

Implements authentication for APIs: JWTs, OAuth 2.0, API keys, and mTLS.

## When to Use
- Adding auth to an API
- Implementing OAuth client flows
- Securing service-to-service calls

## Real Commands

```bash
# JWT
npm install jsonwebtoken
jwt decode $(node -e "const j=require('jsonwebtoken');console.log(j.sign({sub:'u1'},'secret',{expiresIn:'1h'}))") 2>/dev/null || node -e "const j=require('jsonwebtoken');console.log(j.verify(j.sign({sub:'u1'},'secret',{expiresIn:'1h'}),'secret'))"

# Keycloak client
kcadm.sh config credentials --server http://localhost:8080 --realm master --user admin --password admin
kcadm.sh create clients -r demo -s clientId=api-client -s secret=change-me

# Client credentials token
curl -s -X POST http://localhost:8080/realms/demo/protocol/openid-connect/token -d 'grant_type=client_credentials&client_id=api-client&client_secret=change-me'

# mTLS certs
openssl req -x509 -newkey rsa:2048 -keyout key.pem -out cert.pem -days 365 -nodes
```

## Token Design
- Short-lived access tokens (15m)
- Refresh tokens with rotation
- Audience and scope claims enforced

## Testing
Verify expired tokens are rejected and scopes are enforced per route.

## Best Practices
- Rotate signing keys on a schedule
- Never log tokens or secrets

## Capabilities

### jwt-implementation
Issue, validate, and rotate JWTs for API access

**Parameters:**
- `audience` (string): Token audience
- `expiry` (string): Token lifetime

**Commands:**
- `npm install jsonwebtoken`
- `node -e "const j=require('jsonwebtoken');const t=j.sign({sub:'u1',scope:'read'},'secret',{expiresIn:'1h'});console.log(t)"`
- `node -e "const j=require('jsonwebtoken');const t=j.sign({sub:'u1'},'secret',{expiresIn:'1h'});console.log(j.verify(t,'secret'))"`
- `jwt decode $(node -e "const j=require('jsonwebtoken');console.log(j.sign({sub:'u1'},'secret',{expiresIn:'1h'}))")`
- `node -e "const j=require('jsonwebtoken');try{j.verify('bad.token.here','secret')}catch(e){console.log(e.message)}"`

**Examples:**
- jwt decode $(node -e "const j=require('jsonwebtoken');console.log(j.sign({sub:'u1'},'secret',{expiresIn:'1h'}))")
- node -e "const j=require('jsonwebtoken');const t=j.sign({sub:'u1'},'secret',{expiresIn:'1h'});setTimeout(()=>{try{j.verify(t,'secret');console.log('ok')}catch(e){console.log('expired')}},2000)"
- node -e "const j=require('jsonwebtoken');console.log(j.sign({sub:'u1'},'secret',{expiresIn:'15m',aud:'api'}) && 'token issued')"

### oauth2-flows
Configure OAuth 2.0 authorization code and client credentials flows

**Parameters:**
- `issuer` (string): OIDC issuer URL
- `clientId` (string): OAuth client ID

**Commands:**
- `npm install openid-client`
- `node -e "const {Issuer}=require('openid-client');Issuer.discover('http://localhost:8080/.well-known/openid-configuration').then(i=>console.log(i.metadata.token_endpoint))"`
- `kcadm.sh config credentials --server http://localhost:8080 --realm master --user admin --password admin`
- `kcadm.sh create clients -r demo -s clientId=api-client -s publicClient=false -s secret=change-me`
- `curl -s -X POST http://localhost:8080/realms/demo/protocol/openid-connect/token -d 'grant_type=client_credentials&client_id=api-client&client_secret=change-me'`

**Examples:**
- node -e "const {Issuer}=require('openid-client');Issuer.discover('http://localhost:8080/.well-known/openid-configuration').then(i=>console.log(i.metadata.token_endpoint))"
- kcadm.sh create clients -r demo -s clientId=api-client -s secret=change-me
- curl -s -X POST http://localhost:8080/realms/demo/protocol/openid-connect/token -d 'grant_type=client_credentials&client_id=api-client&client_secret=change-me'

## References
- [JWT Introduction](https://jwt.io/introduction)
- [OAuth 2.0](https://oauth.net/2/)
- [Keycloak Admin CLI](https://www.keycloak.org/docs/latest/server_admin/)

