Auth & OAuth
Auth & OAuth
Every request must authenticate. Three paths — all converge to a single RequestContext.
Three Auth Paths → RequestContext
What & Why
Auth is the gateway. Every request must authenticate before the middleware stack continues. The three modes serve different use cases:
- JWT — user-delegated flows where an identity provider issues a signed token. Octopus validates the signature, expiry, and extracts
sub(user email) andtenant_id. - API Key — service-to-service calls. The key is hashed before Redis lookup; the stored record carries the tenant and allowed scopes.
- Token Passthrough — the caller hands Octopus a raw OAuth access token (e.g. a user's Google token). Octopus does not validate it; it forwards the token directly to the adapter as a Bearer token for the external API.
All three paths produce the same RequestContext object, so service and adapter code never needs to know which auth mode was used.
Authorization Code Flow
Token Storage & TTL
oauth:{tenant_id}:{service}:{user_email}:access_token
oauth:{tenant_id}:{service}:{user_email}:refresh_token
Reference
Request Headers
| Header | Auth Method | Format | Notes |
|---|---|---|---|
Authorization | JWT | Bearer <jwt> | RS256 or HS256 signed token |
Authorization | API Key | ApiKey <key> | Raw key; hashed before Redis lookup |
X-API-Key | API Key | <key> | Alternative to Authorization ApiKey |
Access-Token | Token Passthrough | <raw_token> | Not validated; forwarded to adapter |
JWT Claims
| Claim | Type | Description |
|---|---|---|
sub | string | User email address — maps to RequestContext.user_email |
tenant_id | string | Tenant identifier — maps to RequestContext.tenant_id |
exp | number | Unix timestamp expiry — validated on every request |
iat | number | Issued-at timestamp — informational |
iss | string | Issuer — validated against configured allowed issuers |
OAuth Endpoints
| Endpoint | Method | Description |
|---|---|---|
/v1/oauth/{service}/authorize | GET | Initiate OAuth flow. Returns redirect URL to provider. Query params: redirect_uri (required), scopes (optional). |
/v1/oauth/{service}/callback | POST | Handle provider callback. Query params: code, state. Exchanges code for tokens and stores in Redis. |
/v1/oauth/{service}/refresh | POST | Manually trigger a token refresh for a service. Useful for pre-warming tokens before a long job. |
OIDC (Enterprise SSO)
For enterprise deployments, Octopus supports OpenID Connect for identity federation. The ID token from Google Workspace, Azure AD, or Okta is validated against the provider's JWKS endpoint. The extracted identity (sub, email) populates RequestContext identically to a JWT flow — downstream services see no difference.
Supported OAuth Services
| Service | Auth Flow | Scopes |
|---|---|---|
| Google (Gmail, Calendar, Drive) | Authorization Code | Per-product, e.g. https://www.googleapis.com/auth/gmail.readonly |
| Microsoft 365 (Outlook, Teams, SharePoint) | Authorization Code | Delegated, e.g. Mail.Read, Calendars.ReadWrite |
| GitHub | Authorization Code | repo, read:org, read:user |
| Notion | Authorization Code | read_content, update_content |
| Slack | Authorization Code | channels:read, chat:write |