Authentication SSO and Identity
16.1 Methods
Section titled “16.1 Methods”- API Key (
X-API-Key/Bearer) - JWT Session (cookie + header)
- OAuth2 / OIDC (multiple providers per org)
- SAML 2.0 (native SP,
@node-saml/node-saml) - LDAP / Active Directory (
ldapts, with LDAPS + CA cert + skip-verify TLS) - User API Keys (
ak_…format — unified per-user key with budgets/expiry) - SCIM v2 (per-org endpoint, token-authenticated)
16.2 Unified Auth Wizard
Section titled “16.2 Unified Auth Wizard”A single hub-and-spoke admin wizard guides administrators through:
- Vendor selection (brand logos for Microsoft Entra ID, Okta, Google Workspace, Auth0, GitHub, generic OIDC, generic SAML, Active Directory / LDAP)
- Protocol setup (OIDC, SAML 2.0, LDAP — declarative protocol descriptors drive the form)
- Group mapping mode (Off / Auto / Mapped — see 16.6)
- Test connection + enable
The wizard exposes Auto-create and Enabled toggles per provider, supports draft saves (draftAt), and round-trips group-mapping configuration through the API.
16.3 OAuth2/OIDC
Section titled “16.3 OAuth2/OIDC”OIDC discovery, auto-user creation, domain restriction, default roles, group claim key (groupClaimKey), logo URL, brand. Templates: Google, Microsoft, Okta, Auth0, GitHub, Custom OIDC. Admin APIs for CRUD and connection testing. Auto-created teams seed their budgets from the org’s default budget template (from Company Settings).
Flows supported: SSO login uses the OIDC Authorization Code flow with state + nonce and PKCE (RFC 7636, S256) since 2.0.412. Every authorization request carries a code_challenge (code_challenge_method=S256), and the token exchange presents the matching code_verifier, which AgentWatch keeps server-side, bound to that sign-in’s state, single-use, and expiring with it; it never reaches the browser. PKCE is on by default for every provider, including existing ones, with no reconfiguration. It is skipped automatically when the IdP’s discovery document lists code_challenge_methods_supported without S256, and can be switched off per provider ("pkceDisabled": true on PUT /api/admin/oauth2/providers/:id) for a legacy IdP that rejects unknown parameters. The Google Workspace email-sender consent flow uses PKCE too. Implicit, Resource Owner Password Credentials and Refresh Token grants are not implemented.
OAuth 2.0 client credentials flow (machine-to-machine): supported via POST /oauth/token (RFC 6749 §4.4), with M2M clients managed at /api/admin/oauth2/clients. Scoped API keys (ak_…) remain the primary M2M credential — see Section 16.8 + Section 35.
OpenAPI / Swagger documentation: the gateway auto-publishes an OpenAPI 3.x spec generated from its gateway routes (/api/admin/gateway/openapi.json, Swagger UI at /api/admin/gateway/docs) with a Bearer security scheme. Developers can Authorize → Try It Out against live endpoints from the docs page.
16.4 SAML 2.0 (Native)
Section titled “16.4 SAML 2.0 (Native)”| Endpoint | Purpose |
|---|---|
GET /api/auth/saml/metadata/:providerId |
Download SP metadata XML for IdP registration |
GET /api/auth/saml/authorize/:providerId |
Generate SAML AuthnRequest and redirect to IdP |
POST /api/auth/saml/callback/:providerId |
SAML assertion callback (ACS) |
GET/POST /api/auth/saml/logout/:providerId |
Single Logout service (2.0.412+), HTTP-Redirect and HTTP-POST bindings: accepts a signed IdP LogoutRequest (revokes every AgentWatch session for that NameID/SessionIndex, answers with a LogoutResponse) and the IdP’s LogoutResponse to an SP-initiated logout (InResponseTo must match a request AgentWatch issued; single use). Unsigned or invalid requests → 403 |
POST /api/auth/saml/logout |
Accepts a LogoutResponse (provider found from the pending request); a LogoutRequest is pointed at the provider-specific URL; no SAML message → 400. (Answered 501 before 2.0.412.) |
POST /api/auth/logout |
Console sign-out. For a SAML session whose provider has an IdP Single Logout URL, the response also carries samlLogoutUrl (the IdP redirect with the LogoutRequest); the session is revoked first either way |
Per-provider fields: samlEntryPoint, samlIssuer, samlCertificate, samlCallbackUrl, and optional samlLogoutUrl (the IdP’s Single Logout URL, stored in the provider’s metadata JSON — no schema change; empty = local logout only). SP metadata publishes SingleLogoutService. Optional AW_SAML_SP_SIGNING_KEY (PEM text or file path) signs logout messages only — required by Okta’s single logout; AuthnRequests stay unsigned. Requires signed assertions (SHA-256). Email, name, and group claims are extracted with configurable claim keys.
16.5 LDAP / Active Directory
Section titled “16.5 LDAP / Active Directory”Per-org LdapProvider records with:
host,port,useSsl(LDAPS)tlsCaCert(PEM upload),tlsRejectUnauthorized(skip-verify toggle)bindDn+bindPassword,searchBase,searchFilter(default(sAMAccountName={{username}}))groupSearchBase,groupAttribute(defaultmemberOf)usernameAttribute(defaultsAMAccountName),emailAttribute(defaultmail),nameAttribute(defaultdisplayName)domainRestriction(limit by email domain)autoCreateUsers,defaultRole
Login flow: POST /api/auth/ldap/login — discovers providers via GET /api/auth/ldap-providers/for-domain?email=…. Super-admin local fallback keeps the platform recoverable if directory binding fails.
Admin CRUD: /api/admin/ldap/providers (list/create), /:id (get/edit/delete), /:id/test (test bind), /:id/sync-groups (force group sync).
Target-org routing (multi-tenant LDAP): A single provider can route users into different organizations:
- Provider-level default (
targetOrganizationId) - Per-rule domain → org table (
LdapOrgRoutingRulewithsignalType='domain', pattern like@example.com, lowerprioritywins) - Group-based routing reserved for a later phase
16.6 Group-to-Team Mapping (Unified across OIDC / SAML / LDAP)
Section titled “16.6 Group-to-Team Mapping (Unified across OIDC / SAML / LDAP)”All three protocols share the SsoGroupMapping table and the applyGroupMappings() pipeline.
groupMappingMode per provider:
- Off — no group sync; users get the provider’s
defaultRoleand no team - Auto — directory group names are parsed by
autoTeamParseRule(regex / pattern), anautoDefaultRoleis assigned, and anautoDefaultBudgetTemplateIdseeds the team budget. Mappings are synthesized on the fly at login time - Mapped — admin-defined
SsoGroupMappingrows:(provider, adGroupName) → (teamId | autoTeamName, orgRole, budgetTemplateId, priority)
Group mappings apply at first login (and on subsequent logins to update memberships) and are managed via a dedicated UI panel.
16.7 SCIM v2 (Per-Org Provisioning)
Section titled “16.7 SCIM v2 (Per-Org Provisioning)”Endpoint format: /scim/v2/:orgId/… — every org gets its own SCIM tenant.
| Endpoint | RFC 7644 | Purpose |
|---|---|---|
GET /scim/v2/:orgId/ServiceProviderConfig |
Discovery | Public |
GET /scim/v2/:orgId/ResourceTypes |
Discovery | Public |
GET /scim/v2/:orgId/Schemas |
Discovery | Public |
GET / POST / PUT / PATCH / DELETE /scim/v2/:orgId/Users[/:id] |
RFC 7644 | Token-auth |
GET / POST / PATCH / DELETE /scim/v2/:orgId/Groups[/:id] |
RFC 7644 | Token-auth |
Accepts both application/scim+json (spec) and application/json (Okta).
Per-org configuration (ScimConfig):
enabledgroupSyncMode— Off / Auto / Mapped (same semantics as 16.6)groupParseRuledefaultOrgRole,defaultBudgetTemplateId
Token management (ScimToken): named tokens with hashed storage, reveal-once display, prefix/suffix masking, lastUsedAt / lastUsedIp telemetry, expiry, revoke. Admin UI provides a generate-token modal and a tokens list. Admin APIs: /api/admin/scim/config, /api/admin/scim/tokens.
Users carry an externalId so IdP-side ID changes don’t fork accounts.
16.8 Account Security
Section titled “16.8 Account Security”Failed-login lockout, forced password change, admin transfer tracking, key expiry, rotation alerts (90-day default).