Skip to content

Package: identity

Generated from api/packages/identity

Source: api/packages/identity. The sections after the README are extracted from the code on every docs build.

OpenID Connect and SAML 2.0 login with per-tenant identity providers (Keycloak, Entra ID, Okta, Google, any OIDC or SAML provider), account creation on first sign-in, strict account linking and a hash-chained audit trail (Phase 6.3, milestones ID-1, ID-2 and ID-4 of docs/plans/phase-6-identity.md; ADR 0120, ADR 0121, ADR 0198, ADR 0199) and a SCIM 2.0 server for users. HRIS import is a later milestone.

  • Guides for operators: front/docs-site/src/content/docs/operators/single-sign-on.mdx (OpenID Connect) and single-sign-on-saml.mdx; protocol: developers/authentication.mdx.
  • Public routes (/api/identity/*, throttled per IP): providers list, sso/{slug}/start, oidc/{slug}/callback, sso/exchange, SAML saml/{slug}/metadata, saml/{slug}/acs (POST), saml/{slug}/slo (GET and POST); POST saml/{slug}/logout needs the user’s token.
  • SCIM 2.0 (/api/scim/v2/*, ScimAuthenticate: only a scim token of one provider; 600 requests per minute per token): ServiceProviderConfig, ResourceTypes, Schemas, Users and Groups (CRUD, .search, filters, PATCH, ETag). Guide: operators/scim.mdx, reference: developers/scim-api.mdx.
  • Admin routes (/api/admin/identity/*, permissions identity_provider_manage, identity_audit_read, identity_scim_manage for providers/{id}/scim-tokens, token scope identity:read|write): providers CRUD, audit list and chain verification. OpenAPI tags “Identity” and “Admin Identity”.
  • Tables (tenant database): identity_providers (client secret and SAML SP private keys encrypted with the tenant APP_KEY), identity_links, saml_replays (accepted assertion ids), identity_sessions (token to IdP session, for single logout), identity_audit + identity_audit_head (append-only, PostgreSQL trigger), identity_external_ids (SCIM ids of users per provider, userName, tombstone on deprovisioning).
SsoLoginService start (state + nonce + PKCE), callback (code -> ID token -> account -> one-time code), exchange
OidcClient discovery, authorization URL, token request, ID token validation on firebase/php-jwt, userinfo
AccountResolver link, create a student, or refuse (verified e-mail, trust_email + domain, never admins/tutors)
ProviderService create/update/delete with audit rows; secrets write-only
IdentityAuditLog the only writer of identity_audit; verify() recomputes the chain
Saml\SamlService onelogin/php-saml per provider and request: settings, SP metadata, AuthnRequest, response validation, replay
Saml\SamlLogout single logout both ways (signed LogoutRequest/Response, sessions, token revocation)
Saml\IdpMetadata IdP metadata over SafeHttp, certificates; ProviderService applies the refresh policy
Saml\SamlXml size, DOCTYPE, algorithm allow-lists and comment checks that run before the library
Scim\FilterParser RFC 7644 filter grammar to a tree; Scim\FilterCompiler turns it into bound-parameter SQL on a fixed column map
Scim\PatchApplier add/replace/remove on the SCIM representation (Entra and Okta quirks); nothing is written until all succeed
Scim\UserProvisioner create, adopt, update, deactivate, delete through UserService, model fields and ManagerService
Scim\GroupProvisioner / GroupRoleMapper groups through UserGroupService; roles from group names (student/tutor only)
Scim\ScimDirectory what a provider's client can see: only the users it provisioned
Scim\ScimTokenService service user and scoped tokens of kind `scim` (two active, shown once)

Commands: identity:refresh-metadata (daily 03:30, per tenant), identity:prune (daily).

The login hand-off (signed state, one-time code, return URL allow-list) is Ulams\Auth\Services\LoginHandoffService. Every request to a provider goes through Ulams\Core\Http\SafeHttp.

Config: ulams_identity.* (IDENTITY_ENABLED, IDENTITY_MAX_PROVIDERS, IDENTITY_SAML_MAX_AGE, IDENTITY_SCIM_RATE, IDENTITY_SCIM_DELETE, IDENTITY_ALLOW_INSECURE_URLS for development only).

Install: registered in api/config/app.php; run the migrations and PermissionsSeeder. Tests: php artisan test --testsuite identity (fixture providers in tests/Support/FakeIdp.php and FakeSamlIdp.php, which signs, encrypts and attacks SAML documents with xmlseclibs). A real Keycloak runs OpenID Connect and SAML in .github/workflows/identity-keycloak.yml (nightly and on pull requests labelled identity).

Dependency: onelogin/php-saml 4.x (MIT) and its robrichards/xmlseclibs (BSD-3-Clause); see LICENSING.md for why and what they cost.

Method Path Auth Action
GET /api/identity/providers SsoController@providers
GET /api/identity/sso/{slug}/start SsoController@start
GET /api/identity/oidc/{slug}/callback SsoController@callback
POST /api/identity/sso/exchange SsoController@exchange
GET /api/identity/saml/{slug}/metadata SamlController@metadata
POST /api/identity/saml/{slug}/acs SamlController@acs
GET|POST /api/identity/saml/{slug}/slo SamlController@slo
POST /api/identity/saml/{slug}/logout yes SamlController@logout
GET /api/admin/identity/providers yes ProviderController@index
POST /api/admin/identity/providers yes ProviderController@store
GET /api/admin/identity/providers/{provider} yes ProviderController@show
PUT /api/admin/identity/providers/{provider} yes ProviderController@update
DELETE /api/admin/identity/providers/{provider} yes ProviderController@destroy
POST /api/admin/identity/providers/{provider}/metadata/refresh yes ProviderController@refreshMetadata
POST /api/admin/identity/providers/{provider}/sp-keys/rotate yes ProviderController@rotateSpKeys
GET /api/admin/identity/providers/{provider}/scim-tokens yes ScimTokenController@index
POST /api/admin/identity/providers/{provider}/scim-tokens yes ScimTokenController@store
DELETE /api/admin/identity/providers/{provider}/scim-tokens/{token} yes ScimTokenController@destroy
GET /api/admin/identity/audit yes AuditController@index
GET /api/admin/identity/audit/verify yes AuditController@verify
GET /api/scim/v2/ServiceProviderConfig yes ScimDiscoveryController@config
GET /api/scim/v2/ResourceTypes yes ScimDiscoveryController@resourceTypes
GET /api/scim/v2/ResourceTypes/{id} yes ScimDiscoveryController@resourceType
GET /api/scim/v2/Schemas yes ScimDiscoveryController@schemas
GET /api/scim/v2/Schemas/{id} yes ScimDiscoveryController@schema
GET /api/scim/v2/Users yes ScimUsersController@index
POST /api/scim/v2/Users yes ScimUsersController@store
POST /api/scim/v2/Users/.search yes ScimUsersController@search
GET /api/scim/v2/Users/{id} yes ScimUsersController@show
PUT /api/scim/v2/Users/{id} yes ScimUsersController@replace
PATCH /api/scim/v2/Users/{id} yes ScimUsersController@patch
DELETE /api/scim/v2/Users/{id} yes ScimUsersController@destroy
GET /api/scim/v2/Groups yes ScimGroupsController@index
POST /api/scim/v2/Groups yes ScimGroupsController@store
POST /api/scim/v2/Groups/.search yes ScimGroupsController@search
GET /api/scim/v2/Groups/{id} yes ScimGroupsController@show
PUT /api/scim/v2/Groups/{id} yes ScimGroupsController@replace
PATCH /api/scim/v2/Groups/{id} yes ScimGroupsController@patch
DELETE /api/scim/v2/Groups/{id} yes ScimGroupsController@destroy
Permission Seeded for roles Constant
identity_provider_manage admin IdentityPermissionEnum::PROVIDER_MANAGE
identity_audit_read admin IdentityPermissionEnum::AUDIT_READ
identity_scim_manage admin IdentityPermissionEnum::SCIM_MANAGE

Registered with AdministrableConfig::registerConfig (editable in the admin panel under Configuration → Settings).

None.

Event Description Notification templates
SamlMetadataNeedsAttention The daily metadata refresh found a change it will not apply on its own (a different entity id, certificates with nothing in common with the trusted ones): an administrator has to look. Listeners can notify people; the change is also in the identity audit trail and in the provider’s last_error.
Command Description Signature
identity:prune Delete expired SAML replay records and old identity sessions identity:prune
identity:refresh-metadata Refresh the SAML identity provider metadata (new signing certificates are added; other changes wait for an administrator) identity:refresh-metadata {--provider= : Only this provider slug}
Kind Target Frequency
command 'identity:refresh-metadata' dailyAt((string) config('ulams_identity.saml.metadata_refresh_at', '03:30'))->withoutOverlapping()
command 'identity:prune' dailyAt('03:50')->withoutOverlapping()

IDENTITY_ALLOW_INSECURE_URLS, IDENTITY_ENABLED, IDENTITY_MAX_PROVIDERS, IDENTITY_SAML_MAX_AGE, IDENTITY_SCIM_DELETE, IDENTITY_SCIM_RATE, ULAMS_DOCS_URL