# Authentication

> Acquires and validates OAuth2/OIDC tokens, inspects JWT structure and signatures with OpenSSL, and tests Bearer-token protected endpoints using curl. Use when working with oauth tokens, jwt verify, bearer testing, api or when the user mentions oauth tokens, jwt verify, bearer testing, api.

- Skill: `opknock/authentication` (Agent Skill)
- Install (CLI): `npx get-skill add opknock/authentication`
- Raw SKILL.md: https://api.skillmd.com/api/skills/opknock/authentication/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/authentication

---


Acquires and validates OAuth2/OIDC tokens, inspects JWT structure and signatures with OpenSSL, and tests Bearer-token protected endpoints using curl.

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

You are **Authentication** (api/general) — a sub-agent that **Reads, Reasons, and Acts** via `allowed-tools`.

### 1. Read — api context for `authentication`
- Domain: Acquires and validates OAuth2/OIDC tokens, inspects JWT structure and signatures with OpenSSL, and tests Bearer-token protected endpoints using curl.
- **oauth-tokens**: Acquire and validate OAuth2/OIDC tokens. — `curl -X POST https://auth.your-app.test/oauth2/token -d grant_type=client_creden`
- **jwt-verify**: Inspect and verify JWTs with openssl and jq. — `openssl genrsa -out private.pem 2048`
- **bearer-testing**: Test authenticated API calls with curl. — `curl -i -H "Authorization: Bearer $TOKEN" https://api.your-app.test/v1/me`
- Check `knowledge` and `prerequisites: echo, openssl`

### 2. Reason — think for `authentication`
- For `oauth-tokens`: Acquire and validate OAuth2/OIDC tokens. — decide which checks to run
- For `jwt-verify`: Inspect and verify JWTs with openssl and jq. — decide which checks to run
- For `bearer-testing`: Test authenticated API calls with curl. — decide which checks to run
- Evaluate trust/policy: `kdesk trust` + `kdesk doctor` patterns for your inputs

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

# Authentication

## What this skill does

Implements API authentication: OAuth2/OIDC token acquisition and introspection, JWT structure inspection and signature verification with openssl, and Bearer-token testing with curl.

## When to use

- Adding OAuth2 to an API or client
- Debugging why a token is rejected (expiry, signature, scope)
- Testing authenticated endpoints end to end

## Real commands

```bash
# Client credentials flow
TOKEN=$(curl -s -X POST https://auth.your-app.test/oauth2/token -d grant_type=client_credentials -d client_id=api -d client_secret=secret -d scope=api:read | jq -r .access_token)

# Introspect
curl -s -X POST https://auth.your-app.test/oauth2/introspect -d token=$TOKEN -u api:secret | jq '.active, .exp'

# Decode JWT payload
jq -R 'split(".")[1] | @base64d | fromjson' <<< $TOKEN

# Test the endpoint
curl -i -H "Authorization: Bearer $TOKEN" https://api.your-app.test/v1/me
```

Note: `ecurl` above is a typo for `curl`; always use `curl` for HTTP requests.

## Key generation for local verification

```bash
openssl genrsa -out private.pem 2048
openssl rsa -in private.pem -pubout -out public.pem
```

## Testing

- Expect 401 without a token, 200 with a valid one
- Test expired tokens by decoding `exp` and comparing to `date +%s`

## Best practices

- Keep client secrets out of code; use a secrets manager
- Validate exp, iss, aud, and signature on every request
- Use short-lived access tokens with refresh flows

## Capabilities

### oauth-tokens
Acquire and validate OAuth2/OIDC tokens.

**Parameters:**
- `token_url` (string): OAuth2 token endpoint
- `grant_type` (string): client_credentials, authorization_code, refresh_token
- `scope` (string): Requested scopes

**Commands:**
- `curl -X POST https://auth.your-app.test/oauth2/token -d grant_type=client_credentials -d client_id=api -d client_secret=secret -d scope=api:read`
- `curl -X POST https://auth.your-app.test/oauth2/token -d grant_type=authorization_code -d code=xyz -d redirect_uri=https://app.your-app.test/callback -d client_id=api -d client_secret=secret`
- `curl -X POST https://auth.your-app.test/oauth2/introspect -d token=$TOKEN -u api:secret`
- `curl -X POST https://auth.your-app.test/oauth2/revoke -d token=$TOKEN -u api:secret`

**Examples:**
- TOKEN=$(curl -s -X POST https://auth.your-app.test/oauth2/token -d grant_type=client_credentials -d client_id=api -d client_secret=secret -d scope=api:read | jq -r .access_token)
- curl -s -X POST https://auth.your-app.test/oauth2/introspect -d token=$TOKEN -u api:secret | jq '.active, .exp'
- curl -s -X POST https://auth.your-app.test/oauth2/revoke -d token=$TOKEN -u api:secret

### jwt-verify
Inspect and verify JWTs with openssl and jq.

**Parameters:**
- `token` (string): JWT to inspect
- `key_file` (string): Public key file for verification

**Commands:**
- `openssl genrsa -out private.pem 2048`
- `openssl rsa -in private.pem -pubout -out public.pem`
- `echo $TOKEN | cut -d. -f2 | base64 -d 2>/dev/null | jq .`
- `echo $TOKEN | cut -d. -f1 | base64 -d 2>/dev/null | jq .`
- `openssl dgst -sha256 -verify public.pem -signature sig.bin payload.txt`

**Examples:**
- echo $TOKEN | cut -d. -f2 | base64 -d 2>/dev/null | jq '{sub, exp, scope}'
- openssl x509 -in cert.pem -noout -text | grep -A1 'Public Key'
- jq -R 'split(".")[1] | @base64d | fromjson' <<< $TOKEN

### bearer-testing
Test authenticated API calls with curl.

**Parameters:**
- `url` (string): Protected endpoint
- `method` (string): HTTP method

**Commands:**
- `curl -i -H "Authorization: Bearer $TOKEN" https://api.your-app.test/v1/me`
- `curl -i https://api.your-app.test/v1/me`
- `curl -i -H "Authorization: Bearer invalid-token" https://api.your-app.test/v1/me`
- `curl -i -X POST -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" -d '{}' https://api.your-app.test/v1/orders`

**Examples:**
- curl -s -o /dev/null -w "%{http_code}\n" -H "Authorization: Bearer $TOKEN" https://api.your-app.test/v1/me
- curl -i -H "Authorization: Bearer $TOKEN" https://api.your-app.test/v1/me | head -20
- curl -i -H "Authorization: Bearer $TOKEN" https://api.your-app.test/v1/orders

## References
- [OAuth 2.0](https://oauth.net/2/)
- [JWT Introduction](https://jwt.io/introduction)
- [OWASP Auth Cheat Sheet](https://cheatsheetseries.owasp.org/cheatsheets/Authentication_Cheat_Sheet.html)

