@hilbras/keystone 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +53 -0
- package/LICENSE +21 -0
- package/README.md +691 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +144 -0
- package/dist/cli.js.map +1 -0
- package/dist/config.d.ts +68 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +118 -0
- package/dist/config.js.map +1 -0
- package/dist/container.d.ts +27 -0
- package/dist/container.d.ts.map +1 -0
- package/dist/container.js +14 -0
- package/dist/container.js.map +1 -0
- package/dist/db/index.d.ts +17 -0
- package/dist/db/index.d.ts.map +1 -0
- package/dist/db/index.js +46 -0
- package/dist/db/index.js.map +1 -0
- package/dist/db/migrations/0000_skinny_ben_parker.sql +553 -0
- package/dist/db/migrations/0001_brief_joseph.sql +10 -0
- package/dist/db/migrations/0002_add_account_lockout.sql +3 -0
- package/dist/db/migrations/0003_steep_rachel_grey.sql +1 -0
- package/dist/db/migrations/0004_clever_bill_hollister.sql +20 -0
- package/dist/db/migrations/0005_steep_the_call.sql +2 -0
- package/dist/db/migrations/0006_ambitious_boomer.sql +17 -0
- package/dist/db/migrations/0007_greedy_vindicator.sql +40 -0
- package/dist/db/migrations/meta/0000_snapshot.json +2964 -0
- package/dist/db/migrations/meta/0001_snapshot.json +3031 -0
- package/dist/db/migrations/meta/0003_snapshot.json +3051 -0
- package/dist/db/migrations/meta/0004_snapshot.json +3163 -0
- package/dist/db/migrations/meta/0005_snapshot.json +3177 -0
- package/dist/db/migrations/meta/0006_snapshot.json +3270 -0
- package/dist/db/migrations/meta/0007_snapshot.json +3489 -0
- package/dist/db/migrations/meta/_journal.json +62 -0
- package/dist/db/schema.d.ts +3671 -0
- package/dist/db/schema.d.ts.map +1 -0
- package/dist/db/schema.js +475 -0
- package/dist/db/schema.js.map +1 -0
- package/dist/db/seed.d.ts +2 -0
- package/dist/db/seed.d.ts.map +1 -0
- package/dist/db/seed.js +139 -0
- package/dist/db/seed.js.map +1 -0
- package/dist/di.d.ts +12 -0
- package/dist/di.d.ts.map +1 -0
- package/dist/di.js +56 -0
- package/dist/di.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +295 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/errors.d.ts +46 -0
- package/dist/lib/errors.d.ts.map +1 -0
- package/dist/lib/errors.js +78 -0
- package/dist/lib/errors.js.map +1 -0
- package/dist/lib/result.d.ts +21 -0
- package/dist/lib/result.d.ts.map +1 -0
- package/dist/lib/result.js +22 -0
- package/dist/lib/result.js.map +1 -0
- package/dist/lib/webhookSignature.d.ts +11 -0
- package/dist/lib/webhookSignature.d.ts.map +1 -0
- package/dist/lib/webhookSignature.js +35 -0
- package/dist/lib/webhookSignature.js.map +1 -0
- package/dist/plugins/appContext.d.ts +4 -0
- package/dist/plugins/appContext.d.ts.map +1 -0
- package/dist/plugins/appContext.js +63 -0
- package/dist/plugins/appContext.js.map +1 -0
- package/dist/plugins/audit.d.ts +11 -0
- package/dist/plugins/audit.d.ts.map +1 -0
- package/dist/plugins/audit.js +23 -0
- package/dist/plugins/audit.js.map +1 -0
- package/dist/plugins/auth.d.ts +21 -0
- package/dist/plugins/auth.d.ts.map +1 -0
- package/dist/plugins/auth.js +190 -0
- package/dist/plugins/auth.js.map +1 -0
- package/dist/plugins/metrics.d.ts +8 -0
- package/dist/plugins/metrics.d.ts.map +1 -0
- package/dist/plugins/metrics.js +36 -0
- package/dist/plugins/metrics.js.map +1 -0
- package/dist/plugins/mtls.d.ts +14 -0
- package/dist/plugins/mtls.d.ts.map +1 -0
- package/dist/plugins/mtls.js +76 -0
- package/dist/plugins/mtls.js.map +1 -0
- package/dist/plugins/permissions.d.ts +9 -0
- package/dist/plugins/permissions.d.ts.map +1 -0
- package/dist/plugins/permissions.js +20 -0
- package/dist/plugins/permissions.js.map +1 -0
- package/dist/plugins/rateLimit.d.ts +20 -0
- package/dist/plugins/rateLimit.d.ts.map +1 -0
- package/dist/plugins/rateLimit.js +101 -0
- package/dist/plugins/rateLimit.js.map +1 -0
- package/dist/plugins/requestLogger.d.ts +4 -0
- package/dist/plugins/requestLogger.d.ts.map +1 -0
- package/dist/plugins/requestLogger.js +20 -0
- package/dist/plugins/requestLogger.js.map +1 -0
- package/dist/plugins/tracing.d.ts +3 -0
- package/dist/plugins/tracing.d.ts.map +1 -0
- package/dist/plugins/tracing.js +21 -0
- package/dist/plugins/tracing.js.map +1 -0
- package/dist/repositories/apiKey.d.ts +40 -0
- package/dist/repositories/apiKey.d.ts.map +1 -0
- package/dist/repositories/apiKey.js +122 -0
- package/dist/repositories/apiKey.js.map +1 -0
- package/dist/repositories/application.d.ts +13 -0
- package/dist/repositories/application.d.ts.map +1 -0
- package/dist/repositories/application.js +57 -0
- package/dist/repositories/application.js.map +1 -0
- package/dist/repositories/audit.d.ts +13 -0
- package/dist/repositories/audit.d.ts.map +1 -0
- package/dist/repositories/audit.js +26 -0
- package/dist/repositories/audit.js.map +1 -0
- package/dist/repositories/index.d.ts +10 -0
- package/dist/repositories/index.d.ts.map +1 -0
- package/dist/repositories/index.js +10 -0
- package/dist/repositories/index.js.map +1 -0
- package/dist/repositories/oidcConnection.d.ts +131 -0
- package/dist/repositories/oidcConnection.d.ts.map +1 -0
- package/dist/repositories/oidcConnection.js +59 -0
- package/dist/repositories/oidcConnection.js.map +1 -0
- package/dist/repositories/organization.d.ts +44 -0
- package/dist/repositories/organization.d.ts.map +1 -0
- package/dist/repositories/organization.js +145 -0
- package/dist/repositories/organization.js.map +1 -0
- package/dist/repositories/permission.d.ts +24 -0
- package/dist/repositories/permission.d.ts.map +1 -0
- package/dist/repositories/permission.js +133 -0
- package/dist/repositories/permission.js.map +1 -0
- package/dist/repositories/samlConnection.d.ts +107 -0
- package/dist/repositories/samlConnection.d.ts.map +1 -0
- package/dist/repositories/samlConnection.js +53 -0
- package/dist/repositories/samlConnection.js.map +1 -0
- package/dist/repositories/session.d.ts +73 -0
- package/dist/repositories/session.d.ts.map +1 -0
- package/dist/repositories/session.js +68 -0
- package/dist/repositories/session.js.map +1 -0
- package/dist/repositories/types.d.ts +155 -0
- package/dist/repositories/types.d.ts.map +1 -0
- package/dist/repositories/types.js +2 -0
- package/dist/repositories/types.js.map +1 -0
- package/dist/repositories/user.d.ts +40 -0
- package/dist/repositories/user.d.ts.map +1 -0
- package/dist/repositories/user.js +135 -0
- package/dist/repositories/user.js.map +1 -0
- package/dist/routes/admin/billing.d.ts +3 -0
- package/dist/routes/admin/billing.d.ts.map +1 -0
- package/dist/routes/admin/billing.js +31 -0
- package/dist/routes/admin/billing.js.map +1 -0
- package/dist/routes/admin/helpers.d.ts +36 -0
- package/dist/routes/admin/helpers.d.ts.map +1 -0
- package/dist/routes/admin/helpers.js +45 -0
- package/dist/routes/admin/helpers.js.map +1 -0
- package/dist/routes/admin/index.d.ts +3 -0
- package/dist/routes/admin/index.d.ts.map +1 -0
- package/dist/routes/admin/index.js +15 -0
- package/dist/routes/admin/index.js.map +1 -0
- package/dist/routes/admin/organizations.d.ts +3 -0
- package/dist/routes/admin/organizations.d.ts.map +1 -0
- package/dist/routes/admin/organizations.js +222 -0
- package/dist/routes/admin/organizations.js.map +1 -0
- package/dist/routes/admin/permissions.d.ts +3 -0
- package/dist/routes/admin/permissions.d.ts.map +1 -0
- package/dist/routes/admin/permissions.js +63 -0
- package/dist/routes/admin/permissions.js.map +1 -0
- package/dist/routes/admin/platform.d.ts +3 -0
- package/dist/routes/admin/platform.d.ts.map +1 -0
- package/dist/routes/admin/platform.js +294 -0
- package/dist/routes/admin/platform.js.map +1 -0
- package/dist/routes/admin/sso.d.ts +3 -0
- package/dist/routes/admin/sso.d.ts.map +1 -0
- package/dist/routes/admin/sso.js +97 -0
- package/dist/routes/admin/sso.js.map +1 -0
- package/dist/routes/admin/webhooks.d.ts +3 -0
- package/dist/routes/admin/webhooks.d.ts.map +1 -0
- package/dist/routes/admin/webhooks.js +68 -0
- package/dist/routes/admin/webhooks.js.map +1 -0
- package/dist/routes/admin.d.ts +2 -0
- package/dist/routes/admin.d.ts.map +1 -0
- package/dist/routes/admin.js +2 -0
- package/dist/routes/admin.js.map +1 -0
- package/dist/routes/apiKeys.d.ts +3 -0
- package/dist/routes/apiKeys.d.ts.map +1 -0
- package/dist/routes/apiKeys.js +50 -0
- package/dist/routes/apiKeys.js.map +1 -0
- package/dist/routes/auth.d.ts +3 -0
- package/dist/routes/auth.d.ts.map +1 -0
- package/dist/routes/auth.js +174 -0
- package/dist/routes/auth.js.map +1 -0
- package/dist/routes/authz.d.ts +3 -0
- package/dist/routes/authz.d.ts.map +1 -0
- package/dist/routes/authz.js +28 -0
- package/dist/routes/authz.js.map +1 -0
- package/dist/routes/config.d.ts +3 -0
- package/dist/routes/config.d.ts.map +1 -0
- package/dist/routes/config.js +63 -0
- package/dist/routes/config.js.map +1 -0
- package/dist/routes/emailVerification.d.ts +3 -0
- package/dist/routes/emailVerification.d.ts.map +1 -0
- package/dist/routes/emailVerification.js +64 -0
- package/dist/routes/emailVerification.js.map +1 -0
- package/dist/routes/federation.d.ts +3 -0
- package/dist/routes/federation.d.ts.map +1 -0
- package/dist/routes/federation.js +133 -0
- package/dist/routes/federation.js.map +1 -0
- package/dist/routes/helpers.d.ts +14 -0
- package/dist/routes/helpers.d.ts.map +1 -0
- package/dist/routes/helpers.js +15 -0
- package/dist/routes/helpers.js.map +1 -0
- package/dist/routes/magicLinks.d.ts +3 -0
- package/dist/routes/magicLinks.d.ts.map +1 -0
- package/dist/routes/magicLinks.js +82 -0
- package/dist/routes/magicLinks.js.map +1 -0
- package/dist/routes/oauth.d.ts +3 -0
- package/dist/routes/oauth.d.ts.map +1 -0
- package/dist/routes/oauth.js +146 -0
- package/dist/routes/oauth.js.map +1 -0
- package/dist/routes/oauth2.d.ts +3 -0
- package/dist/routes/oauth2.d.ts.map +1 -0
- package/dist/routes/oauth2.js +219 -0
- package/dist/routes/oauth2.js.map +1 -0
- package/dist/routes/oidcEnterprise.d.ts +3 -0
- package/dist/routes/oidcEnterprise.d.ts.map +1 -0
- package/dist/routes/oidcEnterprise.js +119 -0
- package/dist/routes/oidcEnterprise.js.map +1 -0
- package/dist/routes/password.d.ts +3 -0
- package/dist/routes/password.d.ts.map +1 -0
- package/dist/routes/password.js +83 -0
- package/dist/routes/password.js.map +1 -0
- package/dist/routes/profile.d.ts +3 -0
- package/dist/routes/profile.d.ts.map +1 -0
- package/dist/routes/profile.js +43 -0
- package/dist/routes/profile.js.map +1 -0
- package/dist/routes/saml.d.ts +3 -0
- package/dist/routes/saml.d.ts.map +1 -0
- package/dist/routes/saml.js +164 -0
- package/dist/routes/saml.js.map +1 -0
- package/dist/routes/scim.d.ts +3 -0
- package/dist/routes/scim.d.ts.map +1 -0
- package/dist/routes/scim.js +175 -0
- package/dist/routes/scim.js.map +1 -0
- package/dist/routes/sdk.d.ts +3 -0
- package/dist/routes/sdk.d.ts.map +1 -0
- package/dist/routes/sdk.js +129 -0
- package/dist/routes/sdk.js.map +1 -0
- package/dist/routes/serviceAccounts.d.ts +3 -0
- package/dist/routes/serviceAccounts.d.ts.map +1 -0
- package/dist/routes/serviceAccounts.js +82 -0
- package/dist/routes/serviceAccounts.js.map +1 -0
- package/dist/routes/sessions.d.ts +3 -0
- package/dist/routes/sessions.d.ts.map +1 -0
- package/dist/routes/sessions.js +55 -0
- package/dist/routes/sessions.js.map +1 -0
- package/dist/routes/setup.d.ts +3 -0
- package/dist/routes/setup.d.ts.map +1 -0
- package/dist/routes/setup.js +304 -0
- package/dist/routes/setup.js.map +1 -0
- package/dist/routes/smsOtp.d.ts +3 -0
- package/dist/routes/smsOtp.d.ts.map +1 -0
- package/dist/routes/smsOtp.js +50 -0
- package/dist/routes/smsOtp.js.map +1 -0
- package/dist/routes/totp.d.ts +3 -0
- package/dist/routes/totp.d.ts.map +1 -0
- package/dist/routes/totp.js +78 -0
- package/dist/routes/totp.js.map +1 -0
- package/dist/routes/webauthn.d.ts +3 -0
- package/dist/routes/webauthn.d.ts.map +1 -0
- package/dist/routes/webauthn.js +100 -0
- package/dist/routes/webauthn.js.map +1 -0
- package/dist/routes/workflows.d.ts +3 -0
- package/dist/routes/workflows.d.ts.map +1 -0
- package/dist/routes/workflows.js +140 -0
- package/dist/routes/workflows.js.map +1 -0
- package/dist/sdk/index.d.ts +5 -0
- package/dist/sdk/index.d.ts.map +1 -0
- package/dist/sdk/index.js +125 -0
- package/dist/sdk/index.js.map +1 -0
- package/dist/sdk/types.d.ts +110 -0
- package/dist/sdk/types.d.ts.map +1 -0
- package/dist/sdk/types.js +2 -0
- package/dist/sdk/types.js.map +1 -0
- package/dist/services/anomalyDetection.d.ts +14 -0
- package/dist/services/anomalyDetection.d.ts.map +1 -0
- package/dist/services/anomalyDetection.js +68 -0
- package/dist/services/anomalyDetection.js.map +1 -0
- package/dist/services/application/authentication.d.ts +38 -0
- package/dist/services/application/authentication.d.ts.map +1 -0
- package/dist/services/application/authentication.js +48 -0
- package/dist/services/application/authentication.js.map +1 -0
- package/dist/services/application/identity.d.ts +34 -0
- package/dist/services/application/identity.d.ts.map +1 -0
- package/dist/services/application/identity.js +34 -0
- package/dist/services/application/identity.js.map +1 -0
- package/dist/services/application/index.d.ts +4 -0
- package/dist/services/application/index.d.ts.map +1 -0
- package/dist/services/application/index.js +4 -0
- package/dist/services/application/index.js.map +1 -0
- package/dist/services/application/organization.d.ts +44 -0
- package/dist/services/application/organization.d.ts.map +1 -0
- package/dist/services/application/organization.js +53 -0
- package/dist/services/application/organization.js.map +1 -0
- package/dist/services/applications.d.ts +25 -0
- package/dist/services/applications.d.ts.map +1 -0
- package/dist/services/applications.js +64 -0
- package/dist/services/applications.js.map +1 -0
- package/dist/services/audit.d.ts +16 -0
- package/dist/services/audit.d.ts.map +1 -0
- package/dist/services/audit.js +28 -0
- package/dist/services/audit.js.map +1 -0
- package/dist/services/auditExport.d.ts +17 -0
- package/dist/services/auditExport.d.ts.map +1 -0
- package/dist/services/auditExport.js +37 -0
- package/dist/services/auditExport.js.map +1 -0
- package/dist/services/billing.d.ts +23 -0
- package/dist/services/billing.d.ts.map +1 -0
- package/dist/services/billing.js +67 -0
- package/dist/services/billing.js.map +1 -0
- package/dist/services/cache.d.ts +23 -0
- package/dist/services/cache.d.ts.map +1 -0
- package/dist/services/cache.js +114 -0
- package/dist/services/cache.js.map +1 -0
- package/dist/services/configuration/profiles.d.ts +13 -0
- package/dist/services/configuration/profiles.d.ts.map +1 -0
- package/dist/services/configuration/profiles.js +108 -0
- package/dist/services/configuration/profiles.js.map +1 -0
- package/dist/services/configuration.d.ts +50 -0
- package/dist/services/configuration.d.ts.map +1 -0
- package/dist/services/configuration.js +74 -0
- package/dist/services/configuration.js.map +1 -0
- package/dist/services/connectors/google.d.ts +17 -0
- package/dist/services/connectors/google.d.ts.map +1 -0
- package/dist/services/connectors/google.js +81 -0
- package/dist/services/connectors/google.js.map +1 -0
- package/dist/services/connectors/oidc.d.ts +14 -0
- package/dist/services/connectors/oidc.d.ts.map +1 -0
- package/dist/services/connectors/oidc.js +100 -0
- package/dist/services/connectors/oidc.js.map +1 -0
- package/dist/services/connectors/registry.d.ts +13 -0
- package/dist/services/connectors/registry.d.ts.map +1 -0
- package/dist/services/connectors/registry.js +109 -0
- package/dist/services/connectors/registry.js.map +1 -0
- package/dist/services/connectors/types.d.ts +36 -0
- package/dist/services/connectors/types.d.ts.map +1 -0
- package/dist/services/connectors/types.js +2 -0
- package/dist/services/connectors/types.js.map +1 -0
- package/dist/services/connectors/zitadel.d.ts +14 -0
- package/dist/services/connectors/zitadel.d.ts.map +1 -0
- package/dist/services/connectors/zitadel.js +70 -0
- package/dist/services/connectors/zitadel.js.map +1 -0
- package/dist/services/devices.d.ts +4 -0
- package/dist/services/devices.d.ts.map +1 -0
- package/dist/services/devices.js +59 -0
- package/dist/services/devices.js.map +1 -0
- package/dist/services/domain/authentication.d.ts +51 -0
- package/dist/services/domain/authentication.d.ts.map +1 -0
- package/dist/services/domain/authentication.js +218 -0
- package/dist/services/domain/authentication.js.map +1 -0
- package/dist/services/domain/authorization.d.ts +20 -0
- package/dist/services/domain/authorization.d.ts.map +1 -0
- package/dist/services/domain/authorization.js +36 -0
- package/dist/services/domain/authorization.js.map +1 -0
- package/dist/services/domain/identity.d.ts +43 -0
- package/dist/services/domain/identity.d.ts.map +1 -0
- package/dist/services/domain/identity.js +75 -0
- package/dist/services/domain/identity.js.map +1 -0
- package/dist/services/domain/index.d.ts +5 -0
- package/dist/services/domain/index.d.ts.map +1 -0
- package/dist/services/domain/index.js +5 -0
- package/dist/services/domain/index.js.map +1 -0
- package/dist/services/domain/organization.d.ts +60 -0
- package/dist/services/domain/organization.d.ts.map +1 -0
- package/dist/services/domain/organization.js +87 -0
- package/dist/services/domain/organization.js.map +1 -0
- package/dist/services/email.d.ts +24 -0
- package/dist/services/email.d.ts.map +1 -0
- package/dist/services/email.js +127 -0
- package/dist/services/email.js.map +1 -0
- package/dist/services/emailVerification.d.ts +20 -0
- package/dist/services/emailVerification.d.ts.map +1 -0
- package/dist/services/emailVerification.js +58 -0
- package/dist/services/emailVerification.js.map +1 -0
- package/dist/services/enterpriseSso.d.ts +34 -0
- package/dist/services/enterpriseSso.d.ts.map +1 -0
- package/dist/services/enterpriseSso.js +40 -0
- package/dist/services/enterpriseSso.js.map +1 -0
- package/dist/services/events/bus.d.ts +9 -0
- package/dist/services/events/bus.d.ts.map +1 -0
- package/dist/services/events/bus.js +36 -0
- package/dist/services/events/bus.js.map +1 -0
- package/dist/services/events/subscribers/anomaly.d.ts +3 -0
- package/dist/services/events/subscribers/anomaly.d.ts.map +1 -0
- package/dist/services/events/subscribers/anomaly.js +13 -0
- package/dist/services/events/subscribers/anomaly.js.map +1 -0
- package/dist/services/events/subscribers/auditLog.d.ts +3 -0
- package/dist/services/events/subscribers/auditLog.d.ts.map +1 -0
- package/dist/services/events/subscribers/auditLog.js +21 -0
- package/dist/services/events/subscribers/auditLog.js.map +1 -0
- package/dist/services/events/subscribers/webhook.d.ts +3 -0
- package/dist/services/events/subscribers/webhook.d.ts.map +1 -0
- package/dist/services/events/subscribers/webhook.js +36 -0
- package/dist/services/events/subscribers/webhook.js.map +1 -0
- package/dist/services/events/subscribers/webhookDispatch.d.ts +7 -0
- package/dist/services/events/subscribers/webhookDispatch.d.ts.map +1 -0
- package/dist/services/events/subscribers/webhookDispatch.js +14 -0
- package/dist/services/events/subscribers/webhookDispatch.js.map +1 -0
- package/dist/services/events/types.d.ts +21 -0
- package/dist/services/events/types.d.ts.map +1 -0
- package/dist/services/events/types.js +8 -0
- package/dist/services/events/types.js.map +1 -0
- package/dist/services/events/validate.d.ts +9 -0
- package/dist/services/events/validate.d.ts.map +1 -0
- package/dist/services/events/validate.js +103 -0
- package/dist/services/events/validate.js.map +1 -0
- package/dist/services/featureFlags.d.ts +15 -0
- package/dist/services/featureFlags.d.ts.map +1 -0
- package/dist/services/featureFlags.js +74 -0
- package/dist/services/featureFlags.js.map +1 -0
- package/dist/services/features.d.ts +12 -0
- package/dist/services/features.d.ts.map +1 -0
- package/dist/services/features.js +17 -0
- package/dist/services/features.js.map +1 -0
- package/dist/services/federation.d.ts +12 -0
- package/dist/services/federation.d.ts.map +1 -0
- package/dist/services/federation.js +22 -0
- package/dist/services/federation.js.map +1 -0
- package/dist/services/hibp.d.ts +2 -0
- package/dist/services/hibp.d.ts.map +1 -0
- package/dist/services/hibp.js +29 -0
- package/dist/services/hibp.js.map +1 -0
- package/dist/services/ipControls.d.ts +7 -0
- package/dist/services/ipControls.d.ts.map +1 -0
- package/dist/services/ipControls.js +92 -0
- package/dist/services/ipControls.js.map +1 -0
- package/dist/services/magicLinks.d.ts +16 -0
- package/dist/services/magicLinks.d.ts.map +1 -0
- package/dist/services/magicLinks.js +39 -0
- package/dist/services/magicLinks.js.map +1 -0
- package/dist/services/oauth2.d.ts +58 -0
- package/dist/services/oauth2.d.ts.map +1 -0
- package/dist/services/oauth2.js +144 -0
- package/dist/services/oauth2.js.map +1 -0
- package/dist/services/organizations.d.ts +39 -0
- package/dist/services/organizations.d.ts.map +1 -0
- package/dist/services/organizations.js +135 -0
- package/dist/services/organizations.js.map +1 -0
- package/dist/services/permissions.d.ts +19 -0
- package/dist/services/permissions.d.ts.map +1 -0
- package/dist/services/permissions.js +119 -0
- package/dist/services/permissions.js.map +1 -0
- package/dist/services/plugins/registry.d.ts +17 -0
- package/dist/services/plugins/registry.d.ts.map +1 -0
- package/dist/services/plugins/registry.js +196 -0
- package/dist/services/plugins/registry.js.map +1 -0
- package/dist/services/plugins/types.d.ts +86 -0
- package/dist/services/plugins/types.d.ts.map +1 -0
- package/dist/services/plugins/types.js +2 -0
- package/dist/services/plugins/types.js.map +1 -0
- package/dist/services/queue/bullmq.d.ts +16 -0
- package/dist/services/queue/bullmq.d.ts.map +1 -0
- package/dist/services/queue/bullmq.js +89 -0
- package/dist/services/queue/bullmq.js.map +1 -0
- package/dist/services/queue/inProcess.d.ts +15 -0
- package/dist/services/queue/inProcess.d.ts.map +1 -0
- package/dist/services/queue/inProcess.js +63 -0
- package/dist/services/queue/inProcess.js.map +1 -0
- package/dist/services/queue/index.d.ts +7 -0
- package/dist/services/queue/index.d.ts.map +1 -0
- package/dist/services/queue/index.js +19 -0
- package/dist/services/queue/index.js.map +1 -0
- package/dist/services/queue/types.d.ts +24 -0
- package/dist/services/queue/types.d.ts.map +1 -0
- package/dist/services/queue/types.js +2 -0
- package/dist/services/queue/types.js.map +1 -0
- package/dist/services/redis.d.ts +9 -0
- package/dist/services/redis.d.ts.map +1 -0
- package/dist/services/redis.js +15 -0
- package/dist/services/redis.js.map +1 -0
- package/dist/services/secrets/awsKms.d.ts +41 -0
- package/dist/services/secrets/awsKms.d.ts.map +1 -0
- package/dist/services/secrets/awsKms.js +81 -0
- package/dist/services/secrets/awsKms.js.map +1 -0
- package/dist/services/secrets/azureKeyVault.d.ts +44 -0
- package/dist/services/secrets/azureKeyVault.d.ts.map +1 -0
- package/dist/services/secrets/azureKeyVault.js +152 -0
- package/dist/services/secrets/azureKeyVault.js.map +1 -0
- package/dist/services/secrets/database.d.ts +29 -0
- package/dist/services/secrets/database.d.ts.map +1 -0
- package/dist/services/secrets/database.js +138 -0
- package/dist/services/secrets/database.js.map +1 -0
- package/dist/services/secrets/environment.d.ts +27 -0
- package/dist/services/secrets/environment.d.ts.map +1 -0
- package/dist/services/secrets/environment.js +102 -0
- package/dist/services/secrets/environment.js.map +1 -0
- package/dist/services/secrets/index.d.ts +30 -0
- package/dist/services/secrets/index.d.ts.map +1 -0
- package/dist/services/secrets/index.js +46 -0
- package/dist/services/secrets/index.js.map +1 -0
- package/dist/services/secrets/password.d.ts +10 -0
- package/dist/services/secrets/password.d.ts.map +1 -0
- package/dist/services/secrets/password.js +62 -0
- package/dist/services/secrets/password.js.map +1 -0
- package/dist/services/secrets/provider.d.ts +36 -0
- package/dist/services/secrets/provider.d.ts.map +1 -0
- package/dist/services/secrets/provider.js +2 -0
- package/dist/services/secrets/provider.js.map +1 -0
- package/dist/services/secrets/vault.d.ts +41 -0
- package/dist/services/secrets/vault.d.ts.map +1 -0
- package/dist/services/secrets/vault.js +133 -0
- package/dist/services/secrets/vault.js.map +1 -0
- package/dist/services/secrets.d.ts +2 -0
- package/dist/services/secrets.d.ts.map +1 -0
- package/dist/services/secrets.js +3 -0
- package/dist/services/secrets.js.map +1 -0
- package/dist/services/serviceAccounts.d.ts +24 -0
- package/dist/services/serviceAccounts.d.ts.map +1 -0
- package/dist/services/serviceAccounts.js +53 -0
- package/dist/services/serviceAccounts.js.map +1 -0
- package/dist/services/setup/configWriter.d.ts +18 -0
- package/dist/services/setup/configWriter.d.ts.map +1 -0
- package/dist/services/setup/configWriter.js +192 -0
- package/dist/services/setup/configWriter.js.map +1 -0
- package/dist/services/setup/diagnostics.d.ts +7 -0
- package/dist/services/setup/diagnostics.d.ts.map +1 -0
- package/dist/services/setup/diagnostics.js +73 -0
- package/dist/services/setup/diagnostics.js.map +1 -0
- package/dist/services/setup/token.d.ts +5 -0
- package/dist/services/setup/token.d.ts.map +1 -0
- package/dist/services/setup/token.js +37 -0
- package/dist/services/setup/token.js.map +1 -0
- package/dist/services/setup/types.d.ts +35 -0
- package/dist/services/setup/types.d.ts.map +1 -0
- package/dist/services/setup/types.js +2 -0
- package/dist/services/setup/types.js.map +1 -0
- package/dist/services/setup/validation.d.ts +7 -0
- package/dist/services/setup/validation.d.ts.map +1 -0
- package/dist/services/setup/validation.js +198 -0
- package/dist/services/setup/validation.js.map +1 -0
- package/dist/services/sms.d.ts +10 -0
- package/dist/services/sms.d.ts.map +1 -0
- package/dist/services/sms.js +62 -0
- package/dist/services/sms.js.map +1 -0
- package/dist/services/smsOtp.d.ts +7 -0
- package/dist/services/smsOtp.d.ts.map +1 -0
- package/dist/services/smsOtp.js +56 -0
- package/dist/services/smsOtp.js.map +1 -0
- package/dist/services/tokens.d.ts +66 -0
- package/dist/services/tokens.d.ts.map +1 -0
- package/dist/services/tokens.js +205 -0
- package/dist/services/tokens.js.map +1 -0
- package/dist/services/totp.d.ts +16 -0
- package/dist/services/totp.d.ts.map +1 -0
- package/dist/services/totp.js +96 -0
- package/dist/services/totp.js.map +1 -0
- package/dist/services/users.d.ts +39 -0
- package/dist/services/users.d.ts.map +1 -0
- package/dist/services/users.js +181 -0
- package/dist/services/users.js.map +1 -0
- package/dist/services/webauthn.d.ts +45 -0
- package/dist/services/webauthn.d.ts.map +1 -0
- package/dist/services/webauthn.js +147 -0
- package/dist/services/webauthn.js.map +1 -0
- package/dist/services/webhooks.d.ts +86 -0
- package/dist/services/webhooks.d.ts.map +1 -0
- package/dist/services/webhooks.js +164 -0
- package/dist/services/webhooks.js.map +1 -0
- package/dist/services/workflows/engine.d.ts +18 -0
- package/dist/services/workflows/engine.d.ts.map +1 -0
- package/dist/services/workflows/engine.js +104 -0
- package/dist/services/workflows/engine.js.map +1 -0
- package/dist/services/workflows/steps.d.ts +17 -0
- package/dist/services/workflows/steps.d.ts.map +1 -0
- package/dist/services/workflows/steps.js +109 -0
- package/dist/services/workflows/steps.js.map +1 -0
- package/dist/services/zitadel.d.ts +21 -0
- package/dist/services/zitadel.d.ts.map +1 -0
- package/dist/services/zitadel.js +228 -0
- package/dist/services/zitadel.js.map +1 -0
- package/dist/setup-server.d.ts +2 -0
- package/dist/setup-server.d.ts.map +1 -0
- package/dist/setup-server.js +63 -0
- package/dist/setup-server.js.map +1 -0
- package/dist/tests/errors.test.d.ts +2 -0
- package/dist/tests/errors.test.d.ts.map +1 -0
- package/dist/tests/errors.test.js +64 -0
- package/dist/tests/errors.test.js.map +1 -0
- package/dist/tests/events.test.d.ts +2 -0
- package/dist/tests/events.test.d.ts.map +1 -0
- package/dist/tests/events.test.js +45 -0
- package/dist/tests/events.test.js.map +1 -0
- package/dist/tests/featureFlags.test.d.ts +2 -0
- package/dist/tests/featureFlags.test.d.ts.map +1 -0
- package/dist/tests/featureFlags.test.js +24 -0
- package/dist/tests/featureFlags.test.js.map +1 -0
- package/dist/tests/integration/queue.test.d.ts +2 -0
- package/dist/tests/integration/queue.test.d.ts.map +1 -0
- package/dist/tests/integration/queue.test.js +49 -0
- package/dist/tests/integration/queue.test.js.map +1 -0
- package/dist/tests/plugins.test.d.ts +2 -0
- package/dist/tests/plugins.test.d.ts.map +1 -0
- package/dist/tests/plugins.test.js +56 -0
- package/dist/tests/plugins.test.js.map +1 -0
- package/dist/tests/result.test.d.ts +2 -0
- package/dist/tests/result.test.d.ts.map +1 -0
- package/dist/tests/result.test.js +46 -0
- package/dist/tests/result.test.js.map +1 -0
- package/dist/tests/setup/configWriter.test.d.ts +2 -0
- package/dist/tests/setup/configWriter.test.d.ts.map +1 -0
- package/dist/tests/setup/configWriter.test.js +55 -0
- package/dist/tests/setup/configWriter.test.js.map +1 -0
- package/dist/tests/setup/validation.test.d.ts +2 -0
- package/dist/tests/setup/validation.test.d.ts.map +1 -0
- package/dist/tests/setup/validation.test.js +26 -0
- package/dist/tests/setup/validation.test.js.map +1 -0
- package/dist/tests/smoke.test.d.ts +2 -0
- package/dist/tests/smoke.test.d.ts.map +1 -0
- package/dist/tests/smoke.test.js +124 -0
- package/dist/tests/smoke.test.js.map +1 -0
- package/dist/types.d.ts +50 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +17 -0
- package/dist/types.js.map +1 -0
- package/package.json +69 -0
- package/src/cli.ts +172 -0
- package/src/config.ts +143 -0
- package/src/container.ts +48 -0
- package/src/db/index.ts +53 -0
- package/src/db/migrations/0000_skinny_ben_parker.sql +553 -0
- package/src/db/migrations/0001_brief_joseph.sql +10 -0
- package/src/db/migrations/0002_add_account_lockout.sql +3 -0
- package/src/db/migrations/0003_steep_rachel_grey.sql +1 -0
- package/src/db/migrations/0004_clever_bill_hollister.sql +20 -0
- package/src/db/migrations/0005_steep_the_call.sql +2 -0
- package/src/db/migrations/0006_ambitious_boomer.sql +17 -0
- package/src/db/migrations/0007_greedy_vindicator.sql +40 -0
- package/src/db/migrations/meta/0000_snapshot.json +2964 -0
- package/src/db/migrations/meta/0001_snapshot.json +3031 -0
- package/src/db/migrations/meta/0003_snapshot.json +3051 -0
- package/src/db/migrations/meta/0004_snapshot.json +3163 -0
- package/src/db/migrations/meta/0005_snapshot.json +3177 -0
- package/src/db/migrations/meta/0006_snapshot.json +3270 -0
- package/src/db/migrations/meta/0007_snapshot.json +3489 -0
- package/src/db/migrations/meta/_journal.json +62 -0
- package/src/db/schema.ts +676 -0
- package/src/db/seed.ts +146 -0
- package/src/di.ts +81 -0
- package/src/index.ts +326 -0
- package/src/lib/errors.ts +139 -0
- package/src/lib/result.ts +44 -0
- package/src/lib/webhookSignature.ts +41 -0
- package/src/plugins/appContext.ts +76 -0
- package/src/plugins/audit.ts +42 -0
- package/src/plugins/auth.ts +230 -0
- package/src/plugins/metrics.ts +41 -0
- package/src/plugins/mtls.ts +94 -0
- package/src/plugins/permissions.ts +29 -0
- package/src/plugins/rateLimit.ts +133 -0
- package/src/plugins/requestLogger.ts +25 -0
- package/src/plugins/tracing.ts +22 -0
- package/src/repositories/apiKey.ts +158 -0
- package/src/repositories/application.ts +70 -0
- package/src/repositories/audit.ts +32 -0
- package/src/repositories/index.ts +9 -0
- package/src/repositories/oidcConnection.ts +111 -0
- package/src/repositories/organization.ts +167 -0
- package/src/repositories/permission.ts +153 -0
- package/src/repositories/samlConnection.ts +96 -0
- package/src/repositories/session.ts +86 -0
- package/src/repositories/types.ts +134 -0
- package/src/repositories/user.ts +161 -0
- package/src/routes/admin/billing.ts +48 -0
- package/src/routes/admin/helpers.ts +50 -0
- package/src/routes/admin/index.ts +16 -0
- package/src/routes/admin/organizations.ts +299 -0
- package/src/routes/admin/permissions.ts +80 -0
- package/src/routes/admin/platform.ts +335 -0
- package/src/routes/admin/sso.ts +138 -0
- package/src/routes/admin/webhooks.ts +73 -0
- package/src/routes/admin.ts +1 -0
- package/src/routes/apiKeys.ts +60 -0
- package/src/routes/auth.ts +214 -0
- package/src/routes/authz.ts +38 -0
- package/src/routes/config.ts +67 -0
- package/src/routes/emailVerification.ts +73 -0
- package/src/routes/federation.ts +156 -0
- package/src/routes/helpers.ts +17 -0
- package/src/routes/magicLinks.ts +107 -0
- package/src/routes/oauth.ts +167 -0
- package/src/routes/oauth2.ts +284 -0
- package/src/routes/oidcEnterprise.ts +166 -0
- package/src/routes/password.ts +90 -0
- package/src/routes/profile.ts +44 -0
- package/src/routes/saml.ts +209 -0
- package/src/routes/scim.ts +199 -0
- package/src/routes/sdk.ts +141 -0
- package/src/routes/serviceAccounts.ts +124 -0
- package/src/routes/sessions.ts +62 -0
- package/src/routes/setup.ts +315 -0
- package/src/routes/smsOtp.ts +67 -0
- package/src/routes/totp.ts +122 -0
- package/src/routes/webauthn.ts +147 -0
- package/src/routes/workflows.ts +157 -0
- package/src/sdk/index.ts +152 -0
- package/src/sdk/types.ts +54 -0
- package/src/services/anomalyDetection.ts +73 -0
- package/src/services/application/authentication.ts +75 -0
- package/src/services/application/identity.ts +56 -0
- package/src/services/application/index.ts +3 -0
- package/src/services/application/organization.ts +77 -0
- package/src/services/applications.ts +89 -0
- package/src/services/audit.ts +41 -0
- package/src/services/auditExport.ts +59 -0
- package/src/services/billing.ts +87 -0
- package/src/services/cache.ts +131 -0
- package/src/services/configuration/profiles.ts +115 -0
- package/src/services/configuration.ts +120 -0
- package/src/services/connectors/google.ts +92 -0
- package/src/services/connectors/oidc.ts +111 -0
- package/src/services/connectors/registry.ts +124 -0
- package/src/services/connectors/types.ts +38 -0
- package/src/services/connectors/zitadel.ts +77 -0
- package/src/services/devices.ts +76 -0
- package/src/services/domain/authentication.ts +279 -0
- package/src/services/domain/authorization.ts +49 -0
- package/src/services/domain/identity.ts +108 -0
- package/src/services/domain/index.ts +4 -0
- package/src/services/domain/organization.ts +114 -0
- package/src/services/email.ts +167 -0
- package/src/services/emailVerification.ts +75 -0
- package/src/services/enterpriseSso.ts +58 -0
- package/src/services/events/bus.ts +43 -0
- package/src/services/events/subscribers/anomaly.ts +13 -0
- package/src/services/events/subscribers/auditLog.ts +21 -0
- package/src/services/events/subscribers/webhook.ts +39 -0
- package/src/services/events/subscribers/webhookDispatch.ts +14 -0
- package/src/services/events/types.ts +106 -0
- package/src/services/events/validate.ts +118 -0
- package/src/services/featureFlags.ts +90 -0
- package/src/services/features.ts +22 -0
- package/src/services/federation.ts +30 -0
- package/src/services/hibp.ts +28 -0
- package/src/services/ipControls.ts +99 -0
- package/src/services/magicLinks.ts +51 -0
- package/src/services/oauth2.ts +216 -0
- package/src/services/organizations.ts +171 -0
- package/src/services/permissions.ts +146 -0
- package/src/services/plugins/registry.ts +242 -0
- package/src/services/plugins/types.ts +98 -0
- package/src/services/queue/bullmq.ts +104 -0
- package/src/services/queue/inProcess.ts +75 -0
- package/src/services/queue/index.ts +19 -0
- package/src/services/queue/types.ts +26 -0
- package/src/services/redis.ts +16 -0
- package/src/services/secrets/awsKms.ts +97 -0
- package/src/services/secrets/azureKeyVault.ts +171 -0
- package/src/services/secrets/database.ts +166 -0
- package/src/services/secrets/environment.ts +117 -0
- package/src/services/secrets/index.ts +50 -0
- package/src/services/secrets/password.ts +73 -0
- package/src/services/secrets/provider.ts +38 -0
- package/src/services/secrets/vault.ts +149 -0
- package/src/services/secrets.ts +2 -0
- package/src/services/serviceAccounts.ts +74 -0
- package/src/services/setup/configWriter.ts +200 -0
- package/src/services/setup/diagnostics.ts +76 -0
- package/src/services/setup/token.ts +42 -0
- package/src/services/setup/types.ts +40 -0
- package/src/services/setup/validation.ts +205 -0
- package/src/services/sms.ts +81 -0
- package/src/services/smsOtp.ts +74 -0
- package/src/services/tokens.ts +288 -0
- package/src/services/totp.ts +113 -0
- package/src/services/users.ts +239 -0
- package/src/services/webauthn.ts +193 -0
- package/src/services/webhooks.ts +190 -0
- package/src/services/workflows/engine.ts +125 -0
- package/src/services/workflows/steps.ts +129 -0
- package/src/services/zitadel.ts +277 -0
- package/src/setup-server.ts +71 -0
- package/src/tests/errors.test.ts +74 -0
- package/src/tests/events.test.ts +52 -0
- package/src/tests/featureFlags.test.ts +26 -0
- package/src/tests/integration/queue.test.ts +54 -0
- package/src/tests/plugins.test.ts +73 -0
- package/src/tests/result.test.ts +52 -0
- package/src/tests/setup/configWriter.test.ts +69 -0
- package/src/tests/setup/validation.test.ts +29 -0
- package/src/tests/smoke.test.ts +136 -0
- package/src/types.ts +70 -0
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import type { FastifyInstance, FastifyRequest, FastifyReply } from "fastify";
|
|
3
|
+
import { toPublicUser } from "../types.js";
|
|
4
|
+
|
|
5
|
+
const UpdateProfileSchema = z.object({
|
|
6
|
+
name: z.string().max(255).optional(),
|
|
7
|
+
avatarUrl: z.string().url().max(2048).nullable().optional(),
|
|
8
|
+
phoneNumber: z.string().max(32).nullable().optional(),
|
|
9
|
+
metadata: z.record(z.unknown()).optional(),
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
export default async function profileRoutes(app: FastifyInstance) {
|
|
13
|
+
app.get("/profile", { preHandler: [app.authenticate] }, async (request: FastifyRequest, reply: FastifyReply) => {
|
|
14
|
+
const userId = request.user?.id;
|
|
15
|
+
if (!userId) return reply.status(401).send({ error: "Unauthorized" });
|
|
16
|
+
|
|
17
|
+
const user = await app.container.userRepository.findById(userId);
|
|
18
|
+
if (!user) return reply.status(404).send({ error: "User not found" });
|
|
19
|
+
|
|
20
|
+
return { user: toPublicUser(user) };
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
app.patch("/profile", { preHandler: [app.authenticate] }, async (request: FastifyRequest, reply: FastifyReply) => {
|
|
24
|
+
const userId = request.user?.id;
|
|
25
|
+
if (!userId) return reply.status(401).send({ error: "Unauthorized" });
|
|
26
|
+
|
|
27
|
+
const body = UpdateProfileSchema.parse(request.body);
|
|
28
|
+
const updates: Record<string, unknown> = {};
|
|
29
|
+
if (body.name !== undefined) updates.name = body.name;
|
|
30
|
+
if (body.avatarUrl !== undefined) updates.avatarUrl = body.avatarUrl;
|
|
31
|
+
if (body.metadata !== undefined) updates.metadata = body.metadata;
|
|
32
|
+
// Changing the phone number resets its verification status.
|
|
33
|
+
if (body.phoneNumber !== undefined) {
|
|
34
|
+
updates.phoneNumber = body.phoneNumber;
|
|
35
|
+
updates.phoneVerified = false;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const updated = await app.container.userRepository.update(userId, updates);
|
|
39
|
+
if (!updated) return reply.status(404).send({ error: "User not found" });
|
|
40
|
+
|
|
41
|
+
await request.audit("profile_updated", { userId });
|
|
42
|
+
return { user: toPublicUser(updated) };
|
|
43
|
+
});
|
|
44
|
+
}
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import type { FastifyInstance, FastifyRequest, FastifyReply } from "fastify";
|
|
3
|
+
import { ServiceProvider, IdentityProvider } from "samlify";
|
|
4
|
+
import type { SamlConnection } from "../db/schema.js";
|
|
5
|
+
import { provisionEnterpriseUser, defaultRoleForOrg } from "../services/enterpriseSso.js";
|
|
6
|
+
import { createTokenSet } from "../services/tokens.js";
|
|
7
|
+
import { setSessionCookies } from "../plugins/auth.js";
|
|
8
|
+
import { fingerprintFromRequest, recordDevice } from "../services/devices.js";
|
|
9
|
+
import { toPublicUser } from "../types.js";
|
|
10
|
+
import { config } from "../config.js";
|
|
11
|
+
import { escapeXml } from "./helpers.js";
|
|
12
|
+
|
|
13
|
+
const RelayStateSchema = z.object({
|
|
14
|
+
connectionId: z.string(),
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
const DEFAULT_ATTRIBUTE_MAPPING: Record<string, string[]> = {
|
|
18
|
+
email: [
|
|
19
|
+
"email",
|
|
20
|
+
"mail",
|
|
21
|
+
"urn:oid:0.9.2342.19200300.100.1.3",
|
|
22
|
+
"http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress",
|
|
23
|
+
"http://schemas.microsoft.com/identity/claims/email",
|
|
24
|
+
],
|
|
25
|
+
name: [
|
|
26
|
+
"name",
|
|
27
|
+
"displayName",
|
|
28
|
+
"cn",
|
|
29
|
+
"commonName",
|
|
30
|
+
"urn:oid:2.16.840.1.113730.3.1.241",
|
|
31
|
+
"http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name",
|
|
32
|
+
"http://schemas.microsoft.com/identity/claims/displayname",
|
|
33
|
+
],
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
function buildSamlEntities(connection: SamlConnection) {
|
|
37
|
+
if (!connection.idpEntityId || !connection.idpSsoUrl || !connection.idpCertificate) {
|
|
38
|
+
throw new Error("SAML connection is missing IdP metadata");
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const sp = ServiceProvider({
|
|
42
|
+
entityID: connection.spEntityId,
|
|
43
|
+
wantAssertionsSigned: true,
|
|
44
|
+
wantMessageSigned: true,
|
|
45
|
+
assertionConsumerService: [
|
|
46
|
+
{
|
|
47
|
+
Binding: "urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST",
|
|
48
|
+
Location: connection.spAcsUrl,
|
|
49
|
+
},
|
|
50
|
+
],
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
const idp = IdentityProvider({
|
|
54
|
+
entityID: connection.idpEntityId,
|
|
55
|
+
signingCert: connection.idpCertificate,
|
|
56
|
+
singleSignOnService: [
|
|
57
|
+
{
|
|
58
|
+
Binding: "urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect",
|
|
59
|
+
Location: connection.idpSsoUrl,
|
|
60
|
+
},
|
|
61
|
+
],
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
return { sp, idp };
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function getAttribute(
|
|
68
|
+
attributes: Record<string, string | string[]> | undefined,
|
|
69
|
+
key: string,
|
|
70
|
+
mapping: Record<string, string[]>,
|
|
71
|
+
fallbackMapping: Record<string, string[]>
|
|
72
|
+
): string | undefined {
|
|
73
|
+
const candidates = mapping[key] ?? fallbackMapping[key] ?? [key];
|
|
74
|
+
for (const candidate of candidates) {
|
|
75
|
+
const value = attributes?.[candidate];
|
|
76
|
+
if (value === undefined || value === null) continue;
|
|
77
|
+
const normalized = Array.isArray(value) ? value[0] : value;
|
|
78
|
+
if (normalized) return normalized;
|
|
79
|
+
}
|
|
80
|
+
return undefined;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function parseSamlAttributes(
|
|
84
|
+
attributes: Record<string, string | string[]> | undefined,
|
|
85
|
+
connection: SamlConnection
|
|
86
|
+
): { email?: string; name?: string } {
|
|
87
|
+
const mapping = (connection.attributeMapping ?? {}) as Record<string, string[]>;
|
|
88
|
+
return {
|
|
89
|
+
email: getAttribute(attributes, "email", mapping, DEFAULT_ATTRIBUTE_MAPPING),
|
|
90
|
+
name: getAttribute(attributes, "name", mapping, DEFAULT_ATTRIBUTE_MAPPING),
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function sanitizeSamlError(error: unknown): { statusCode: number; body: { error: string } } {
|
|
95
|
+
const message = config.NODE_ENV === "development" && error instanceof Error ? error.message : "SAML validation failed";
|
|
96
|
+
return { statusCode: 400, body: { error: message } };
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export default async function samlRoutes(app: FastifyInstance) {
|
|
100
|
+
app.get("/saml/:connectionId", async (request: FastifyRequest, reply: FastifyReply) => {
|
|
101
|
+
const { connectionId } = request.params as { connectionId: string };
|
|
102
|
+
const connection = await app.container.samlConnectionRepository.findActiveById(connectionId);
|
|
103
|
+
|
|
104
|
+
if (!connection) {
|
|
105
|
+
return reply.status(404).send({ error: "SAML connection not found" });
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
if (!connection.idpSsoUrl) {
|
|
109
|
+
return reply.status(400).send({ error: "SAML connection missing IdP SSO URL" });
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
try {
|
|
113
|
+
const { sp, idp } = buildSamlEntities(connection);
|
|
114
|
+
const relayState = Buffer.from(JSON.stringify({ connectionId })).toString("base64url");
|
|
115
|
+
const loginRequest = sp.createLoginRequest(idp, "redirect", { relayState });
|
|
116
|
+
|
|
117
|
+
const url = new URL(connection.idpSsoUrl);
|
|
118
|
+
url.searchParams.set("SAMLRequest", loginRequest.context);
|
|
119
|
+
if (relayState) url.searchParams.set("RelayState", relayState);
|
|
120
|
+
|
|
121
|
+
return reply.redirect(url.toString());
|
|
122
|
+
} catch (err) {
|
|
123
|
+
request.log.error({ err }, "Failed to build SAML login request");
|
|
124
|
+
const { statusCode, body } = sanitizeSamlError(err);
|
|
125
|
+
return reply.status(statusCode).send(body);
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
app.post("/saml/acs", async (request: FastifyRequest, reply: FastifyReply) => {
|
|
130
|
+
const body = request.body as { SAMLResponse?: string; RelayState?: string };
|
|
131
|
+
if (!body.SAMLResponse) {
|
|
132
|
+
return reply.status(400).send({ error: "Missing SAMLResponse" });
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
let relayState: { connectionId: string } | undefined;
|
|
136
|
+
try {
|
|
137
|
+
relayState = RelayStateSchema.parse(
|
|
138
|
+
JSON.parse(Buffer.from(body.RelayState || "", "base64url").toString("utf8"))
|
|
139
|
+
);
|
|
140
|
+
} catch {
|
|
141
|
+
return reply.status(400).send({ error: "Invalid RelayState" });
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
const connection = await app.container.samlConnectionRepository.findActiveById(relayState.connectionId);
|
|
145
|
+
|
|
146
|
+
if (!connection) {
|
|
147
|
+
return reply.status(400).send({ error: "SAML connection not found" });
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
try {
|
|
151
|
+
const { sp, idp } = buildSamlEntities(connection);
|
|
152
|
+
const result = await sp.parseLoginResponse(idp, "post", { body });
|
|
153
|
+
const claims = parseSamlAttributes(result.extract.attributes, connection);
|
|
154
|
+
|
|
155
|
+
if (!claims.email) {
|
|
156
|
+
return reply.status(400).send({ error: "SAML response did not contain an email" });
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
const org = await app.container.organizationRepository.findById(connection.orgId);
|
|
160
|
+
|
|
161
|
+
const user = await provisionEnterpriseUser(
|
|
162
|
+
connection.orgId,
|
|
163
|
+
{ email: claims.email, name: claims.name },
|
|
164
|
+
org ? defaultRoleForOrg(org) : "member"
|
|
165
|
+
);
|
|
166
|
+
|
|
167
|
+
const fingerprint = fingerprintFromRequest(request);
|
|
168
|
+
await recordDevice(user.id, fingerprint, request.ip, request.headers["user-agent"]);
|
|
169
|
+
const tokens = await createTokenSet(
|
|
170
|
+
user,
|
|
171
|
+
request.ip,
|
|
172
|
+
request.headers["user-agent"],
|
|
173
|
+
{ orgId: connection.orgId },
|
|
174
|
+
fingerprint
|
|
175
|
+
);
|
|
176
|
+
setSessionCookies(reply, tokens.accessToken, tokens.refreshToken);
|
|
177
|
+
|
|
178
|
+
await request.audit("saml_sso_login", {
|
|
179
|
+
orgId: connection.orgId,
|
|
180
|
+
connectionId: connection.id,
|
|
181
|
+
userId: user.id,
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
return { user: toPublicUser(user) };
|
|
185
|
+
} catch (err) {
|
|
186
|
+
request.log.error({ err }, "SAML ACS validation failed");
|
|
187
|
+
const { statusCode, body } = sanitizeSamlError(err);
|
|
188
|
+
return reply.status(statusCode).send(body);
|
|
189
|
+
}
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
app.get("/saml/:connectionId/metadata", async (request: FastifyRequest, reply: FastifyReply) => {
|
|
193
|
+
const { connectionId } = request.params as { connectionId: string };
|
|
194
|
+
const connection = await app.container.samlConnectionRepository.findActiveById(connectionId);
|
|
195
|
+
|
|
196
|
+
if (!connection) {
|
|
197
|
+
return reply.status(404).send({ error: "SAML connection not found" });
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
const metadata = `
|
|
201
|
+
<md:EntityDescriptor xmlns:md="urn:oasis:names:tc:SAML:2.0:metadata" entityID="${escapeXml(connection.spEntityId)}">
|
|
202
|
+
<md:SPSSODescriptor protocolSupportEnumeration="urn:oasis:names:tc:SAML:2.0:protocol">
|
|
203
|
+
<md:AssertionConsumerService Binding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST" Location="${escapeXml(connection.spAcsUrl)}" index="0"/>
|
|
204
|
+
</md:SPSSODescriptor>
|
|
205
|
+
</md:EntityDescriptor>`.trim();
|
|
206
|
+
|
|
207
|
+
return reply.header("Content-Type", "application/xml").send(metadata);
|
|
208
|
+
});
|
|
209
|
+
}
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import type { FastifyInstance, FastifyRequest, FastifyReply } from "fastify";
|
|
3
|
+
import { eq, and } from "drizzle-orm";
|
|
4
|
+
import { db } from "../db/index.js";
|
|
5
|
+
import { orgMemberships, users } from "../db/schema.js";
|
|
6
|
+
|
|
7
|
+
const ScimUserSchema = z.object({
|
|
8
|
+
userName: z.string().email(),
|
|
9
|
+
name: z.object({ givenName: z.string().optional(), familyName: z.string().optional() }).optional(),
|
|
10
|
+
emails: z.array(z.object({ value: z.string().email(), primary: z.boolean().optional() })).optional(),
|
|
11
|
+
active: z.boolean().optional(),
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
function scimUserResponse(user: { id: string; email: string; name: string | null }): Record<string, unknown> {
|
|
15
|
+
return {
|
|
16
|
+
schemas: ["urn:ietf:params:scim:schemas:core:2.0:User"],
|
|
17
|
+
id: user.id,
|
|
18
|
+
userName: user.email,
|
|
19
|
+
name: {
|
|
20
|
+
givenName: user.name?.split(" ")[0] || "",
|
|
21
|
+
familyName: user.name?.split(" ").slice(1).join(" ") || "",
|
|
22
|
+
},
|
|
23
|
+
emails: [{ value: user.email, primary: true }],
|
|
24
|
+
active: true,
|
|
25
|
+
meta: {
|
|
26
|
+
resourceType: "User",
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function scimGroupResponse(group: { id: string; displayName: string; members: { value: string; display: string }[] }): Record<string, unknown> {
|
|
32
|
+
return {
|
|
33
|
+
schemas: ["urn:ietf:params:scim:schemas:core:2.0:Group"],
|
|
34
|
+
id: group.id,
|
|
35
|
+
displayName: group.displayName,
|
|
36
|
+
members: group.members.map((m) => ({
|
|
37
|
+
value: m.value,
|
|
38
|
+
display: m.display,
|
|
39
|
+
$ref: `Users/${m.value}`,
|
|
40
|
+
})),
|
|
41
|
+
meta: {
|
|
42
|
+
resourceType: "Group",
|
|
43
|
+
},
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function scimError(status: number, detail: string): Record<string, unknown> {
|
|
48
|
+
return {
|
|
49
|
+
schemas: ["urn:ietf:params:scim:api:messages:2.0:Error"],
|
|
50
|
+
status: String(status),
|
|
51
|
+
detail,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export default async function scimRoutes(app: FastifyInstance) {
|
|
56
|
+
app.addHook("onRequest", async (request: FastifyRequest, reply: FastifyReply) => {
|
|
57
|
+
const auth = request.headers.authorization;
|
|
58
|
+
const expected = process.env.SCIM_BEARER_TOKEN;
|
|
59
|
+
if (!expected) {
|
|
60
|
+
return reply.status(501).send(scimError(501, "SCIM not configured"));
|
|
61
|
+
}
|
|
62
|
+
if (!auth || !auth.startsWith("Bearer ") || auth.slice(7) !== expected) {
|
|
63
|
+
return reply.status(401).send(scimError(401, "Unauthorized"));
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
app.get("/scim/v2/Users", async () => {
|
|
68
|
+
const allUsers = await app.container.userRepository.listAll();
|
|
69
|
+
return {
|
|
70
|
+
schemas: ["urn:ietf:params:scim:api:messages:2.0:ListResponse"],
|
|
71
|
+
totalResults: allUsers.length,
|
|
72
|
+
Resources: allUsers.map(scimUserResponse),
|
|
73
|
+
};
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
app.get("/scim/v2/Users/:userId", async (request: FastifyRequest, reply: FastifyReply) => {
|
|
77
|
+
const { userId } = request.params as { userId: string };
|
|
78
|
+
const user = await app.container.userRepository.findById(userId);
|
|
79
|
+
if (!user) {
|
|
80
|
+
return reply.status(404).send(scimError(404, "User not found"));
|
|
81
|
+
}
|
|
82
|
+
return scimUserResponse(user);
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
app.post("/scim/v2/Users", async (request: FastifyRequest, reply: FastifyReply) => {
|
|
86
|
+
const body = ScimUserSchema.parse(request.body);
|
|
87
|
+
const email = body.userName.toLowerCase().trim();
|
|
88
|
+
|
|
89
|
+
let user = await app.container.userRepository.findByEmail(email);
|
|
90
|
+
let isNewUser = false;
|
|
91
|
+
if (!user) {
|
|
92
|
+
const base = email.split("@")[0];
|
|
93
|
+
const username = await app.container.userRepository.ensureUniqueUsername(base);
|
|
94
|
+
const name = body.name
|
|
95
|
+
? `${body.name.givenName || ""} ${body.name.familyName || ""}`.trim() || username
|
|
96
|
+
: username;
|
|
97
|
+
user = await app.container.userRepository.create({
|
|
98
|
+
email,
|
|
99
|
+
username,
|
|
100
|
+
name,
|
|
101
|
+
provider: "scim",
|
|
102
|
+
emailVerified: true,
|
|
103
|
+
});
|
|
104
|
+
isNewUser = true;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
await request.audit(isNewUser ? "scim_user_created" : "scim_user_updated", { userId: user.id, email: user.email });
|
|
108
|
+
return reply.status(201).send(scimUserResponse(user));
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
app.put("/scim/v2/Users/:userId", async (request: FastifyRequest, reply: FastifyReply) => {
|
|
112
|
+
const { userId } = request.params as { userId: string };
|
|
113
|
+
const body = ScimUserSchema.parse(request.body);
|
|
114
|
+
|
|
115
|
+
const updated = await app.container.userRepository.update(userId, {
|
|
116
|
+
email: body.userName.toLowerCase().trim(),
|
|
117
|
+
name: body.name
|
|
118
|
+
? `${body.name.givenName || ""} ${body.name.familyName || ""}`.trim()
|
|
119
|
+
: undefined,
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
if (!updated) {
|
|
123
|
+
return reply.status(404).send(scimError(404, "User not found"));
|
|
124
|
+
}
|
|
125
|
+
await request.audit("scim_user_updated", { userId: updated.id, email: updated.email });
|
|
126
|
+
return scimUserResponse(updated);
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
app.delete("/scim/v2/Users/:userId", async (request: FastifyRequest, reply: FastifyReply) => {
|
|
130
|
+
const { userId } = request.params as { userId: string };
|
|
131
|
+
const user = await app.container.userRepository.findById(userId);
|
|
132
|
+
await app.container.userRepository.deleteById(userId);
|
|
133
|
+
await request.audit("scim_user_deleted", { userId, email: user?.email });
|
|
134
|
+
return reply.status(204).send();
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
app.get("/scim/v2/Groups", async () => {
|
|
138
|
+
const memberships = await db
|
|
139
|
+
.select({ orgId: orgMemberships.orgId, role: orgMemberships.role })
|
|
140
|
+
.from(orgMemberships);
|
|
141
|
+
|
|
142
|
+
const groupMap = new Map<string, { orgId: string; role: string; members: { value: string; display: string }[] }>();
|
|
143
|
+
for (const m of memberships) {
|
|
144
|
+
const key = `${m.orgId}:${m.role}`;
|
|
145
|
+
if (!groupMap.has(key)) {
|
|
146
|
+
groupMap.set(key, { orgId: m.orgId, role: m.role, members: [] });
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
const groups: { id: string; displayName: string; members: { value: string; display: string }[] }[] = [];
|
|
151
|
+
for (const [key, group] of groupMap) {
|
|
152
|
+
const org = await app.container.organizationRepository.findById(group.orgId);
|
|
153
|
+
const orgName = org?.name || group.orgId;
|
|
154
|
+
const members = await db
|
|
155
|
+
.select({ userId: orgMemberships.userId, email: users.email })
|
|
156
|
+
.from(orgMemberships)
|
|
157
|
+
.where(and(eq(orgMemberships.orgId, group.orgId), eq(orgMemberships.role, group.role)))
|
|
158
|
+
.innerJoin(users, eq(orgMemberships.userId, users.id));
|
|
159
|
+
|
|
160
|
+
groups.push({
|
|
161
|
+
id: key,
|
|
162
|
+
displayName: `${orgName}:${group.role}`,
|
|
163
|
+
members: members.map((m) => ({ value: m.userId, display: m.email })),
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
return {
|
|
168
|
+
schemas: ["urn:ietf:params:scim:api:messages:2.0:ListResponse"],
|
|
169
|
+
totalResults: groups.length,
|
|
170
|
+
Resources: groups.map(scimGroupResponse),
|
|
171
|
+
};
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
app.get("/scim/v2/Groups/:groupId", async (request: FastifyRequest, reply: FastifyReply) => {
|
|
175
|
+
const { groupId } = request.params as { groupId: string };
|
|
176
|
+
const [orgId, role] = groupId.split(":");
|
|
177
|
+
|
|
178
|
+
if (!orgId || !role) {
|
|
179
|
+
return reply.status(400).send(scimError(400, "Invalid group ID format. Expected orgId:role"));
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
const org = await app.container.organizationRepository.findById(orgId);
|
|
183
|
+
if (!org) {
|
|
184
|
+
return reply.status(404).send(scimError(404, "Organization not found"));
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
const members = await db
|
|
188
|
+
.select({ userId: orgMemberships.userId, email: users.email })
|
|
189
|
+
.from(orgMemberships)
|
|
190
|
+
.where(and(eq(orgMemberships.orgId, orgId), eq(orgMemberships.role, role)))
|
|
191
|
+
.innerJoin(users, eq(orgMemberships.userId, users.id));
|
|
192
|
+
|
|
193
|
+
return scimGroupResponse({
|
|
194
|
+
id: groupId,
|
|
195
|
+
displayName: `${org.name}:${role}`,
|
|
196
|
+
members: members.map((m) => ({ value: m.userId, display: m.email })),
|
|
197
|
+
});
|
|
198
|
+
});
|
|
199
|
+
}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import fs from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import crypto from "node:crypto";
|
|
4
|
+
import { gzip } from "node:zlib";
|
|
5
|
+
import { promisify } from "node:util";
|
|
6
|
+
import { fileURLToPath } from "node:url";
|
|
7
|
+
import type { FastifyInstance, FastifyRequest, FastifyReply } from "fastify";
|
|
8
|
+
import { z } from "zod";
|
|
9
|
+
import { createApplication, findApplicationByClientId } from "../services/applications.js";
|
|
10
|
+
import { createOrganization, findOrganizationBySlug, findOrganizationById } from "../services/organizations.js";
|
|
11
|
+
|
|
12
|
+
const gzipAsync = promisify(gzip);
|
|
13
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
14
|
+
const SDK_FILE = path.resolve(__dirname, "../../packages/keystone-sdk/dist/keystone-dropin.js");
|
|
15
|
+
|
|
16
|
+
const ConnectSchema = z.object({
|
|
17
|
+
projectId: z.string().min(1).max(128).regex(/^[a-zA-Z0-9_-]+$/),
|
|
18
|
+
redirectUri: z.string().url().optional(),
|
|
19
|
+
clientId: z.string().optional(),
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
export default async function sdkRoutes(app: FastifyInstance) {
|
|
23
|
+
// Serve the drop-in SDK so external projects can load it with one script tag.
|
|
24
|
+
app.get("/keystone-dropin.js", async (request: FastifyRequest, reply: FastifyReply) => {
|
|
25
|
+
try {
|
|
26
|
+
const content = await fs.readFile(SDK_FILE, "utf-8");
|
|
27
|
+
const hash = crypto.createHash("sha256").update(content).digest("base64");
|
|
28
|
+
const etag = `"${hash}"`;
|
|
29
|
+
const ifNoneMatch = request.headers["if-none-match"];
|
|
30
|
+
if (ifNoneMatch === etag) {
|
|
31
|
+
return reply.status(304).send();
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const acceptEncoding = request.headers["accept-encoding"] || "";
|
|
35
|
+
const useGzip = acceptEncoding.includes("gzip");
|
|
36
|
+
const body = useGzip ? await gzipAsync(content) : content;
|
|
37
|
+
|
|
38
|
+
reply
|
|
39
|
+
.header("Content-Type", "application/javascript; charset=utf-8")
|
|
40
|
+
.header("Cache-Control", "public, max-age=86400, immutable")
|
|
41
|
+
.header("ETag", etag);
|
|
42
|
+
if (useGzip) reply.header("Content-Encoding", "gzip");
|
|
43
|
+
return reply.send(body);
|
|
44
|
+
} catch (err) {
|
|
45
|
+
app.log.error({ err }, "SDK file not found");
|
|
46
|
+
return reply.status(404).send({ error: "SDK not built. Run npm run build:sdk first." });
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
// SRI hash for the drop-in SDK so consumers can use integrity="sha256-…".
|
|
51
|
+
app.get("/keystone-dropin.js.sri", async (request: FastifyRequest, reply: FastifyReply) => {
|
|
52
|
+
try {
|
|
53
|
+
const content = await fs.readFile(SDK_FILE, "utf-8");
|
|
54
|
+
const hash = crypto.createHash("sha256").update(content).digest("base64");
|
|
55
|
+
reply.header("Cache-Control", "public, max-age=86400, immutable");
|
|
56
|
+
return { integrity: `sha256-${hash}` };
|
|
57
|
+
} catch (err) {
|
|
58
|
+
app.log.error({ err }, "SDK file not found");
|
|
59
|
+
return reply.status(404).send({ error: "SDK not built. Run npm run build:sdk first." });
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
// Public branding lookup for hosted login pages and the drop-in SDK.
|
|
64
|
+
// Returns only display-safe fields — never secrets.
|
|
65
|
+
app.get("/branding/:clientId", async (request: FastifyRequest, reply: FastifyReply) => {
|
|
66
|
+
const { clientId } = request.params as { clientId: string };
|
|
67
|
+
const application = await findApplicationByClientId(clientId);
|
|
68
|
+
if (!application) {
|
|
69
|
+
return reply.status(404).send({ error: "Application not found" });
|
|
70
|
+
}
|
|
71
|
+
const org = await findOrganizationById(application.orgId);
|
|
72
|
+
|
|
73
|
+
type Branding = Record<string, unknown>;
|
|
74
|
+
const orgBranding = (org?.branding ?? {}) as Branding;
|
|
75
|
+
const appBranding = (application.branding ?? {}) as Branding;
|
|
76
|
+
// App-level branding wins over org-level defaults.
|
|
77
|
+
const merged: Branding = { ...orgBranding, ...appBranding };
|
|
78
|
+
const pick = (key: string) => (typeof merged[key] === "string" ? merged[key] : undefined);
|
|
79
|
+
|
|
80
|
+
reply.header("Cache-Control", "public, max-age=300");
|
|
81
|
+
return {
|
|
82
|
+
name: pick("companyName") ?? application.name,
|
|
83
|
+
logoUrl: pick("logoUrl"),
|
|
84
|
+
primaryColor: pick("primaryColor"),
|
|
85
|
+
accentColor: pick("accentColor"),
|
|
86
|
+
supportEmail: pick("supportEmail"),
|
|
87
|
+
loginTitle: pick("loginTitle"),
|
|
88
|
+
loginSubtitle: pick("loginSubtitle"),
|
|
89
|
+
};
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
// Register or connect an external project/application.
|
|
93
|
+
app.post("/connect", async (request: FastifyRequest, reply: FastifyReply) => {
|
|
94
|
+
const parsed = ConnectSchema.safeParse(request.body);
|
|
95
|
+
if (!parsed.success) {
|
|
96
|
+
return reply.status(400).send({ error: "Invalid input", details: parsed.error.issues });
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const { projectId, redirectUri, clientId } = parsed.data;
|
|
100
|
+
|
|
101
|
+
try {
|
|
102
|
+
// If clientId is provided, verify the application exists.
|
|
103
|
+
if (clientId) {
|
|
104
|
+
const existing = await findApplicationByClientId(clientId);
|
|
105
|
+
if (!existing) {
|
|
106
|
+
return reply.status(404).send({ error: "Application not found" });
|
|
107
|
+
}
|
|
108
|
+
return reply.send({
|
|
109
|
+
connected: true,
|
|
110
|
+
clientId: existing.clientId,
|
|
111
|
+
message: "Connected to existing application",
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// Otherwise create a new public client application for this project.
|
|
116
|
+
// In production this endpoint should be protected or require an admin API key.
|
|
117
|
+
let defaultOrg = await findOrganizationBySlug("external-projects");
|
|
118
|
+
if (!defaultOrg) {
|
|
119
|
+
defaultOrg = await createOrganization({ name: "External Projects", slug: "external-projects" });
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
const app = await createApplication({
|
|
123
|
+
orgId: defaultOrg.id,
|
|
124
|
+
name: projectId,
|
|
125
|
+
clientId: projectId,
|
|
126
|
+
redirectUris: redirectUri ? [redirectUri] : [],
|
|
127
|
+
allowedOrigins: [request.headers.origin || "*"].filter(Boolean),
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
return reply.status(201).send({
|
|
131
|
+
connected: true,
|
|
132
|
+
clientId: app.clientId,
|
|
133
|
+
clientSecret: app.clientSecret,
|
|
134
|
+
message: "Application connected to Keystone",
|
|
135
|
+
});
|
|
136
|
+
} catch (err) {
|
|
137
|
+
request.log.error({ err }, "SDK connect failed");
|
|
138
|
+
return reply.status(500).send({ error: "Connection failed" });
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
}
|