# scorpiox-identity-server-native

Native C CGI route handlers for **Personal Identity Server** — a local OpenID Connect (OIDC) and OAuth 2.0 authorization server.

Powered by `scorpiox-server.dll` (pure C HTTP engine) with zero external runtime dependencies.

## Architecture

```
scorpiox-server.dll   web_server_start(port, {root_dir: handlers/})
        │
        ▼  (native CGI executable dispatch)
  wellknown  authorize  token  revoke  introspect  userinfo  jwks  login  logout  end_session
  account  api  index  _fallback
        │
        ▼
  JSON Data Store in IDENTITY_DATA_DIR:
    users.json    clients.json    tokens.json    secret.key    keys.json    revoked.json
    consents.json login_attempts.json login_attempts_ip.json
```

## Features

- **OpenID Connect Discovery**: `/.well-known/openid-configuration` & `/wellknown`
- **OAuth 2.0 Authorization Code Flow + PKCE**:
  - `S256` only (PKCE `plain` was dropped in v1.2.0 — OAuth 2.1)
  - Secure redirect URI validation (exact matching)
- **Token Endpoint**:
  - `grant_type=authorization_code` (PKCE verification -> access_token + id_token + refresh_token)
  - `grant_type=refresh_token` (single-use refresh token rotation)
- **RFC 7009 /revoke + RFC 7662 /introspect** (v1.4.0): a relying party can withdraw its own
  tokens. `/revoke` is always `200` with an empty body (§2.2 — never leaks token existence) and
  revokes the whole refresh rotation family; revoked access tokens are deny-listed by `jti` in
  `revoked.json` so `/userinfo` and `/introspect` reject them immediately. `/introspect` returns
  the RFC 7662 claim set for an active token and exactly `{"active":false}` for anything else.
  Both are client-authenticated by the same `id_authenticate_client()` rule as `/token`.
- **JWT RS256** (v1.3.0+): RSA-2048 signing via vendored BearSSL subset; real JWKS; key rotation/pruning via /api?r=keys. HS256 tokens from v1.2.x remain verifiable for their lifetime (dropped in v1.4).
- **Roles (v1.3.1)**: `users.json` carries `role` (`owner`/`admin`/`user`). The first user created becomes `owner`; `/api` beyond `?r=status` requires owner/admin (or the `X-Identity-Admin` secret). A plain user can only read their own token list.
- **Password/legacy crypto**: Embedded pure-C SHA-256 / HMAC-SHA256 / PBKDF2 (100,000 iterations)
- **User Management**: Session cookies, login form / JSON authentication, password hashing
- **Administration API**: `/api?r=users`, `/api?r=clients`, `/api?r=tokens`, `/api?r=status`
- **Zero Dependencies**: Pure C99, vendored `yyjson` (MIT), embedded crypto.

## Build

### Linux
```bash
mkdir build && cd build
cmake ..
cmake --build . -j8
```

### Windows (MinGW static)
```powershell
cmake -G Ninja -DCMAKE_BUILD_TYPE=Release -S . -B build
cmake --build build --config Release
```

## License
MIT / Public Domain.
