docs/auth.md
- Source: docs/auth.md
Imported Content
Authentication and Authorization
Modes
AUTH_MODE=disabled: development mode; gateway injects a local admin auth context.AUTH_MODE=jwt: bearer JWT is required on non-public routes.- In
staging/production,AUTH_MODE=jwtis mandatory.
JWT verification paths
- HS256 shared secret:
- Set
JWT_SIGNING_SECRET - Used when
AUTH_JWKS_URLis not set
- OIDC/JWKS:
- Set
AUTH_JWKS_URLto your identity provider JWKS endpoint - Set
AUTH_ISSUERandAUTH_AUDIENCE - Gateway validates tokens with remote signing keys (
RS*/ES*algorithms via JOSE)
Required claims
sub(required)roles(non-empty array)workspaceIds(non-empty array, use"*"for all)exp(required instaging/production)audandissshould align with configured audience/issuerjtiis required for portal-only invite tokens (roles=["client_portal"]) and is checked against persisted invite records.
Portal invite JWT model (GA)
- Invite tokens are generated from
POST /api/v1/portal/invites. - Claims are workspace-scoped (
workspaceIds) with roleclient_portal. - Invite records are persisted in
portal_inviteswith status (active,revoked,expired). - Gateway auth validates portal token
jtiand subject against persisted invite state. - Revocation is immediate via
POST /api/v1/portal/invites/{id}/revoke. - Web portal invite links now exchange invite token through
POST /api/v1/portal/session/exchangeand set an httpOnly session cookie (anchor_portal_session) in Next.js runtime. - Portal session termination is handled by
POST /api/v1/portal/session/terminate+ cookie clear. - Portal pages (
/portal) are expected to run on invite-session token auth for client-facing usage; operator JWT fallback is not used for normal portal client sessions.
Web operator JWT guardrails
- The Next.js web runtime accepts operator auth from:
anchor_operator_sessionhttpOnly cookie (set from/auth/operator)- fallback
ANCHOR_OPERATOR_JWTenv token
- Web pages auto-resolve workspace context when
workspaceIdis omitted:workspaceIdquery parameter- first concrete workspace in
ANCHOR_OPERATOR_JWT.workspaceIds
- In production,
ANCHOR_OPERATOR_JWTis required by default (ANCHOR_REQUIRE_OPERATOR_JWT). - In production, wildcard
workspaceIds=["*"]is rejected by default for web runtime (ANCHOR_ALLOW_WILDCARD_WORKSPACE_IDSmust be explicitly set totrueto bypass). - Recommended practice: issue one operator JWT per workspace and rotate regularly.
- Portal-only tokens (
roles=["client_portal"]) are not valid for operator session sign-in.
Example payload
{
"sub": "user-123",
"roles": ["msp_admin"],
"workspaceIds": ["*"],
"aud": "anchor-gateway",
"iss": "https://auth.anchor-msp.com/",
"exp": 1999999999
}
Public routes
GET /healthGET /api/v1/openapiPOST /api/v1/webhooks/workflow-completedPOST /api/v1/integrations/github/webhook(when enabled)POST /api/v1/portal/session/exchange
Non-tenant routes
/api/v1/platform/*routes require JWT auth but do not requirex-workspace-id.- Use
platform_admin(ormsp_admin) role for platform-level configuration.