@robelest/convex-auth 0.0.4-preview.25 → 0.0.4-preview.28
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/README.md +43 -36
- package/dist/bin.js +5765 -4880
- package/dist/browser/index.d.ts +30 -0
- package/dist/browser/index.js +93 -0
- package/dist/browser/locks.js +11 -0
- package/dist/browser/navigation.js +14 -0
- package/dist/{factors → browser}/passkey.js +23 -32
- package/dist/browser/runtime.js +92 -0
- package/dist/client/core/types.d.ts +452 -5
- package/dist/client/core/types.js +17 -0
- package/dist/client/errors.js +19 -0
- package/dist/client/factors/device.js +94 -0
- package/dist/{factors → client/factors}/totp.js +12 -4
- package/dist/client/index.d.ts +47 -1
- package/dist/client/index.js +269 -232
- package/dist/client/runtime/mutex.js +24 -0
- package/dist/client/runtime/proxy.js +30 -0
- package/dist/client/runtime/storage.js +45 -0
- package/dist/client/services/adapters.js +7 -0
- package/dist/client/services/http.js +6 -0
- package/dist/client/services/resolve.js +13 -0
- package/dist/client/services/runtime.js +6 -0
- package/dist/component/_generated/component.d.ts +1355 -1399
- package/dist/component/convex.config.d.ts +2 -2
- package/dist/component/index.d.ts +4 -26
- package/dist/component/index.js +1 -1
- package/dist/component/model.d.ts +26 -112
- package/dist/component/model.js +76 -54
- package/dist/component/modules.js +38 -0
- package/dist/component/public/factors/devices.js +1 -1
- package/dist/component/public/factors/passkeys.js +1 -1
- package/dist/component/public/factors/totp.js +1 -1
- package/dist/component/public/groups/core.js +2 -2
- package/dist/component/public/groups/invites.js +1 -1
- package/dist/component/public/groups/members.js +1 -1
- package/dist/component/public/identity/accounts.js +1 -1
- package/dist/component/public/identity/codes.js +1 -1
- package/dist/component/public/identity/sessions.js +39 -2
- package/dist/component/public/identity/tokens.js +82 -4
- package/dist/component/public/identity/users.js +1 -1
- package/dist/component/public/identity/verifiers.js +10 -4
- package/dist/component/public/security/keys.js +1 -1
- package/dist/component/public/security/limits.js +1 -1
- package/dist/component/public/{enterprise → sso}/audit.js +26 -26
- package/dist/component/public/sso/core.js +263 -0
- package/dist/component/public/sso/domains.js +280 -0
- package/dist/component/public/{enterprise → sso}/scim.js +87 -87
- package/dist/component/public/sso/secrets.js +125 -0
- package/dist/component/public/{enterprise → sso}/webhooks.js +59 -59
- package/dist/component/public.js +9 -9
- package/dist/component/schema.d.ts +472 -393
- package/dist/component/schema.js +36 -35
- package/dist/core/index.d.ts +380 -0
- package/dist/core/index.js +83 -0
- package/dist/otel.d.ts +69 -0
- package/dist/otel.js +82 -0
- package/dist/providers/anonymous.d.ts +15 -34
- package/dist/providers/anonymous.js +27 -35
- package/dist/providers/apple.d.ts +59 -0
- package/dist/providers/apple.js +58 -0
- package/dist/providers/credentials.d.ts +18 -34
- package/dist/providers/credentials.js +16 -27
- package/dist/providers/custom.d.ts +94 -0
- package/dist/providers/custom.js +119 -0
- package/dist/providers/device.d.ts +15 -49
- package/dist/providers/device.js +17 -34
- package/dist/providers/email.d.ts +21 -38
- package/dist/providers/email.js +36 -55
- package/dist/providers/github.d.ts +54 -0
- package/dist/providers/github.js +75 -0
- package/dist/providers/google.d.ts +54 -0
- package/dist/providers/google.js +61 -0
- package/dist/providers/index.d.ts +16 -12
- package/dist/providers/index.js +15 -11
- package/dist/providers/microsoft.d.ts +57 -0
- package/dist/providers/microsoft.js +101 -0
- package/dist/providers/passkey.d.ts +19 -35
- package/dist/providers/passkey.js +20 -30
- package/dist/providers/password.d.ts +17 -18
- package/dist/providers/password.js +121 -143
- package/dist/providers/phone.d.ts +13 -28
- package/dist/providers/phone.js +21 -46
- package/dist/providers/sso.d.ts +16 -36
- package/dist/providers/sso.js +21 -22
- package/dist/providers/totp.d.ts +13 -29
- package/dist/providers/totp.js +17 -27
- package/dist/server/auth-context.d.ts +204 -0
- package/dist/server/auth-context.js +76 -0
- package/dist/server/auth.d.ts +99 -244
- package/dist/server/auth.js +56 -152
- package/dist/server/componentContext.d.ts +12 -0
- package/dist/server/componentContext.js +1 -0
- package/dist/server/config.js +6 -67
- package/dist/server/constants.js +6 -0
- package/dist/server/contract.d.ts +105 -0
- package/dist/server/contract.js +43 -0
- package/dist/server/cookies.js +3 -2
- package/dist/server/core.js +31 -36
- package/dist/server/crypto.js +34 -44
- package/dist/server/db.js +6 -1
- package/dist/server/device.js +96 -130
- package/dist/server/env.js +48 -0
- package/dist/server/errors.js +20 -0
- package/dist/server/http.d.ts +15 -59
- package/dist/server/http.js +136 -120
- package/dist/server/identity.js +2 -2
- package/dist/server/index.d.ts +5 -4
- package/dist/server/index.js +3 -3
- package/dist/server/keys.js +10 -1
- package/dist/server/limits.js +26 -26
- package/dist/server/log.js +28 -0
- package/dist/server/mounts.d.ts +1107 -296
- package/dist/server/mounts.js +315 -196
- package/dist/server/mutations/account.js +11 -14
- package/dist/server/mutations/code.js +6 -5
- package/dist/server/mutations/invalidate.js +9 -11
- package/dist/server/mutations/oauth.js +112 -73
- package/dist/server/mutations/refresh.js +47 -97
- package/dist/server/mutations/register.js +37 -35
- package/dist/server/mutations/retrieve.js +16 -16
- package/dist/server/mutations/signature.js +15 -18
- package/dist/server/mutations/signin.js +10 -5
- package/dist/server/mutations/signout.js +11 -14
- package/dist/server/mutations/store.js +25 -18
- package/dist/server/mutations/verifier.js +11 -8
- package/dist/server/mutations/verify.js +53 -41
- package/dist/server/oauth/factory.js +44 -0
- package/dist/server/oauth/index.js +12 -0
- package/dist/server/oauth/runtime.js +248 -0
- package/dist/server/passkey.js +331 -365
- package/dist/server/payloads.d.ts +16 -0
- package/dist/server/payloads.js +30 -0
- package/dist/server/{ssr.d.ts → prefetch.d.ts} +2 -2
- package/dist/server/prefetch.js +635 -0
- package/dist/server/random.js +19 -0
- package/dist/server/redirects.js +10 -5
- package/dist/server/refresh.js +14 -86
- package/dist/server/runtime.d.ts +531 -31
- package/dist/server/runtime.js +106 -267
- package/dist/server/secret.js +44 -0
- package/dist/server/services/config.js +10 -0
- package/dist/server/services/group.js +211 -0
- package/dist/server/services/logger.js +8 -0
- package/dist/server/services/providers.js +22 -0
- package/dist/server/services/refresh.js +8 -0
- package/dist/server/services/resolve.js +27 -0
- package/dist/server/services/signin.js +8 -0
- package/dist/server/sessions.js +35 -34
- package/dist/server/signin.js +229 -140
- package/dist/server/{enterprise → sso}/config.js +10 -3
- package/dist/server/sso/domain.d.ts +614 -0
- package/dist/server/sso/domain.js +1175 -0
- package/dist/server/sso/http.js +1060 -0
- package/dist/server/sso/oidc.js +324 -0
- package/dist/server/sso/policies.js +59 -0
- package/dist/server/sso/policy.js +139 -0
- package/dist/server/sso/profile.js +22 -0
- package/dist/server/sso/provision.js +179 -0
- package/dist/{component/server/enterprise → server/sso}/saml.js +142 -56
- package/dist/{component/server/enterprise → server/sso}/scim.js +13 -7
- package/dist/server/sso/shared.js +74 -0
- package/dist/server/sso/validators.js +88 -0
- package/dist/server/sso/webhook.js +94 -0
- package/dist/server/tokens.js +16 -4
- package/dist/server/totp.js +155 -164
- package/dist/server/types.d.ts +306 -296
- package/dist/server/types.js +1 -30
- package/dist/server/url.js +32 -0
- package/dist/server/users.js +74 -40
- package/dist/server/utils/cache.js +51 -0
- package/dist/server/utils/dispatch.js +36 -0
- package/dist/server/utils/retry.js +24 -0
- package/dist/server/utils/span.js +32 -0
- package/dist/shared/errors.js +19 -0
- package/dist/shared/log.js +45 -0
- package/{src/test.ts → dist/test.d.ts} +21 -22
- package/dist/test.js +51 -0
- package/package.json +70 -42
- package/dist/authorization/index.d.ts.map +0 -1
- package/dist/authorization/index.js.map +0 -1
- package/dist/client/core/types.d.ts.map +0 -1
- package/dist/client/index.d.ts.map +0 -1
- package/dist/client/index.js.map +0 -1
- package/dist/component/_generated/api.d.ts +0 -75
- package/dist/component/_generated/api.d.ts.map +0 -1
- package/dist/component/_generated/api.js.map +0 -1
- package/dist/component/_generated/component.d.ts.map +0 -1
- package/dist/component/_generated/dataModel.d.ts +0 -42
- package/dist/component/_generated/dataModel.d.ts.map +0 -1
- package/dist/component/_generated/server.d.ts +0 -117
- package/dist/component/_generated/server.d.ts.map +0 -1
- package/dist/component/_generated/server.js.map +0 -1
- package/dist/component/_virtual/rolldown_runtime.js +0 -18
- package/dist/component/client/core/types.d.ts +0 -2
- package/dist/component/client/index.d.ts +0 -1
- package/dist/component/convex.config.d.ts.map +0 -1
- package/dist/component/convex.config.js.map +0 -1
- package/dist/component/functions.d.ts +0 -25
- package/dist/component/functions.d.ts.map +0 -1
- package/dist/component/functions.js.map +0 -1
- package/dist/component/index.d.ts.map +0 -1
- package/dist/component/model.d.ts.map +0 -1
- package/dist/component/model.js.map +0 -1
- package/dist/component/providers/anonymous.d.ts +0 -54
- package/dist/component/providers/anonymous.d.ts.map +0 -1
- package/dist/component/providers/credentials.d.ts +0 -38
- package/dist/component/providers/credentials.d.ts.map +0 -1
- package/dist/component/providers/device.d.ts +0 -67
- package/dist/component/providers/device.d.ts.map +0 -1
- package/dist/component/providers/email.d.ts +0 -62
- package/dist/component/providers/email.d.ts.map +0 -1
- package/dist/component/providers/oauth.d.ts +0 -25
- package/dist/component/providers/oauth.d.ts.map +0 -1
- package/dist/component/providers/oauth.js +0 -13
- package/dist/component/providers/oauth.js.map +0 -1
- package/dist/component/providers/passkey.d.ts +0 -57
- package/dist/component/providers/passkey.d.ts.map +0 -1
- package/dist/component/providers/password.d.ts +0 -88
- package/dist/component/providers/password.d.ts.map +0 -1
- package/dist/component/providers/phone.d.ts +0 -48
- package/dist/component/providers/phone.d.ts.map +0 -1
- package/dist/component/providers/sso.d.ts +0 -50
- package/dist/component/providers/sso.d.ts.map +0 -1
- package/dist/component/providers/totp.d.ts +0 -45
- package/dist/component/providers/totp.d.ts.map +0 -1
- package/dist/component/public/enterprise/audit.d.ts +0 -73
- package/dist/component/public/enterprise/audit.d.ts.map +0 -1
- package/dist/component/public/enterprise/audit.js.map +0 -1
- package/dist/component/public/enterprise/core.d.ts +0 -176
- package/dist/component/public/enterprise/core.d.ts.map +0 -1
- package/dist/component/public/enterprise/core.js +0 -292
- package/dist/component/public/enterprise/core.js.map +0 -1
- package/dist/component/public/enterprise/domains.d.ts +0 -174
- package/dist/component/public/enterprise/domains.d.ts.map +0 -1
- package/dist/component/public/enterprise/domains.js +0 -271
- package/dist/component/public/enterprise/domains.js.map +0 -1
- package/dist/component/public/enterprise/scim.d.ts +0 -245
- package/dist/component/public/enterprise/scim.d.ts.map +0 -1
- package/dist/component/public/enterprise/scim.js.map +0 -1
- package/dist/component/public/enterprise/secrets.d.ts +0 -78
- package/dist/component/public/enterprise/secrets.d.ts.map +0 -1
- package/dist/component/public/enterprise/secrets.js +0 -118
- package/dist/component/public/enterprise/secrets.js.map +0 -1
- package/dist/component/public/enterprise/webhooks.d.ts +0 -211
- package/dist/component/public/enterprise/webhooks.d.ts.map +0 -1
- package/dist/component/public/enterprise/webhooks.js.map +0 -1
- package/dist/component/public/factors/devices.d.ts +0 -157
- package/dist/component/public/factors/devices.d.ts.map +0 -1
- package/dist/component/public/factors/devices.js.map +0 -1
- package/dist/component/public/factors/passkeys.d.ts +0 -175
- package/dist/component/public/factors/passkeys.d.ts.map +0 -1
- package/dist/component/public/factors/passkeys.js.map +0 -1
- package/dist/component/public/factors/totp.d.ts +0 -189
- package/dist/component/public/factors/totp.d.ts.map +0 -1
- package/dist/component/public/factors/totp.js.map +0 -1
- package/dist/component/public/groups/core.d.ts +0 -137
- package/dist/component/public/groups/core.d.ts.map +0 -1
- package/dist/component/public/groups/core.js.map +0 -1
- package/dist/component/public/groups/invites.d.ts +0 -217
- package/dist/component/public/groups/invites.d.ts.map +0 -1
- package/dist/component/public/groups/invites.js.map +0 -1
- package/dist/component/public/groups/members.d.ts +0 -204
- package/dist/component/public/groups/members.d.ts.map +0 -1
- package/dist/component/public/groups/members.js.map +0 -1
- package/dist/component/public/identity/accounts.d.ts +0 -147
- package/dist/component/public/identity/accounts.d.ts.map +0 -1
- package/dist/component/public/identity/accounts.js.map +0 -1
- package/dist/component/public/identity/codes.d.ts +0 -104
- package/dist/component/public/identity/codes.d.ts.map +0 -1
- package/dist/component/public/identity/codes.js.map +0 -1
- package/dist/component/public/identity/sessions.d.ts +0 -128
- package/dist/component/public/identity/sessions.d.ts.map +0 -1
- package/dist/component/public/identity/sessions.js.map +0 -1
- package/dist/component/public/identity/tokens.d.ts +0 -169
- package/dist/component/public/identity/tokens.d.ts.map +0 -1
- package/dist/component/public/identity/tokens.js.map +0 -1
- package/dist/component/public/identity/users.d.ts +0 -212
- package/dist/component/public/identity/users.d.ts.map +0 -1
- package/dist/component/public/identity/users.js.map +0 -1
- package/dist/component/public/identity/verifiers.d.ts +0 -116
- package/dist/component/public/identity/verifiers.d.ts.map +0 -1
- package/dist/component/public/identity/verifiers.js.map +0 -1
- package/dist/component/public/security/keys.d.ts +0 -209
- package/dist/component/public/security/keys.d.ts.map +0 -1
- package/dist/component/public/security/keys.js.map +0 -1
- package/dist/component/public/security/limits.d.ts +0 -114
- package/dist/component/public/security/limits.d.ts.map +0 -1
- package/dist/component/public/security/limits.js.map +0 -1
- package/dist/component/public.d.ts +0 -28
- package/dist/component/public.d.ts.map +0 -1
- package/dist/component/schema.d.ts.map +0 -1
- package/dist/component/schema.js.map +0 -1
- package/dist/component/server/auth.d.ts +0 -447
- package/dist/component/server/auth.d.ts.map +0 -1
- package/dist/component/server/auth.js +0 -254
- package/dist/component/server/auth.js.map +0 -1
- package/dist/component/server/config.js +0 -121
- package/dist/component/server/config.js.map +0 -1
- package/dist/component/server/context.js +0 -53
- package/dist/component/server/context.js.map +0 -1
- package/dist/component/server/cookies.js +0 -47
- package/dist/component/server/cookies.js.map +0 -1
- package/dist/component/server/core.js +0 -576
- package/dist/component/server/core.js.map +0 -1
- package/dist/component/server/crypto.js +0 -56
- package/dist/component/server/crypto.js.map +0 -1
- package/dist/component/server/db.js +0 -87
- package/dist/component/server/db.js.map +0 -1
- package/dist/component/server/device.js +0 -152
- package/dist/component/server/device.js.map +0 -1
- package/dist/component/server/enterprise/config.js +0 -46
- package/dist/component/server/enterprise/config.js.map +0 -1
- package/dist/component/server/enterprise/domain.js +0 -974
- package/dist/component/server/enterprise/domain.js.map +0 -1
- package/dist/component/server/enterprise/http.js +0 -787
- package/dist/component/server/enterprise/http.js.map +0 -1
- package/dist/component/server/enterprise/oidc.js +0 -248
- package/dist/component/server/enterprise/oidc.js.map +0 -1
- package/dist/component/server/enterprise/policy.js +0 -85
- package/dist/component/server/enterprise/policy.js.map +0 -1
- package/dist/component/server/enterprise/saml.js.map +0 -1
- package/dist/component/server/enterprise/scim.js.map +0 -1
- package/dist/component/server/enterprise/shared.js +0 -51
- package/dist/component/server/enterprise/shared.js.map +0 -1
- package/dist/component/server/http.d.ts +0 -85
- package/dist/component/server/http.d.ts.map +0 -1
- package/dist/component/server/http.js +0 -351
- package/dist/component/server/http.js.map +0 -1
- package/dist/component/server/identity.js +0 -16
- package/dist/component/server/identity.js.map +0 -1
- package/dist/component/server/keys.js +0 -96
- package/dist/component/server/keys.js.map +0 -1
- package/dist/component/server/limits.js +0 -52
- package/dist/component/server/limits.js.map +0 -1
- package/dist/component/server/mutations/account.js +0 -46
- package/dist/component/server/mutations/account.js.map +0 -1
- package/dist/component/server/mutations/code.js +0 -68
- package/dist/component/server/mutations/code.js.map +0 -1
- package/dist/component/server/mutations/invalidate.js +0 -32
- package/dist/component/server/mutations/invalidate.js.map +0 -1
- package/dist/component/server/mutations/oauth.js +0 -116
- package/dist/component/server/mutations/oauth.js.map +0 -1
- package/dist/component/server/mutations/refresh.js +0 -119
- package/dist/component/server/mutations/refresh.js.map +0 -1
- package/dist/component/server/mutations/register.js +0 -87
- package/dist/component/server/mutations/register.js.map +0 -1
- package/dist/component/server/mutations/retrieve.js +0 -61
- package/dist/component/server/mutations/retrieve.js.map +0 -1
- package/dist/component/server/mutations/signature.js +0 -38
- package/dist/component/server/mutations/signature.js.map +0 -1
- package/dist/component/server/mutations/signin.js +0 -27
- package/dist/component/server/mutations/signin.js.map +0 -1
- package/dist/component/server/mutations/signout.js +0 -27
- package/dist/component/server/mutations/signout.js.map +0 -1
- package/dist/component/server/mutations/store/refs.js +0 -15
- package/dist/component/server/mutations/store/refs.js.map +0 -1
- package/dist/component/server/mutations/store.js +0 -70
- package/dist/component/server/mutations/store.js.map +0 -1
- package/dist/component/server/mutations/verifier.js +0 -18
- package/dist/component/server/mutations/verifier.js.map +0 -1
- package/dist/component/server/mutations/verify.js +0 -98
- package/dist/component/server/mutations/verify.js.map +0 -1
- package/dist/component/server/oauth.js +0 -242
- package/dist/component/server/oauth.js.map +0 -1
- package/dist/component/server/passkey.js +0 -415
- package/dist/component/server/passkey.js.map +0 -1
- package/dist/component/server/redirects.js +0 -40
- package/dist/component/server/redirects.js.map +0 -1
- package/dist/component/server/refresh.js +0 -99
- package/dist/component/server/refresh.js.map +0 -1
- package/dist/component/server/runtime.d.ts +0 -136
- package/dist/component/server/runtime.d.ts.map +0 -1
- package/dist/component/server/runtime.js +0 -456
- package/dist/component/server/runtime.js.map +0 -1
- package/dist/component/server/sessions.js +0 -71
- package/dist/component/server/sessions.js.map +0 -1
- package/dist/component/server/signin.js +0 -225
- package/dist/component/server/signin.js.map +0 -1
- package/dist/component/server/tokens.js +0 -17
- package/dist/component/server/tokens.js.map +0 -1
- package/dist/component/server/totp.js +0 -208
- package/dist/component/server/totp.js.map +0 -1
- package/dist/component/server/types.d.ts +0 -949
- package/dist/component/server/types.d.ts.map +0 -1
- package/dist/component/server/types.js +0 -79
- package/dist/component/server/types.js.map +0 -1
- package/dist/component/server/users.js +0 -123
- package/dist/component/server/users.js.map +0 -1
- package/dist/component/server/utils.js +0 -140
- package/dist/component/server/utils.js.map +0 -1
- package/dist/core/types.d.ts +0 -361
- package/dist/core/types.d.ts.map +0 -1
- package/dist/factors/device.js +0 -104
- package/dist/factors/device.js.map +0 -1
- package/dist/factors/passkey.js.map +0 -1
- package/dist/factors/totp.js.map +0 -1
- package/dist/providers/anonymous.d.ts.map +0 -1
- package/dist/providers/anonymous.js.map +0 -1
- package/dist/providers/credentials.d.ts.map +0 -1
- package/dist/providers/credentials.js.map +0 -1
- package/dist/providers/device.d.ts.map +0 -1
- package/dist/providers/device.js.map +0 -1
- package/dist/providers/email.d.ts.map +0 -1
- package/dist/providers/email.js.map +0 -1
- package/dist/providers/oauth.d.ts +0 -69
- package/dist/providers/oauth.d.ts.map +0 -1
- package/dist/providers/oauth.js +0 -43
- package/dist/providers/oauth.js.map +0 -1
- package/dist/providers/passkey.d.ts.map +0 -1
- package/dist/providers/passkey.js.map +0 -1
- package/dist/providers/password.d.ts.map +0 -1
- package/dist/providers/password.js.map +0 -1
- package/dist/providers/phone.d.ts.map +0 -1
- package/dist/providers/phone.js.map +0 -1
- package/dist/providers/sso.d.ts.map +0 -1
- package/dist/providers/sso.js.map +0 -1
- package/dist/providers/totp.d.ts.map +0 -1
- package/dist/providers/totp.js.map +0 -1
- package/dist/runtime/browser.js +0 -68
- package/dist/runtime/browser.js.map +0 -1
- package/dist/runtime/invite.js.map +0 -1
- package/dist/runtime/proxy.js +0 -70
- package/dist/runtime/proxy.js.map +0 -1
- package/dist/runtime/storage.js +0 -37
- package/dist/runtime/storage.js.map +0 -1
- package/dist/server/auth.d.ts.map +0 -1
- package/dist/server/auth.js.map +0 -1
- package/dist/server/config.d.ts +0 -1
- package/dist/server/config.js.map +0 -1
- package/dist/server/context.d.ts +0 -1
- package/dist/server/context.js.map +0 -1
- package/dist/server/cookies.d.ts +0 -1
- package/dist/server/cookies.js.map +0 -1
- package/dist/server/core.d.ts +0 -1315
- package/dist/server/core.d.ts.map +0 -1
- package/dist/server/core.js.map +0 -1
- package/dist/server/crypto.d.ts +0 -8
- package/dist/server/crypto.d.ts.map +0 -1
- package/dist/server/crypto.js.map +0 -1
- package/dist/server/db.d.ts +0 -1
- package/dist/server/db.js.map +0 -1
- package/dist/server/device.d.ts +0 -1
- package/dist/server/device.js.map +0 -1
- package/dist/server/enterprise/config.d.ts +0 -1
- package/dist/server/enterprise/config.js.map +0 -1
- package/dist/server/enterprise/domain.d.ts +0 -401
- package/dist/server/enterprise/domain.d.ts.map +0 -1
- package/dist/server/enterprise/domain.js +0 -974
- package/dist/server/enterprise/domain.js.map +0 -1
- package/dist/server/enterprise/http.d.ts +0 -26
- package/dist/server/enterprise/http.d.ts.map +0 -1
- package/dist/server/enterprise/http.js +0 -787
- package/dist/server/enterprise/http.js.map +0 -1
- package/dist/server/enterprise/oidc.d.ts +0 -1
- package/dist/server/enterprise/oidc.js +0 -248
- package/dist/server/enterprise/oidc.js.map +0 -1
- package/dist/server/enterprise/policy.d.ts +0 -1
- package/dist/server/enterprise/policy.js +0 -85
- package/dist/server/enterprise/policy.js.map +0 -1
- package/dist/server/enterprise/saml.d.ts +0 -1
- package/dist/server/enterprise/saml.js +0 -338
- package/dist/server/enterprise/saml.js.map +0 -1
- package/dist/server/enterprise/scim.d.ts +0 -1
- package/dist/server/enterprise/scim.js +0 -97
- package/dist/server/enterprise/scim.js.map +0 -1
- package/dist/server/enterprise/shared.d.ts +0 -5
- package/dist/server/enterprise/shared.d.ts.map +0 -1
- package/dist/server/enterprise/shared.js +0 -51
- package/dist/server/enterprise/shared.js.map +0 -1
- package/dist/server/enterprise/validators.d.ts +0 -1
- package/dist/server/enterprise/validators.js +0 -60
- package/dist/server/enterprise/validators.js.map +0 -1
- package/dist/server/http.d.ts.map +0 -1
- package/dist/server/http.js.map +0 -1
- package/dist/server/identity.d.ts +0 -1
- package/dist/server/identity.js.map +0 -1
- package/dist/server/keys.d.ts +0 -1
- package/dist/server/keys.js.map +0 -1
- package/dist/server/limits.d.ts +0 -1
- package/dist/server/limits.js.map +0 -1
- package/dist/server/mounts.d.ts.map +0 -1
- package/dist/server/mounts.js.map +0 -1
- package/dist/server/mutations/account.d.ts +0 -29
- package/dist/server/mutations/account.d.ts.map +0 -1
- package/dist/server/mutations/account.js.map +0 -1
- package/dist/server/mutations/code.d.ts +0 -30
- package/dist/server/mutations/code.d.ts.map +0 -1
- package/dist/server/mutations/code.js.map +0 -1
- package/dist/server/mutations/index.d.ts +0 -14
- package/dist/server/mutations/invalidate.d.ts +0 -20
- package/dist/server/mutations/invalidate.d.ts.map +0 -1
- package/dist/server/mutations/invalidate.js.map +0 -1
- package/dist/server/mutations/oauth.d.ts +0 -30
- package/dist/server/mutations/oauth.d.ts.map +0 -1
- package/dist/server/mutations/oauth.js.map +0 -1
- package/dist/server/mutations/refresh.d.ts +0 -21
- package/dist/server/mutations/refresh.d.ts.map +0 -1
- package/dist/server/mutations/refresh.js.map +0 -1
- package/dist/server/mutations/register.d.ts +0 -38
- package/dist/server/mutations/register.d.ts.map +0 -1
- package/dist/server/mutations/register.js.map +0 -1
- package/dist/server/mutations/retrieve.d.ts +0 -33
- package/dist/server/mutations/retrieve.d.ts.map +0 -1
- package/dist/server/mutations/retrieve.js.map +0 -1
- package/dist/server/mutations/signature.d.ts +0 -21
- package/dist/server/mutations/signature.d.ts.map +0 -1
- package/dist/server/mutations/signature.js.map +0 -1
- package/dist/server/mutations/signin.d.ts +0 -22
- package/dist/server/mutations/signin.d.ts.map +0 -1
- package/dist/server/mutations/signin.js.map +0 -1
- package/dist/server/mutations/signout.d.ts +0 -16
- package/dist/server/mutations/signout.d.ts.map +0 -1
- package/dist/server/mutations/signout.js.map +0 -1
- package/dist/server/mutations/store/refs.d.ts +0 -12
- package/dist/server/mutations/store/refs.d.ts.map +0 -1
- package/dist/server/mutations/store/refs.js.map +0 -1
- package/dist/server/mutations/store.d.ts +0 -306
- package/dist/server/mutations/store.d.ts.map +0 -1
- package/dist/server/mutations/store.js.map +0 -1
- package/dist/server/mutations/verifier.d.ts +0 -13
- package/dist/server/mutations/verifier.d.ts.map +0 -1
- package/dist/server/mutations/verifier.js.map +0 -1
- package/dist/server/mutations/verify.d.ts +0 -26
- package/dist/server/mutations/verify.d.ts.map +0 -1
- package/dist/server/mutations/verify.js.map +0 -1
- package/dist/server/oauth.d.ts +0 -1
- package/dist/server/oauth.js +0 -242
- package/dist/server/oauth.js.map +0 -1
- package/dist/server/passkey.d.ts +0 -27
- package/dist/server/passkey.d.ts.map +0 -1
- package/dist/server/passkey.js.map +0 -1
- package/dist/server/redirects.d.ts +0 -1
- package/dist/server/redirects.js.map +0 -1
- package/dist/server/refresh.d.ts +0 -1
- package/dist/server/refresh.js.map +0 -1
- package/dist/server/runtime.d.ts.map +0 -1
- package/dist/server/runtime.js.map +0 -1
- package/dist/server/sessions.d.ts +0 -1
- package/dist/server/sessions.js.map +0 -1
- package/dist/server/signin.d.ts +0 -1
- package/dist/server/signin.js.map +0 -1
- package/dist/server/ssr.d.ts.map +0 -1
- package/dist/server/ssr.js +0 -777
- package/dist/server/ssr.js.map +0 -1
- package/dist/server/templates.d.ts +0 -1
- package/dist/server/templates.js.map +0 -1
- package/dist/server/tokens.d.ts +0 -1
- package/dist/server/tokens.js.map +0 -1
- package/dist/server/totp.d.ts +0 -1
- package/dist/server/totp.js.map +0 -1
- package/dist/server/types.d.ts.map +0 -1
- package/dist/server/types.js.map +0 -1
- package/dist/server/users.d.ts +0 -1
- package/dist/server/users.js.map +0 -1
- package/dist/server/utils.d.ts +0 -1
- package/dist/server/utils.js +0 -140
- package/dist/server/utils.js.map +0 -1
- package/src/authorization/index.ts +0 -83
- package/src/cli/bin.ts +0 -5
- package/src/cli/command.ts +0 -70
- package/src/cli/index.ts +0 -1112
- package/src/cli/keys.ts +0 -23
- package/src/client/core/types.ts +0 -437
- package/src/client/factors/device.ts +0 -158
- package/src/client/factors/passkey.ts +0 -279
- package/src/client/factors/totp.ts +0 -150
- package/src/client/index.ts +0 -1124
- package/src/client/runtime/browser.ts +0 -112
- package/src/client/runtime/invite.ts +0 -63
- package/src/client/runtime/proxy.ts +0 -111
- package/src/client/runtime/storage.ts +0 -79
- package/src/component/_generated/api.ts +0 -96
- package/src/component/_generated/component.ts +0 -3774
- package/src/component/_generated/dataModel.ts +0 -60
- package/src/component/_generated/server.ts +0 -156
- package/src/component/convex.config.ts +0 -5
- package/src/component/functions.ts +0 -104
- package/src/component/index.ts +0 -42
- package/src/component/model.ts +0 -449
- package/src/component/public/enterprise/audit.ts +0 -125
- package/src/component/public/enterprise/core.ts +0 -355
- package/src/component/public/enterprise/domains.ts +0 -327
- package/src/component/public/enterprise/scim.ts +0 -397
- package/src/component/public/enterprise/secrets.ts +0 -133
- package/src/component/public/enterprise/webhooks.ts +0 -307
- package/src/component/public/factors/devices.ts +0 -224
- package/src/component/public/factors/passkeys.ts +0 -243
- package/src/component/public/factors/totp.ts +0 -259
- package/src/component/public/groups/core.ts +0 -481
- package/src/component/public/groups/invites.ts +0 -608
- package/src/component/public/groups/members.ts +0 -410
- package/src/component/public/identity/accounts.ts +0 -207
- package/src/component/public/identity/codes.ts +0 -149
- package/src/component/public/identity/sessions.ts +0 -210
- package/src/component/public/identity/tokens.ts +0 -251
- package/src/component/public/identity/users.ts +0 -355
- package/src/component/public/identity/verifiers.ts +0 -158
- package/src/component/public/security/keys.ts +0 -366
- package/src/component/public/security/limits.ts +0 -174
- package/src/component/public.ts +0 -27
- package/src/component/schema.ts +0 -505
- package/src/providers/anonymous.ts +0 -99
- package/src/providers/credentials.ts +0 -102
- package/src/providers/device.ts +0 -87
- package/src/providers/email.ts +0 -99
- package/src/providers/index.ts +0 -31
- package/src/providers/oauth.ts +0 -117
- package/src/providers/passkey.ts +0 -77
- package/src/providers/password.ts +0 -441
- package/src/providers/phone.ts +0 -93
- package/src/providers/sso.ts +0 -54
- package/src/providers/totp.ts +0 -62
- package/src/samlify.d.ts +0 -53
- package/src/server/auth.ts +0 -949
- package/src/server/config.ts +0 -200
- package/src/server/context.ts +0 -90
- package/src/server/cookies.ts +0 -49
- package/src/server/core.ts +0 -2004
- package/src/server/crypto.ts +0 -90
- package/src/server/db.ts +0 -203
- package/src/server/device.ts +0 -254
- package/src/server/enterprise/config.ts +0 -51
- package/src/server/enterprise/domain.ts +0 -1739
- package/src/server/enterprise/http.ts +0 -1331
- package/src/server/enterprise/oidc.ts +0 -500
- package/src/server/enterprise/policy.ts +0 -128
- package/src/server/enterprise/saml.ts +0 -578
- package/src/server/enterprise/scim.ts +0 -135
- package/src/server/enterprise/shared.ts +0 -134
- package/src/server/enterprise/validators.ts +0 -93
- package/src/server/http.ts +0 -790
- package/src/server/identity.ts +0 -18
- package/src/server/index.ts +0 -40
- package/src/server/keys.ts +0 -158
- package/src/server/limits.ts +0 -107
- package/src/server/mounts.ts +0 -924
- package/src/server/mutations/account.ts +0 -62
- package/src/server/mutations/code.ts +0 -119
- package/src/server/mutations/index.ts +0 -13
- package/src/server/mutations/invalidate.ts +0 -50
- package/src/server/mutations/oauth.ts +0 -243
- package/src/server/mutations/refresh.ts +0 -299
- package/src/server/mutations/register.ts +0 -155
- package/src/server/mutations/retrieve.ts +0 -109
- package/src/server/mutations/signature.ts +0 -57
- package/src/server/mutations/signin.ts +0 -54
- package/src/server/mutations/signout.ts +0 -43
- package/src/server/mutations/store/refs.ts +0 -10
- package/src/server/mutations/store.ts +0 -123
- package/src/server/mutations/verifier.ts +0 -34
- package/src/server/mutations/verify.ts +0 -200
- package/src/server/oauth.ts +0 -418
- package/src/server/passkey.ts +0 -838
- package/src/server/redirects.ts +0 -59
- package/src/server/refresh.ts +0 -218
- package/src/server/runtime.ts +0 -918
- package/src/server/sessions.ts +0 -132
- package/src/server/signin.ts +0 -445
- package/src/server/ssr.ts +0 -1747
- package/src/server/templates.ts +0 -82
- package/src/server/tokens.ts +0 -35
- package/src/server/totp.ts +0 -399
- package/src/server/types.ts +0 -1942
- package/src/server/users.ts +0 -291
- package/src/server/utils.ts +0 -220
- /package/dist/{runtime → client/runtime}/invite.js +0 -0
|
@@ -1,1739 +0,0 @@
|
|
|
1
|
-
import { Fx } from "@robelest/fx";
|
|
2
|
-
import { Cv } from "@robelest/fx/convex";
|
|
3
|
-
import { GenericActionCtx, GenericDataModel } from "convex/server";
|
|
4
|
-
|
|
5
|
-
import type { EnterprisePolicyPatch } from "../types";
|
|
6
|
-
|
|
7
|
-
type ComponentCtx = Pick<
|
|
8
|
-
GenericActionCtx<GenericDataModel>,
|
|
9
|
-
"runQuery" | "runMutation"
|
|
10
|
-
>;
|
|
11
|
-
type ComponentReadCtx = Pick<GenericActionCtx<GenericDataModel>, "runQuery">;
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Build the enterprise and SSO management domain.
|
|
15
|
-
*/
|
|
16
|
-
export function createEnterpriseDomain(deps: any) {
|
|
17
|
-
const {
|
|
18
|
-
config,
|
|
19
|
-
normalizeEnterprisePolicy,
|
|
20
|
-
normalizeDomain,
|
|
21
|
-
getEnterpriseSecret,
|
|
22
|
-
loadEnterpriseOrThrow,
|
|
23
|
-
validateEnterprisePolicy,
|
|
24
|
-
recordEnterpriseAuditEvent,
|
|
25
|
-
emitEnterpriseWebhookDeliveries,
|
|
26
|
-
enterpriseNotFoundError,
|
|
27
|
-
ENTERPRISE_OIDC_CLIENT_SECRET_KIND,
|
|
28
|
-
requireEnv,
|
|
29
|
-
generateRandomString,
|
|
30
|
-
INVITE_TOKEN_ALPHABET,
|
|
31
|
-
sha256,
|
|
32
|
-
encryptSecret,
|
|
33
|
-
upsertProtocolConfig,
|
|
34
|
-
parseSamlIdpMetadata,
|
|
35
|
-
createServiceProviderMetadata,
|
|
36
|
-
getSamlServiceProviderOptions,
|
|
37
|
-
getPublicOidcConfig,
|
|
38
|
-
withOidcSecretState,
|
|
39
|
-
getOidcConfig,
|
|
40
|
-
getEnterpriseOidcUrls,
|
|
41
|
-
enterpriseOidcProviderId,
|
|
42
|
-
getPolicyFromEnterprise,
|
|
43
|
-
patchEnterprisePolicy,
|
|
44
|
-
} = deps;
|
|
45
|
-
|
|
46
|
-
const ENTERPRISE_DOMAIN_VERIFICATION_PREFIX = "_convex-auth-verification";
|
|
47
|
-
const ENTERPRISE_DOMAIN_VERIFICATION_TTL_MS = 1000 * 60 * 60 * 24 * 7;
|
|
48
|
-
|
|
49
|
-
const toDomainSummary = (domain: {
|
|
50
|
-
_id: string;
|
|
51
|
-
domain: string;
|
|
52
|
-
isPrimary: boolean;
|
|
53
|
-
verifiedAt?: number;
|
|
54
|
-
}) => ({
|
|
55
|
-
domainId: domain._id,
|
|
56
|
-
domain: domain.domain,
|
|
57
|
-
isPrimary: domain.isPrimary,
|
|
58
|
-
verified: domain.verifiedAt !== undefined,
|
|
59
|
-
verifiedAt: domain.verifiedAt ?? null,
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
const getDomainVerificationRecordName = (domain: string) =>
|
|
63
|
-
`${ENTERPRISE_DOMAIN_VERIFICATION_PREFIX}.${normalizeDomain(domain)}`;
|
|
64
|
-
|
|
65
|
-
const parseTxtAnswer = (value: string) => {
|
|
66
|
-
const quoted = [...value.matchAll(/"([^"]*)"/g)].map((match) => match[1]);
|
|
67
|
-
if (quoted.length > 0) {
|
|
68
|
-
return quoted.join("");
|
|
69
|
-
}
|
|
70
|
-
return value.replace(/^"|"$/g, "").trim();
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
const resolveTxtValues = async (recordName: string) => {
|
|
74
|
-
const url = new URL("https://dns.google/resolve");
|
|
75
|
-
url.searchParams.set("name", recordName);
|
|
76
|
-
url.searchParams.set("type", "TXT");
|
|
77
|
-
|
|
78
|
-
const response = await fetch(url, {
|
|
79
|
-
headers: { accept: "application/json" },
|
|
80
|
-
});
|
|
81
|
-
if (!response.ok) {
|
|
82
|
-
throw new Error(`DNS TXT lookup failed with status ${response.status}.`);
|
|
83
|
-
}
|
|
84
|
-
const data = (await response.json()) as {
|
|
85
|
-
Answer?: Array<{ data?: string }>;
|
|
86
|
-
};
|
|
87
|
-
return (data.Answer ?? [])
|
|
88
|
-
.map((answer) =>
|
|
89
|
-
typeof answer.data === "string" ? parseTxtAnswer(answer.data) : null,
|
|
90
|
-
)
|
|
91
|
-
.filter((value): value is string => value !== null && value.length > 0);
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
return {
|
|
95
|
-
connection: {
|
|
96
|
-
create: async (
|
|
97
|
-
ctx: ComponentCtx,
|
|
98
|
-
data: {
|
|
99
|
-
groupId: string;
|
|
100
|
-
slug?: string;
|
|
101
|
-
name?: string;
|
|
102
|
-
status?: "draft" | "active" | "disabled";
|
|
103
|
-
policy?: EnterprisePolicyPatch;
|
|
104
|
-
config?: Record<string, unknown>;
|
|
105
|
-
extend?: Record<string, unknown>;
|
|
106
|
-
},
|
|
107
|
-
): Promise<{ enterpriseId: string; groupId: string }> => {
|
|
108
|
-
const enterpriseId = (await ctx.runMutation(
|
|
109
|
-
config.component.public.enterpriseCreate,
|
|
110
|
-
{
|
|
111
|
-
...data,
|
|
112
|
-
policy: normalizeEnterprisePolicy(data.policy),
|
|
113
|
-
},
|
|
114
|
-
)) as string;
|
|
115
|
-
return {
|
|
116
|
-
enterpriseId,
|
|
117
|
-
groupId: data.groupId,
|
|
118
|
-
};
|
|
119
|
-
},
|
|
120
|
-
get: async (ctx: ComponentReadCtx, enterpriseId: string) => {
|
|
121
|
-
return await ctx.runQuery(config.component.public.enterpriseGet, {
|
|
122
|
-
enterpriseId,
|
|
123
|
-
});
|
|
124
|
-
},
|
|
125
|
-
getByGroup: async (ctx: ComponentReadCtx, groupId: string) => {
|
|
126
|
-
return await ctx.runQuery(
|
|
127
|
-
config.component.public.enterpriseGetByGroup,
|
|
128
|
-
{
|
|
129
|
-
groupId,
|
|
130
|
-
},
|
|
131
|
-
);
|
|
132
|
-
},
|
|
133
|
-
getByDomain: async (ctx: ComponentReadCtx, domain: string) => {
|
|
134
|
-
return await ctx.runQuery(
|
|
135
|
-
config.component.public.enterpriseGetByDomain,
|
|
136
|
-
{
|
|
137
|
-
domain: normalizeDomain(domain),
|
|
138
|
-
},
|
|
139
|
-
);
|
|
140
|
-
},
|
|
141
|
-
list: async (
|
|
142
|
-
ctx: ComponentReadCtx,
|
|
143
|
-
opts?: {
|
|
144
|
-
where?: {
|
|
145
|
-
groupId?: string;
|
|
146
|
-
slug?: string;
|
|
147
|
-
status?: "draft" | "active" | "disabled";
|
|
148
|
-
};
|
|
149
|
-
limit?: number;
|
|
150
|
-
cursor?: string | null;
|
|
151
|
-
orderBy?: "_creationTime" | "name" | "slug" | "status";
|
|
152
|
-
order?: "asc" | "desc";
|
|
153
|
-
},
|
|
154
|
-
) => {
|
|
155
|
-
return await ctx.runQuery(config.component.public.enterpriseList, {
|
|
156
|
-
where: opts?.where,
|
|
157
|
-
limit: opts?.limit,
|
|
158
|
-
cursor: opts?.cursor,
|
|
159
|
-
orderBy: opts?.orderBy,
|
|
160
|
-
order: opts?.order,
|
|
161
|
-
});
|
|
162
|
-
},
|
|
163
|
-
update: async (
|
|
164
|
-
ctx: ComponentCtx,
|
|
165
|
-
enterpriseId: string,
|
|
166
|
-
data: Record<string, unknown>,
|
|
167
|
-
) => {
|
|
168
|
-
await ctx.runMutation(config.component.public.enterpriseUpdate, {
|
|
169
|
-
enterpriseId,
|
|
170
|
-
data,
|
|
171
|
-
});
|
|
172
|
-
return { enterpriseId };
|
|
173
|
-
},
|
|
174
|
-
delete: async (ctx: ComponentCtx, enterpriseId: string) => {
|
|
175
|
-
await ctx.runMutation(config.component.public.enterpriseDelete, {
|
|
176
|
-
enterpriseId,
|
|
177
|
-
});
|
|
178
|
-
return { enterpriseId };
|
|
179
|
-
},
|
|
180
|
-
/**
|
|
181
|
-
* Aggregate readiness status across all configured protocols for an
|
|
182
|
-
* enterprise connection.
|
|
183
|
-
*
|
|
184
|
-
* Returns a structured result indicating whether the connection is
|
|
185
|
-
* ready, with per-protocol checks so callers can surface actionable
|
|
186
|
-
* diagnostics without running full network validation.
|
|
187
|
-
*/
|
|
188
|
-
status: async (ctx: ComponentReadCtx, enterpriseId: string) => {
|
|
189
|
-
const enterprise = await ctx.runQuery(
|
|
190
|
-
config.component.public.enterpriseGet,
|
|
191
|
-
{ enterpriseId },
|
|
192
|
-
);
|
|
193
|
-
if (!enterprise) {
|
|
194
|
-
throw Cv.error({
|
|
195
|
-
code: "INVALID_PARAMETERS",
|
|
196
|
-
message: enterpriseNotFoundError,
|
|
197
|
-
});
|
|
198
|
-
}
|
|
199
|
-
const policy = getPolicyFromEnterprise(enterprise);
|
|
200
|
-
const protocols = enterprise.config?.protocols ?? {};
|
|
201
|
-
const oidcConfig = protocols.oidc;
|
|
202
|
-
const oidcSecret = await getEnterpriseSecret(
|
|
203
|
-
ctx,
|
|
204
|
-
enterprise._id,
|
|
205
|
-
ENTERPRISE_OIDC_CLIENT_SECRET_KIND,
|
|
206
|
-
);
|
|
207
|
-
const samlConfig = protocols.saml;
|
|
208
|
-
const scimConfig = await ctx.runQuery(
|
|
209
|
-
config.component.public.enterpriseScimConfigGetByEnterprise,
|
|
210
|
-
{ enterpriseId },
|
|
211
|
-
);
|
|
212
|
-
const domains = await ctx.runQuery(
|
|
213
|
-
config.component.public.enterpriseDomainList,
|
|
214
|
-
{ enterpriseId },
|
|
215
|
-
);
|
|
216
|
-
|
|
217
|
-
const oidcReady =
|
|
218
|
-
oidcConfig?.enabled === true &&
|
|
219
|
-
typeof oidcConfig?.clientId === "string" &&
|
|
220
|
-
oidcConfig.clientId.length > 0 &&
|
|
221
|
-
oidcSecret !== null &&
|
|
222
|
-
(typeof oidcConfig?.issuer === "string" ||
|
|
223
|
-
typeof oidcConfig?.discoveryUrl === "string");
|
|
224
|
-
const samlReady =
|
|
225
|
-
samlConfig?.enabled === true &&
|
|
226
|
-
typeof samlConfig?.idp?.entityId === "string";
|
|
227
|
-
const scimReady =
|
|
228
|
-
scimConfig !== null &&
|
|
229
|
-
scimConfig !== undefined &&
|
|
230
|
-
(scimConfig as any).status === "active";
|
|
231
|
-
|
|
232
|
-
const ready =
|
|
233
|
-
enterprise.status === "active" && (oidcReady || samlReady);
|
|
234
|
-
|
|
235
|
-
return {
|
|
236
|
-
enterpriseId: enterprise._id,
|
|
237
|
-
status: enterprise.status,
|
|
238
|
-
ready,
|
|
239
|
-
domainCount: (domains as unknown[]).length,
|
|
240
|
-
protocols: {
|
|
241
|
-
oidc: {
|
|
242
|
-
configured: oidcReady,
|
|
243
|
-
ready: oidcReady,
|
|
244
|
-
clientId: oidcConfig?.clientId ?? null,
|
|
245
|
-
issuer: oidcConfig?.issuer ?? oidcConfig?.discoveryUrl ?? null,
|
|
246
|
-
},
|
|
247
|
-
saml: {
|
|
248
|
-
configured: samlReady,
|
|
249
|
-
ready: samlReady,
|
|
250
|
-
entityId: samlConfig?.idp?.entityId ?? null,
|
|
251
|
-
},
|
|
252
|
-
scim: {
|
|
253
|
-
configured: scimReady,
|
|
254
|
-
ready: scimReady,
|
|
255
|
-
basePath: scimConfig?.basePath ?? null,
|
|
256
|
-
deprovisionMode: policy.provisioning.deprovision.mode,
|
|
257
|
-
},
|
|
258
|
-
},
|
|
259
|
-
};
|
|
260
|
-
},
|
|
261
|
-
},
|
|
262
|
-
domain: {
|
|
263
|
-
add: async (
|
|
264
|
-
ctx: ComponentCtx,
|
|
265
|
-
data: {
|
|
266
|
-
enterpriseId: string;
|
|
267
|
-
groupId: string;
|
|
268
|
-
domain: string;
|
|
269
|
-
isPrimary?: boolean;
|
|
270
|
-
},
|
|
271
|
-
): Promise<string> => {
|
|
272
|
-
return (await ctx.runMutation(
|
|
273
|
-
config.component.public.enterpriseDomainAdd,
|
|
274
|
-
{
|
|
275
|
-
...data,
|
|
276
|
-
domain: normalizeDomain(data.domain),
|
|
277
|
-
},
|
|
278
|
-
)) as string;
|
|
279
|
-
},
|
|
280
|
-
list: async (ctx: ComponentReadCtx, enterpriseId: string) => {
|
|
281
|
-
return await ctx.runQuery(
|
|
282
|
-
config.component.public.enterpriseDomainList,
|
|
283
|
-
{
|
|
284
|
-
enterpriseId,
|
|
285
|
-
},
|
|
286
|
-
);
|
|
287
|
-
},
|
|
288
|
-
validate: async (ctx: ComponentReadCtx, enterpriseId: string) => {
|
|
289
|
-
const enterprise = await ctx.runQuery(
|
|
290
|
-
config.component.public.enterpriseGet,
|
|
291
|
-
{ enterpriseId },
|
|
292
|
-
);
|
|
293
|
-
if (enterprise === null) {
|
|
294
|
-
throw Cv.error({
|
|
295
|
-
code: "INVALID_PARAMETERS",
|
|
296
|
-
message: enterpriseNotFoundError,
|
|
297
|
-
});
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
const domains = await ctx.runQuery(
|
|
301
|
-
config.component.public.enterpriseDomainList,
|
|
302
|
-
{ enterpriseId },
|
|
303
|
-
);
|
|
304
|
-
const primaryDomains = domains.filter(
|
|
305
|
-
(domain: (typeof domains)[number]) => domain.isPrimary,
|
|
306
|
-
);
|
|
307
|
-
const verifiedDomains = domains.filter(
|
|
308
|
-
(domain: (typeof domains)[number]) => domain.verifiedAt !== undefined,
|
|
309
|
-
);
|
|
310
|
-
|
|
311
|
-
const warnings: string[] = [];
|
|
312
|
-
if (domains.length === 0) {
|
|
313
|
-
warnings.push("No domains configured.");
|
|
314
|
-
}
|
|
315
|
-
if (primaryDomains.length === 0 && domains.length > 0) {
|
|
316
|
-
warnings.push("No primary domain configured.");
|
|
317
|
-
}
|
|
318
|
-
if (primaryDomains.length > 1) {
|
|
319
|
-
warnings.push("Multiple primary domains configured.");
|
|
320
|
-
}
|
|
321
|
-
if (verifiedDomains.length === 0 && domains.length > 0) {
|
|
322
|
-
warnings.push("No verified domains yet.");
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
return {
|
|
326
|
-
enterpriseId,
|
|
327
|
-
ready:
|
|
328
|
-
enterprise.status === "active" &&
|
|
329
|
-
domains.length > 0 &&
|
|
330
|
-
primaryDomains.length === 1 &&
|
|
331
|
-
verifiedDomains.length > 0,
|
|
332
|
-
summary: {
|
|
333
|
-
domainCount: domains.length,
|
|
334
|
-
primaryCount: primaryDomains.length,
|
|
335
|
-
verifiedCount: verifiedDomains.length,
|
|
336
|
-
},
|
|
337
|
-
domains: domains.map((domain: (typeof domains)[number]) =>
|
|
338
|
-
toDomainSummary(domain),
|
|
339
|
-
),
|
|
340
|
-
warnings,
|
|
341
|
-
};
|
|
342
|
-
},
|
|
343
|
-
remove: async (ctx: ComponentCtx, domainId: string) => {
|
|
344
|
-
await ctx.runMutation(config.component.public.enterpriseDomainDelete, {
|
|
345
|
-
domainId,
|
|
346
|
-
});
|
|
347
|
-
},
|
|
348
|
-
verification: {
|
|
349
|
-
request: async (
|
|
350
|
-
ctx: ComponentCtx,
|
|
351
|
-
args: { enterpriseId: string; domain: string },
|
|
352
|
-
) => {
|
|
353
|
-
const enterprise = await loadEnterpriseOrThrow(
|
|
354
|
-
ctx,
|
|
355
|
-
args.enterpriseId,
|
|
356
|
-
);
|
|
357
|
-
const normalizedDomain = normalizeDomain(args.domain);
|
|
358
|
-
const domains = await ctx.runQuery(
|
|
359
|
-
config.component.public.enterpriseDomainList,
|
|
360
|
-
{ enterpriseId: enterprise._id },
|
|
361
|
-
);
|
|
362
|
-
const domain = domains.find(
|
|
363
|
-
(entry: (typeof domains)[number]) =>
|
|
364
|
-
entry.domain === normalizedDomain,
|
|
365
|
-
);
|
|
366
|
-
if (!domain) {
|
|
367
|
-
throw Cv.error({
|
|
368
|
-
code: "INVALID_PARAMETERS",
|
|
369
|
-
message: "Domain is not attached to this enterprise.",
|
|
370
|
-
});
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
const requestedAt = Date.now();
|
|
374
|
-
const expiresAt = requestedAt + ENTERPRISE_DOMAIN_VERIFICATION_TTL_MS;
|
|
375
|
-
const token = generateRandomString(32, INVITE_TOKEN_ALPHABET);
|
|
376
|
-
const tokenHash = await sha256(token);
|
|
377
|
-
const recordName = getDomainVerificationRecordName(normalizedDomain);
|
|
378
|
-
|
|
379
|
-
await ctx.runMutation(
|
|
380
|
-
config.component.public.enterpriseDomainVerificationUpsert,
|
|
381
|
-
{
|
|
382
|
-
enterpriseId: enterprise._id,
|
|
383
|
-
groupId: enterprise.groupId,
|
|
384
|
-
domainId: domain._id,
|
|
385
|
-
domain: normalizedDomain,
|
|
386
|
-
recordName,
|
|
387
|
-
token,
|
|
388
|
-
tokenHash,
|
|
389
|
-
requestedAt,
|
|
390
|
-
expiresAt,
|
|
391
|
-
},
|
|
392
|
-
);
|
|
393
|
-
|
|
394
|
-
await recordEnterpriseAuditEvent(ctx, {
|
|
395
|
-
enterpriseId: enterprise._id,
|
|
396
|
-
groupId: enterprise.groupId,
|
|
397
|
-
eventType: "enterprise.domain.verification_requested",
|
|
398
|
-
actorType: "system",
|
|
399
|
-
subjectType: "enterprise_domain",
|
|
400
|
-
subjectId: domain._id,
|
|
401
|
-
ok: true,
|
|
402
|
-
metadata: { domain: normalizedDomain, recordName, expiresAt },
|
|
403
|
-
});
|
|
404
|
-
|
|
405
|
-
return {
|
|
406
|
-
enterpriseId: enterprise._id,
|
|
407
|
-
domain: normalizedDomain,
|
|
408
|
-
requestedAt,
|
|
409
|
-
expiresAt,
|
|
410
|
-
challenge: {
|
|
411
|
-
recordType: "TXT" as const,
|
|
412
|
-
recordName,
|
|
413
|
-
recordValue: token,
|
|
414
|
-
},
|
|
415
|
-
};
|
|
416
|
-
},
|
|
417
|
-
confirm: async (
|
|
418
|
-
ctx: ComponentCtx,
|
|
419
|
-
args: { enterpriseId: string; domain: string },
|
|
420
|
-
) => {
|
|
421
|
-
const enterprise = await loadEnterpriseOrThrow(
|
|
422
|
-
ctx,
|
|
423
|
-
args.enterpriseId,
|
|
424
|
-
);
|
|
425
|
-
const normalizedDomain = normalizeDomain(args.domain);
|
|
426
|
-
const domains = await ctx.runQuery(
|
|
427
|
-
config.component.public.enterpriseDomainList,
|
|
428
|
-
{ enterpriseId: enterprise._id },
|
|
429
|
-
);
|
|
430
|
-
const domain = domains.find(
|
|
431
|
-
(entry: (typeof domains)[number]) =>
|
|
432
|
-
entry.domain === normalizedDomain,
|
|
433
|
-
);
|
|
434
|
-
if (!domain) {
|
|
435
|
-
throw Cv.error({
|
|
436
|
-
code: "INVALID_PARAMETERS",
|
|
437
|
-
message: "Domain is not attached to this enterprise.",
|
|
438
|
-
});
|
|
439
|
-
}
|
|
440
|
-
|
|
441
|
-
if (domain.verifiedAt !== undefined) {
|
|
442
|
-
return {
|
|
443
|
-
ok: true,
|
|
444
|
-
enterpriseId: enterprise._id,
|
|
445
|
-
domain: normalizedDomain,
|
|
446
|
-
verifiedAt: domain.verifiedAt,
|
|
447
|
-
checks: [
|
|
448
|
-
{
|
|
449
|
-
name: "domain_verified",
|
|
450
|
-
ok: true,
|
|
451
|
-
message: "Domain is already verified.",
|
|
452
|
-
},
|
|
453
|
-
],
|
|
454
|
-
};
|
|
455
|
-
}
|
|
456
|
-
|
|
457
|
-
const verification = await ctx.runQuery(
|
|
458
|
-
config.component.public.enterpriseDomainVerificationGet,
|
|
459
|
-
{ domainId: domain._id },
|
|
460
|
-
);
|
|
461
|
-
const checks: Array<{ name: string; ok: boolean; message?: string }> =
|
|
462
|
-
[];
|
|
463
|
-
if (!verification) {
|
|
464
|
-
checks.push({
|
|
465
|
-
name: "verification_requested",
|
|
466
|
-
ok: false,
|
|
467
|
-
message: "No active domain verification challenge exists.",
|
|
468
|
-
});
|
|
469
|
-
return {
|
|
470
|
-
ok: false,
|
|
471
|
-
enterpriseId: enterprise._id,
|
|
472
|
-
domain: normalizedDomain,
|
|
473
|
-
checks,
|
|
474
|
-
};
|
|
475
|
-
}
|
|
476
|
-
|
|
477
|
-
checks.push({ name: "verification_requested", ok: true });
|
|
478
|
-
|
|
479
|
-
if (verification.expiresAt < Date.now()) {
|
|
480
|
-
await ctx.runMutation(
|
|
481
|
-
config.component.public.enterpriseDomainVerificationDelete,
|
|
482
|
-
{ domainId: domain._id },
|
|
483
|
-
);
|
|
484
|
-
checks.push({
|
|
485
|
-
name: "challenge_active",
|
|
486
|
-
ok: false,
|
|
487
|
-
message: "The verification challenge expired. Request a new one.",
|
|
488
|
-
});
|
|
489
|
-
return {
|
|
490
|
-
ok: false,
|
|
491
|
-
enterpriseId: enterprise._id,
|
|
492
|
-
domain: normalizedDomain,
|
|
493
|
-
checks,
|
|
494
|
-
};
|
|
495
|
-
}
|
|
496
|
-
|
|
497
|
-
checks.push({ name: "challenge_active", ok: true });
|
|
498
|
-
|
|
499
|
-
let txtValues: string[];
|
|
500
|
-
try {
|
|
501
|
-
txtValues = await resolveTxtValues(verification.recordName);
|
|
502
|
-
} catch (error) {
|
|
503
|
-
throw Cv.error({
|
|
504
|
-
code: "INTERNAL_ERROR",
|
|
505
|
-
message:
|
|
506
|
-
error instanceof Error
|
|
507
|
-
? error.message
|
|
508
|
-
: "Failed to resolve DNS TXT records.",
|
|
509
|
-
});
|
|
510
|
-
}
|
|
511
|
-
|
|
512
|
-
checks.push({
|
|
513
|
-
name: "dns_record_present",
|
|
514
|
-
ok: txtValues.length > 0,
|
|
515
|
-
message:
|
|
516
|
-
txtValues.length > 0
|
|
517
|
-
? undefined
|
|
518
|
-
: `No TXT records found at ${verification.recordName}.`,
|
|
519
|
-
});
|
|
520
|
-
|
|
521
|
-
const matches = txtValues.includes(verification.token);
|
|
522
|
-
checks.push({
|
|
523
|
-
name: "dns_record_matches",
|
|
524
|
-
ok: matches,
|
|
525
|
-
message: matches
|
|
526
|
-
? undefined
|
|
527
|
-
: `TXT record at ${verification.recordName} does not match the expected value.`,
|
|
528
|
-
});
|
|
529
|
-
|
|
530
|
-
if (!checks.every((check) => check.ok)) {
|
|
531
|
-
return {
|
|
532
|
-
ok: false,
|
|
533
|
-
enterpriseId: enterprise._id,
|
|
534
|
-
domain: normalizedDomain,
|
|
535
|
-
checks,
|
|
536
|
-
};
|
|
537
|
-
}
|
|
538
|
-
|
|
539
|
-
const verifiedAt = Date.now();
|
|
540
|
-
await ctx.runMutation(
|
|
541
|
-
config.component.public.enterpriseDomainVerify,
|
|
542
|
-
{
|
|
543
|
-
domainId: domain._id,
|
|
544
|
-
verifiedAt,
|
|
545
|
-
},
|
|
546
|
-
);
|
|
547
|
-
|
|
548
|
-
await recordEnterpriseAuditEvent(ctx, {
|
|
549
|
-
enterpriseId: enterprise._id,
|
|
550
|
-
groupId: enterprise.groupId,
|
|
551
|
-
eventType: "enterprise.domain.verified",
|
|
552
|
-
actorType: "system",
|
|
553
|
-
subjectType: "enterprise_domain",
|
|
554
|
-
subjectId: domain._id,
|
|
555
|
-
ok: true,
|
|
556
|
-
metadata: { domain: normalizedDomain, verifiedAt },
|
|
557
|
-
});
|
|
558
|
-
|
|
559
|
-
return {
|
|
560
|
-
ok: true,
|
|
561
|
-
enterpriseId: enterprise._id,
|
|
562
|
-
domain: normalizedDomain,
|
|
563
|
-
verifiedAt,
|
|
564
|
-
checks,
|
|
565
|
-
};
|
|
566
|
-
},
|
|
567
|
-
},
|
|
568
|
-
},
|
|
569
|
-
saml: {
|
|
570
|
-
configure: async <DataModel extends GenericDataModel>(
|
|
571
|
-
ctx: GenericActionCtx<DataModel>,
|
|
572
|
-
data: {
|
|
573
|
-
enterpriseId: string;
|
|
574
|
-
metadataXml?: string;
|
|
575
|
-
metadataUrl?: string;
|
|
576
|
-
domains?: string[];
|
|
577
|
-
signAuthnRequests?: boolean;
|
|
578
|
-
attributeMapping?: {
|
|
579
|
-
subject?: string;
|
|
580
|
-
email?: string;
|
|
581
|
-
name?: string;
|
|
582
|
-
firstName?: string;
|
|
583
|
-
lastName?: string;
|
|
584
|
-
};
|
|
585
|
-
sp?: {
|
|
586
|
-
entityId?: string;
|
|
587
|
-
acsUrl?: string;
|
|
588
|
-
sloUrl?: string;
|
|
589
|
-
signingCert?: string | string[];
|
|
590
|
-
encryptCert?: string | string[];
|
|
591
|
-
privateKey?: string;
|
|
592
|
-
privateKeyPass?: string;
|
|
593
|
-
encPrivateKey?: string;
|
|
594
|
-
encPrivateKeyPass?: string;
|
|
595
|
-
};
|
|
596
|
-
},
|
|
597
|
-
) => {
|
|
598
|
-
return await Fx.run(
|
|
599
|
-
Fx.gen(function* () {
|
|
600
|
-
const enterprise = yield* Fx.from({
|
|
601
|
-
ok: () =>
|
|
602
|
-
ctx.runQuery(config.component.public.enterpriseGet, {
|
|
603
|
-
enterpriseId: data.enterpriseId,
|
|
604
|
-
}),
|
|
605
|
-
err: () =>
|
|
606
|
-
Cv.error({
|
|
607
|
-
code: "INTERNAL_ERROR",
|
|
608
|
-
message: "Failed to load enterprise.",
|
|
609
|
-
}),
|
|
610
|
-
}).pipe(
|
|
611
|
-
Fx.chain((ent) =>
|
|
612
|
-
ent === null
|
|
613
|
-
? Cv.fail({
|
|
614
|
-
code: "INVALID_PARAMETERS",
|
|
615
|
-
message: enterpriseNotFoundError,
|
|
616
|
-
})
|
|
617
|
-
: Fx.succeed(ent),
|
|
618
|
-
),
|
|
619
|
-
);
|
|
620
|
-
const metadataXml = yield* data.metadataXml
|
|
621
|
-
? Fx.succeed(data.metadataXml)
|
|
622
|
-
: data.metadataUrl
|
|
623
|
-
? Fx.defer(() =>
|
|
624
|
-
Fx.from({
|
|
625
|
-
ok: async () => {
|
|
626
|
-
const response = await fetch(data.metadataUrl!);
|
|
627
|
-
if (!response.ok) {
|
|
628
|
-
throw new Error(
|
|
629
|
-
`Failed to fetch SAML metadata: ${response.status}`,
|
|
630
|
-
);
|
|
631
|
-
}
|
|
632
|
-
return await response.text();
|
|
633
|
-
},
|
|
634
|
-
err: (error) =>
|
|
635
|
-
Cv.error({
|
|
636
|
-
code: "INVALID_PARAMETERS",
|
|
637
|
-
message:
|
|
638
|
-
error instanceof Error
|
|
639
|
-
? error.message
|
|
640
|
-
: "Failed to fetch SAML metadata",
|
|
641
|
-
}),
|
|
642
|
-
}),
|
|
643
|
-
).pipe(
|
|
644
|
-
Fx.timeout(10_000),
|
|
645
|
-
Fx.retry(
|
|
646
|
-
Fx.retry.compose(
|
|
647
|
-
Fx.retry.jittered(Fx.retry.exponential(200)),
|
|
648
|
-
Fx.retry.recurs(2),
|
|
649
|
-
),
|
|
650
|
-
),
|
|
651
|
-
Fx.recover((error) =>
|
|
652
|
-
Cv.fail({
|
|
653
|
-
code: "INVALID_PARAMETERS",
|
|
654
|
-
message:
|
|
655
|
-
error instanceof Error
|
|
656
|
-
? error.message
|
|
657
|
-
: "Failed to fetch SAML metadata",
|
|
658
|
-
}),
|
|
659
|
-
),
|
|
660
|
-
)
|
|
661
|
-
: Cv.fail({
|
|
662
|
-
code: "INVALID_PARAMETERS",
|
|
663
|
-
message:
|
|
664
|
-
"SAML registration requires metadataXml or metadataUrl.",
|
|
665
|
-
});
|
|
666
|
-
|
|
667
|
-
const parsed = yield* Fx.from({
|
|
668
|
-
ok: () => parseSamlIdpMetadata(metadataXml),
|
|
669
|
-
err: () =>
|
|
670
|
-
Cv.error({
|
|
671
|
-
code: "INVALID_PARAMETERS",
|
|
672
|
-
message: "Failed to parse SAML metadata.",
|
|
673
|
-
}),
|
|
674
|
-
});
|
|
675
|
-
|
|
676
|
-
const baseConfig = upsertProtocolConfig(enterprise.config, "saml", {
|
|
677
|
-
enabled: true,
|
|
678
|
-
idp: {
|
|
679
|
-
metadataXml,
|
|
680
|
-
...parsed,
|
|
681
|
-
},
|
|
682
|
-
sp: data.sp,
|
|
683
|
-
signAuthnRequests:
|
|
684
|
-
data.signAuthnRequests ?? parsed.wantsSignedAuthnRequests,
|
|
685
|
-
attributeMapping: data.attributeMapping,
|
|
686
|
-
});
|
|
687
|
-
const normalizedDomains = data.domains?.map(normalizeDomain);
|
|
688
|
-
const nextConfig = normalizedDomains
|
|
689
|
-
? { ...baseConfig, domains: normalizedDomains }
|
|
690
|
-
: baseConfig;
|
|
691
|
-
|
|
692
|
-
yield* Fx.from({
|
|
693
|
-
ok: () =>
|
|
694
|
-
ctx.runMutation(config.component.public.enterpriseUpdate, {
|
|
695
|
-
enterpriseId: enterprise._id,
|
|
696
|
-
data: {
|
|
697
|
-
status: "active",
|
|
698
|
-
config: nextConfig,
|
|
699
|
-
},
|
|
700
|
-
}),
|
|
701
|
-
err: () =>
|
|
702
|
-
Cv.error({
|
|
703
|
-
code: "INTERNAL_ERROR",
|
|
704
|
-
message: "Failed to persist SAML registration.",
|
|
705
|
-
}),
|
|
706
|
-
});
|
|
707
|
-
|
|
708
|
-
if (normalizedDomains) {
|
|
709
|
-
for (const [index, domain] of normalizedDomains.entries()) {
|
|
710
|
-
yield* Fx.from({
|
|
711
|
-
ok: () =>
|
|
712
|
-
ctx.runMutation(
|
|
713
|
-
config.component.public.enterpriseDomainAdd,
|
|
714
|
-
{
|
|
715
|
-
enterpriseId: enterprise._id,
|
|
716
|
-
groupId: enterprise.groupId,
|
|
717
|
-
domain,
|
|
718
|
-
isPrimary: index === 0,
|
|
719
|
-
},
|
|
720
|
-
),
|
|
721
|
-
err: () =>
|
|
722
|
-
Cv.error({
|
|
723
|
-
code: "INTERNAL_ERROR",
|
|
724
|
-
message: "Failed to persist enterprise domain.",
|
|
725
|
-
}),
|
|
726
|
-
});
|
|
727
|
-
}
|
|
728
|
-
}
|
|
729
|
-
|
|
730
|
-
yield* Fx.from({
|
|
731
|
-
ok: () =>
|
|
732
|
-
recordEnterpriseAuditEvent(ctx, {
|
|
733
|
-
enterpriseId: enterprise._id,
|
|
734
|
-
groupId: enterprise.groupId,
|
|
735
|
-
eventType: "enterprise.saml.registered",
|
|
736
|
-
actorType: "system",
|
|
737
|
-
subjectType: "enterprise_saml",
|
|
738
|
-
subjectId: enterprise._id,
|
|
739
|
-
ok: true,
|
|
740
|
-
metadata: {
|
|
741
|
-
metadataUrl: data.metadataUrl,
|
|
742
|
-
domains: normalizedDomains,
|
|
743
|
-
},
|
|
744
|
-
}),
|
|
745
|
-
err: () =>
|
|
746
|
-
Cv.error({
|
|
747
|
-
code: "INTERNAL_ERROR",
|
|
748
|
-
message: "Failed to record SAML registration audit event.",
|
|
749
|
-
}),
|
|
750
|
-
});
|
|
751
|
-
|
|
752
|
-
return {
|
|
753
|
-
enterpriseId: enterprise._id,
|
|
754
|
-
groupId: enterprise.groupId,
|
|
755
|
-
};
|
|
756
|
-
}).pipe(Fx.recover((e) => Fx.fatal(e))),
|
|
757
|
-
);
|
|
758
|
-
},
|
|
759
|
-
metadata: async <DataModel extends GenericDataModel>(
|
|
760
|
-
ctx: GenericActionCtx<DataModel>,
|
|
761
|
-
opts: {
|
|
762
|
-
enterpriseId: string;
|
|
763
|
-
entityId?: string;
|
|
764
|
-
acsUrl?: string;
|
|
765
|
-
sloUrl?: string;
|
|
766
|
-
},
|
|
767
|
-
) => {
|
|
768
|
-
const enterprise = await ctx.runQuery(
|
|
769
|
-
config.component.public.enterpriseGet,
|
|
770
|
-
{
|
|
771
|
-
enterpriseId: opts.enterpriseId,
|
|
772
|
-
},
|
|
773
|
-
);
|
|
774
|
-
if (!enterprise) {
|
|
775
|
-
throw Cv.error({
|
|
776
|
-
code: "INVALID_PARAMETERS",
|
|
777
|
-
message: "Enterprise not found.",
|
|
778
|
-
});
|
|
779
|
-
}
|
|
780
|
-
|
|
781
|
-
return createServiceProviderMetadata(
|
|
782
|
-
getSamlServiceProviderOptions({
|
|
783
|
-
rootUrl: requireEnv("CONVEX_SITE_URL"),
|
|
784
|
-
source: { kind: "enterprise", id: enterprise._id },
|
|
785
|
-
config: enterprise.config,
|
|
786
|
-
overrides: {
|
|
787
|
-
entityId: opts.entityId,
|
|
788
|
-
acsUrl: opts.acsUrl,
|
|
789
|
-
sloUrl: opts.sloUrl,
|
|
790
|
-
},
|
|
791
|
-
}),
|
|
792
|
-
);
|
|
793
|
-
},
|
|
794
|
-
/**
|
|
795
|
-
* Validate the stored SAML config for an enterprise connection.
|
|
796
|
-
*
|
|
797
|
-
* Re-parses IdP metadata, checks signing cert presence, and verifies
|
|
798
|
-
* SP metadata can be generated. Returns a structured result with
|
|
799
|
-
* per-check details rather than throwing on first failure.
|
|
800
|
-
*/
|
|
801
|
-
validate: async <DataModel extends GenericDataModel>(
|
|
802
|
-
ctx: GenericActionCtx<DataModel>,
|
|
803
|
-
enterpriseId: string,
|
|
804
|
-
) => {
|
|
805
|
-
const checks: Array<{
|
|
806
|
-
name: string;
|
|
807
|
-
ok: boolean;
|
|
808
|
-
message?: string;
|
|
809
|
-
}> = [];
|
|
810
|
-
|
|
811
|
-
const enterprise = await ctx.runQuery(
|
|
812
|
-
config.component.public.enterpriseGet,
|
|
813
|
-
{ enterpriseId },
|
|
814
|
-
);
|
|
815
|
-
|
|
816
|
-
if (!enterprise) {
|
|
817
|
-
return {
|
|
818
|
-
ok: false,
|
|
819
|
-
enterpriseId,
|
|
820
|
-
checks: [
|
|
821
|
-
{
|
|
822
|
-
name: "enterprise_exists",
|
|
823
|
-
ok: false,
|
|
824
|
-
message: "Enterprise not found.",
|
|
825
|
-
},
|
|
826
|
-
],
|
|
827
|
-
};
|
|
828
|
-
}
|
|
829
|
-
|
|
830
|
-
const samlConfig = enterprise.config?.protocols?.saml;
|
|
831
|
-
const samlConfigured =
|
|
832
|
-
samlConfig?.enabled === true &&
|
|
833
|
-
typeof samlConfig?.idp?.metadataXml === "string";
|
|
834
|
-
|
|
835
|
-
checks.push({
|
|
836
|
-
name: "saml_configured",
|
|
837
|
-
ok: samlConfigured,
|
|
838
|
-
message: samlConfigured ? undefined : "SAML is not configured.",
|
|
839
|
-
});
|
|
840
|
-
|
|
841
|
-
const hasIdpMetadata =
|
|
842
|
-
typeof samlConfig?.idp?.metadataXml === "string" &&
|
|
843
|
-
samlConfig.idp.metadataXml.length > 0;
|
|
844
|
-
checks.push({
|
|
845
|
-
name: "idp_metadata_present",
|
|
846
|
-
ok: hasIdpMetadata,
|
|
847
|
-
message: hasIdpMetadata ? undefined : "IdP metadata XML is missing.",
|
|
848
|
-
});
|
|
849
|
-
|
|
850
|
-
const hasEntityId =
|
|
851
|
-
typeof samlConfig?.idp?.entityId === "string" &&
|
|
852
|
-
samlConfig.idp.entityId.length > 0;
|
|
853
|
-
checks.push({
|
|
854
|
-
name: "idp_entity_id",
|
|
855
|
-
ok: hasEntityId,
|
|
856
|
-
message: hasEntityId
|
|
857
|
-
? undefined
|
|
858
|
-
: "IdP entityId could not be parsed from metadata.",
|
|
859
|
-
});
|
|
860
|
-
|
|
861
|
-
let spMetadataOk = false;
|
|
862
|
-
let spMetadataMessage: string | undefined;
|
|
863
|
-
if (samlConfigured) {
|
|
864
|
-
try {
|
|
865
|
-
createServiceProviderMetadata(
|
|
866
|
-
getSamlServiceProviderOptions({
|
|
867
|
-
rootUrl: requireEnv("CONVEX_SITE_URL"),
|
|
868
|
-
source: { kind: "enterprise", id: enterprise._id },
|
|
869
|
-
config: enterprise.config,
|
|
870
|
-
overrides: {},
|
|
871
|
-
}),
|
|
872
|
-
);
|
|
873
|
-
spMetadataOk = true;
|
|
874
|
-
} catch (e) {
|
|
875
|
-
spMetadataMessage =
|
|
876
|
-
e instanceof Error ? e.message : "SP metadata generation failed.";
|
|
877
|
-
}
|
|
878
|
-
} else {
|
|
879
|
-
spMetadataMessage = "Skipped — SAML not configured.";
|
|
880
|
-
}
|
|
881
|
-
checks.push({
|
|
882
|
-
name: "sp_metadata_generates",
|
|
883
|
-
ok: spMetadataOk,
|
|
884
|
-
message: spMetadataMessage,
|
|
885
|
-
});
|
|
886
|
-
|
|
887
|
-
return {
|
|
888
|
-
ok: checks.every((c) => c.ok),
|
|
889
|
-
enterpriseId: enterprise._id,
|
|
890
|
-
checks,
|
|
891
|
-
};
|
|
892
|
-
},
|
|
893
|
-
},
|
|
894
|
-
policy: {
|
|
895
|
-
get: async (ctx: ComponentReadCtx, enterpriseId: string) => {
|
|
896
|
-
const enterprise = await loadEnterpriseOrThrow(ctx, enterpriseId);
|
|
897
|
-
return getPolicyFromEnterprise(enterprise);
|
|
898
|
-
},
|
|
899
|
-
update: async (
|
|
900
|
-
ctx: ComponentCtx,
|
|
901
|
-
enterpriseId: string,
|
|
902
|
-
patch: EnterprisePolicyPatch,
|
|
903
|
-
) => {
|
|
904
|
-
const enterprise = await loadEnterpriseOrThrow(ctx, enterpriseId);
|
|
905
|
-
const policy = patchEnterprisePolicy(enterprise.policy, patch);
|
|
906
|
-
await ctx.runMutation(config.component.public.enterpriseUpdate, {
|
|
907
|
-
enterpriseId,
|
|
908
|
-
data: { policy },
|
|
909
|
-
});
|
|
910
|
-
await recordEnterpriseAuditEvent(ctx, {
|
|
911
|
-
enterpriseId: enterprise._id,
|
|
912
|
-
groupId: enterprise.groupId,
|
|
913
|
-
eventType: "enterprise.policy.updated",
|
|
914
|
-
actorType: "system",
|
|
915
|
-
subjectType: "enterprise_policy",
|
|
916
|
-
subjectId: enterprise._id,
|
|
917
|
-
ok: true,
|
|
918
|
-
metadata: { version: policy.version },
|
|
919
|
-
});
|
|
920
|
-
return policy;
|
|
921
|
-
},
|
|
922
|
-
validate: async (ctx: ComponentReadCtx, enterpriseId: string) => {
|
|
923
|
-
const enterprise = await ctx.runQuery(
|
|
924
|
-
config.component.public.enterpriseGet,
|
|
925
|
-
{ enterpriseId },
|
|
926
|
-
);
|
|
927
|
-
if (!enterprise) {
|
|
928
|
-
return {
|
|
929
|
-
ok: false,
|
|
930
|
-
enterpriseId,
|
|
931
|
-
checks: [
|
|
932
|
-
{
|
|
933
|
-
name: "enterprise_exists",
|
|
934
|
-
ok: false,
|
|
935
|
-
message: enterpriseNotFoundError,
|
|
936
|
-
},
|
|
937
|
-
],
|
|
938
|
-
};
|
|
939
|
-
}
|
|
940
|
-
const policy = getPolicyFromEnterprise(enterprise);
|
|
941
|
-
const checks = validateEnterprisePolicy(policy);
|
|
942
|
-
return {
|
|
943
|
-
ok: checks.every((check: { ok: boolean }) => check.ok),
|
|
944
|
-
enterpriseId,
|
|
945
|
-
policy,
|
|
946
|
-
checks,
|
|
947
|
-
};
|
|
948
|
-
},
|
|
949
|
-
},
|
|
950
|
-
oidc: {
|
|
951
|
-
/**
|
|
952
|
-
* Register or update enterprise OIDC connection settings.
|
|
953
|
-
*
|
|
954
|
-
* Persists protocol config under `enterprise.config.protocols.oidc` and
|
|
955
|
-
* records an `enterprise.oidc.registered` audit event.
|
|
956
|
-
*/
|
|
957
|
-
configure: async (
|
|
958
|
-
ctx: ComponentCtx,
|
|
959
|
-
data: {
|
|
960
|
-
enterpriseId: string;
|
|
961
|
-
issuer?: string;
|
|
962
|
-
discoveryUrl?: string;
|
|
963
|
-
clientId: string;
|
|
964
|
-
clientSecret?: string;
|
|
965
|
-
scopes?: string[];
|
|
966
|
-
authorizationParams?: Record<string, string>;
|
|
967
|
-
clockToleranceSeconds?: number;
|
|
968
|
-
strictIssuer?: boolean;
|
|
969
|
-
/**
|
|
970
|
-
* Map OIDC claim names to `user.extend` field names.
|
|
971
|
-
* Example: `{ department: "department", role: "job_title" }` means
|
|
972
|
-
* the OIDC `department` claim is stored as `user.extend.department`.
|
|
973
|
-
*/
|
|
974
|
-
extraFields?: Record<string, string>;
|
|
975
|
-
},
|
|
976
|
-
) => {
|
|
977
|
-
return await Fx.run(
|
|
978
|
-
Fx.gen(function* () {
|
|
979
|
-
yield* Fx.guard(
|
|
980
|
-
data.issuer === undefined && data.discoveryUrl === undefined,
|
|
981
|
-
Cv.fail({
|
|
982
|
-
code: "INVALID_PARAMETERS",
|
|
983
|
-
message: "OIDC registration requires issuer or discoveryUrl.",
|
|
984
|
-
}),
|
|
985
|
-
);
|
|
986
|
-
|
|
987
|
-
const enterprise = yield* Fx.from({
|
|
988
|
-
ok: () =>
|
|
989
|
-
ctx.runQuery(config.component.public.enterpriseGet, {
|
|
990
|
-
enterpriseId: data.enterpriseId,
|
|
991
|
-
}),
|
|
992
|
-
err: () =>
|
|
993
|
-
Cv.error({
|
|
994
|
-
code: "INTERNAL_ERROR",
|
|
995
|
-
message: "Failed to load enterprise.",
|
|
996
|
-
}),
|
|
997
|
-
}).pipe(
|
|
998
|
-
Fx.chain((ent) =>
|
|
999
|
-
ent === null
|
|
1000
|
-
? Cv.fail({
|
|
1001
|
-
code: "INVALID_PARAMETERS",
|
|
1002
|
-
message: enterpriseNotFoundError,
|
|
1003
|
-
})
|
|
1004
|
-
: Fx.succeed(ent),
|
|
1005
|
-
),
|
|
1006
|
-
);
|
|
1007
|
-
const nextConfig = upsertProtocolConfig(enterprise.config, "oidc", {
|
|
1008
|
-
enabled: true,
|
|
1009
|
-
issuer: data.issuer,
|
|
1010
|
-
discoveryUrl: data.discoveryUrl,
|
|
1011
|
-
clientId: data.clientId,
|
|
1012
|
-
scopes: data.scopes ?? ["openid", "profile", "email"],
|
|
1013
|
-
authorizationParams: data.authorizationParams,
|
|
1014
|
-
clockToleranceSeconds: data.clockToleranceSeconds,
|
|
1015
|
-
strictIssuer: data.strictIssuer,
|
|
1016
|
-
extraFields: data.extraFields,
|
|
1017
|
-
});
|
|
1018
|
-
|
|
1019
|
-
yield* Fx.from({
|
|
1020
|
-
ok: () =>
|
|
1021
|
-
ctx.runMutation(config.component.public.enterpriseUpdate, {
|
|
1022
|
-
enterpriseId: data.enterpriseId,
|
|
1023
|
-
data: { config: nextConfig },
|
|
1024
|
-
}),
|
|
1025
|
-
err: () =>
|
|
1026
|
-
Cv.error({
|
|
1027
|
-
code: "INTERNAL_ERROR",
|
|
1028
|
-
message: "Failed to persist OIDC registration.",
|
|
1029
|
-
}),
|
|
1030
|
-
});
|
|
1031
|
-
|
|
1032
|
-
if (data.clientSecret !== undefined) {
|
|
1033
|
-
const ciphertext = yield* Fx.from({
|
|
1034
|
-
ok: () => encryptSecret(data.clientSecret!),
|
|
1035
|
-
err: () =>
|
|
1036
|
-
Cv.error({
|
|
1037
|
-
code: "INTERNAL_ERROR",
|
|
1038
|
-
message: "Failed to encrypt OIDC client secret.",
|
|
1039
|
-
}),
|
|
1040
|
-
});
|
|
1041
|
-
yield* Fx.from({
|
|
1042
|
-
ok: () =>
|
|
1043
|
-
ctx.runMutation(
|
|
1044
|
-
config.component.public.enterpriseSecretUpsert,
|
|
1045
|
-
{
|
|
1046
|
-
enterpriseId: data.enterpriseId,
|
|
1047
|
-
groupId: enterprise.groupId,
|
|
1048
|
-
kind: ENTERPRISE_OIDC_CLIENT_SECRET_KIND,
|
|
1049
|
-
ciphertext,
|
|
1050
|
-
updatedAt: Date.now(),
|
|
1051
|
-
},
|
|
1052
|
-
),
|
|
1053
|
-
err: () =>
|
|
1054
|
-
Cv.error({
|
|
1055
|
-
code: "INTERNAL_ERROR",
|
|
1056
|
-
message: "Failed to persist OIDC client secret.",
|
|
1057
|
-
}),
|
|
1058
|
-
});
|
|
1059
|
-
}
|
|
1060
|
-
|
|
1061
|
-
yield* Fx.from({
|
|
1062
|
-
ok: () =>
|
|
1063
|
-
recordEnterpriseAuditEvent(ctx, {
|
|
1064
|
-
enterpriseId: data.enterpriseId,
|
|
1065
|
-
groupId: enterprise.groupId,
|
|
1066
|
-
eventType: "enterprise.oidc.registered",
|
|
1067
|
-
actorType: "system",
|
|
1068
|
-
subjectType: "enterprise_oidc",
|
|
1069
|
-
subjectId: data.enterpriseId,
|
|
1070
|
-
ok: true,
|
|
1071
|
-
metadata: {
|
|
1072
|
-
issuer: data.issuer,
|
|
1073
|
-
discoveryUrl: data.discoveryUrl,
|
|
1074
|
-
},
|
|
1075
|
-
}),
|
|
1076
|
-
err: () =>
|
|
1077
|
-
Cv.error({
|
|
1078
|
-
code: "INTERNAL_ERROR",
|
|
1079
|
-
message: "Failed to record OIDC registration audit event.",
|
|
1080
|
-
}),
|
|
1081
|
-
});
|
|
1082
|
-
|
|
1083
|
-
const secret = yield* Fx.from({
|
|
1084
|
-
ok: () =>
|
|
1085
|
-
getEnterpriseSecret(
|
|
1086
|
-
ctx,
|
|
1087
|
-
data.enterpriseId,
|
|
1088
|
-
ENTERPRISE_OIDC_CLIENT_SECRET_KIND,
|
|
1089
|
-
),
|
|
1090
|
-
err: () =>
|
|
1091
|
-
Cv.error({
|
|
1092
|
-
code: "INTERNAL_ERROR",
|
|
1093
|
-
message: "Failed to load OIDC secret metadata.",
|
|
1094
|
-
}),
|
|
1095
|
-
});
|
|
1096
|
-
|
|
1097
|
-
return withOidcSecretState(
|
|
1098
|
-
getPublicOidcConfig(nextConfig),
|
|
1099
|
-
secret !== null,
|
|
1100
|
-
);
|
|
1101
|
-
}).pipe(Fx.recover((e) => Fx.fatal(e))),
|
|
1102
|
-
);
|
|
1103
|
-
},
|
|
1104
|
-
/**
|
|
1105
|
-
* Fetch the stored OIDC config for an enterprise.
|
|
1106
|
-
*/
|
|
1107
|
-
get: async (ctx: ComponentReadCtx, enterpriseId: string) => {
|
|
1108
|
-
return await Fx.run(
|
|
1109
|
-
Fx.from({
|
|
1110
|
-
ok: () =>
|
|
1111
|
-
ctx.runQuery(config.component.public.enterpriseGet, {
|
|
1112
|
-
enterpriseId,
|
|
1113
|
-
}),
|
|
1114
|
-
err: () =>
|
|
1115
|
-
Cv.error({
|
|
1116
|
-
code: "INTERNAL_ERROR",
|
|
1117
|
-
message: "Failed to load enterprise.",
|
|
1118
|
-
}),
|
|
1119
|
-
}).pipe(
|
|
1120
|
-
Fx.chain((ent) =>
|
|
1121
|
-
ent === null
|
|
1122
|
-
? Cv.fail({
|
|
1123
|
-
code: "INVALID_PARAMETERS",
|
|
1124
|
-
message: enterpriseNotFoundError,
|
|
1125
|
-
})
|
|
1126
|
-
: Fx.succeed(ent),
|
|
1127
|
-
),
|
|
1128
|
-
Fx.chain((enterprise) =>
|
|
1129
|
-
Fx.from({
|
|
1130
|
-
ok: async () => {
|
|
1131
|
-
const secret = await getEnterpriseSecret(
|
|
1132
|
-
ctx,
|
|
1133
|
-
enterprise._id,
|
|
1134
|
-
ENTERPRISE_OIDC_CLIENT_SECRET_KIND,
|
|
1135
|
-
);
|
|
1136
|
-
return withOidcSecretState(
|
|
1137
|
-
getPublicOidcConfig(enterprise.config),
|
|
1138
|
-
secret !== null,
|
|
1139
|
-
);
|
|
1140
|
-
},
|
|
1141
|
-
err: () =>
|
|
1142
|
-
Cv.error({
|
|
1143
|
-
code: "INTERNAL_ERROR",
|
|
1144
|
-
message: "Failed to load OIDC secret metadata.",
|
|
1145
|
-
}),
|
|
1146
|
-
}),
|
|
1147
|
-
),
|
|
1148
|
-
Fx.recover((e) => Fx.fatal(e)),
|
|
1149
|
-
),
|
|
1150
|
-
);
|
|
1151
|
-
},
|
|
1152
|
-
/**
|
|
1153
|
-
* Resolve enterprise OIDC sign-in route from enterprise id, domain, or
|
|
1154
|
-
* user email domain.
|
|
1155
|
-
*/
|
|
1156
|
-
signIn: async (
|
|
1157
|
-
ctx: ComponentReadCtx,
|
|
1158
|
-
data: {
|
|
1159
|
-
enterpriseId?: string;
|
|
1160
|
-
email?: string;
|
|
1161
|
-
domain?: string;
|
|
1162
|
-
redirectTo?: string;
|
|
1163
|
-
},
|
|
1164
|
-
) => {
|
|
1165
|
-
return await Fx.run(
|
|
1166
|
-
Fx.gen(function* () {
|
|
1167
|
-
const enterprise =
|
|
1168
|
-
data.enterpriseId !== undefined
|
|
1169
|
-
? yield* Fx.from({
|
|
1170
|
-
ok: () =>
|
|
1171
|
-
ctx.runQuery(config.component.public.enterpriseGet, {
|
|
1172
|
-
enterpriseId: data.enterpriseId,
|
|
1173
|
-
}),
|
|
1174
|
-
err: () =>
|
|
1175
|
-
Cv.error({
|
|
1176
|
-
code: "INTERNAL_ERROR",
|
|
1177
|
-
message: "Failed to load enterprise.",
|
|
1178
|
-
}),
|
|
1179
|
-
}).pipe(
|
|
1180
|
-
Fx.chain((ent) =>
|
|
1181
|
-
ent === null
|
|
1182
|
-
? Cv.fail({
|
|
1183
|
-
code: "INVALID_PARAMETERS",
|
|
1184
|
-
message: enterpriseNotFoundError,
|
|
1185
|
-
})
|
|
1186
|
-
: Fx.succeed(ent),
|
|
1187
|
-
),
|
|
1188
|
-
)
|
|
1189
|
-
: data.domain !== undefined || data.email !== undefined
|
|
1190
|
-
? yield* Fx.from({
|
|
1191
|
-
ok: () =>
|
|
1192
|
-
ctx.runQuery(
|
|
1193
|
-
config.component.public.enterpriseGetByDomain,
|
|
1194
|
-
{
|
|
1195
|
-
domain: normalizeDomain(
|
|
1196
|
-
data.domain ??
|
|
1197
|
-
String(data.email).split("@").pop() ??
|
|
1198
|
-
"",
|
|
1199
|
-
),
|
|
1200
|
-
},
|
|
1201
|
-
),
|
|
1202
|
-
err: () =>
|
|
1203
|
-
Cv.error({
|
|
1204
|
-
code: "INTERNAL_ERROR",
|
|
1205
|
-
message: "Failed to resolve enterprise by domain.",
|
|
1206
|
-
}),
|
|
1207
|
-
}).pipe(
|
|
1208
|
-
Fx.chain((result) =>
|
|
1209
|
-
result?.enterprise &&
|
|
1210
|
-
result.domain?.verifiedAt !== undefined
|
|
1211
|
-
? Fx.succeed(result.enterprise)
|
|
1212
|
-
: Cv.fail({
|
|
1213
|
-
code: "INVALID_PARAMETERS",
|
|
1214
|
-
message:
|
|
1215
|
-
"No enterprise OIDC connection matched the provided input.",
|
|
1216
|
-
}),
|
|
1217
|
-
),
|
|
1218
|
-
)
|
|
1219
|
-
: yield* Cv.fail({
|
|
1220
|
-
code: "INVALID_PARAMETERS",
|
|
1221
|
-
message:
|
|
1222
|
-
"No enterprise OIDC connection matched the provided input.",
|
|
1223
|
-
});
|
|
1224
|
-
|
|
1225
|
-
yield* Fx.guard(
|
|
1226
|
-
enterprise.status !== "active",
|
|
1227
|
-
Cv.fail({
|
|
1228
|
-
code: "INVALID_PARAMETERS",
|
|
1229
|
-
message: "Enterprise connection is not active.",
|
|
1230
|
-
}),
|
|
1231
|
-
);
|
|
1232
|
-
|
|
1233
|
-
const oidc = getOidcConfig(enterprise.config);
|
|
1234
|
-
yield* Fx.guard(
|
|
1235
|
-
oidc.enabled !== true,
|
|
1236
|
-
Cv.fail({
|
|
1237
|
-
code: "PROVIDER_NOT_CONFIGURED",
|
|
1238
|
-
message: "OIDC is not configured for this enterprise.",
|
|
1239
|
-
}),
|
|
1240
|
-
);
|
|
1241
|
-
|
|
1242
|
-
const urls = getEnterpriseOidcUrls({
|
|
1243
|
-
rootUrl: requireEnv("CONVEX_SITE_URL"),
|
|
1244
|
-
enterpriseId: enterprise._id,
|
|
1245
|
-
});
|
|
1246
|
-
return {
|
|
1247
|
-
enterpriseId: enterprise._id,
|
|
1248
|
-
providerId: enterpriseOidcProviderId(enterprise._id),
|
|
1249
|
-
signInPath: urls.signInUrl,
|
|
1250
|
-
callbackPath: urls.callbackUrl,
|
|
1251
|
-
redirectTo: data.redirectTo,
|
|
1252
|
-
};
|
|
1253
|
-
}).pipe(Fx.recover((e) => Fx.fatal(e))),
|
|
1254
|
-
);
|
|
1255
|
-
},
|
|
1256
|
-
/**
|
|
1257
|
-
* Validate the stored OIDC config for an enterprise connection.
|
|
1258
|
-
*
|
|
1259
|
-
* Fetches the OIDC discovery document from the configured issuer or
|
|
1260
|
-
* discoveryUrl, verifies required fields are present, and checks that
|
|
1261
|
-
* clientId is set. Returns a structured result with per-check details.
|
|
1262
|
-
*/
|
|
1263
|
-
validate: async (ctx: ComponentReadCtx, enterpriseId: string) => {
|
|
1264
|
-
const checks: Array<{
|
|
1265
|
-
name: string;
|
|
1266
|
-
ok: boolean;
|
|
1267
|
-
message?: string;
|
|
1268
|
-
}> = [];
|
|
1269
|
-
|
|
1270
|
-
const enterprise = await ctx.runQuery(
|
|
1271
|
-
config.component.public.enterpriseGet,
|
|
1272
|
-
{ enterpriseId },
|
|
1273
|
-
);
|
|
1274
|
-
|
|
1275
|
-
if (!enterprise) {
|
|
1276
|
-
return {
|
|
1277
|
-
ok: false,
|
|
1278
|
-
enterpriseId,
|
|
1279
|
-
checks: [
|
|
1280
|
-
{
|
|
1281
|
-
name: "enterprise_exists",
|
|
1282
|
-
ok: false,
|
|
1283
|
-
message: "Enterprise not found.",
|
|
1284
|
-
},
|
|
1285
|
-
],
|
|
1286
|
-
};
|
|
1287
|
-
}
|
|
1288
|
-
|
|
1289
|
-
const oidc = getOidcConfig(enterprise.config);
|
|
1290
|
-
const secret = await getEnterpriseSecret(
|
|
1291
|
-
ctx,
|
|
1292
|
-
enterprise._id,
|
|
1293
|
-
ENTERPRISE_OIDC_CLIENT_SECRET_KIND,
|
|
1294
|
-
);
|
|
1295
|
-
const oidcConfigured =
|
|
1296
|
-
oidc.enabled === true &&
|
|
1297
|
-
typeof oidc.clientId === "string" &&
|
|
1298
|
-
oidc.clientId.length > 0;
|
|
1299
|
-
|
|
1300
|
-
checks.push({
|
|
1301
|
-
name: "oidc_configured",
|
|
1302
|
-
ok: oidcConfigured,
|
|
1303
|
-
message: oidcConfigured ? undefined : "OIDC is not configured.",
|
|
1304
|
-
});
|
|
1305
|
-
|
|
1306
|
-
const hasClientId =
|
|
1307
|
-
typeof oidc.clientId === "string" && oidc.clientId.length > 0;
|
|
1308
|
-
checks.push({
|
|
1309
|
-
name: "client_id_present",
|
|
1310
|
-
ok: hasClientId,
|
|
1311
|
-
message: hasClientId ? undefined : "clientId is missing.",
|
|
1312
|
-
});
|
|
1313
|
-
|
|
1314
|
-
checks.push({
|
|
1315
|
-
name: "client_secret_stored",
|
|
1316
|
-
ok: secret !== null,
|
|
1317
|
-
message:
|
|
1318
|
-
secret !== null ? undefined : "OIDC client secret is missing.",
|
|
1319
|
-
});
|
|
1320
|
-
|
|
1321
|
-
const discoveryTarget = oidc.discoveryUrl ?? oidc.issuer;
|
|
1322
|
-
const hasDiscovery =
|
|
1323
|
-
typeof discoveryTarget === "string" && discoveryTarget.length > 0;
|
|
1324
|
-
checks.push({
|
|
1325
|
-
name: "issuer_or_discovery_url_present",
|
|
1326
|
-
ok: hasDiscovery,
|
|
1327
|
-
message: hasDiscovery
|
|
1328
|
-
? undefined
|
|
1329
|
-
: "issuer or discoveryUrl is missing.",
|
|
1330
|
-
});
|
|
1331
|
-
|
|
1332
|
-
let discoveryOk = false;
|
|
1333
|
-
let discoveryMessage: string | undefined;
|
|
1334
|
-
if (hasDiscovery) {
|
|
1335
|
-
const discoveryUrl = oidc.discoveryUrl?.length
|
|
1336
|
-
? oidc.discoveryUrl
|
|
1337
|
-
: `${oidc.issuer}/.well-known/openid-configuration`;
|
|
1338
|
-
try {
|
|
1339
|
-
const res = await fetch(discoveryUrl, {
|
|
1340
|
-
headers: { Accept: "application/json" },
|
|
1341
|
-
signal: AbortSignal.timeout(8_000),
|
|
1342
|
-
});
|
|
1343
|
-
if (!res.ok) {
|
|
1344
|
-
discoveryMessage = `Discovery endpoint returned ${res.status}.`;
|
|
1345
|
-
} else {
|
|
1346
|
-
const json = (await res.json()) as Record<string, unknown>;
|
|
1347
|
-
if (typeof json.issuer !== "string") {
|
|
1348
|
-
discoveryMessage =
|
|
1349
|
-
"Discovery document is missing issuer field.";
|
|
1350
|
-
} else if (typeof json.authorization_endpoint !== "string") {
|
|
1351
|
-
discoveryMessage =
|
|
1352
|
-
"Discovery document is missing authorization_endpoint.";
|
|
1353
|
-
} else {
|
|
1354
|
-
discoveryOk = true;
|
|
1355
|
-
}
|
|
1356
|
-
}
|
|
1357
|
-
} catch (e) {
|
|
1358
|
-
discoveryMessage =
|
|
1359
|
-
e instanceof Error
|
|
1360
|
-
? `Discovery fetch failed: ${e.message}`
|
|
1361
|
-
: "Discovery fetch failed.";
|
|
1362
|
-
}
|
|
1363
|
-
} else {
|
|
1364
|
-
discoveryMessage = "Skipped — issuer or discoveryUrl not set.";
|
|
1365
|
-
}
|
|
1366
|
-
checks.push({
|
|
1367
|
-
name: "discovery_reachable",
|
|
1368
|
-
ok: discoveryOk,
|
|
1369
|
-
message: discoveryMessage,
|
|
1370
|
-
});
|
|
1371
|
-
|
|
1372
|
-
return {
|
|
1373
|
-
ok: checks.every((c) => c.ok),
|
|
1374
|
-
enterpriseId: enterprise._id,
|
|
1375
|
-
checks,
|
|
1376
|
-
};
|
|
1377
|
-
},
|
|
1378
|
-
},
|
|
1379
|
-
scim: {
|
|
1380
|
-
configure: async (
|
|
1381
|
-
ctx: ComponentCtx,
|
|
1382
|
-
data: {
|
|
1383
|
-
enterpriseId: string;
|
|
1384
|
-
basePath?: string;
|
|
1385
|
-
status?: "draft" | "active" | "disabled";
|
|
1386
|
-
},
|
|
1387
|
-
) => {
|
|
1388
|
-
const enterprise = await ctx.runQuery(
|
|
1389
|
-
config.component.public.enterpriseGet,
|
|
1390
|
-
{
|
|
1391
|
-
enterpriseId: data.enterpriseId,
|
|
1392
|
-
},
|
|
1393
|
-
);
|
|
1394
|
-
if (enterprise === null) {
|
|
1395
|
-
throw Cv.error({
|
|
1396
|
-
code: "INVALID_PARAMETERS",
|
|
1397
|
-
message: "Enterprise not found.",
|
|
1398
|
-
});
|
|
1399
|
-
}
|
|
1400
|
-
const rawToken = generateRandomString(48, INVITE_TOKEN_ALPHABET);
|
|
1401
|
-
const tokenHash = await sha256(rawToken);
|
|
1402
|
-
const configId = (await ctx.runMutation(
|
|
1403
|
-
config.component.public.enterpriseScimConfigUpsert,
|
|
1404
|
-
{
|
|
1405
|
-
enterpriseId: enterprise._id,
|
|
1406
|
-
groupId: enterprise.groupId,
|
|
1407
|
-
status: data.status ?? "active",
|
|
1408
|
-
basePath:
|
|
1409
|
-
data.basePath ??
|
|
1410
|
-
`${requireEnv("CONVEX_SITE_URL")}/api/auth/sso/${enterprise._id}/scim/v2`,
|
|
1411
|
-
tokenHash,
|
|
1412
|
-
lastRotatedAt: Date.now(),
|
|
1413
|
-
},
|
|
1414
|
-
)) as string;
|
|
1415
|
-
const auditEventId = await recordEnterpriseAuditEvent(ctx, {
|
|
1416
|
-
enterpriseId: enterprise._id,
|
|
1417
|
-
groupId: enterprise.groupId,
|
|
1418
|
-
eventType: "enterprise.scim.configured",
|
|
1419
|
-
actorType: "system",
|
|
1420
|
-
subjectType: "enterprise_scim",
|
|
1421
|
-
subjectId: configId,
|
|
1422
|
-
ok: true,
|
|
1423
|
-
});
|
|
1424
|
-
await emitEnterpriseWebhookDeliveries(ctx, {
|
|
1425
|
-
enterpriseId: enterprise._id,
|
|
1426
|
-
eventType: "enterprise.scim.configured",
|
|
1427
|
-
auditEventId,
|
|
1428
|
-
payload: { enterpriseId: enterprise._id, scimConfigId: configId },
|
|
1429
|
-
});
|
|
1430
|
-
return {
|
|
1431
|
-
enterpriseId: enterprise._id,
|
|
1432
|
-
configId,
|
|
1433
|
-
basePath:
|
|
1434
|
-
data.basePath ??
|
|
1435
|
-
`${requireEnv("CONVEX_SITE_URL")}/api/auth/sso/${enterprise._id}/scim/v2`,
|
|
1436
|
-
token: rawToken,
|
|
1437
|
-
};
|
|
1438
|
-
},
|
|
1439
|
-
get: async (ctx: ComponentReadCtx, enterpriseId: string) => {
|
|
1440
|
-
return await ctx.runQuery(
|
|
1441
|
-
config.component.public.enterpriseScimConfigGetByEnterprise,
|
|
1442
|
-
{ enterpriseId },
|
|
1443
|
-
);
|
|
1444
|
-
},
|
|
1445
|
-
getConfigByToken: async (ctx: ComponentReadCtx, token: string) => {
|
|
1446
|
-
return await ctx.runQuery(
|
|
1447
|
-
config.component.public.enterpriseScimConfigGetByTokenHash,
|
|
1448
|
-
{ tokenHash: await sha256(token) },
|
|
1449
|
-
);
|
|
1450
|
-
},
|
|
1451
|
-
/**
|
|
1452
|
-
* Validate the stored SCIM config for an enterprise connection.
|
|
1453
|
-
*
|
|
1454
|
-
* Checks that a SCIM config record exists, is active, has a token
|
|
1455
|
-
* hash set, and has a non-empty basePath. Returns a structured result
|
|
1456
|
-
* with per-check details.
|
|
1457
|
-
*/
|
|
1458
|
-
validate: async (ctx: ComponentReadCtx, enterpriseId: string) => {
|
|
1459
|
-
const checks: Array<{
|
|
1460
|
-
name: string;
|
|
1461
|
-
ok: boolean;
|
|
1462
|
-
message?: string;
|
|
1463
|
-
}> = [];
|
|
1464
|
-
|
|
1465
|
-
const enterprise = await ctx.runQuery(
|
|
1466
|
-
config.component.public.enterpriseGet,
|
|
1467
|
-
{ enterpriseId },
|
|
1468
|
-
);
|
|
1469
|
-
|
|
1470
|
-
if (!enterprise) {
|
|
1471
|
-
return {
|
|
1472
|
-
ok: false,
|
|
1473
|
-
enterpriseId,
|
|
1474
|
-
checks: [
|
|
1475
|
-
{
|
|
1476
|
-
name: "enterprise_exists",
|
|
1477
|
-
ok: false,
|
|
1478
|
-
message: "Enterprise not found.",
|
|
1479
|
-
},
|
|
1480
|
-
],
|
|
1481
|
-
};
|
|
1482
|
-
}
|
|
1483
|
-
|
|
1484
|
-
const policy = getPolicyFromEnterprise(enterprise);
|
|
1485
|
-
|
|
1486
|
-
const scimConfig = await ctx.runQuery(
|
|
1487
|
-
config.component.public.enterpriseScimConfigGetByEnterprise,
|
|
1488
|
-
{ enterpriseId },
|
|
1489
|
-
);
|
|
1490
|
-
|
|
1491
|
-
const hasConfig = scimConfig !== null && scimConfig !== undefined;
|
|
1492
|
-
checks.push({
|
|
1493
|
-
name: "scim_config_exists",
|
|
1494
|
-
ok: hasConfig,
|
|
1495
|
-
message: hasConfig ? undefined : "SCIM has not been configured.",
|
|
1496
|
-
});
|
|
1497
|
-
|
|
1498
|
-
const isActive = hasConfig && (scimConfig as any).status === "active";
|
|
1499
|
-
checks.push({
|
|
1500
|
-
name: "scim_config_active",
|
|
1501
|
-
ok: isActive,
|
|
1502
|
-
message: isActive
|
|
1503
|
-
? undefined
|
|
1504
|
-
: `SCIM config status is ${hasConfig ? (scimConfig as any).status : "unknown"}.`,
|
|
1505
|
-
});
|
|
1506
|
-
|
|
1507
|
-
const hasToken =
|
|
1508
|
-
hasConfig &&
|
|
1509
|
-
typeof (scimConfig as any).tokenHash === "string" &&
|
|
1510
|
-
(scimConfig as any).tokenHash.length > 0;
|
|
1511
|
-
checks.push({
|
|
1512
|
-
name: "token_hash_set",
|
|
1513
|
-
ok: hasToken,
|
|
1514
|
-
message: hasToken ? undefined : "SCIM bearer token has not been set.",
|
|
1515
|
-
});
|
|
1516
|
-
|
|
1517
|
-
const hasBasePath =
|
|
1518
|
-
hasConfig &&
|
|
1519
|
-
typeof (scimConfig as any).basePath === "string" &&
|
|
1520
|
-
(scimConfig as any).basePath.length > 0;
|
|
1521
|
-
checks.push({
|
|
1522
|
-
name: "base_path_set",
|
|
1523
|
-
ok: hasBasePath,
|
|
1524
|
-
message: hasBasePath ? undefined : "SCIM basePath is missing.",
|
|
1525
|
-
});
|
|
1526
|
-
|
|
1527
|
-
return {
|
|
1528
|
-
ok: checks.every((c) => c.ok),
|
|
1529
|
-
enterpriseId: enterprise._id,
|
|
1530
|
-
basePath: hasBasePath ? (scimConfig as any).basePath : null,
|
|
1531
|
-
deprovisionMode: policy.provisioning.deprovision.mode,
|
|
1532
|
-
checks,
|
|
1533
|
-
};
|
|
1534
|
-
},
|
|
1535
|
-
identity: {
|
|
1536
|
-
get: async (
|
|
1537
|
-
ctx: ComponentReadCtx,
|
|
1538
|
-
data: {
|
|
1539
|
-
enterpriseId: string;
|
|
1540
|
-
resourceType: "user" | "group";
|
|
1541
|
-
externalId: string;
|
|
1542
|
-
},
|
|
1543
|
-
) => {
|
|
1544
|
-
return await ctx.runQuery(
|
|
1545
|
-
config.component.public.enterpriseScimIdentityGet,
|
|
1546
|
-
data,
|
|
1547
|
-
);
|
|
1548
|
-
},
|
|
1549
|
-
upsert: async (
|
|
1550
|
-
ctx: ComponentCtx,
|
|
1551
|
-
data: {
|
|
1552
|
-
enterpriseId: string;
|
|
1553
|
-
groupId: string;
|
|
1554
|
-
resourceType: "user" | "group";
|
|
1555
|
-
externalId: string;
|
|
1556
|
-
userId?: string;
|
|
1557
|
-
mappedGroupId?: string;
|
|
1558
|
-
active?: boolean;
|
|
1559
|
-
raw?: Record<string, unknown>;
|
|
1560
|
-
},
|
|
1561
|
-
) => {
|
|
1562
|
-
return (await ctx.runMutation(
|
|
1563
|
-
config.component.public.enterpriseScimIdentityUpsert,
|
|
1564
|
-
{ ...data, lastProvisionedAt: Date.now() },
|
|
1565
|
-
)) as string;
|
|
1566
|
-
},
|
|
1567
|
-
},
|
|
1568
|
-
},
|
|
1569
|
-
audit: {
|
|
1570
|
-
record: async (
|
|
1571
|
-
ctx: ComponentCtx,
|
|
1572
|
-
data: {
|
|
1573
|
-
enterpriseId: string;
|
|
1574
|
-
groupId: string;
|
|
1575
|
-
eventType: string;
|
|
1576
|
-
actorType: "user" | "system" | "scim" | "api_key" | "webhook";
|
|
1577
|
-
actorId?: string;
|
|
1578
|
-
subjectType: string;
|
|
1579
|
-
subjectId?: string;
|
|
1580
|
-
ok: boolean;
|
|
1581
|
-
requestId?: string;
|
|
1582
|
-
ip?: string;
|
|
1583
|
-
metadata?: Record<string, unknown>;
|
|
1584
|
-
},
|
|
1585
|
-
) => {
|
|
1586
|
-
return await recordEnterpriseAuditEvent(ctx, data);
|
|
1587
|
-
},
|
|
1588
|
-
list: async (
|
|
1589
|
-
ctx: ComponentReadCtx,
|
|
1590
|
-
data: { enterpriseId?: string; groupId?: string; limit?: number },
|
|
1591
|
-
) => {
|
|
1592
|
-
return await ctx.runQuery(
|
|
1593
|
-
config.component.public.enterpriseAuditEventList,
|
|
1594
|
-
data,
|
|
1595
|
-
);
|
|
1596
|
-
},
|
|
1597
|
-
},
|
|
1598
|
-
webhook: {
|
|
1599
|
-
endpoint: {
|
|
1600
|
-
get: async (ctx: ComponentReadCtx, endpointId: string) => {
|
|
1601
|
-
return await ctx.runQuery(
|
|
1602
|
-
config.component.public.enterpriseWebhookEndpointGet,
|
|
1603
|
-
{ endpointId },
|
|
1604
|
-
);
|
|
1605
|
-
},
|
|
1606
|
-
create: async (
|
|
1607
|
-
ctx: ComponentCtx,
|
|
1608
|
-
data: {
|
|
1609
|
-
enterpriseId: string;
|
|
1610
|
-
url: string;
|
|
1611
|
-
secret: string;
|
|
1612
|
-
subscriptions: string[];
|
|
1613
|
-
createdByUserId?: string;
|
|
1614
|
-
},
|
|
1615
|
-
) => {
|
|
1616
|
-
const enterprise = await ctx.runQuery(
|
|
1617
|
-
config.component.public.enterpriseGet,
|
|
1618
|
-
{
|
|
1619
|
-
enterpriseId: data.enterpriseId,
|
|
1620
|
-
},
|
|
1621
|
-
);
|
|
1622
|
-
if (enterprise === null) {
|
|
1623
|
-
throw Cv.error({
|
|
1624
|
-
code: "INVALID_PARAMETERS",
|
|
1625
|
-
message: "Enterprise not found.",
|
|
1626
|
-
});
|
|
1627
|
-
}
|
|
1628
|
-
const secretHash = await sha256(data.secret);
|
|
1629
|
-
const endpointId = (await ctx.runMutation(
|
|
1630
|
-
config.component.public.enterpriseWebhookEndpointCreate,
|
|
1631
|
-
{
|
|
1632
|
-
enterpriseId: enterprise._id,
|
|
1633
|
-
groupId: enterprise.groupId,
|
|
1634
|
-
url: data.url,
|
|
1635
|
-
secretHash,
|
|
1636
|
-
subscriptions: data.subscriptions,
|
|
1637
|
-
createdByUserId: data.createdByUserId,
|
|
1638
|
-
},
|
|
1639
|
-
)) as string;
|
|
1640
|
-
await recordEnterpriseAuditEvent(ctx, {
|
|
1641
|
-
enterpriseId: enterprise._id,
|
|
1642
|
-
groupId: enterprise.groupId,
|
|
1643
|
-
eventType: "enterprise.webhook.endpoint.created",
|
|
1644
|
-
actorType: data.createdByUserId ? "user" : "system",
|
|
1645
|
-
actorId: data.createdByUserId,
|
|
1646
|
-
subjectType: "enterprise_webhook_endpoint",
|
|
1647
|
-
subjectId: endpointId,
|
|
1648
|
-
ok: true,
|
|
1649
|
-
});
|
|
1650
|
-
return { endpointId };
|
|
1651
|
-
},
|
|
1652
|
-
list: async (ctx: ComponentReadCtx, enterpriseId: string) => {
|
|
1653
|
-
return await ctx.runQuery(
|
|
1654
|
-
config.component.public.enterpriseWebhookEndpointList,
|
|
1655
|
-
{ enterpriseId },
|
|
1656
|
-
);
|
|
1657
|
-
},
|
|
1658
|
-
disable: async (ctx: ComponentCtx, endpointId: string) => {
|
|
1659
|
-
await ctx.runMutation(
|
|
1660
|
-
config.component.public.enterpriseWebhookEndpointUpdate,
|
|
1661
|
-
{ endpointId, data: { status: "disabled" } },
|
|
1662
|
-
);
|
|
1663
|
-
return { endpointId };
|
|
1664
|
-
},
|
|
1665
|
-
},
|
|
1666
|
-
emit: async (
|
|
1667
|
-
ctx: ComponentCtx,
|
|
1668
|
-
data: {
|
|
1669
|
-
enterpriseId: string;
|
|
1670
|
-
eventType: string;
|
|
1671
|
-
payload: Record<string, unknown>;
|
|
1672
|
-
auditEventId?: string;
|
|
1673
|
-
},
|
|
1674
|
-
) => {
|
|
1675
|
-
await emitEnterpriseWebhookDeliveries(ctx, data);
|
|
1676
|
-
},
|
|
1677
|
-
delivery: {
|
|
1678
|
-
list: async (
|
|
1679
|
-
ctx: ComponentReadCtx,
|
|
1680
|
-
data: { enterpriseId: string; limit?: number },
|
|
1681
|
-
) => {
|
|
1682
|
-
return await ctx.runQuery(
|
|
1683
|
-
(config.component.public as any).enterpriseWebhookDeliveryList,
|
|
1684
|
-
data,
|
|
1685
|
-
);
|
|
1686
|
-
},
|
|
1687
|
-
listReady: async (ctx: ComponentReadCtx, limit?: number) => {
|
|
1688
|
-
return await ctx.runQuery(
|
|
1689
|
-
config.component.public.enterpriseWebhookDeliveryListReady,
|
|
1690
|
-
{ now: Date.now(), limit },
|
|
1691
|
-
);
|
|
1692
|
-
},
|
|
1693
|
-
markDelivered: async (
|
|
1694
|
-
ctx: ComponentCtx,
|
|
1695
|
-
deliveryId: string,
|
|
1696
|
-
responseStatus?: number,
|
|
1697
|
-
) => {
|
|
1698
|
-
await ctx.runMutation(
|
|
1699
|
-
config.component.public.enterpriseWebhookDeliveryPatch,
|
|
1700
|
-
{
|
|
1701
|
-
deliveryId,
|
|
1702
|
-
data: {
|
|
1703
|
-
status: "delivered",
|
|
1704
|
-
attemptCount: 1,
|
|
1705
|
-
lastAttemptAt: Date.now(),
|
|
1706
|
-
lastResponseStatus: responseStatus,
|
|
1707
|
-
},
|
|
1708
|
-
},
|
|
1709
|
-
);
|
|
1710
|
-
},
|
|
1711
|
-
markFailed: async (
|
|
1712
|
-
ctx: ComponentCtx,
|
|
1713
|
-
deliveryId: string,
|
|
1714
|
-
data: {
|
|
1715
|
-
attemptCount: number;
|
|
1716
|
-
responseStatus?: number;
|
|
1717
|
-
error?: string;
|
|
1718
|
-
retryAt?: number;
|
|
1719
|
-
},
|
|
1720
|
-
) => {
|
|
1721
|
-
await ctx.runMutation(
|
|
1722
|
-
config.component.public.enterpriseWebhookDeliveryPatch,
|
|
1723
|
-
{
|
|
1724
|
-
deliveryId,
|
|
1725
|
-
data: {
|
|
1726
|
-
status: data.retryAt ? "pending" : "failed",
|
|
1727
|
-
attemptCount: data.attemptCount,
|
|
1728
|
-
lastAttemptAt: Date.now(),
|
|
1729
|
-
lastResponseStatus: data.responseStatus,
|
|
1730
|
-
lastError: data.error,
|
|
1731
|
-
nextAttemptAt: data.retryAt ?? Date.now(),
|
|
1732
|
-
},
|
|
1733
|
-
},
|
|
1734
|
-
);
|
|
1735
|
-
},
|
|
1736
|
-
},
|
|
1737
|
-
},
|
|
1738
|
-
};
|
|
1739
|
-
}
|