API auth with OpenID Connect - discovery, authorization code flow with PKCE, ID token validation, and userinfo retrieval.
Agentic Workflow: Read -> Reason -> Act (api-auth-oidc)
You are Api Auth OIDC (security) — a sub-agent that Reads, Reasons, and Acts via allowed-tools.
1. Read — security context for api-auth-oidc
- Domain: API auth with OpenID Connect - discovery, authorization code flow with PKCE, ID token validation, and userinfo retrieval.
- oidc-flow: Implement and test OpenID Connect flows —
curl -s http://localhost:8080/realms/demo/.well-known/openid-configuration | jq
- Check
knowledge and prerequisites: node.js, python, jsonwebtoken
2. Reason — think for api-auth-oidc
- For
oidc-flow: Implement and test OpenID Connect flows — decide which checks to run
- Evaluate trust/policy:
kdesk trust + kdesk doctor patterns for your inputs
3. Act — execute with api-auth-oidc tools
- Tools:
Glob, Grep, Read, Bash (see frontmatter tools/allowed-tools)
- Use
safe_path for any write; record evidence (paths, checksums)
- Fingerprint:
api-auth-oidc:995af076
API Auth (OpenID Connect)
What this skill does
Implement OpenID Connect on top of OAuth2: run discovery, drive the authorization code flow with PKCE, validate ID tokens, and call the userinfo endpoint.
When to use
- Building SPAs that need identity (not just access)
- Federating login with an external IdP
- Moving from opaque sessions to OIDC
Real commands
# Discovery
curl -s http://localhost:8080/realms/demo/.well-known/openid-configuration | jq '.authorization_endpoint, .userinfo_endpoint, .jwks_uri'
# Generate PKCE pair
node -e "const c=require('crypto');\
const v=c.randomBytes(32).toString('base64url');\
console.log('verifier:',v);\
console.log('challenge:',c.createHash('sha256').update(v).digest('base64url'))"
# Authorization request
curl -s 'http://localhost:8080/realms/demo/protocol/openid-connect/auth?client_id=spa&redirect_uri=http://localhost:3000/cb&response_type=code&scope=openid%20profile&code_challenge=CHALLENGE&code_challenge_method=S256' -o /dev/null -w '%{redirect_url}'
# Exchange code
curl -s -X POST http://localhost:8080/realms/demo/protocol/openid-connect/token \
-H 'Content-Type: application/x-www-form-urlencoded' \
-d 'grant_type=authorization_code&client_id=spa&code=$CODE&redirect_uri=http://localhost:3000/cb&code_verifier=VERIFIER' | jq -r '.id_token'
# Userinfo
curl -s http://localhost:8080/realms/demo/protocol/openid-connect/userinfo -H "Authorization: Bearer $ACCESS" | jq '.preferred_username'
# JWKS for ID token validation
curl -s http://localhost:8080/realms/demo/protocol/openid-connect/certs | jq '.keys | length'
# Logout
curl -s http://localhost:8080/realms/demo/protocol/openid-connect/logout?post_logout_redirect_uri=http://localhost:3000 -o /dev/null -w '%{http_code}'
ID token validation
- Verify signature against the JWKS
- Check iss, aud, exp, nonce, azp if present
- Always use the code flow with PKCE for SPAs
Best practices
- Never expose client secrets in SPAs (use PKCE)
- Validate the nonce to prevent replay
- Use
openid scope so an ID token is returned
Testing
curl -s http://localhost:8080/realms/demo/.well-known/openid-configuration | jq -e '.issuer' && echo OK
Capabilities
oidc-flow
Implement and test OpenID Connect flows
Parameters:
realm (string): OIDC realm/tenant
scope (string): Scopes, e.g. openid profile email
code_challenge (string): PKCE S256 challenge
Commands:
curl -s http://localhost:8080/realms/demo/.well-known/openid-configuration | jq '.authorization_endpoint, .userinfo_endpoint'
curl -s 'http://localhost:8080/realms/demo/protocol/openid-connect/auth?client_id=spa&redirect_uri=http://localhost:3000/cb&response_type=code&scope=openid%20profile&code_challenge=CHALLENGE&code_challenge_method=S256' -o /dev/null -w '%{redirect_url}'
curl -s -X POST http://localhost:8080/realms/demo/protocol/openid-connect/token -H 'Content-Type: application/x-www-form-urlencoded' -d 'grant_type=authorization_code&client_id=spa&code=$CODE&redirect_uri=http://localhost:3000/cb&code_verifier=VERIFIER' | jq -r '.id_token'
curl -s http://localhost:8080/realms/demo/protocol/openid-connect/userinfo -H "Authorization: Bearer $ACCESS" | jq '.preferred_username'
curl -s http://localhost:8080/realms/demo/protocol/openid-connect/certs | jq '.keys | length'
Examples:
References
1---2name: "api-auth-oidc"3description: "API auth with OpenID Connect - discovery, authorization code flow with PKCE, ID token validation, and userinfo retrieval. Use when working with oidc flow or when the user mentions oidc flow."4license: "MIT"5compatibility: "Requires node.js, python, jsonwebtoken, passport, keycloak. Needs network access."6metadata:7 source: https://skillmd.com/skills/opknock/api-auth-oidc8 author: Kdesk9 version: 2.0.010 category: security11allowed-tools: "Glob Grep Read Bash(curl:*)"12---1314API auth with OpenID Connect - discovery, authorization code flow with PKCE, ID token validation, and userinfo retrieval.1516## Agentic Workflow: Read -> Reason -> Act (api-auth-oidc)1718You are **Api Auth OIDC** (security) — a sub-agent that **Reads, Reasons, and Acts** via `allowed-tools`.1920### 1. Read — security context for `api-auth-oidc`21- Domain: API auth with OpenID Connect - discovery, authorization code flow with PKCE, ID token validation, and userinfo retrieval.22- **oidc-flow**: Implement and test OpenID Connect flows — `curl -s http://localhost:8080/realms/demo/.well-known/openid-configuration | jq `23- Check `knowledge` and `prerequisites: node.js, python, jsonwebtoken`2425### 2. Reason — think for `api-auth-oidc`26- For `oidc-flow`: Implement and test OpenID Connect flows — decide which checks to run27- Evaluate trust/policy: `kdesk trust` + `kdesk doctor` patterns for your inputs2829### 3. Act — execute with `api-auth-oidc` 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-oidc:995af076`3334# API Auth (OpenID Connect)3536## What this skill does37Implement OpenID Connect on top of OAuth2: run discovery, drive the authorization code flow with PKCE, validate ID tokens, and call the userinfo endpoint.3839## When to use40- Building SPAs that need identity (not just access)41- Federating login with an external IdP42- Moving from opaque sessions to OIDC4344## Real commands45```bash46# Discovery47curl -s http://localhost:8080/realms/demo/.well-known/openid-configuration | jq '.authorization_endpoint, .userinfo_endpoint, .jwks_uri'4849# Generate PKCE pair50node -e "const c=require('crypto');\51const v=c.randomBytes(32).toString('base64url');\52console.log('verifier:',v);\53console.log('challenge:',c.createHash('sha256').update(v).digest('base64url'))"5455# Authorization request56curl -s 'http://localhost:8080/realms/demo/protocol/openid-connect/auth?client_id=spa&redirect_uri=http://localhost:3000/cb&response_type=code&scope=openid%20profile&code_challenge=CHALLENGE&code_challenge_method=S256' -o /dev/null -w '%{redirect_url}'5758# Exchange code59curl -s -X POST http://localhost:8080/realms/demo/protocol/openid-connect/token \60 -H 'Content-Type: application/x-www-form-urlencoded' \61 -d 'grant_type=authorization_code&client_id=spa&code=$CODE&redirect_uri=http://localhost:3000/cb&code_verifier=VERIFIER' | jq -r '.id_token'6263# Userinfo64curl -s http://localhost:8080/realms/demo/protocol/openid-connect/userinfo -H "Authorization: Bearer $ACCESS" | jq '.preferred_username'6566# JWKS for ID token validation67curl -s http://localhost:8080/realms/demo/protocol/openid-connect/certs | jq '.keys | length'6869# Logout70curl -s http://localhost:8080/realms/demo/protocol/openid-connect/logout?post_logout_redirect_uri=http://localhost:3000 -o /dev/null -w '%{http_code}'71```7273## ID token validation74- Verify signature against the JWKS75- Check iss, aud, exp, nonce, azp if present76- Always use the code flow with PKCE for SPAs7778## Best practices79- Never expose client secrets in SPAs (use PKCE)80- Validate the nonce to prevent replay81- Use `openid` scope so an ID token is returned8283## Testing84```bash85curl -s http://localhost:8080/realms/demo/.well-known/openid-configuration | jq -e '.issuer' && echo OK86```8788## Capabilities8990### oidc-flow91Implement and test OpenID Connect flows9293**Parameters:**94- `realm` (string): OIDC realm/tenant95- `scope` (string): Scopes, e.g. openid profile email96- `code_challenge` (string): PKCE S256 challenge9798**Commands:**99- `curl -s http://localhost:8080/realms/demo/.well-known/openid-configuration | jq '.authorization_endpoint, .userinfo_endpoint'`100- `curl -s 'http://localhost:8080/realms/demo/protocol/openid-connect/auth?client_id=spa&redirect_uri=http://localhost:3000/cb&response_type=code&scope=openid%20profile&code_challenge=CHALLENGE&code_challenge_method=S256' -o /dev/null -w '%{redirect_url}'`101- `curl -s -X POST http://localhost:8080/realms/demo/protocol/openid-connect/token -H 'Content-Type: application/x-www-form-urlencoded' -d 'grant_type=authorization_code&client_id=spa&code=$CODE&redirect_uri=http://localhost:3000/cb&code_verifier=VERIFIER' | jq -r '.id_token'`102- `curl -s http://localhost:8080/realms/demo/protocol/openid-connect/userinfo -H "Authorization: Bearer $ACCESS" | jq '.preferred_username'`103- `curl -s http://localhost:8080/realms/demo/protocol/openid-connect/certs | jq '.keys | length'`104105**Examples:**106- node -e "const c=require('crypto');const v=c.randomBytes(32).toString('base64url');console.log(v);console.log(c.createHash('sha256').update(v).digest('base64url'))"107- curl -s -X POST http://localhost:8080/realms/demo/protocol/openid-connect/token -d 'grant_type=authorization_code&client_id=spa&code=$CODE&redirect_uri=http://localhost:3000/cb&code_verifier=VERIFIER' | jq '.expires_in'108- curl -s http://localhost:8080/realms/demo/protocol/openid-connect/logout?post_logout_redirect_uri=http://localhost:3000 -o /dev/null -w '%{http_code}'109110## References111- [OpenID Connect Core 1.0](https://openid.net/specs/openid-connect-core-1_0.html)112- [OAuth 2.0 PKCE (RFC 7636)](https://datatracker.ietf.org/doc/html/rfc7636)