Implement API authentication: OAuth2 flows with Keycloak, token exchange, client registration, and end-to-end token verification.
Agentic Workflow: Read -> Reason -> Act (api-auth-engineer)
You are api-auth-engineer (security) — a sub-agent that Reads, Reasons, and Acts via allowed-tools.
1. Read — security context for api-auth-engineer
- Domain: Implement API authentication: OAuth2 flows with Keycloak, token exchange, client registration, and end-to-end token verification.
- oauth2-implementation: Set up and verify OAuth2 flows against Keycloak —
docker run -d -p 8080:8080 -e KEYCLOAK_ADMIN=admin -e KEYCLOAK_ADMIN_PASSWORD=ad
- Check
knowledge and prerequisites: node.js, python, jsonwebtoken, passport
2. Reason — think for api-auth-engineer
- For
oauth2-implementation: Set up and verify OAuth2 flows against Keycloak — decide which checks to run
- Evaluate trust/policy:
kdesk trust + kdesk doctor patterns for your inputs
3. Act — execute with api-auth-engineer tools
- Tools:
Glob, Grep, Read, Bash (see frontmatter tools/allowed-tools)
- Use
safe_path for any write; record evidence (paths, checksums)
- Fingerprint:
api-auth-engineer:16b30556
API Auth Engineer
What this skill does
Implement and verify API authentication using OAuth2 with Keycloak as the identity provider. Covers realm setup, the password and client-credentials grants, and verifying tokens at the API.
When to use
- Adding OAuth2 to an API
- Standing up a local identity provider
- Testing grant flows and token verification
Real commands
# Start Keycloak (dev mode)
docker run -d -p 8080:8080 \
-e KEYCLOAK_ADMIN=admin -e KEYCLOAK_ADMIN_PASSWORD=admin \
quay.io/keycloak/keycloak:latest start-dev
# Discovery endpoints
curl -s 'http://localhost:8080/realms/demo/.well-known/openid-configuration' | jq '.token_endpoint, .authorization_endpoint'
# Password grant
curl -s -X POST 'http://localhost:8080/realms/demo/protocol/openid-connect/token' \
-H 'Content-Type: application/x-www-form-urlencoded' \
-d 'grant_type=password&client_id=api&username=alice&password=secret' | jq -r '.access_token'
# Client credentials grant
curl -s -X POST 'http://localhost:8080/realms/demo/protocol/openid-connect/token' \
-d 'grant_type=client_credentials&client_id=orders-api&client_secret=abc123' | jq -r '.access_token'
# Refresh token
curl -s -X POST 'http://localhost:8080/realms/demo/protocol/openid-connect/token' \
-d 'grant_type=refresh_token&refresh_token=$REFRESH&client_id=api&client_secret=abc123' | jq -r '.access_token'
# Revoke
curl -s -X POST 'http://localhost:8080/realms/demo/protocol/openid-connect/revoke' -d 'token=$TOKEN&client_id=api'
# Verify at the API
curl -s http://localhost:8080/api/verify -H 'Authorization: Bearer $TOKEN' | jq '.subject'
Flow selection
- password: first-party apps with user creds (no longer recommended)
- client_credentials: server-to-server
- authorization_code + PKCE: SPAs and mobile
- refresh_token: long-lived sessions
Best practices
- Never use the password grant for third parties
- Use PKCE for public clients
- Validate signatures, issuer, audience, and expiry
- Rotate client secrets and refresh tokens
Testing
TOKEN=$(curl -s -X POST 'http://localhost:8080/realms/demo/protocol/openid-connect/token' -d 'grant_type=password&client_id=api&username=alice&password=secret' | jq -r '.access_token')
curl -s http://localhost:8080/api/verify -H "Authorization: Bearer $TOKEN" | jq
Capabilities
oauth2-implementation
Set up and verify OAuth2 flows against Keycloak
Parameters:
realm (string): Keycloak realm name
client_id (string): OAuth2 client ID
grant_type (string): password, client_credentials, authorization_code, or refresh_token
Commands:
docker run -d -p 8080:8080 -e KEYCLOAK_ADMIN=admin -e KEYCLOAK_ADMIN_PASSWORD=admin quay.io/keycloak/keycloak:latest start-dev
curl -s -X POST 'http://localhost:8080/realms/demo/protocol/openid-connect/token' -H 'Content-Type: application/x-www-form-urlencoded' -d 'grant_type=password&client_id=api&username=alice&password=secret' | jq -r '.access_token'
curl -s 'http://localhost:8080/realms/demo/.well-known/openid-configuration' | jq '.token_endpoint, .authorization_endpoint'
curl -s -X POST 'http://localhost:8080/admin/realms/demo/clients' -H 'Authorization: Bearer $ADMIN_TOKEN' -H 'Content-Type: application/json' -d '{"clientId":"orders-api","publicClient":false,"serviceAccountsEnabled":true}'
curl -s http://localhost:8080/api/verify -H 'Authorization: Bearer $TOKEN' | jq '.subject'
Examples:
References
1---2name: "api-auth-engineer"3description: "Implement API authentication: OAuth2 flows with Keycloak, token exchange, client registration, and end-to-end token verification. Use when working with oauth2 implementation or when the user mentions oauth2 implementation."4license: "MIT"5compatibility: "Requires node.js, python, jsonwebtoken, passport, keycloak, auth0. Needs network access."6metadata:7 source: https://skillmd.com/skills/opknock/api-auth-engineer8 author: Kdesk9 version: 2.0.010 category: security11allowed-tools: "Glob Grep Read Bash(curl:*) Bash(docker:*)"12---1314Implement API authentication: OAuth2 flows with Keycloak, token exchange, client registration, and end-to-end token verification.1516## Agentic Workflow: Read -> Reason -> Act (api-auth-engineer)1718You are **api-auth-engineer** (security) — a sub-agent that **Reads, Reasons, and Acts** via `allowed-tools`.1920### 1. Read — security context for `api-auth-engineer`21- Domain: Implement API authentication: OAuth2 flows with Keycloak, token exchange, client registration, and end-to-end token verification.22- **oauth2-implementation**: Set up and verify OAuth2 flows against Keycloak — `docker run -d -p 8080:8080 -e KEYCLOAK_ADMIN=admin -e KEYCLOAK_ADMIN_PASSWORD=ad`23- Check `knowledge` and `prerequisites: node.js, python, jsonwebtoken, passport`2425### 2. Reason — think for `api-auth-engineer`26- For `oauth2-implementation`: Set up and verify OAuth2 flows against Keycloak — decide which checks to run27- Evaluate trust/policy: `kdesk trust` + `kdesk doctor` patterns for your inputs2829### 3. Act — execute with `api-auth-engineer` tools30- Tools: `Glob`, `Grep`, `Read`, `Bash` (see frontmatter `tools`/`allowed-tools`)31- Use `safe_path` for any write; record evidence (paths, checksums)32- Fingerprint: `api-auth-engineer:16b30556`3334# API Auth Engineer3536## What this skill does37Implement and verify API authentication using OAuth2 with Keycloak as the identity provider. Covers realm setup, the password and client-credentials grants, and verifying tokens at the API.3839## When to use40- Adding OAuth2 to an API41- Standing up a local identity provider42- Testing grant flows and token verification4344## Real commands45```bash46# Start Keycloak (dev mode)47docker run -d -p 8080:8080 \48 -e KEYCLOAK_ADMIN=admin -e KEYCLOAK_ADMIN_PASSWORD=admin \49 quay.io/keycloak/keycloak:latest start-dev5051# Discovery endpoints52curl -s 'http://localhost:8080/realms/demo/.well-known/openid-configuration' | jq '.token_endpoint, .authorization_endpoint'5354# Password grant55curl -s -X POST 'http://localhost:8080/realms/demo/protocol/openid-connect/token' \56 -H 'Content-Type: application/x-www-form-urlencoded' \57 -d 'grant_type=password&client_id=api&username=alice&password=secret' | jq -r '.access_token'5859# Client credentials grant60curl -s -X POST 'http://localhost:8080/realms/demo/protocol/openid-connect/token' \61 -d 'grant_type=client_credentials&client_id=orders-api&client_secret=abc123' | jq -r '.access_token'6263# Refresh token64curl -s -X POST 'http://localhost:8080/realms/demo/protocol/openid-connect/token' \65 -d 'grant_type=refresh_token&refresh_token=$REFRESH&client_id=api&client_secret=abc123' | jq -r '.access_token'6667# Revoke68curl -s -X POST 'http://localhost:8080/realms/demo/protocol/openid-connect/revoke' -d 'token=$TOKEN&client_id=api'6970# Verify at the API71curl -s http://localhost:8080/api/verify -H 'Authorization: Bearer $TOKEN' | jq '.subject'72```7374## Flow selection75- password: first-party apps with user creds (no longer recommended)76- client_credentials: server-to-server77- authorization_code + PKCE: SPAs and mobile78- refresh_token: long-lived sessions7980## Best practices81- Never use the password grant for third parties82- Use PKCE for public clients83- Validate signatures, issuer, audience, and expiry84- Rotate client secrets and refresh tokens8586## Testing87```bash88TOKEN=$(curl -s -X POST 'http://localhost:8080/realms/demo/protocol/openid-connect/token' -d 'grant_type=password&client_id=api&username=alice&password=secret' | jq -r '.access_token')89curl -s http://localhost:8080/api/verify -H "Authorization: Bearer $TOKEN" | jq90```9192## Capabilities9394### oauth2-implementation95Set up and verify OAuth2 flows against Keycloak9697**Parameters:**98- `realm` (string): Keycloak realm name99- `client_id` (string): OAuth2 client ID100- `grant_type` (string): password, client_credentials, authorization_code, or refresh_token101102**Commands:**103- `docker run -d -p 8080:8080 -e KEYCLOAK_ADMIN=admin -e KEYCLOAK_ADMIN_PASSWORD=admin quay.io/keycloak/keycloak:latest start-dev`104- `curl -s -X POST 'http://localhost:8080/realms/demo/protocol/openid-connect/token' -H 'Content-Type: application/x-www-form-urlencoded' -d 'grant_type=password&client_id=api&username=alice&password=secret' | jq -r '.access_token'`105- `curl -s 'http://localhost:8080/realms/demo/.well-known/openid-configuration' | jq '.token_endpoint, .authorization_endpoint'`106- `curl -s -X POST 'http://localhost:8080/admin/realms/demo/clients' -H 'Authorization: Bearer $ADMIN_TOKEN' -H 'Content-Type: application/json' -d '{"clientId":"orders-api","publicClient":false,"serviceAccountsEnabled":true}'`107- `curl -s http://localhost:8080/api/verify -H 'Authorization: Bearer $TOKEN' | jq '.subject'`108109**Examples:**110- curl -s -X POST 'http://localhost:8080/realms/demo/protocol/openid-connect/token' -d 'grant_type=client_credentials&client_id=orders-api&client_secret=abc123' | jq -r '.access_token'111- curl -s -X POST 'http://localhost:8080/realms/demo/protocol/openid-connect/revoke' -d 'token=$REFRESH&client_id=api&client_secret=abc123'112- curl -s -H 'Authorization: Bearer $TOKEN' http://localhost:8080/api/protected | jq '.role'113114## References115- [OAuth 2.0 Framework (RFC 6749)](https://datatracker.ietf.org/doc/html/rfc6749)116- [Keycloak Docs](https://www.keycloak.org/documentation)