Skip to content

feat(api): GET /v1/whoami — identity probe for SDK clients#63

Merged
CryptoJones merged 1 commit into
masterfrom
feat/whoami-endpoint
May 18, 2026
Merged

feat(api): GET /v1/whoami — identity probe for SDK clients#63
CryptoJones merged 1 commit into
masterfrom
feat/whoami-endpoint

Conversation

@CryptoJones
Copy link
Copy Markdown
Owner

Summary

Adds GET /v1/whoami — clients can hit this to learn whether their authKey is recognized, whether it's a master key, and which company it scopes to. Avoids the current pattern of "hit /v1/customer/1 with my key, infer from 403/200/404 what my permissions are."

Response shape:

{
  "authenticated": true,
  "isMaster": false,
  "companyId": 42
}

Three states: master / scoped / unknown. Unknown is 200 with authenticated: false (not 403), so a client can distinguish "header missing" from "header present but credential wrong."

Test plan

  • vitest: 227 passing + 4 integration skipped (was 223 + 4 skipped)
  • 403 when authKey header missing
  • DB-unreachable fallback path returns documented unknown-key shape
  • Response shape invariants (three keys, correct types)
  • Live integration with real PG hitting recognized master + scoped keys (deferred — current mock setup doesn't intercept nested CJS requires, so behavioral testing needs the integration harness)

Proudly Made in Nebraska. Go Big Red! 🌽 https://xkcd.com/2347/

Lightweight diagnostic endpoint. SDK clients (or curious operators)
can hit /v1/whoami and learn what their authKey resolves to
without firing a domain call and inferring from 403/200 patterns.

Response shape:
  {
    "authenticated": bool,
    "isMaster": bool,
    "companyId": int | null
  }

Three documented states:
  - master key:    {true,  true,  null}
  - scoped key:    {true,  false, <compId>}
  - unknown key:   {false, false, null}   (200, not 403)

The 200-vs-403 split is deliberate: a missing authKey header
returns 403 (the client never sent credentials), but a present
header with an unrecognized key returns 200 with
`authenticated: false` so the client can distinguish "network
plumbing wrong" from "credential wrong" without parsing error
messages.

Tests: 4 cases covering the auth contract (403 without header),
route mounting, the DB-unreachable fallback path (which under
test env's broken DB happens to produce the documented unknown-
key shape — so we test the public contract there), and response
shape invariants.

OpenAPI spec gets the path + response schema. Suite: 31 files /
227 passing + 4 integration skipped (was 30 / 223 + 4 skipped).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@CryptoJones CryptoJones merged commit 4878691 into master May 18, 2026
2 of 3 checks passed
@CryptoJones CryptoJones deleted the feat/whoami-endpoint branch May 18, 2026 01:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant