@estifanos-sh/convex-auth 0.0.1-preview.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +52 -0
- package/dist/_generated/component.d.ts +2981 -0
- package/dist/bin.js +7194 -0
- package/dist/browser/index.d.ts +22 -0
- package/dist/browser/index.js +61 -0
- package/dist/browser/locks.js +20 -0
- package/dist/browser/navigation.js +14 -0
- package/dist/browser/runtime.js +90 -0
- package/dist/browser/webauthn.js +99 -0
- package/dist/client/core/types.d.ts +615 -0
- package/dist/client/core/types.js +23 -0
- package/dist/client/errors.js +30 -0
- package/dist/client/factors/device.js +100 -0
- package/dist/client/factors/totp.js +111 -0
- package/dist/client/factors/webauthn.js +69 -0
- package/dist/client/index.d.ts +60 -0
- package/dist/client/index.js +976 -0
- package/dist/client/runtime/invite.js +50 -0
- package/dist/client/runtime/mutex.js +25 -0
- package/dist/client/runtime/proxy.js +75 -0
- package/dist/client/runtime/storage.js +65 -0
- package/dist/component/_generated/api.js +26 -0
- package/dist/component/_generated/component.d.ts +2981 -0
- package/dist/component/_generated/component.js +1 -0
- package/dist/component/_generated/dataModel.js +1 -0
- package/dist/component/_generated/server.js +74 -0
- package/dist/component/account.js +197 -0
- package/dist/component/connection/audit.js +152 -0
- package/dist/component/connection/cache.js +205 -0
- package/dist/component/connection/domain/verification.js +63 -0
- package/dist/component/connection/domain.js +108 -0
- package/dist/component/connection/saml/assertion.js +41 -0
- package/dist/component/connection/saml/request.js +61 -0
- package/dist/component/connection/scim/config.js +55 -0
- package/dist/component/connection/scim/identity.js +162 -0
- package/dist/component/connection/secret.js +65 -0
- package/dist/component/connection/webhook/delivery.js +396 -0
- package/dist/component/connection/webhook/endpoint.js +77 -0
- package/dist/component/connection.js +204 -0
- package/dist/component/convex.config.d.ts +7 -0
- package/dist/component/convex.config.js +15 -0
- package/dist/component/crons.js +27 -0
- package/dist/component/event.js +341 -0
- package/dist/component/factor/device.js +141 -0
- package/dist/component/factor/passkey.js +385 -0
- package/dist/component/factor/totp.js +253 -0
- package/dist/component/functions.js +3 -0
- package/dist/component/group/active.js +63 -0
- package/dist/component/group/invite.js +300 -0
- package/dist/component/group/member.js +188 -0
- package/dist/component/group.js +431 -0
- package/dist/component/http.js +9 -0
- package/dist/component/index.d.ts +5 -0
- package/dist/component/index.js +3 -0
- package/dist/component/limits.js +103 -0
- package/dist/component/maintenance.js +205 -0
- package/dist/component/migrations.js +277 -0
- package/dist/component/model.d.ts +384 -0
- package/dist/component/model.js +709 -0
- package/dist/component/modules.js +53 -0
- package/dist/component/oauth/client.js +196 -0
- package/dist/component/oauth/code.js +97 -0
- package/dist/component/oauth/refresh.js +230 -0
- package/dist/component/schema.d.ts +1530 -0
- package/dist/component/schema.js +401 -0
- package/dist/component/session.js +134 -0
- package/dist/component/token/pkce.js +121 -0
- package/dist/component/token/refresh.js +189 -0
- package/dist/component/token/verification.js +155 -0
- package/dist/component/user/email.js +147 -0
- package/dist/component/user/key.js +273 -0
- package/dist/component/user.js +173 -0
- package/dist/core/index.d.ts +531 -0
- package/dist/core/index.js +81 -0
- package/dist/expo/index.d.ts +43 -0
- package/dist/expo/index.js +131 -0
- package/dist/expo/webauthn.js +88 -0
- package/dist/node_modules/.pnpm/@opentelemetry_api-logs@0.214.0/node_modules/@opentelemetry/api-logs/build/src/NoopLogger.d.ts +2 -0
- package/dist/node_modules/.pnpm/@opentelemetry_api-logs@0.214.0/node_modules/@opentelemetry/api-logs/build/src/api/logs.d.ts +3 -0
- package/dist/node_modules/.pnpm/@opentelemetry_api-logs@0.214.0/node_modules/@opentelemetry/api-logs/build/src/index.d.ts +7 -0
- package/dist/node_modules/.pnpm/@opentelemetry_api-logs@0.214.0/node_modules/@opentelemetry/api-logs/build/src/types/AnyValue.d.ts +21 -0
- package/dist/node_modules/.pnpm/@opentelemetry_api-logs@0.214.0/node_modules/@opentelemetry/api-logs/build/src/types/LogRecord.d.ts +36 -0
- package/dist/node_modules/.pnpm/@opentelemetry_api-logs@0.214.0/node_modules/@opentelemetry/api-logs/build/src/types/Logger.d.ts +1 -0
- package/dist/node_modules/.pnpm/@opentelemetry_api-logs@0.214.0/node_modules/@opentelemetry/api-logs/build/src/types/LoggerOptions.d.ts +1 -0
- package/dist/node_modules/.pnpm/@opentelemetry_api-logs@0.214.0/node_modules/@opentelemetry/api-logs/build/src/types/LoggerProvider.d.ts +2 -0
- package/dist/node_modules/.pnpm/@opentelemetry_core@2.6.1_@opentelemetry_api@1.9.1/node_modules/@opentelemetry/core/build/src/baggage/propagation/W3CBaggagePropagator.d.ts +1 -0
- package/dist/node_modules/.pnpm/@opentelemetry_core@2.6.1_@opentelemetry_api@1.9.1/node_modules/@opentelemetry/core/build/src/baggage/utils.d.ts +1 -0
- package/dist/node_modules/.pnpm/@opentelemetry_core@2.6.1_@opentelemetry_api@1.9.1/node_modules/@opentelemetry/core/build/src/common/attributes.d.ts +1 -0
- package/dist/node_modules/.pnpm/@opentelemetry_core@2.6.1_@opentelemetry_api@1.9.1/node_modules/@opentelemetry/core/build/src/common/global-error-handler.d.ts +2 -0
- package/dist/node_modules/.pnpm/@opentelemetry_core@2.6.1_@opentelemetry_api@1.9.1/node_modules/@opentelemetry/core/build/src/common/logging-error-handler.d.ts +1 -0
- package/dist/node_modules/.pnpm/@opentelemetry_core@2.6.1_@opentelemetry_api@1.9.1/node_modules/@opentelemetry/core/build/src/common/time.d.ts +1 -0
- package/dist/node_modules/.pnpm/@opentelemetry_core@2.6.1_@opentelemetry_api@1.9.1/node_modules/@opentelemetry/core/build/src/common/types.d.ts +16 -0
- package/dist/node_modules/.pnpm/@opentelemetry_core@2.6.1_@opentelemetry_api@1.9.1/node_modules/@opentelemetry/core/build/src/index.d.ts +13 -0
- package/dist/node_modules/.pnpm/@opentelemetry_core@2.6.1_@opentelemetry_api@1.9.1/node_modules/@opentelemetry/core/build/src/propagation/composite.d.ts +1 -0
- package/dist/node_modules/.pnpm/@opentelemetry_core@2.6.1_@opentelemetry_api@1.9.1/node_modules/@opentelemetry/core/build/src/trace/TraceState.d.ts +1 -0
- package/dist/node_modules/.pnpm/@opentelemetry_core@2.6.1_@opentelemetry_api@1.9.1/node_modules/@opentelemetry/core/build/src/trace/W3CTraceContextPropagator.d.ts +1 -0
- package/dist/node_modules/.pnpm/@opentelemetry_core@2.6.1_@opentelemetry_api@1.9.1/node_modules/@opentelemetry/core/build/src/trace/rpc-metadata.d.ts +1 -0
- package/dist/node_modules/.pnpm/@opentelemetry_core@2.6.1_@opentelemetry_api@1.9.1/node_modules/@opentelemetry/core/build/src/trace/suppress-tracing.d.ts +1 -0
- package/dist/node_modules/.pnpm/@opentelemetry_core@2.6.1_@opentelemetry_api@1.9.1/node_modules/@opentelemetry/core/build/src/utils/configuration.d.ts +1 -0
- package/dist/node_modules/.pnpm/@opentelemetry_sdk-logs@0.214.0_@opentelemetry_api@1.9.1/node_modules/@opentelemetry/sdk-logs/build/src/LogRecordProcessor.d.ts +24 -0
- package/dist/node_modules/.pnpm/@opentelemetry_sdk-logs@0.214.0_@opentelemetry_api@1.9.1/node_modules/@opentelemetry/sdk-logs/build/src/LoggerProvider.d.ts +2 -0
- package/dist/node_modules/.pnpm/@opentelemetry_sdk-logs@0.214.0_@opentelemetry_api@1.9.1/node_modules/@opentelemetry/sdk-logs/build/src/config/LoggerConfigurators.d.ts +1 -0
- package/dist/node_modules/.pnpm/@opentelemetry_sdk-logs@0.214.0_@opentelemetry_api@1.9.1/node_modules/@opentelemetry/sdk-logs/build/src/export/BatchLogRecordProcessorBase.d.ts +4 -0
- package/dist/node_modules/.pnpm/@opentelemetry_sdk-logs@0.214.0_@opentelemetry_api@1.9.1/node_modules/@opentelemetry/sdk-logs/build/src/export/ConsoleLogRecordExporter.d.ts +3 -0
- package/dist/node_modules/.pnpm/@opentelemetry_sdk-logs@0.214.0_@opentelemetry_api@1.9.1/node_modules/@opentelemetry/sdk-logs/build/src/export/InMemoryLogRecordExporter.d.ts +3 -0
- package/dist/node_modules/.pnpm/@opentelemetry_sdk-logs@0.214.0_@opentelemetry_api@1.9.1/node_modules/@opentelemetry/sdk-logs/build/src/export/LogRecordExporter.d.ts +2 -0
- package/dist/node_modules/.pnpm/@opentelemetry_sdk-logs@0.214.0_@opentelemetry_api@1.9.1/node_modules/@opentelemetry/sdk-logs/build/src/export/ReadableLogRecord.d.ts +4 -0
- package/dist/node_modules/.pnpm/@opentelemetry_sdk-logs@0.214.0_@opentelemetry_api@1.9.1/node_modules/@opentelemetry/sdk-logs/build/src/export/SdkLogRecord.d.ts +71 -0
- package/dist/node_modules/.pnpm/@opentelemetry_sdk-logs@0.214.0_@opentelemetry_api@1.9.1/node_modules/@opentelemetry/sdk-logs/build/src/export/SimpleLogRecordProcessor.d.ts +3 -0
- package/dist/node_modules/.pnpm/@opentelemetry_sdk-logs@0.214.0_@opentelemetry_api@1.9.1/node_modules/@opentelemetry/sdk-logs/build/src/index.d.ts +11 -0
- package/dist/node_modules/.pnpm/@opentelemetry_sdk-logs@0.214.0_@opentelemetry_api@1.9.1/node_modules/@opentelemetry/sdk-logs/build/src/platform/index.d.ts +1 -0
- package/dist/node_modules/.pnpm/@opentelemetry_sdk-logs@0.214.0_@opentelemetry_api@1.9.1/node_modules/@opentelemetry/sdk-logs/build/src/platform/node/export/BatchLogRecordProcessor.d.ts +2 -0
- package/dist/node_modules/.pnpm/@opentelemetry_sdk-logs@0.214.0_@opentelemetry_api@1.9.1/node_modules/@opentelemetry/sdk-logs/build/src/platform/node/index.d.ts +1 -0
- package/dist/node_modules/.pnpm/@opentelemetry_sdk-logs@0.214.0_@opentelemetry_api@1.9.1/node_modules/@opentelemetry/sdk-logs/build/src/types.d.ts +4 -0
- package/dist/node_modules/.pnpm/@opentelemetry_sdk-metrics@2.6.1_@opentelemetry_api@1.9.1/node_modules/@opentelemetry/sdk-metrics/build/src/InstrumentDescriptor.d.ts +3 -0
- package/dist/node_modules/.pnpm/@opentelemetry_sdk-metrics@2.6.1_@opentelemetry_api@1.9.1/node_modules/@opentelemetry/sdk-metrics/build/src/MeterProvider.d.ts +4 -0
- package/dist/node_modules/.pnpm/@opentelemetry_sdk-metrics@2.6.1_@opentelemetry_api@1.9.1/node_modules/@opentelemetry/sdk-metrics/build/src/aggregator/Drop.d.ts +4 -0
- package/dist/node_modules/.pnpm/@opentelemetry_sdk-metrics@2.6.1_@opentelemetry_api@1.9.1/node_modules/@opentelemetry/sdk-metrics/build/src/aggregator/ExponentialHistogram.d.ts +5 -0
- package/dist/node_modules/.pnpm/@opentelemetry_sdk-metrics@2.6.1_@opentelemetry_api@1.9.1/node_modules/@opentelemetry/sdk-metrics/build/src/aggregator/Histogram.d.ts +5 -0
- package/dist/node_modules/.pnpm/@opentelemetry_sdk-metrics@2.6.1_@opentelemetry_api@1.9.1/node_modules/@opentelemetry/sdk-metrics/build/src/aggregator/LastValue.d.ts +5 -0
- package/dist/node_modules/.pnpm/@opentelemetry_sdk-metrics@2.6.1_@opentelemetry_api@1.9.1/node_modules/@opentelemetry/sdk-metrics/build/src/aggregator/Sum.d.ts +5 -0
- package/dist/node_modules/.pnpm/@opentelemetry_sdk-metrics@2.6.1_@opentelemetry_api@1.9.1/node_modules/@opentelemetry/sdk-metrics/build/src/aggregator/index.d.ts +6 -0
- package/dist/node_modules/.pnpm/@opentelemetry_sdk-metrics@2.6.1_@opentelemetry_api@1.9.1/node_modules/@opentelemetry/sdk-metrics/build/src/aggregator/types.d.ts +53 -0
- package/dist/node_modules/.pnpm/@opentelemetry_sdk-metrics@2.6.1_@opentelemetry_api@1.9.1/node_modules/@opentelemetry/sdk-metrics/build/src/export/AggregationSelector.d.ts +16 -0
- package/dist/node_modules/.pnpm/@opentelemetry_sdk-metrics@2.6.1_@opentelemetry_api@1.9.1/node_modules/@opentelemetry/sdk-metrics/build/src/export/AggregationTemporality.d.ts +11 -0
- package/dist/node_modules/.pnpm/@opentelemetry_sdk-metrics@2.6.1_@opentelemetry_api@1.9.1/node_modules/@opentelemetry/sdk-metrics/build/src/export/CardinalitySelector.d.ts +10 -0
- package/dist/node_modules/.pnpm/@opentelemetry_sdk-metrics@2.6.1_@opentelemetry_api@1.9.1/node_modules/@opentelemetry/sdk-metrics/build/src/export/ConsoleMetricExporter.d.ts +4 -0
- package/dist/node_modules/.pnpm/@opentelemetry_sdk-metrics@2.6.1_@opentelemetry_api@1.9.1/node_modules/@opentelemetry/sdk-metrics/build/src/export/InMemoryMetricExporter.d.ts +3 -0
- package/dist/node_modules/.pnpm/@opentelemetry_sdk-metrics@2.6.1_@opentelemetry_api@1.9.1/node_modules/@opentelemetry/sdk-metrics/build/src/export/MetricData.d.ts +148 -0
- package/dist/node_modules/.pnpm/@opentelemetry_sdk-metrics@2.6.1_@opentelemetry_api@1.9.1/node_modules/@opentelemetry/sdk-metrics/build/src/export/MetricExporter.d.ts +3 -0
- package/dist/node_modules/.pnpm/@opentelemetry_sdk-metrics@2.6.1_@opentelemetry_api@1.9.1/node_modules/@opentelemetry/sdk-metrics/build/src/export/MetricProducer.d.ts +27 -0
- package/dist/node_modules/.pnpm/@opentelemetry_sdk-metrics@2.6.1_@opentelemetry_api@1.9.1/node_modules/@opentelemetry/sdk-metrics/build/src/export/MetricReader.d.ts +138 -0
- package/dist/node_modules/.pnpm/@opentelemetry_sdk-metrics@2.6.1_@opentelemetry_api@1.9.1/node_modules/@opentelemetry/sdk-metrics/build/src/export/PeriodicExportingMetricReader.d.ts +3 -0
- package/dist/node_modules/.pnpm/@opentelemetry_sdk-metrics@2.6.1_@opentelemetry_api@1.9.1/node_modules/@opentelemetry/sdk-metrics/build/src/index.d.ts +15 -0
- package/dist/node_modules/.pnpm/@opentelemetry_sdk-metrics@2.6.1_@opentelemetry_api@1.9.1/node_modules/@opentelemetry/sdk-metrics/build/src/types.d.ts +10 -0
- package/dist/node_modules/.pnpm/@opentelemetry_sdk-metrics@2.6.1_@opentelemetry_api@1.9.1/node_modules/@opentelemetry/sdk-metrics/build/src/utils.d.ts +2 -0
- package/dist/node_modules/.pnpm/@opentelemetry_sdk-metrics@2.6.1_@opentelemetry_api@1.9.1/node_modules/@opentelemetry/sdk-metrics/build/src/view/Aggregation.d.ts +4 -0
- package/dist/node_modules/.pnpm/@opentelemetry_sdk-metrics@2.6.1_@opentelemetry_api@1.9.1/node_modules/@opentelemetry/sdk-metrics/build/src/view/AggregationOption.d.ts +41 -0
- package/dist/node_modules/.pnpm/@opentelemetry_sdk-metrics@2.6.1_@opentelemetry_api@1.9.1/node_modules/@opentelemetry/sdk-metrics/build/src/view/AttributesProcessor.d.ts +1 -0
- package/dist/node_modules/.pnpm/@opentelemetry_sdk-metrics@2.6.1_@opentelemetry_api@1.9.1/node_modules/@opentelemetry/sdk-metrics/build/src/view/InstrumentSelector.d.ts +1 -0
- package/dist/node_modules/.pnpm/@opentelemetry_sdk-metrics@2.6.1_@opentelemetry_api@1.9.1/node_modules/@opentelemetry/sdk-metrics/build/src/view/View.d.ts +5 -0
- package/dist/node_modules/.pnpm/@opentelemetry_sdk-trace-base@2.6.1_@opentelemetry_api@1.9.1/node_modules/@opentelemetry/sdk-trace-base/build/src/BasicTracerProvider.d.ts +2 -0
- package/dist/node_modules/.pnpm/@opentelemetry_sdk-trace-base@2.6.1_@opentelemetry_api@1.9.1/node_modules/@opentelemetry/sdk-trace-base/build/src/IdGenerator.d.ts +11 -0
- package/dist/node_modules/.pnpm/@opentelemetry_sdk-trace-base@2.6.1_@opentelemetry_api@1.9.1/node_modules/@opentelemetry/sdk-trace-base/build/src/Sampler.d.ts +74 -0
- package/dist/node_modules/.pnpm/@opentelemetry_sdk-trace-base@2.6.1_@opentelemetry_api@1.9.1/node_modules/@opentelemetry/sdk-trace-base/build/src/Span.d.ts +17 -0
- package/dist/node_modules/.pnpm/@opentelemetry_sdk-trace-base@2.6.1_@opentelemetry_api@1.9.1/node_modules/@opentelemetry/sdk-trace-base/build/src/SpanProcessor.d.ts +43 -0
- package/dist/node_modules/.pnpm/@opentelemetry_sdk-trace-base@2.6.1_@opentelemetry_api@1.9.1/node_modules/@opentelemetry/sdk-trace-base/build/src/TimedEvent.d.ts +19 -0
- package/dist/node_modules/.pnpm/@opentelemetry_sdk-trace-base@2.6.1_@opentelemetry_api@1.9.1/node_modules/@opentelemetry/sdk-trace-base/build/src/export/BatchSpanProcessorBase.d.ts +6 -0
- package/dist/node_modules/.pnpm/@opentelemetry_sdk-trace-base@2.6.1_@opentelemetry_api@1.9.1/node_modules/@opentelemetry/sdk-trace-base/build/src/export/ConsoleSpanExporter.d.ts +3 -0
- package/dist/node_modules/.pnpm/@opentelemetry_sdk-trace-base@2.6.1_@opentelemetry_api@1.9.1/node_modules/@opentelemetry/sdk-trace-base/build/src/export/InMemorySpanExporter.d.ts +3 -0
- package/dist/node_modules/.pnpm/@opentelemetry_sdk-trace-base@2.6.1_@opentelemetry_api@1.9.1/node_modules/@opentelemetry/sdk-trace-base/build/src/export/NoopSpanProcessor.d.ts +4 -0
- package/dist/node_modules/.pnpm/@opentelemetry_sdk-trace-base@2.6.1_@opentelemetry_api@1.9.1/node_modules/@opentelemetry/sdk-trace-base/build/src/export/ReadableSpan.d.ts +29 -0
- package/dist/node_modules/.pnpm/@opentelemetry_sdk-trace-base@2.6.1_@opentelemetry_api@1.9.1/node_modules/@opentelemetry/sdk-trace-base/build/src/export/SimpleSpanProcessor.d.ts +5 -0
- package/dist/node_modules/.pnpm/@opentelemetry_sdk-trace-base@2.6.1_@opentelemetry_api@1.9.1/node_modules/@opentelemetry/sdk-trace-base/build/src/export/SpanExporter.d.ts +2 -0
- package/dist/node_modules/.pnpm/@opentelemetry_sdk-trace-base@2.6.1_@opentelemetry_api@1.9.1/node_modules/@opentelemetry/sdk-trace-base/build/src/index.d.ts +18 -0
- package/dist/node_modules/.pnpm/@opentelemetry_sdk-trace-base@2.6.1_@opentelemetry_api@1.9.1/node_modules/@opentelemetry/sdk-trace-base/build/src/platform/index.d.ts +1 -0
- package/dist/node_modules/.pnpm/@opentelemetry_sdk-trace-base@2.6.1_@opentelemetry_api@1.9.1/node_modules/@opentelemetry/sdk-trace-base/build/src/platform/node/export/BatchSpanProcessor.d.ts +2 -0
- package/dist/node_modules/.pnpm/@opentelemetry_sdk-trace-base@2.6.1_@opentelemetry_api@1.9.1/node_modules/@opentelemetry/sdk-trace-base/build/src/platform/node/index.d.ts +1 -0
- package/dist/node_modules/.pnpm/@opentelemetry_sdk-trace-base@2.6.1_@opentelemetry_api@1.9.1/node_modules/@opentelemetry/sdk-trace-base/build/src/sampler/AlwaysOffSampler.d.ts +1 -0
- package/dist/node_modules/.pnpm/@opentelemetry_sdk-trace-base@2.6.1_@opentelemetry_api@1.9.1/node_modules/@opentelemetry/sdk-trace-base/build/src/sampler/AlwaysOnSampler.d.ts +1 -0
- package/dist/node_modules/.pnpm/@opentelemetry_sdk-trace-base@2.6.1_@opentelemetry_api@1.9.1/node_modules/@opentelemetry/sdk-trace-base/build/src/sampler/ParentBasedSampler.d.ts +2 -0
- package/dist/node_modules/.pnpm/@opentelemetry_sdk-trace-base@2.6.1_@opentelemetry_api@1.9.1/node_modules/@opentelemetry/sdk-trace-base/build/src/sampler/TraceIdRatioBasedSampler.d.ts +1 -0
- package/dist/node_modules/.pnpm/@opentelemetry_sdk-trace-base@2.6.1_@opentelemetry_api@1.9.1/node_modules/@opentelemetry/sdk-trace-base/build/src/types.d.ts +66 -0
- package/dist/otel.d.ts +73 -0
- package/dist/otel.js +82 -0
- package/dist/permissions/index.d.ts +81 -0
- package/dist/permissions/index.js +18 -0
- package/dist/providers/anonymous.d.ts +35 -0
- package/dist/providers/anonymous.js +40 -0
- package/dist/providers/apple.d.ts +61 -0
- package/dist/providers/apple.js +57 -0
- package/dist/providers/connection.d.ts +30 -0
- package/dist/providers/connection.js +33 -0
- package/dist/providers/credentials.d.ts +78 -0
- package/dist/providers/credentials.js +31 -0
- package/dist/providers/custom.d.ts +96 -0
- package/dist/providers/custom.js +108 -0
- package/dist/providers/device.d.ts +33 -0
- package/dist/providers/device.js +30 -0
- package/dist/providers/email.d.ts +45 -0
- package/dist/providers/email.js +52 -0
- package/dist/providers/github.d.ts +56 -0
- package/dist/providers/github.js +79 -0
- package/dist/providers/google.d.ts +56 -0
- package/dist/providers/google.js +59 -0
- package/dist/providers/index.d.ts +16 -0
- package/dist/providers/index.js +16 -0
- package/dist/providers/microsoft.d.ts +59 -0
- package/dist/providers/microsoft.js +98 -0
- package/dist/providers/password.d.ts +68 -0
- package/dist/providers/password.js +348 -0
- package/dist/providers/phone.d.ts +33 -0
- package/dist/providers/phone.js +35 -0
- package/dist/providers/redirect.d.ts +1 -0
- package/dist/providers/redirect.js +11 -0
- package/dist/providers/totp.d.ts +29 -0
- package/dist/providers/totp.js +29 -0
- package/dist/providers/webauthn/attestation.d.ts +42 -0
- package/dist/providers/webauthn/attestation.js +167 -0
- package/dist/providers/webauthn.d.ts +83 -0
- package/dist/providers/webauthn.js +57 -0
- package/dist/react/index.d.ts +55 -0
- package/dist/react/index.js +80 -0
- package/dist/server/auth.d.ts +443 -0
- package/dist/server/auth.js +178 -0
- package/dist/server/cache/context.js +94 -0
- package/dist/server/component/api.d.ts +14 -0
- package/dist/server/component/api.js +13 -0
- package/dist/server/component/context.d.ts +16 -0
- package/dist/server/component/context.js +1 -0
- package/dist/server/component/factor/db.js +71 -0
- package/dist/server/config.d.ts +3 -0
- package/dist/server/config.js +78 -0
- package/dist/server/connection/config.js +101 -0
- package/dist/server/connection/domain.d.ts +878 -0
- package/dist/server/connection/domain.js +1122 -0
- package/dist/server/connection/group/service.d.ts +25 -0
- package/dist/server/connection/group/service.js +250 -0
- package/dist/server/connection/http.js +1485 -0
- package/dist/server/connection/oidc.js +366 -0
- package/dist/server/connection/policy/domain.js +59 -0
- package/dist/server/connection/policy.d.ts +1 -0
- package/dist/server/connection/policy.js +163 -0
- package/dist/server/connection/profile.js +22 -0
- package/dist/server/connection/provision.js +182 -0
- package/dist/server/connection/saml/api.js +70 -0
- package/dist/server/connection/saml/binding/post.js +140 -0
- package/dist/server/connection/saml/binding/redirect.js +139 -0
- package/dist/server/connection/saml/binding/shared.js +18 -0
- package/dist/server/connection/saml/c14n.js +224 -0
- package/dist/server/connection/saml/constants.js +100 -0
- package/dist/server/connection/saml/crypto.js +170 -0
- package/dist/server/connection/saml/dom/select.js +299 -0
- package/dist/server/connection/saml/encoding.js +93 -0
- package/dist/server/connection/saml/encryption.js +34 -0
- package/dist/server/connection/saml/entity.js +24 -0
- package/dist/server/connection/saml/extractor.js +408 -0
- package/dist/server/connection/saml/flow.js +150 -0
- package/dist/server/connection/saml/identity/provider.js +66 -0
- package/dist/server/connection/saml/index.js +5 -0
- package/dist/server/connection/saml/metadata.js +294 -0
- package/dist/server/connection/saml/service/provider.js +117 -0
- package/dist/server/connection/saml/signature.js +214 -0
- package/dist/server/connection/saml/template.js +68 -0
- package/dist/server/connection/saml/types.js +1 -0
- package/dist/server/connection/saml/validator.js +32 -0
- package/dist/server/connection/saml/xml/builder.js +68 -0
- package/dist/server/connection/saml/xmldsig.js +598 -0
- package/dist/server/connection/saml/xmlenc.js +162 -0
- package/dist/server/connection/saml.d.ts +56 -0
- package/dist/server/connection/saml.js +762 -0
- package/dist/server/connection/scim.js +115 -0
- package/dist/server/connection/shared.js +74 -0
- package/dist/server/connection/webhook.js +163 -0
- package/dist/server/context.d.ts +137 -0
- package/dist/server/context.js +108 -0
- package/dist/server/contract.d.ts +48 -0
- package/dist/server/contract.js +107 -0
- package/dist/server/cookies.js +90 -0
- package/dist/server/core.js +163 -0
- package/dist/server/cors.d.ts +22 -0
- package/dist/server/cors.js +93 -0
- package/dist/server/crypto.js +43 -0
- package/dist/server/db.js +88 -0
- package/dist/server/device.js +140 -0
- package/dist/server/domains/access.js +29 -0
- package/dist/server/domains/account.d.ts +16 -0
- package/dist/server/domains/account.js +92 -0
- package/dist/server/domains/factor.d.ts +28 -0
- package/dist/server/domains/factor.js +115 -0
- package/dist/server/domains/group.js +87 -0
- package/dist/server/domains/invite.js +76 -0
- package/dist/server/domains/key.js +253 -0
- package/dist/server/domains/member.js +149 -0
- package/dist/server/domains/session.js +29 -0
- package/dist/server/domains/user.js +119 -0
- package/dist/server/env.d.ts +46 -0
- package/dist/server/env.js +96 -0
- package/dist/server/errors.js +38 -0
- package/dist/server/events.d.ts +880 -0
- package/dist/server/events.js +406 -0
- package/dist/server/facade.d.ts +83 -0
- package/dist/server/facade.js +124 -0
- package/dist/server/http.d.ts +125 -0
- package/dist/server/http.js +566 -0
- package/dist/server/identity/claims.js +58 -0
- package/dist/server/identity/convex.d.ts +15 -0
- package/dist/server/identity/convex.js +1 -0
- package/dist/server/index.d.ts +17 -0
- package/dist/server/index.js +11 -0
- package/dist/server/keys.js +60 -0
- package/dist/server/limits.js +41 -0
- package/dist/server/log.js +28 -0
- package/dist/server/mcp.d.ts +19 -0
- package/dist/server/mcp.js +250 -0
- package/dist/server/mutations/account.js +47 -0
- package/dist/server/mutations/calls.js +16 -0
- package/dist/server/mutations/code.js +91 -0
- package/dist/server/mutations/credentials/signin.js +210 -0
- package/dist/server/mutations/invalidate.js +60 -0
- package/dist/server/mutations/oauth.js +251 -0
- package/dist/server/mutations/refresh.js +152 -0
- package/dist/server/mutations/register.js +93 -0
- package/dist/server/mutations/retrieve.js +66 -0
- package/dist/server/mutations/signature.js +36 -0
- package/dist/server/mutations/signin.js +81 -0
- package/dist/server/mutations/signout.js +61 -0
- package/dist/server/mutations/store/refs.js +15 -0
- package/dist/server/mutations/store.js +82 -0
- package/dist/server/mutations/verifier.js +25 -0
- package/dist/server/mutations/verify.js +199 -0
- package/dist/server/oauth/authorize.js +98 -0
- package/dist/server/oauth/client.d.ts +93 -0
- package/dist/server/oauth/client.js +115 -0
- package/dist/server/oauth/code.d.ts +63 -0
- package/dist/server/oauth/code.js +124 -0
- package/dist/server/oauth/domain.d.ts +23 -0
- package/dist/server/oauth/domain.js +1 -0
- package/dist/server/oauth/factory.js +46 -0
- package/dist/server/oauth/grant.js +46 -0
- package/dist/server/oauth/handlers.js +108 -0
- package/dist/server/oauth/manage.js +121 -0
- package/dist/server/oauth/normalize.js +27 -0
- package/dist/server/oauth/refresh.d.ts +71 -0
- package/dist/server/oauth/refresh.js +132 -0
- package/dist/server/oauth/register.js +147 -0
- package/dist/server/oauth/runtime.js +280 -0
- package/dist/server/oauth/token.js +355 -0
- package/dist/server/payloads.d.ts +16 -0
- package/dist/server/payloads.js +30 -0
- package/dist/server/preload.d.ts +249 -0
- package/dist/server/preload.js +673 -0
- package/dist/server/random.js +25 -0
- package/dist/server/redirects.js +85 -0
- package/dist/server/runtime.d.ts +845 -0
- package/dist/server/runtime.js +387 -0
- package/dist/server/secret.js +46 -0
- package/dist/server/services/factors.js +117 -0
- package/dist/server/services/providers.js +23 -0
- package/dist/server/services/resolve.js +17 -0
- package/dist/server/session/lifecycle.d.ts +23 -0
- package/dist/server/session/lifecycle.js +139 -0
- package/dist/server/signin/flow.js +359 -0
- package/dist/server/telemetry.js +68 -0
- package/dist/server/templates.js +91 -0
- package/dist/server/token/refresh.js +35 -0
- package/dist/server/tokens.js +164 -0
- package/dist/server/totp.js +282 -0
- package/dist/server/types.d.ts +1154 -0
- package/dist/server/types.js +1 -0
- package/dist/server/url.js +43 -0
- package/dist/server/user/account.js +325 -0
- package/dist/server/utils/bearer.js +24 -0
- package/dist/server/utils/cache.js +51 -0
- package/dist/server/utils/retry.js +3 -0
- package/dist/server/utils/span.js +59 -0
- package/dist/server/validators.d.ts +2061 -0
- package/dist/server/validators.js +320 -0
- package/dist/server/webauthn.js +699 -0
- package/dist/server/wellknown.d.ts +74 -0
- package/dist/server/wellknown.js +195 -0
- package/dist/shared/brand.d.ts +28 -0
- package/dist/shared/brand.js +13 -0
- package/dist/shared/codes.d.ts +99 -0
- package/dist/shared/codes.js +98 -0
- package/dist/shared/compare.js +23 -0
- package/dist/shared/errors.js +24 -0
- package/dist/shared/event/kinds.d.ts +188 -0
- package/dist/shared/event/kinds.js +103 -0
- package/dist/shared/fetch/guard.js +189 -0
- package/dist/shared/log.js +62 -0
- package/dist/shared/results.d.ts +58 -0
- package/dist/shared/retry.js +27 -0
- package/dist/shared/webauthn.js +9 -0
- package/dist/svelte/AuthLoading.svelte +13 -0
- package/dist/svelte/AuthLoading.svelte.d.ts +8 -0
- package/dist/svelte/SignedIn.svelte +14 -0
- package/dist/svelte/SignedIn.svelte.d.ts +8 -0
- package/dist/svelte/SignedOut.svelte +13 -0
- package/dist/svelte/SignedOut.svelte.d.ts +8 -0
- package/dist/svelte/context.svelte.d.ts +26 -0
- package/dist/svelte/context.svelte.js +61 -0
- package/dist/svelte/index.d.ts +5 -0
- package/dist/svelte/index.js +4 -0
- package/dist/test.d.ts +48 -0
- package/dist/test.js +54 -0
- package/package.json +247 -0
|
@@ -0,0 +1,1485 @@
|
|
|
1
|
+
import { ErrorCode } from "../../shared/codes.js";
|
|
2
|
+
import { log } from "../log.js";
|
|
3
|
+
import { convexError } from "../errors.js";
|
|
4
|
+
import { getScimIdentity, getScimIdentityByConnectionAndUser, getScimIdentityByMappedGroup, insertUser, listScimIdentitiesByConnection, provisionScimUser, removeScimIdentity, updateUser, upsertScimIdentity } from "../contract.js";
|
|
5
|
+
import { finalizeNormalizedProfile, normalizeStringArray } from "./profile.js";
|
|
6
|
+
import { SCIM_GROUP_SCHEMA_ID, SCIM_USER_SCHEMA_ID, decodeGroupOidcState, encodeGroupOidcState, groupOidcProviderId, groupSamlProviderId } from "./shared.js";
|
|
7
|
+
import { createGroupConnectionOidcRuntime } from "./oidc.js";
|
|
8
|
+
import { resolveProvisionedRoleIds } from "./policy.js";
|
|
9
|
+
import { addConnectionRoutes, convertErrorsToResponse, getCookies } from "../http.js";
|
|
10
|
+
import { redirectToParamCookie, useRedirectToParam } from "../cookies.js";
|
|
11
|
+
import { redirectAbsoluteUrl, setURLSearchParam } from "../redirects.js";
|
|
12
|
+
import { createOAuthAuthorizationURL, handleOAuthCallback } from "../oauth/runtime.js";
|
|
13
|
+
import { parseScimListRequest, scimError, scimJson, serializeScimGroup, serializeScimUser } from "./scim.js";
|
|
14
|
+
import { createGroupConnectionSamlMetadataXml, createGroupConnectionSamlSignInRequest, createSamlPostBindingResponse, encodeGroupSamlRelayState, enforceGroupConnectionSamlSecurity, getSamlServiceProviderOptions, parseGroupConnectionSamlLoginResponse, parseGroupConnectionSamlLogoutMessage, profileFromSamlExtract, samlReplayIdentifiers, validateGroupConnectionSamlLoginRelayState } from "./saml.js";
|
|
15
|
+
import { ConvexError } from "convex/values";
|
|
16
|
+
import { serialize } from "cookie";
|
|
17
|
+
|
|
18
|
+
//#region src/server/connection/http.ts
|
|
19
|
+
function formDataEntries(formData) {
|
|
20
|
+
return formData;
|
|
21
|
+
}
|
|
22
|
+
async function getOidcCallbackParams(request) {
|
|
23
|
+
const url = new URL(request.url);
|
|
24
|
+
const params = new URLSearchParams(url.searchParams);
|
|
25
|
+
if (request.headers.get("Content-Type")?.includes("application/x-www-form-urlencoded")) {
|
|
26
|
+
const formData = await request.formData();
|
|
27
|
+
for (const [key, value] of formDataEntries(formData)) if (typeof value === "string") params.append(key, value);
|
|
28
|
+
}
|
|
29
|
+
return params;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Upper bound on rows a single SCIM list response will materialize. SCIM list
|
|
33
|
+
* filtering and `totalResults` require the full member/group set, so the
|
|
34
|
+
* handlers cursor-follow to this cap; past it the response is truncated and a
|
|
35
|
+
* warning is logged rather than silently returning a partial first page.
|
|
36
|
+
*/
|
|
37
|
+
const SCIM_COLLECT_LIMIT = 5e3;
|
|
38
|
+
/**
|
|
39
|
+
* Lifetime of a persisted pending SAML AuthnRequest. Bounds how long an ACS
|
|
40
|
+
* response can accept the request; comfortably covers IdP round-trips and the
|
|
41
|
+
* default 300s clock skew while keeping the pending-request table small.
|
|
42
|
+
*/
|
|
43
|
+
const SAML_LOGIN_REQUEST_TTL_MS = 600 * 1e3;
|
|
44
|
+
/**
|
|
45
|
+
* Fallback TTL for the seen-assertion replay cache when an assertion carries no
|
|
46
|
+
* `NotOnOrAfter` bound (only reachable when `requireTimestamps` is disabled).
|
|
47
|
+
*/
|
|
48
|
+
const SAML_SEEN_ASSERTION_FALLBACK_TTL_MS = 600 * 1e3;
|
|
49
|
+
const SCIM_FILTER_OPERATORS = {
|
|
50
|
+
pr: (values) => values.length > 0,
|
|
51
|
+
eq: (values, filterValue) => values.includes(filterValue),
|
|
52
|
+
co: (values, filterValue) => values.some((value) => value.includes(filterValue)),
|
|
53
|
+
sw: (values, filterValue) => values.some((value) => value.startsWith(filterValue)),
|
|
54
|
+
ew: (values, filterValue) => values.some((value) => value.endsWith(filterValue))
|
|
55
|
+
};
|
|
56
|
+
function addGroupHttpRuntime(deps) {
|
|
57
|
+
if (!deps.hasConnection) return;
|
|
58
|
+
const { http, auth, config, requireEnv, loadActiveConnectionSamlOrThrow, loadConnectionOidcOrThrow, getGroupConnectionScimContext, loadGroupPolicyOrThrow, emitGroupAuthEvent, generateRandomString, inviteTokenAlphabet: INVITE_TOKEN_ALPHABET, callUserOAuth, callVerifierSignature, sharedOidcRedirectURI } = deps;
|
|
59
|
+
const GROUP_CONNECTION_ROUTE_BASE = deps.routeBase;
|
|
60
|
+
const errorCodeForEvent = (error, fallback) => {
|
|
61
|
+
if (error instanceof ConvexError && typeof error.data === "object" && error.data !== null && "code" in error.data && typeof error.data.code === "string") return error.data.code;
|
|
62
|
+
return fallback;
|
|
63
|
+
};
|
|
64
|
+
const recordConnectionLoginEvent = async (ctx, args) => {
|
|
65
|
+
await emitGroupAuthEvent(ctx, {
|
|
66
|
+
connectionId: args.connection._id,
|
|
67
|
+
groupId: args.connection.groupId,
|
|
68
|
+
kind: args.outcome === "success" ? "connection.login.succeeded" : "connection.login.failed",
|
|
69
|
+
actor: { type: "anonymous" },
|
|
70
|
+
subject: args.userId ? {
|
|
71
|
+
type: "user",
|
|
72
|
+
id: args.userId
|
|
73
|
+
} : {
|
|
74
|
+
type: "connection",
|
|
75
|
+
id: args.connection._id
|
|
76
|
+
},
|
|
77
|
+
outcome: args.outcome,
|
|
78
|
+
data: args.outcome === "success" ? {
|
|
79
|
+
connectionId: args.connection._id,
|
|
80
|
+
protocol: args.protocol,
|
|
81
|
+
userId: args.userId
|
|
82
|
+
} : {
|
|
83
|
+
connectionId: args.connection._id,
|
|
84
|
+
protocol: args.protocol,
|
|
85
|
+
errorCode: errorCodeForEvent(args.error, "OAUTH_PROVIDER_ERROR")
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
};
|
|
89
|
+
/**
|
|
90
|
+
* Enforce server-side SAML replay prevention at the ACS.
|
|
91
|
+
*
|
|
92
|
+
* The signature, audience/recipient/timestamp, and `InResponseTo` checks that
|
|
93
|
+
* ran earlier all travel inside the same replayable POST, so none of them can
|
|
94
|
+
* tell a captured `SAMLResponse` from a resubmitted one. This consumes the
|
|
95
|
+
* single-use pending request (defeating SP-initiated replay) and records the
|
|
96
|
+
* assertion ID in a bounded seen-cache (defeating IdP-initiated replay, which
|
|
97
|
+
* carries no `InResponseTo`). Either check failing means the response was
|
|
98
|
+
* already used: a connection-login failure is emitted and the login is
|
|
99
|
+
* rejected with no session. Throws (never returns) on rejection.
|
|
100
|
+
*/
|
|
101
|
+
const enforceSamlAcsReplayDefense = async (ctx, connection, parsed) => {
|
|
102
|
+
const nowMs = Date.now();
|
|
103
|
+
const { assertionId, inResponseTo, notOnOrAfter } = samlReplayIdentifiers(parsed);
|
|
104
|
+
const rejectReplay = async (message) => {
|
|
105
|
+
await recordConnectionLoginEvent(ctx, {
|
|
106
|
+
connection,
|
|
107
|
+
protocol: "saml",
|
|
108
|
+
outcome: "failure",
|
|
109
|
+
error: new Error(message)
|
|
110
|
+
});
|
|
111
|
+
throw convexError(ErrorCode.OAUTH_INVALID_STATE, message);
|
|
112
|
+
};
|
|
113
|
+
if (typeof inResponseTo === "string" && inResponseTo.length > 0) {
|
|
114
|
+
if (!await ctx.runMutation(config.component.connection.saml.request.accept, {
|
|
115
|
+
requestId: inResponseTo,
|
|
116
|
+
now: nowMs,
|
|
117
|
+
connectionId: connection._id
|
|
118
|
+
})) await rejectReplay("SAML response replays or references an unknown login request.");
|
|
119
|
+
}
|
|
120
|
+
if (typeof assertionId !== "string" || assertionId.length === 0) await rejectReplay("SAML assertion is missing an ID required for replay detection.");
|
|
121
|
+
const expiresAtMs = typeof notOnOrAfter === "string" && Number.isFinite(new Date(notOnOrAfter).getTime()) ? new Date(notOnOrAfter).getTime() : nowMs + SAML_SEEN_ASSERTION_FALLBACK_TTL_MS;
|
|
122
|
+
if (!await ctx.runMutation(config.component.connection.saml.assertion.accept, {
|
|
123
|
+
connectionId: connection._id,
|
|
124
|
+
assertionId,
|
|
125
|
+
expiresAt: expiresAtMs
|
|
126
|
+
})) await rejectReplay("SAML assertion has already been used.");
|
|
127
|
+
};
|
|
128
|
+
const SCIM_SCHEMAS = [{
|
|
129
|
+
id: SCIM_USER_SCHEMA_ID,
|
|
130
|
+
name: "User",
|
|
131
|
+
description: "User Account",
|
|
132
|
+
attributes: [
|
|
133
|
+
{
|
|
134
|
+
name: "userName",
|
|
135
|
+
type: "string",
|
|
136
|
+
required: true
|
|
137
|
+
},
|
|
138
|
+
{
|
|
139
|
+
name: "displayName",
|
|
140
|
+
type: "string"
|
|
141
|
+
},
|
|
142
|
+
{
|
|
143
|
+
name: "active",
|
|
144
|
+
type: "boolean"
|
|
145
|
+
},
|
|
146
|
+
{
|
|
147
|
+
name: "emails",
|
|
148
|
+
type: "complex",
|
|
149
|
+
multiValued: true
|
|
150
|
+
}
|
|
151
|
+
]
|
|
152
|
+
}, {
|
|
153
|
+
id: SCIM_GROUP_SCHEMA_ID,
|
|
154
|
+
name: "Group",
|
|
155
|
+
description: "Group",
|
|
156
|
+
attributes: [{
|
|
157
|
+
name: "displayName",
|
|
158
|
+
type: "string",
|
|
159
|
+
required: true
|
|
160
|
+
}, {
|
|
161
|
+
name: "members",
|
|
162
|
+
type: "complex",
|
|
163
|
+
multiValued: true
|
|
164
|
+
}]
|
|
165
|
+
}];
|
|
166
|
+
const SCIM_RESOURCE_TYPES = [{
|
|
167
|
+
id: "User",
|
|
168
|
+
name: "User",
|
|
169
|
+
endpoint: "/Users",
|
|
170
|
+
schema: SCIM_USER_SCHEMA_ID
|
|
171
|
+
}, {
|
|
172
|
+
id: "Group",
|
|
173
|
+
name: "Group",
|
|
174
|
+
endpoint: "/Groups",
|
|
175
|
+
schema: SCIM_GROUP_SCHEMA_ID
|
|
176
|
+
}];
|
|
177
|
+
const handleStaticScimCollection = (items, resourceId, opts) => {
|
|
178
|
+
if (resourceId !== void 0) {
|
|
179
|
+
const item = items.find((entry) => entry[opts.by] === decodeURIComponent(resourceId));
|
|
180
|
+
return item ? scimJson(item) : scimError(404, "notFound", opts.notFound);
|
|
181
|
+
}
|
|
182
|
+
return scimJson({
|
|
183
|
+
schemas: ["urn:ietf:params:scim:api:messages:2.0:ListResponse"],
|
|
184
|
+
Resources: items,
|
|
185
|
+
totalResults: items.length,
|
|
186
|
+
startIndex: 1,
|
|
187
|
+
itemsPerPage: items.length
|
|
188
|
+
});
|
|
189
|
+
};
|
|
190
|
+
const pickPrimaryEmail = (body) => Array.isArray(body.emails) ? body.emails.find((entry) => entry.primary === true)?.value ?? body.emails[0]?.value : void 0;
|
|
191
|
+
const pickDisplayName = (body) => {
|
|
192
|
+
const name = typeof body.name === "object" && body.name !== null ? body.name : void 0;
|
|
193
|
+
const derivedName = [name?.givenName, name?.familyName].filter(Boolean).join(" ");
|
|
194
|
+
if (body.displayName !== void 0) return body.displayName;
|
|
195
|
+
if (name?.formatted !== void 0) return name.formatted;
|
|
196
|
+
return derivedName !== "" ? derivedName : void 0;
|
|
197
|
+
};
|
|
198
|
+
const pickPhone = (body) => Array.isArray(body.phoneNumbers) ? body.phoneNumbers[0]?.value : void 0;
|
|
199
|
+
const getScimProfileConfig = (scimConfig) => {
|
|
200
|
+
const extend = typeof scimConfig?.extend === "object" && scimConfig.extend !== null ? scimConfig.extend : {};
|
|
201
|
+
const profile = typeof extend.profile === "object" && extend.profile !== null ? extend.profile : {};
|
|
202
|
+
return {
|
|
203
|
+
mapping: typeof profile.mapping === "object" && profile.mapping !== null ? profile.mapping : {},
|
|
204
|
+
extraFields: typeof profile.extraFields === "object" && profile.extraFields !== null ? profile.extraFields : {}
|
|
205
|
+
};
|
|
206
|
+
};
|
|
207
|
+
const scimFieldAccessors = {
|
|
208
|
+
userName: (body) => body.userName,
|
|
209
|
+
externalId: (body) => body.externalId,
|
|
210
|
+
displayName: (body) => body.displayName,
|
|
211
|
+
"name.formatted": (body) => body.name?.formatted,
|
|
212
|
+
"name.givenName": (body) => body.name?.givenName,
|
|
213
|
+
"name.familyName": (body) => body.name?.familyName,
|
|
214
|
+
"emails.primary": (body) => pickPrimaryEmail(body),
|
|
215
|
+
"emails.value": (body) => Array.isArray(body.emails) ? body.emails.map((entry) => entry.value).filter(Boolean) : void 0,
|
|
216
|
+
"phoneNumbers.primary": (body) => pickPhone(body),
|
|
217
|
+
"phoneNumbers.value": (body) => pickPhone(body),
|
|
218
|
+
active: (body) => body.active,
|
|
219
|
+
groups: (body) => body.groups,
|
|
220
|
+
roles: (body) => body.roles
|
|
221
|
+
};
|
|
222
|
+
const resolveScimField = (body, key) => {
|
|
223
|
+
if (!key) return;
|
|
224
|
+
const accessor = scimFieldAccessors[key];
|
|
225
|
+
return accessor ? accessor(body) : body[key];
|
|
226
|
+
};
|
|
227
|
+
const extractScimProfile = (scimConfig, body) => {
|
|
228
|
+
const { mapping, extraFields } = getScimProfileConfig(scimConfig);
|
|
229
|
+
const extend = Object.fromEntries(Object.entries(extraFields).map(([fieldName, source]) => [fieldName, resolveScimField(body, source)]).filter(([, value]) => value !== void 0));
|
|
230
|
+
return finalizeNormalizedProfile({
|
|
231
|
+
externalId: resolveScimField(body, mapping.externalId) ?? (typeof body.externalId === "string" ? body.externalId : void 0),
|
|
232
|
+
name: resolveScimField(body, mapping.name) ?? pickDisplayName(body),
|
|
233
|
+
firstName: resolveScimField(body, mapping.firstName),
|
|
234
|
+
lastName: resolveScimField(body, mapping.lastName),
|
|
235
|
+
email: resolveScimField(body, mapping.email) ?? pickPrimaryEmail(body) ?? body.userName,
|
|
236
|
+
phone: resolveScimField(body, mapping.phone) ?? pickPhone(body),
|
|
237
|
+
active: resolveScimField(body, mapping.active) ?? body.active,
|
|
238
|
+
groups: pickStringArray(resolveScimField(body, mapping.groups)),
|
|
239
|
+
roles: pickStringArray(resolveScimField(body, mapping.roles)),
|
|
240
|
+
extend: Object.keys(extend).length > 0 ? extend : void 0
|
|
241
|
+
});
|
|
242
|
+
};
|
|
243
|
+
const pickStringArray = (value) => {
|
|
244
|
+
return normalizeStringArray(Array.isArray(value) ? value.map((entry) => {
|
|
245
|
+
if (typeof entry === "string") return entry;
|
|
246
|
+
if (typeof entry === "object" && entry !== null && typeof entry.value === "string") return entry.value;
|
|
247
|
+
}) : value);
|
|
248
|
+
};
|
|
249
|
+
const normalizeScimValues = (value) => {
|
|
250
|
+
if (Array.isArray(value)) return value.flatMap((entry) => normalizeScimValues(entry));
|
|
251
|
+
if (typeof value === "string") return [value];
|
|
252
|
+
if (typeof value === "boolean") return [String(value)];
|
|
253
|
+
return [];
|
|
254
|
+
};
|
|
255
|
+
const applyUserProvisioningPatch = (args) => {
|
|
256
|
+
const mode = args.policy.updateProfileFromScim ?? "always";
|
|
257
|
+
if (mode === "never") return {};
|
|
258
|
+
if (mode === "always") return args.nextUser;
|
|
259
|
+
return Object.fromEntries(Object.entries(args.nextUser).filter(([key, value]) => {
|
|
260
|
+
if (value === void 0) return false;
|
|
261
|
+
const current = args.currentUser[key];
|
|
262
|
+
return current === void 0 || current === null || current === "";
|
|
263
|
+
}));
|
|
264
|
+
};
|
|
265
|
+
const filterScimCollection = (items, filter, filters) => {
|
|
266
|
+
if (!filter) return items;
|
|
267
|
+
const accessor = filters[filter.attribute];
|
|
268
|
+
if (!accessor) throw new Error("Unsupported SCIM filter.");
|
|
269
|
+
const matchesOperator = SCIM_FILTER_OPERATORS[filter.operator];
|
|
270
|
+
return items.filter((item) => matchesOperator(normalizeScimValues(accessor(item)), filter.value ?? ""));
|
|
271
|
+
};
|
|
272
|
+
const paginateScimCollection = (items, listRequest) => {
|
|
273
|
+
const start = listRequest.startIndex - 1;
|
|
274
|
+
return items.slice(start, start + listRequest.count);
|
|
275
|
+
};
|
|
276
|
+
const requireScimResourceId = (resourceId, label) => {
|
|
277
|
+
if (!resourceId) return scimError(400, "invalidPath", `${label} resource ID is required.`);
|
|
278
|
+
return null;
|
|
279
|
+
};
|
|
280
|
+
const readScimJson = async (request) => {
|
|
281
|
+
const contentType = request.headers.get("Content-Type") ?? "";
|
|
282
|
+
if (contentType && !contentType.includes("application/scim+json") && !contentType.includes("application/json")) throw new Error("Unsupported SCIM content type.");
|
|
283
|
+
try {
|
|
284
|
+
return await request.json();
|
|
285
|
+
} catch {
|
|
286
|
+
throw new Error("Invalid SCIM JSON.");
|
|
287
|
+
}
|
|
288
|
+
};
|
|
289
|
+
const unsupportedScimPatch = () => {
|
|
290
|
+
throw new Error("Unsupported SCIM PATCH operation.");
|
|
291
|
+
};
|
|
292
|
+
const scimCollectOverflow = () => /* @__PURE__ */ new Error("SCIM member set too large to reconcile.");
|
|
293
|
+
const handleSamlAcs = async (ctx, request, runtimeRoute) => {
|
|
294
|
+
if (runtimeRoute.protocol !== "saml" || runtimeRoute.rest.length !== 1 || runtimeRoute.rest[0] !== "acs") throw convexError(ErrorCode.INVALID_PARAMETERS, "Invalid connection runtime path.");
|
|
295
|
+
const connectionId = runtimeRoute.connectionId;
|
|
296
|
+
const { loaded, connection, saml } = await loadActiveConnectionSamlOrThrow(ctx, connectionId);
|
|
297
|
+
const rootUrl = requireEnv("CONVEX_SITE_URL");
|
|
298
|
+
const serviceProvider = getSamlServiceProviderOptions({
|
|
299
|
+
rootUrl,
|
|
300
|
+
source: {
|
|
301
|
+
kind: "connection",
|
|
302
|
+
id: connection._id
|
|
303
|
+
},
|
|
304
|
+
config: loaded.config
|
|
305
|
+
});
|
|
306
|
+
let parsedResponse;
|
|
307
|
+
try {
|
|
308
|
+
parsedResponse = await parseGroupConnectionSamlLoginResponse({
|
|
309
|
+
request,
|
|
310
|
+
rootUrl,
|
|
311
|
+
source: {
|
|
312
|
+
kind: "connection",
|
|
313
|
+
id: connection._id
|
|
314
|
+
},
|
|
315
|
+
config: loaded.config
|
|
316
|
+
});
|
|
317
|
+
} catch (error) {
|
|
318
|
+
await recordConnectionLoginEvent(ctx, {
|
|
319
|
+
connection,
|
|
320
|
+
protocol: "saml",
|
|
321
|
+
outcome: "failure",
|
|
322
|
+
error
|
|
323
|
+
});
|
|
324
|
+
throw convexError("OAUTH_PROVIDER_ERROR", `SAML response parse failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
325
|
+
}
|
|
326
|
+
try {
|
|
327
|
+
enforceGroupConnectionSamlSecurity({
|
|
328
|
+
extract: parsedResponse.parsed.extract,
|
|
329
|
+
config: loaded.config,
|
|
330
|
+
expectedAudience: serviceProvider.entityId,
|
|
331
|
+
expectedAcsUrl: serviceProvider.acsUrl
|
|
332
|
+
});
|
|
333
|
+
} catch (error) {
|
|
334
|
+
await recordConnectionLoginEvent(ctx, {
|
|
335
|
+
connection,
|
|
336
|
+
protocol: "saml",
|
|
337
|
+
outcome: "failure",
|
|
338
|
+
error
|
|
339
|
+
});
|
|
340
|
+
throw convexError("OAUTH_PROVIDER_ERROR", error instanceof Error ? error.message : "SAML assertion failed security validation.");
|
|
341
|
+
}
|
|
342
|
+
try {
|
|
343
|
+
validateGroupConnectionSamlLoginRelayState({
|
|
344
|
+
relayState: parsedResponse.relayState,
|
|
345
|
+
source: {
|
|
346
|
+
kind: "connection",
|
|
347
|
+
id: connection._id
|
|
348
|
+
},
|
|
349
|
+
inResponseTo: parsedResponse.parsed.extract?.subjectConfirmation?.inResponseTo
|
|
350
|
+
});
|
|
351
|
+
} catch (error) {
|
|
352
|
+
await recordConnectionLoginEvent(ctx, {
|
|
353
|
+
connection,
|
|
354
|
+
protocol: "saml",
|
|
355
|
+
outcome: "failure",
|
|
356
|
+
error
|
|
357
|
+
});
|
|
358
|
+
throw convexError("OAUTH_INVALID_STATE", "SAML RelayState did not match the pending login request.");
|
|
359
|
+
}
|
|
360
|
+
await enforceSamlAcsReplayDefense(ctx, connection, parsedResponse.parsed);
|
|
361
|
+
const { samlAttributes, samlSessionIndex, ...userProfile } = profileFromSamlExtract(parsedResponse.parsed.extract, saml.profile?.mapping ?? {});
|
|
362
|
+
const profile = userProfile;
|
|
363
|
+
const extraFields = typeof saml.profile === "object" && saml.profile !== null ? saml.profile.extraFields : void 0;
|
|
364
|
+
if (extraFields) {
|
|
365
|
+
const extend = {};
|
|
366
|
+
for (const [fieldName, attributeName] of Object.entries(extraFields)) {
|
|
367
|
+
const value = samlAttributes[attributeName];
|
|
368
|
+
if (value !== void 0) extend[fieldName] = value;
|
|
369
|
+
}
|
|
370
|
+
if (Object.keys(extend).length > 0) profile.extend = extend;
|
|
371
|
+
}
|
|
372
|
+
const maybeRedirectTo = useRedirectToParam(groupSamlProviderId(connection._id), getCookies(request));
|
|
373
|
+
let verificationCode;
|
|
374
|
+
try {
|
|
375
|
+
verificationCode = await callUserOAuth(ctx, {
|
|
376
|
+
provider: groupSamlProviderId(connection._id),
|
|
377
|
+
providerAccountId: profile.id,
|
|
378
|
+
profile,
|
|
379
|
+
signature: parsedResponse.relayState.signature,
|
|
380
|
+
accountExtend: {
|
|
381
|
+
identity: {
|
|
382
|
+
protocol: "saml",
|
|
383
|
+
connectionId: connection._id,
|
|
384
|
+
subject: profile.id,
|
|
385
|
+
entityId: typeof saml.entityId === "string" ? saml.entityId : void 0
|
|
386
|
+
},
|
|
387
|
+
saml: {
|
|
388
|
+
attributes: samlAttributes,
|
|
389
|
+
sessionIndex: samlSessionIndex
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
});
|
|
393
|
+
} catch (error) {
|
|
394
|
+
await recordConnectionLoginEvent(ctx, {
|
|
395
|
+
connection,
|
|
396
|
+
protocol: "saml",
|
|
397
|
+
outcome: "failure",
|
|
398
|
+
error
|
|
399
|
+
});
|
|
400
|
+
throw error;
|
|
401
|
+
}
|
|
402
|
+
await recordConnectionLoginEvent(ctx, {
|
|
403
|
+
connection,
|
|
404
|
+
protocol: "saml",
|
|
405
|
+
outcome: "success"
|
|
406
|
+
});
|
|
407
|
+
const vurl = setURLSearchParam(await redirectAbsoluteUrl(ctx, config, { redirectTo: maybeRedirectTo?.redirectTo ?? (typeof parsedResponse.relayState.redirectTo === "string" ? parsedResponse.relayState.redirectTo : void 0) }), "code", verificationCode);
|
|
408
|
+
const vheaders = new Headers({ Location: vurl });
|
|
409
|
+
vheaders.set("Cache-Control", "must-revalidate");
|
|
410
|
+
for (const { name, value, options } of maybeRedirectTo !== null ? [maybeRedirectTo.updatedCookie] : []) vheaders.append("Set-Cookie", serialize(name, value, options));
|
|
411
|
+
return new Response(null, {
|
|
412
|
+
status: 302,
|
|
413
|
+
headers: vheaders
|
|
414
|
+
});
|
|
415
|
+
};
|
|
416
|
+
const handleSamlSlo = async (ctx, request, runtimeRoute) => {
|
|
417
|
+
if (runtimeRoute.protocol !== "saml" || runtimeRoute.rest.length !== 1 || runtimeRoute.rest[0] !== "slo") throw convexError(ErrorCode.INVALID_PARAMETERS, "Invalid connection runtime path.");
|
|
418
|
+
const { loaded, connection } = await loadActiveConnectionSamlOrThrow(ctx, runtimeRoute.connectionId);
|
|
419
|
+
const parsedMessage = await parseGroupConnectionSamlLogoutMessage({
|
|
420
|
+
request,
|
|
421
|
+
rootUrl: requireEnv("CONVEX_SITE_URL"),
|
|
422
|
+
source: {
|
|
423
|
+
kind: "connection",
|
|
424
|
+
id: connection._id
|
|
425
|
+
},
|
|
426
|
+
config: loaded.config
|
|
427
|
+
});
|
|
428
|
+
if (parsedMessage.hasSamlRequest) {
|
|
429
|
+
if (!parsedMessage.parsedRequest) throw convexError(ErrorCode.INVALID_PARAMETERS, "Missing SAML logout payload.");
|
|
430
|
+
const responseContext = parsedMessage.runtime.sp.createLogoutResponse(parsedMessage.runtime.idp, parsedMessage.parsedRequest.extract, parsedMessage.binding, parsedMessage.relayState ?? "");
|
|
431
|
+
if (parsedMessage.binding === "redirect") return new Response(null, {
|
|
432
|
+
status: 302,
|
|
433
|
+
headers: { Location: responseContext.context }
|
|
434
|
+
});
|
|
435
|
+
return createSamlPostBindingResponse({
|
|
436
|
+
endpoint: responseContext.entityEndpoint,
|
|
437
|
+
parameter: "SAMLResponse",
|
|
438
|
+
value: responseContext.context,
|
|
439
|
+
relayState: parsedMessage.relayState
|
|
440
|
+
});
|
|
441
|
+
} else if (parsedMessage.hasSamlResponse) {
|
|
442
|
+
if (!parsedMessage.parsedResponse) throw convexError(ErrorCode.INVALID_PARAMETERS, "Missing SAML logout response payload.");
|
|
443
|
+
return new Response(null, { status: 204 });
|
|
444
|
+
} else throw convexError(ErrorCode.INVALID_PARAMETERS, "Missing SAML logout payload.");
|
|
445
|
+
};
|
|
446
|
+
const handleScimRequest = async (ctx, request) => {
|
|
447
|
+
try {
|
|
448
|
+
const { scimConfig, connection, parsedPath } = await getGroupConnectionScimContext(ctx, request);
|
|
449
|
+
const state = {
|
|
450
|
+
ctx,
|
|
451
|
+
request,
|
|
452
|
+
url: new URL(request.url),
|
|
453
|
+
parsedPath,
|
|
454
|
+
connection,
|
|
455
|
+
scimConfig,
|
|
456
|
+
policy: await loadGroupPolicyOrThrow(ctx, connection.groupId),
|
|
457
|
+
recordScimEvent: async (kind, outcome, subject, data) => {
|
|
458
|
+
try {
|
|
459
|
+
await emitGroupAuthEvent(ctx, {
|
|
460
|
+
connectionId: connection._id,
|
|
461
|
+
groupId: connection.groupId,
|
|
462
|
+
kind,
|
|
463
|
+
actor: { type: "scim" },
|
|
464
|
+
subject,
|
|
465
|
+
outcome,
|
|
466
|
+
data,
|
|
467
|
+
webhook: { payload: {
|
|
468
|
+
connectionId: connection._id,
|
|
469
|
+
...subject.id ? { subjectId: subject.id } : {},
|
|
470
|
+
...data ? { data } : {}
|
|
471
|
+
} }
|
|
472
|
+
});
|
|
473
|
+
} catch (error) {
|
|
474
|
+
log("WARN", "[connection.scim] audit event emit failed (best-effort)", {
|
|
475
|
+
kind,
|
|
476
|
+
error
|
|
477
|
+
});
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
};
|
|
481
|
+
const collectMembers = async (ctx$1, where) => {
|
|
482
|
+
const first = await auth.member.list(ctx$1, {
|
|
483
|
+
where,
|
|
484
|
+
paginationOpts: {
|
|
485
|
+
numItems: 200,
|
|
486
|
+
cursor: null
|
|
487
|
+
}
|
|
488
|
+
});
|
|
489
|
+
const out = [...first.page];
|
|
490
|
+
let cursor = first.continueCursor;
|
|
491
|
+
let done = first.isDone;
|
|
492
|
+
while (!done && out.length < SCIM_COLLECT_LIMIT) {
|
|
493
|
+
const next = await auth.member.list(ctx$1, {
|
|
494
|
+
where,
|
|
495
|
+
paginationOpts: {
|
|
496
|
+
numItems: 200,
|
|
497
|
+
cursor
|
|
498
|
+
}
|
|
499
|
+
});
|
|
500
|
+
out.push(...next.page);
|
|
501
|
+
done = next.isDone;
|
|
502
|
+
cursor = next.continueCursor;
|
|
503
|
+
}
|
|
504
|
+
if (!done) log("WARN", "[connection.scim] member list truncated at collect limit", {
|
|
505
|
+
groupId: where.groupId,
|
|
506
|
+
limit: SCIM_COLLECT_LIMIT
|
|
507
|
+
});
|
|
508
|
+
return out;
|
|
509
|
+
};
|
|
510
|
+
/**
|
|
511
|
+
* Fully enumerate a group's active members for an authoritative
|
|
512
|
+
* (destructive) membership replace. Unlike {@link collectMembers}, this
|
|
513
|
+
* refuses to truncate: a `replace` diffs the incoming set against the
|
|
514
|
+
* current set and removes the difference, so a partial read would
|
|
515
|
+
* silently drop overflow members. Throws {@link scimCollectOverflow} past
|
|
516
|
+
* the collect limit so the caller fails the reconcile (413) rather than
|
|
517
|
+
* completing a partial authoritative replace.
|
|
518
|
+
*/
|
|
519
|
+
const collectMembersForReplace = async (ctx$1, where) => {
|
|
520
|
+
const first = await auth.member.list(ctx$1, {
|
|
521
|
+
where,
|
|
522
|
+
paginationOpts: {
|
|
523
|
+
numItems: 200,
|
|
524
|
+
cursor: null
|
|
525
|
+
}
|
|
526
|
+
});
|
|
527
|
+
const out = [...first.page];
|
|
528
|
+
let cursor = first.continueCursor;
|
|
529
|
+
let done = first.isDone;
|
|
530
|
+
while (!done) {
|
|
531
|
+
if (out.length > SCIM_COLLECT_LIMIT) throw scimCollectOverflow();
|
|
532
|
+
const next = await auth.member.list(ctx$1, {
|
|
533
|
+
where,
|
|
534
|
+
paginationOpts: {
|
|
535
|
+
numItems: 200,
|
|
536
|
+
cursor
|
|
537
|
+
}
|
|
538
|
+
});
|
|
539
|
+
out.push(...next.page);
|
|
540
|
+
done = next.isDone;
|
|
541
|
+
cursor = next.continueCursor;
|
|
542
|
+
}
|
|
543
|
+
return out;
|
|
544
|
+
};
|
|
545
|
+
const collectGroups = async (ctx$1, where) => {
|
|
546
|
+
const first = await auth.group.list(ctx$1, {
|
|
547
|
+
where,
|
|
548
|
+
paginationOpts: {
|
|
549
|
+
numItems: 200,
|
|
550
|
+
cursor: null
|
|
551
|
+
}
|
|
552
|
+
});
|
|
553
|
+
const out = [...first.page];
|
|
554
|
+
let cursor = first.continueCursor;
|
|
555
|
+
let done = first.isDone;
|
|
556
|
+
while (!done && out.length < SCIM_COLLECT_LIMIT) {
|
|
557
|
+
const next = await auth.group.list(ctx$1, {
|
|
558
|
+
where,
|
|
559
|
+
paginationOpts: {
|
|
560
|
+
numItems: 200,
|
|
561
|
+
cursor
|
|
562
|
+
}
|
|
563
|
+
});
|
|
564
|
+
out.push(...next.page);
|
|
565
|
+
done = next.isDone;
|
|
566
|
+
cursor = next.continueCursor;
|
|
567
|
+
}
|
|
568
|
+
if (!done) log("WARN", "[connection.scim] group list truncated at collect limit", {
|
|
569
|
+
parentGroupId: where.parentGroupId,
|
|
570
|
+
limit: SCIM_COLLECT_LIMIT
|
|
571
|
+
});
|
|
572
|
+
return out;
|
|
573
|
+
};
|
|
574
|
+
const userInConnectionScope = async (state$1, userId) => {
|
|
575
|
+
if (await getScimIdentityByConnectionAndUser(state$1.ctx, config.component.connection, {
|
|
576
|
+
connectionId: state$1.connection._id,
|
|
577
|
+
userId
|
|
578
|
+
})) return true;
|
|
579
|
+
return (await auth.member.list(state$1.ctx, {
|
|
580
|
+
where: {
|
|
581
|
+
groupId: state$1.connection.groupId,
|
|
582
|
+
userId
|
|
583
|
+
},
|
|
584
|
+
paginationOpts: {
|
|
585
|
+
numItems: 1,
|
|
586
|
+
cursor: null
|
|
587
|
+
}
|
|
588
|
+
})).page[0] !== void 0;
|
|
589
|
+
};
|
|
590
|
+
const firstInvalidScimMember = async (state$1, userIds) => {
|
|
591
|
+
for (const userId of userIds) if (!await auth.user.get(state$1.ctx, { id: userId }) || !await userInConnectionScope(state$1, userId)) return userId;
|
|
592
|
+
return null;
|
|
593
|
+
};
|
|
594
|
+
const handleUsersGet = async (state$1) => {
|
|
595
|
+
if (state$1.parsedPath.resourceId) {
|
|
596
|
+
const userId = state$1.parsedPath.resourceId;
|
|
597
|
+
const user = await auth.user.get(state$1.ctx, { id: userId });
|
|
598
|
+
const identity = await getScimIdentityByConnectionAndUser(state$1.ctx, config.component.connection, {
|
|
599
|
+
connectionId: state$1.connection._id,
|
|
600
|
+
userId
|
|
601
|
+
});
|
|
602
|
+
const membership = (await auth.member.list(state$1.ctx, {
|
|
603
|
+
where: {
|
|
604
|
+
groupId: state$1.connection.groupId,
|
|
605
|
+
userId
|
|
606
|
+
},
|
|
607
|
+
paginationOpts: {
|
|
608
|
+
numItems: 1,
|
|
609
|
+
cursor: null
|
|
610
|
+
}
|
|
611
|
+
})).page[0];
|
|
612
|
+
if (!user || !membership) return scimError(404, "notFound", "User not found.");
|
|
613
|
+
const typedUser = user;
|
|
614
|
+
await state$1.recordScimEvent("connection.scim.read", "success", {
|
|
615
|
+
type: "user",
|
|
616
|
+
id: typedUser._id
|
|
617
|
+
}, {
|
|
618
|
+
resourceType: "user",
|
|
619
|
+
resourceId: typedUser._id,
|
|
620
|
+
operation: "get"
|
|
621
|
+
});
|
|
622
|
+
const location = `${state$1.url.origin}${state$1.url.pathname.replace(/\/[^/]+$/, "")}/${typedUser._id}`;
|
|
623
|
+
return scimJson(serializeScimUser({
|
|
624
|
+
id: typedUser._id,
|
|
625
|
+
user: typedUser,
|
|
626
|
+
externalId: identity?.externalId,
|
|
627
|
+
location,
|
|
628
|
+
active: identity?.active ?? membership?.status === "active"
|
|
629
|
+
}), 200, { Location: location });
|
|
630
|
+
}
|
|
631
|
+
const members = { page: await collectMembers(state$1.ctx, { groupId: state$1.connection.groupId }) };
|
|
632
|
+
const identities = await listScimIdentitiesByConnection(state$1.ctx, config.component.connection, state$1.connection._id);
|
|
633
|
+
const identityByUserId = new Map(identities.filter((identity) => typeof identity.userId === "string").map((identity) => [identity.userId, identity]));
|
|
634
|
+
const users = (await Promise.all(members.page.map(async (member) => {
|
|
635
|
+
const user = await auth.user.get(state$1.ctx, { id: member.userId });
|
|
636
|
+
const typedUser = user;
|
|
637
|
+
return user ? {
|
|
638
|
+
user: typedUser,
|
|
639
|
+
member,
|
|
640
|
+
identity: identityByUserId.get(typedUser._id)
|
|
641
|
+
} : null;
|
|
642
|
+
}))).filter(Boolean);
|
|
643
|
+
const listRequest = parseScimListRequest(state$1.url);
|
|
644
|
+
const filtered = filterScimCollection(users, listRequest.filter, {
|
|
645
|
+
id: (item) => item.user._id,
|
|
646
|
+
externalId: (item) => item.identity?.externalId,
|
|
647
|
+
userName: (item) => item.user.email ?? item.user.phone ?? item.user.name ?? item.user._id,
|
|
648
|
+
displayName: (item) => item.user.name,
|
|
649
|
+
name: (item) => item.user.name,
|
|
650
|
+
"name.formatted": (item) => item.user.name,
|
|
651
|
+
"name.givenName": (item) => item.user.firstName,
|
|
652
|
+
"name.familyName": (item) => item.user.lastName,
|
|
653
|
+
"emails.value": (item) => item.user.email,
|
|
654
|
+
"phoneNumbers.value": (item) => item.user.phone,
|
|
655
|
+
active: (item) => item.identity?.active ?? item.member.status === "active"
|
|
656
|
+
});
|
|
657
|
+
const paged = paginateScimCollection(filtered, listRequest);
|
|
658
|
+
await state$1.recordScimEvent("connection.scim.read", "success", {
|
|
659
|
+
type: "connection",
|
|
660
|
+
id: state$1.connection._id
|
|
661
|
+
}, {
|
|
662
|
+
resourceType: "user",
|
|
663
|
+
operation: "list"
|
|
664
|
+
});
|
|
665
|
+
return scimJson({
|
|
666
|
+
schemas: ["urn:ietf:params:scim:api:messages:2.0:ListResponse"],
|
|
667
|
+
Resources: paged.map(({ user, identity, member }) => serializeScimUser({
|
|
668
|
+
id: user._id,
|
|
669
|
+
user,
|
|
670
|
+
externalId: identity?.externalId,
|
|
671
|
+
location: `${state$1.url.origin}${state$1.url.pathname}/${user._id}`,
|
|
672
|
+
active: identity?.active ?? member.status === "active"
|
|
673
|
+
})),
|
|
674
|
+
totalResults: filtered.length,
|
|
675
|
+
startIndex: listRequest.startIndex,
|
|
676
|
+
itemsPerPage: paged.length
|
|
677
|
+
});
|
|
678
|
+
};
|
|
679
|
+
const handleUsersPost = async (state$1) => {
|
|
680
|
+
const body = await readScimJson(state$1.request);
|
|
681
|
+
const extractedBase = extractScimProfile(state$1.scimConfig, body);
|
|
682
|
+
const extracted = await config.connection?.hooks?.profileResolved?.({
|
|
683
|
+
protocol: "scim",
|
|
684
|
+
connectionId: state$1.connection._id,
|
|
685
|
+
profile: extractedBase
|
|
686
|
+
}) ?? extractedBase;
|
|
687
|
+
const provisionProfile = await config.connection?.hooks?.beforeProvision?.({
|
|
688
|
+
protocol: "scim",
|
|
689
|
+
connectionId: state$1.connection._id,
|
|
690
|
+
profile: extracted
|
|
691
|
+
}) ?? extracted;
|
|
692
|
+
const externalId = provisionProfile.externalId;
|
|
693
|
+
const providerId = state$1.connection.protocol === "oidc" ? groupOidcProviderId(state$1.connection._id) : groupSamlProviderId(state$1.connection._id);
|
|
694
|
+
const provisionedRoleIds = resolveProvisionedRoleIds({
|
|
695
|
+
policy: state$1.policy,
|
|
696
|
+
groups: provisionProfile.groups,
|
|
697
|
+
roles: provisionProfile.roles
|
|
698
|
+
});
|
|
699
|
+
const userData = {
|
|
700
|
+
name: provisionProfile.name,
|
|
701
|
+
...typeof provisionProfile.firstName === "string" ? { firstName: provisionProfile.firstName } : {},
|
|
702
|
+
...typeof provisionProfile.lastName === "string" ? { lastName: provisionProfile.lastName } : {},
|
|
703
|
+
email: provisionProfile.email,
|
|
704
|
+
...typeof provisionProfile.email === "string" ? { emailVerificationTime: Date.now() } : {},
|
|
705
|
+
phone: provisionProfile.phone,
|
|
706
|
+
...typeof provisionProfile.phone === "string" ? { phoneVerificationTime: Date.now() } : {},
|
|
707
|
+
...provisionProfile.extend ? { extend: provisionProfile.extend } : {}
|
|
708
|
+
};
|
|
709
|
+
const { userId, created } = externalId ? await provisionScimUser(state$1.ctx, config.component.connection, {
|
|
710
|
+
connectionId: state$1.connection._id,
|
|
711
|
+
groupId: state$1.connection.groupId,
|
|
712
|
+
externalId,
|
|
713
|
+
provider: providerId,
|
|
714
|
+
userData,
|
|
715
|
+
active: provisionProfile.active !== false,
|
|
716
|
+
raw: body,
|
|
717
|
+
lastProvisionedAt: Date.now()
|
|
718
|
+
}) : {
|
|
719
|
+
userId: await insertUser(state$1.ctx, config.component.user, userData),
|
|
720
|
+
created: true
|
|
721
|
+
};
|
|
722
|
+
const existingUser = created ? null : await auth.user.get(state$1.ctx, { id: userId });
|
|
723
|
+
if (!created && existingUser === null) throw new ConvexError({
|
|
724
|
+
code: ErrorCode.ACCOUNT_NOT_FOUND,
|
|
725
|
+
message: "The SCIM identity references a user that no longer exists."
|
|
726
|
+
});
|
|
727
|
+
if (existingUser) {
|
|
728
|
+
const nextUserData = {
|
|
729
|
+
name: provisionProfile.name,
|
|
730
|
+
firstName: provisionProfile.firstName,
|
|
731
|
+
lastName: provisionProfile.lastName,
|
|
732
|
+
email: provisionProfile.email,
|
|
733
|
+
phone: provisionProfile.phone,
|
|
734
|
+
...provisionProfile.extend ? { extend: provisionProfile.extend } : {}
|
|
735
|
+
};
|
|
736
|
+
if (typeof provisionProfile.email === "string") nextUserData.emailVerificationTime = Date.now();
|
|
737
|
+
if (typeof provisionProfile.phone === "string") nextUserData.phoneVerificationTime = Date.now();
|
|
738
|
+
const patchData = applyUserProvisioningPatch({
|
|
739
|
+
currentUser: existingUser,
|
|
740
|
+
nextUser: nextUserData,
|
|
741
|
+
policy: state$1.policy.provisioning.user,
|
|
742
|
+
source: "scim"
|
|
743
|
+
});
|
|
744
|
+
if (Object.keys(patchData).length > 0) await updateUser(state$1.ctx, config.component.user, {
|
|
745
|
+
userId,
|
|
746
|
+
patch: patchData
|
|
747
|
+
});
|
|
748
|
+
}
|
|
749
|
+
const resolution = await auth.member.get(state$1.ctx, {
|
|
750
|
+
groupId: state$1.connection.groupId,
|
|
751
|
+
userId
|
|
752
|
+
});
|
|
753
|
+
if (resolution.membership) await auth.member.update(state$1.ctx, {
|
|
754
|
+
id: resolution.membership._id,
|
|
755
|
+
patch: { status: body.active === false ? "inactive" : "active" }
|
|
756
|
+
});
|
|
757
|
+
else await auth.member.create(state$1.ctx, { data: {
|
|
758
|
+
groupId: state$1.connection.groupId,
|
|
759
|
+
userId,
|
|
760
|
+
roleIds: provisionedRoleIds,
|
|
761
|
+
status: provisionProfile.active === false ? "inactive" : "active"
|
|
762
|
+
} });
|
|
763
|
+
await state$1.recordScimEvent(created ? "connection.scim.user.provisioned" : "connection.scim.user.updated", "success", {
|
|
764
|
+
type: "user",
|
|
765
|
+
id: userId
|
|
766
|
+
});
|
|
767
|
+
const createdUser = await auth.user.get(state$1.ctx, { id: userId });
|
|
768
|
+
await config.connection?.hooks?.afterProvision?.({
|
|
769
|
+
protocol: "scim",
|
|
770
|
+
connectionId: state$1.connection._id,
|
|
771
|
+
profile: provisionProfile,
|
|
772
|
+
userId
|
|
773
|
+
});
|
|
774
|
+
const location = `${state$1.url.origin}${state$1.url.pathname}/${userId}`;
|
|
775
|
+
return scimJson(serializeScimUser({
|
|
776
|
+
id: userId,
|
|
777
|
+
user: createdUser ?? {},
|
|
778
|
+
externalId,
|
|
779
|
+
location,
|
|
780
|
+
active: provisionProfile.active !== false
|
|
781
|
+
}), created ? 201 : 200, { Location: location });
|
|
782
|
+
};
|
|
783
|
+
const handleUsersUpsert = async (state$1) => {
|
|
784
|
+
const missing = requireScimResourceId(state$1.parsedPath.resourceId, "User");
|
|
785
|
+
if (missing) return missing;
|
|
786
|
+
const userId = state$1.parsedPath.resourceId;
|
|
787
|
+
const existingUser = await auth.user.get(state$1.ctx, { id: userId });
|
|
788
|
+
if (!existingUser) return scimError(404, "notFound", "User not found.");
|
|
789
|
+
const existingIdentity = await getScimIdentityByConnectionAndUser(state$1.ctx, config.component.connection, {
|
|
790
|
+
connectionId: state$1.connection._id,
|
|
791
|
+
userId
|
|
792
|
+
});
|
|
793
|
+
const existingMembership = await auth.member.get(state$1.ctx, {
|
|
794
|
+
groupId: state$1.connection.groupId,
|
|
795
|
+
userId
|
|
796
|
+
});
|
|
797
|
+
if (!existingIdentity && !existingMembership.membership) return scimError(404, "notFound", "User not found.");
|
|
798
|
+
const body = await readScimJson(state$1.request);
|
|
799
|
+
const extractedBase = extractScimProfile(state$1.scimConfig, body);
|
|
800
|
+
const extracted = await config.connection?.hooks?.profileResolved?.({
|
|
801
|
+
protocol: "scim",
|
|
802
|
+
connectionId: state$1.connection._id,
|
|
803
|
+
profile: extractedBase
|
|
804
|
+
}) ?? extractedBase;
|
|
805
|
+
const provisionProfile = await config.connection?.hooks?.beforeProvision?.({
|
|
806
|
+
protocol: "scim",
|
|
807
|
+
connectionId: state$1.connection._id,
|
|
808
|
+
profile: extracted
|
|
809
|
+
}) ?? extracted;
|
|
810
|
+
const externalId = provisionProfile.externalId;
|
|
811
|
+
const patchData = {};
|
|
812
|
+
let nextActive;
|
|
813
|
+
if (state$1.request.method === "PUT") {
|
|
814
|
+
patchData.name = provisionProfile.name;
|
|
815
|
+
patchData.firstName = provisionProfile.firstName;
|
|
816
|
+
patchData.lastName = provisionProfile.lastName;
|
|
817
|
+
patchData.email = provisionProfile.email;
|
|
818
|
+
patchData.phone = provisionProfile.phone;
|
|
819
|
+
if (provisionProfile.extend) patchData.extend = provisionProfile.extend;
|
|
820
|
+
if (typeof patchData.email === "string") patchData.emailVerificationTime = Date.now();
|
|
821
|
+
if (typeof patchData.phone === "string") patchData.phoneVerificationTime = Date.now();
|
|
822
|
+
} else {
|
|
823
|
+
const operations = Array.isArray(body.Operations) ? body.Operations : unsupportedScimPatch();
|
|
824
|
+
for (const operation of operations) {
|
|
825
|
+
const op = typeof operation.op === "string" ? operation.op.toLowerCase() : "replace";
|
|
826
|
+
if (op !== "replace" && op !== "add") unsupportedScimPatch();
|
|
827
|
+
if (operation.path === void 0 && typeof operation.value === "object" && operation.value !== null) {
|
|
828
|
+
const value = operation.value;
|
|
829
|
+
if (typeof value.active === "boolean") nextActive = value.active;
|
|
830
|
+
if (typeof value.displayName === "string") patchData.name = value.displayName;
|
|
831
|
+
if (typeof value.userName === "string") {
|
|
832
|
+
patchData.email = value.userName;
|
|
833
|
+
patchData.emailVerificationTime = Date.now();
|
|
834
|
+
}
|
|
835
|
+
continue;
|
|
836
|
+
}
|
|
837
|
+
if (operation.path === "active") {
|
|
838
|
+
nextActive = typeof operation.value === "boolean" ? operation.value : void 0;
|
|
839
|
+
continue;
|
|
840
|
+
}
|
|
841
|
+
if (operation.path === "displayName" || operation.path === "name.formatted") {
|
|
842
|
+
patchData.name = operation.value;
|
|
843
|
+
continue;
|
|
844
|
+
}
|
|
845
|
+
if (operation.path === "name.givenName") {
|
|
846
|
+
patchData.firstName = operation.value;
|
|
847
|
+
continue;
|
|
848
|
+
}
|
|
849
|
+
if (operation.path === "name.familyName") {
|
|
850
|
+
patchData.lastName = operation.value;
|
|
851
|
+
continue;
|
|
852
|
+
}
|
|
853
|
+
if (operation.path === "userName" || operation.path === "emails.value") {
|
|
854
|
+
patchData.email = operation.value;
|
|
855
|
+
if (typeof operation.value === "string") patchData.emailVerificationTime = Date.now();
|
|
856
|
+
continue;
|
|
857
|
+
}
|
|
858
|
+
if (operation.path === "phoneNumbers.value") {
|
|
859
|
+
patchData.phone = operation.value;
|
|
860
|
+
if (typeof operation.value === "string") patchData.phoneVerificationTime = Date.now();
|
|
861
|
+
continue;
|
|
862
|
+
}
|
|
863
|
+
unsupportedScimPatch();
|
|
864
|
+
}
|
|
865
|
+
}
|
|
866
|
+
const nextPatchData = applyUserProvisioningPatch({
|
|
867
|
+
currentUser: existingUser,
|
|
868
|
+
nextUser: patchData,
|
|
869
|
+
policy: state$1.policy.provisioning.user,
|
|
870
|
+
source: "scim"
|
|
871
|
+
});
|
|
872
|
+
if (Object.keys(nextPatchData).length > 0) await updateUser(state$1.ctx, config.component.user, {
|
|
873
|
+
userId,
|
|
874
|
+
patch: nextPatchData
|
|
875
|
+
});
|
|
876
|
+
const resolution = existingMembership;
|
|
877
|
+
if (resolution.membership) await auth.member.update(state$1.ctx, {
|
|
878
|
+
id: resolution.membership._id,
|
|
879
|
+
patch: {
|
|
880
|
+
roleIds: resolveProvisionedRoleIds({
|
|
881
|
+
policy: state$1.policy,
|
|
882
|
+
groups: provisionProfile.groups,
|
|
883
|
+
roles: provisionProfile.roles
|
|
884
|
+
}),
|
|
885
|
+
status: provisionProfile.active === false || nextActive === false ? "inactive" : "active"
|
|
886
|
+
}
|
|
887
|
+
});
|
|
888
|
+
await upsertScimIdentity(state$1.ctx, config.component.connection, {
|
|
889
|
+
connectionId: state$1.connection._id,
|
|
890
|
+
groupId: state$1.connection.groupId,
|
|
891
|
+
resourceType: "user",
|
|
892
|
+
externalId: externalId ?? existingIdentity?.externalId ?? userId,
|
|
893
|
+
userId,
|
|
894
|
+
active: provisionProfile.active !== false && nextActive !== false,
|
|
895
|
+
raw: body,
|
|
896
|
+
lastProvisionedAt: Date.now()
|
|
897
|
+
});
|
|
898
|
+
await state$1.recordScimEvent("connection.scim.user.updated", "success", {
|
|
899
|
+
type: "user",
|
|
900
|
+
id: userId
|
|
901
|
+
});
|
|
902
|
+
const updatedUser = await auth.user.get(state$1.ctx, { id: userId });
|
|
903
|
+
await config.connection?.hooks?.afterProvision?.({
|
|
904
|
+
protocol: "scim",
|
|
905
|
+
connectionId: state$1.connection._id,
|
|
906
|
+
profile: provisionProfile,
|
|
907
|
+
userId
|
|
908
|
+
});
|
|
909
|
+
const location = `${state$1.url.origin}${state$1.url.pathname}`;
|
|
910
|
+
return scimJson(serializeScimUser({
|
|
911
|
+
id: userId,
|
|
912
|
+
user: updatedUser ?? existingUser,
|
|
913
|
+
externalId,
|
|
914
|
+
location,
|
|
915
|
+
active: provisionProfile.active !== false && nextActive !== false
|
|
916
|
+
}), 200, { Location: location });
|
|
917
|
+
};
|
|
918
|
+
const handleUsersDelete = async (state$1) => {
|
|
919
|
+
const missing = requireScimResourceId(state$1.parsedPath.resourceId, "User");
|
|
920
|
+
if (missing) return missing;
|
|
921
|
+
const userId = state$1.parsedPath.resourceId;
|
|
922
|
+
const identity = await getScimIdentityByConnectionAndUser(state$1.ctx, config.component.connection, {
|
|
923
|
+
connectionId: state$1.connection._id,
|
|
924
|
+
userId
|
|
925
|
+
});
|
|
926
|
+
if (!identity) return scimError(404, "notFound", "User not found.");
|
|
927
|
+
const resolution = await auth.member.get(state$1.ctx, {
|
|
928
|
+
groupId: state$1.connection.groupId,
|
|
929
|
+
userId
|
|
930
|
+
});
|
|
931
|
+
if (resolution.membership) await auth.member.remove(state$1.ctx, { id: resolution.membership._id });
|
|
932
|
+
const { revoked } = await state$1.ctx.runMutation(config.component.session.revokeForUser, { userId });
|
|
933
|
+
if (revoked > 0) await state$1.recordScimEvent("session.invalidated", "success", {
|
|
934
|
+
type: "user",
|
|
935
|
+
id: userId
|
|
936
|
+
}, {
|
|
937
|
+
userId,
|
|
938
|
+
reason: "connection_deprovision"
|
|
939
|
+
});
|
|
940
|
+
if (state$1.policy.provisioning.deprovision.mode === "hard") await removeScimIdentity(state$1.ctx, config.component.connection, identity._id);
|
|
941
|
+
else await upsertScimIdentity(state$1.ctx, config.component.connection, {
|
|
942
|
+
connectionId: identity.connectionId,
|
|
943
|
+
groupId: identity.groupId,
|
|
944
|
+
resourceType: identity.resourceType,
|
|
945
|
+
externalId: identity.externalId,
|
|
946
|
+
userId: identity.userId,
|
|
947
|
+
mappedGroupId: identity.mappedGroupId,
|
|
948
|
+
active: false,
|
|
949
|
+
raw: identity.raw,
|
|
950
|
+
lastProvisionedAt: Date.now()
|
|
951
|
+
});
|
|
952
|
+
await state$1.recordScimEvent("connection.scim.user.deactivated", "success", {
|
|
953
|
+
type: "user",
|
|
954
|
+
id: userId
|
|
955
|
+
});
|
|
956
|
+
return new Response(null, { status: 204 });
|
|
957
|
+
};
|
|
958
|
+
const handleGroupsGet = async (state$1) => {
|
|
959
|
+
if (state$1.parsedPath.resourceId) {
|
|
960
|
+
const groupId = state$1.parsedPath.resourceId;
|
|
961
|
+
const group = await auth.group.get(state$1.ctx, { id: groupId });
|
|
962
|
+
if (!group || group.parentGroupId !== state$1.connection.groupId) return scimError(404, "notFound", "Group not found.");
|
|
963
|
+
const identity = await getScimIdentityByMappedGroup(state$1.ctx, config.component.connection, groupId);
|
|
964
|
+
const scopedIdentity = identity && identity.connectionId === state$1.connection._id ? identity : void 0;
|
|
965
|
+
const members = (await collectMembers(state$1.ctx, {
|
|
966
|
+
groupId: group._id,
|
|
967
|
+
status: "active"
|
|
968
|
+
})).map((member) => ({ value: member.userId }));
|
|
969
|
+
const location = `${state$1.url.origin}${state$1.url.pathname.replace(/\/[^/]+$/, "")}/${group._id}`;
|
|
970
|
+
await state$1.recordScimEvent("connection.scim.read", "success", {
|
|
971
|
+
type: "group",
|
|
972
|
+
id: group._id
|
|
973
|
+
}, {
|
|
974
|
+
resourceType: "group",
|
|
975
|
+
resourceId: group._id,
|
|
976
|
+
operation: "get"
|
|
977
|
+
});
|
|
978
|
+
return scimJson(serializeScimGroup({
|
|
979
|
+
id: group._id,
|
|
980
|
+
group,
|
|
981
|
+
externalId: scopedIdentity?.externalId,
|
|
982
|
+
location,
|
|
983
|
+
members
|
|
984
|
+
}), 200, { Location: location });
|
|
985
|
+
}
|
|
986
|
+
const groupsList = { page: await collectGroups(state$1.ctx, { parentGroupId: state$1.connection.groupId }) };
|
|
987
|
+
const identities = await listScimIdentitiesByConnection(state$1.ctx, config.component.connection, state$1.connection._id);
|
|
988
|
+
const identityByGroupId = new Map(identities.filter((identity) => typeof identity.mappedGroupId === "string").map((identity) => [identity.mappedGroupId, identity]));
|
|
989
|
+
const groups = await Promise.all(groupsList.page.map(async (group) => {
|
|
990
|
+
const typedGroup = group;
|
|
991
|
+
const members = await collectMembers(state$1.ctx, {
|
|
992
|
+
groupId: typedGroup._id,
|
|
993
|
+
status: "active"
|
|
994
|
+
});
|
|
995
|
+
return {
|
|
996
|
+
group: typedGroup,
|
|
997
|
+
identity: identityByGroupId.get(typedGroup._id),
|
|
998
|
+
memberIds: members.map((member) => member.userId)
|
|
999
|
+
};
|
|
1000
|
+
}));
|
|
1001
|
+
const listRequest = parseScimListRequest(state$1.url);
|
|
1002
|
+
const filtered = filterScimCollection(groups, listRequest.filter, {
|
|
1003
|
+
id: (item) => item.group._id,
|
|
1004
|
+
externalId: (item) => item.identity?.externalId,
|
|
1005
|
+
displayName: (item) => item.group.name,
|
|
1006
|
+
"members.value": (item) => item.memberIds
|
|
1007
|
+
});
|
|
1008
|
+
const paged = paginateScimCollection(filtered, listRequest);
|
|
1009
|
+
await state$1.recordScimEvent("connection.scim.read", "success", {
|
|
1010
|
+
type: "connection",
|
|
1011
|
+
id: state$1.connection._id
|
|
1012
|
+
}, {
|
|
1013
|
+
resourceType: "group",
|
|
1014
|
+
operation: "list"
|
|
1015
|
+
});
|
|
1016
|
+
return scimJson({
|
|
1017
|
+
schemas: ["urn:ietf:params:scim:api:messages:2.0:ListResponse"],
|
|
1018
|
+
Resources: paged.map(({ group, identity }) => serializeScimGroup({
|
|
1019
|
+
id: group._id,
|
|
1020
|
+
group,
|
|
1021
|
+
externalId: identity?.externalId,
|
|
1022
|
+
location: `${state$1.url.origin}${state$1.url.pathname}/${group._id}`
|
|
1023
|
+
})),
|
|
1024
|
+
totalResults: filtered.length,
|
|
1025
|
+
startIndex: listRequest.startIndex,
|
|
1026
|
+
itemsPerPage: paged.length
|
|
1027
|
+
});
|
|
1028
|
+
};
|
|
1029
|
+
const handleGroupsPost = async (state$1) => {
|
|
1030
|
+
const body = await readScimJson(state$1.request);
|
|
1031
|
+
const externalId = typeof body.externalId === "string" ? body.externalId : void 0;
|
|
1032
|
+
const existingIdentity = externalId ? await getScimIdentity(state$1.ctx, config.component.connection, {
|
|
1033
|
+
connectionId: state$1.connection._id,
|
|
1034
|
+
resourceType: "group",
|
|
1035
|
+
externalId
|
|
1036
|
+
}) : null;
|
|
1037
|
+
const existingGroup = existingIdentity?.mappedGroupId ? await auth.group.get(state$1.ctx, { id: existingIdentity.mappedGroupId }) : null;
|
|
1038
|
+
const created = existingGroup === null;
|
|
1039
|
+
const provisionedRoleIds = resolveProvisionedRoleIds({
|
|
1040
|
+
policy: state$1.policy,
|
|
1041
|
+
groups: typeof body.displayName === "string" ? [body.displayName] : void 0,
|
|
1042
|
+
roles: pickStringArray(body.roles)
|
|
1043
|
+
});
|
|
1044
|
+
const groupId = existingGroup?._id ? existingGroup._id : await auth.group.create(state$1.ctx, { data: {
|
|
1045
|
+
name: typeof body.displayName === "string" ? body.displayName : "Group",
|
|
1046
|
+
parentGroupId: state$1.connection.groupId,
|
|
1047
|
+
type: "organization"
|
|
1048
|
+
} });
|
|
1049
|
+
if (!created && existingGroup) {
|
|
1050
|
+
const location$1 = `${state$1.url.origin}${state$1.url.pathname}/${groupId}`;
|
|
1051
|
+
return scimJson(serializeScimGroup({
|
|
1052
|
+
id: groupId,
|
|
1053
|
+
group: existingGroup,
|
|
1054
|
+
externalId,
|
|
1055
|
+
location: location$1,
|
|
1056
|
+
members: (await collectMembers(state$1.ctx, {
|
|
1057
|
+
groupId,
|
|
1058
|
+
status: "active"
|
|
1059
|
+
})).map((member) => ({ value: member.userId }))
|
|
1060
|
+
}), 200, { Location: location$1 });
|
|
1061
|
+
}
|
|
1062
|
+
await upsertScimIdentity(state$1.ctx, config.component.connection, {
|
|
1063
|
+
connectionId: state$1.connection._id,
|
|
1064
|
+
groupId: state$1.connection.groupId,
|
|
1065
|
+
resourceType: "group",
|
|
1066
|
+
externalId: externalId ?? groupId,
|
|
1067
|
+
mappedGroupId: groupId,
|
|
1068
|
+
active: true,
|
|
1069
|
+
raw: body,
|
|
1070
|
+
lastProvisionedAt: Date.now()
|
|
1071
|
+
});
|
|
1072
|
+
const currentMembers = await collectMembersForReplace(state$1.ctx, {
|
|
1073
|
+
groupId,
|
|
1074
|
+
status: "active"
|
|
1075
|
+
});
|
|
1076
|
+
const currentByUserId = new Map(currentMembers.map((member) => [member.userId, member]));
|
|
1077
|
+
const nextUserIds = new Set((Array.isArray(body.members) ? body.members : []).map((member) => String(member.value)));
|
|
1078
|
+
const toAddUserIds = [...nextUserIds].filter((userId) => !currentByUserId.has(userId));
|
|
1079
|
+
const invalidMember = await firstInvalidScimMember(state$1, toAddUserIds);
|
|
1080
|
+
if (invalidMember !== null) return scimError(400, "invalidValue", `Group member user not found: ${invalidMember}`);
|
|
1081
|
+
for (const member of currentMembers) if (!nextUserIds.has(member.userId)) await auth.member.remove(state$1.ctx, { id: member._id });
|
|
1082
|
+
for (const userId of toAddUserIds) await auth.member.create(state$1.ctx, { data: {
|
|
1083
|
+
groupId,
|
|
1084
|
+
userId,
|
|
1085
|
+
roleIds: provisionedRoleIds,
|
|
1086
|
+
status: "active"
|
|
1087
|
+
} });
|
|
1088
|
+
await state$1.recordScimEvent(created ? "connection.scim.group.provisioned" : "connection.scim.group.updated", "success", {
|
|
1089
|
+
type: "group",
|
|
1090
|
+
id: groupId
|
|
1091
|
+
});
|
|
1092
|
+
const group = await auth.group.get(state$1.ctx, { id: groupId });
|
|
1093
|
+
const location = `${state$1.url.origin}${state$1.url.pathname}/${groupId}`;
|
|
1094
|
+
return scimJson(serializeScimGroup({
|
|
1095
|
+
id: groupId,
|
|
1096
|
+
group: group ?? {},
|
|
1097
|
+
externalId,
|
|
1098
|
+
location,
|
|
1099
|
+
members: (await collectMembers(state$1.ctx, {
|
|
1100
|
+
groupId,
|
|
1101
|
+
status: "active"
|
|
1102
|
+
})).map((member) => ({ value: member.userId }))
|
|
1103
|
+
}), created ? 201 : 200, { Location: location });
|
|
1104
|
+
};
|
|
1105
|
+
const handleGroupsPatch = async (state$1) => {
|
|
1106
|
+
const missing = requireScimResourceId(state$1.parsedPath.resourceId, "Group");
|
|
1107
|
+
if (missing) return missing;
|
|
1108
|
+
const groupId = state$1.parsedPath.resourceId;
|
|
1109
|
+
const identity = await getScimIdentityByMappedGroup(state$1.ctx, config.component.connection, groupId);
|
|
1110
|
+
if (!identity || identity.connectionId !== state$1.connection._id) return scimError(404, "notFound", "Group not found.");
|
|
1111
|
+
const body = await readScimJson(state$1.request);
|
|
1112
|
+
const operations = Array.isArray(body.Operations) ? body.Operations : unsupportedScimPatch();
|
|
1113
|
+
for (const operation of operations) {
|
|
1114
|
+
const op = typeof operation.op === "string" ? operation.op.toLowerCase() : "replace";
|
|
1115
|
+
if (operation.path === void 0 && op === "replace" && typeof operation.value === "object" && operation.value !== null) {
|
|
1116
|
+
const value = operation.value;
|
|
1117
|
+
if (typeof value.displayName === "string") await auth.group.update(state$1.ctx, {
|
|
1118
|
+
id: groupId,
|
|
1119
|
+
patch: { name: value.displayName }
|
|
1120
|
+
});
|
|
1121
|
+
continue;
|
|
1122
|
+
}
|
|
1123
|
+
if (operation.path === "displayName") {
|
|
1124
|
+
if (op !== "replace" && op !== "add") unsupportedScimPatch();
|
|
1125
|
+
await auth.group.update(state$1.ctx, {
|
|
1126
|
+
id: groupId,
|
|
1127
|
+
patch: { name: operation.value }
|
|
1128
|
+
});
|
|
1129
|
+
continue;
|
|
1130
|
+
}
|
|
1131
|
+
if (operation.path === "members" && op === "add") {
|
|
1132
|
+
const addUserIds = (Array.isArray(operation.value) ? operation.value : []).map((member) => String(member.value));
|
|
1133
|
+
const invalidMember = await firstInvalidScimMember(state$1, addUserIds);
|
|
1134
|
+
if (invalidMember !== null) return scimError(400, "invalidValue", `Group member user not found: ${invalidMember}`);
|
|
1135
|
+
for (const userId of addUserIds) if (!(await auth.member.get(state$1.ctx, {
|
|
1136
|
+
groupId,
|
|
1137
|
+
userId
|
|
1138
|
+
})).membership) await auth.member.create(state$1.ctx, { data: {
|
|
1139
|
+
groupId,
|
|
1140
|
+
userId,
|
|
1141
|
+
roleIds: resolveProvisionedRoleIds({
|
|
1142
|
+
policy: state$1.policy,
|
|
1143
|
+
groups: typeof body.displayName === "string" ? [body.displayName] : void 0,
|
|
1144
|
+
roles: pickStringArray(body.roles)
|
|
1145
|
+
}),
|
|
1146
|
+
status: "active"
|
|
1147
|
+
} });
|
|
1148
|
+
continue;
|
|
1149
|
+
}
|
|
1150
|
+
if (operation.path === "members" && op === "replace") {
|
|
1151
|
+
const currentMembers = await collectMembersForReplace(state$1.ctx, {
|
|
1152
|
+
groupId,
|
|
1153
|
+
status: "active"
|
|
1154
|
+
});
|
|
1155
|
+
const currentUserIds = new Set(currentMembers.map((member) => member.userId));
|
|
1156
|
+
const nextUserIds = new Set((Array.isArray(operation.value) ? operation.value : []).map((member) => String(member.value)));
|
|
1157
|
+
const toAddUserIds = [...nextUserIds].filter((userId) => !currentUserIds.has(userId));
|
|
1158
|
+
const invalidMember = await firstInvalidScimMember(state$1, toAddUserIds);
|
|
1159
|
+
if (invalidMember !== null) return scimError(400, "invalidValue", `Group member user not found: ${invalidMember}`);
|
|
1160
|
+
for (const member of currentMembers) if (!nextUserIds.has(member.userId)) await auth.member.remove(state$1.ctx, { id: member._id });
|
|
1161
|
+
for (const userId of toAddUserIds) await auth.member.create(state$1.ctx, { data: {
|
|
1162
|
+
groupId,
|
|
1163
|
+
userId,
|
|
1164
|
+
roleIds: resolveProvisionedRoleIds({
|
|
1165
|
+
policy: state$1.policy,
|
|
1166
|
+
groups: typeof body.displayName === "string" ? [body.displayName] : void 0,
|
|
1167
|
+
roles: pickStringArray(body.roles)
|
|
1168
|
+
}),
|
|
1169
|
+
status: "active"
|
|
1170
|
+
} });
|
|
1171
|
+
continue;
|
|
1172
|
+
}
|
|
1173
|
+
if (typeof operation.path === "string" && op === "remove" && operation.path.startsWith("members[")) {
|
|
1174
|
+
const userId = operation.path.match(/^members\[value eq "([^"]+)"\]$/)?.[1];
|
|
1175
|
+
if (userId) {
|
|
1176
|
+
const resolution = await auth.member.get(state$1.ctx, {
|
|
1177
|
+
groupId,
|
|
1178
|
+
userId
|
|
1179
|
+
});
|
|
1180
|
+
if (resolution.membership) await auth.member.remove(state$1.ctx, { id: resolution.membership._id });
|
|
1181
|
+
}
|
|
1182
|
+
continue;
|
|
1183
|
+
}
|
|
1184
|
+
unsupportedScimPatch();
|
|
1185
|
+
}
|
|
1186
|
+
await state$1.recordScimEvent("connection.scim.group.updated", "success", {
|
|
1187
|
+
type: "group",
|
|
1188
|
+
id: groupId
|
|
1189
|
+
});
|
|
1190
|
+
const group = await auth.group.get(state$1.ctx, { id: groupId });
|
|
1191
|
+
const location = `${state$1.url.origin}${state$1.url.pathname}`;
|
|
1192
|
+
const members = await collectMembers(state$1.ctx, {
|
|
1193
|
+
groupId,
|
|
1194
|
+
status: "active"
|
|
1195
|
+
});
|
|
1196
|
+
return scimJson(serializeScimGroup({
|
|
1197
|
+
id: groupId,
|
|
1198
|
+
group: group ?? {},
|
|
1199
|
+
location,
|
|
1200
|
+
members: members.map((member) => ({ value: member.userId }))
|
|
1201
|
+
}), 200, { Location: location });
|
|
1202
|
+
};
|
|
1203
|
+
const handleGroupsDelete = async (state$1) => {
|
|
1204
|
+
const missing = requireScimResourceId(state$1.parsedPath.resourceId, "Group");
|
|
1205
|
+
if (missing) return missing;
|
|
1206
|
+
const groupId = state$1.parsedPath.resourceId;
|
|
1207
|
+
const identity = await getScimIdentityByMappedGroup(state$1.ctx, config.component.connection, groupId);
|
|
1208
|
+
if (!identity || identity.connectionId !== state$1.connection._id) return scimError(404, "notFound", "Group not found.");
|
|
1209
|
+
await auth.group.remove(state$1.ctx, { id: groupId });
|
|
1210
|
+
await removeScimIdentity(state$1.ctx, config.component.connection, identity._id);
|
|
1211
|
+
await state$1.recordScimEvent("connection.scim.group.deactivated", "success", {
|
|
1212
|
+
type: "group",
|
|
1213
|
+
id: groupId
|
|
1214
|
+
});
|
|
1215
|
+
return new Response(null, { status: 204 });
|
|
1216
|
+
};
|
|
1217
|
+
const handler = {
|
|
1218
|
+
ServiceProviderConfig: { GET: async () => scimJson({
|
|
1219
|
+
schemas: ["urn:ietf:params:scim:schemas:core:2.0:ServiceProviderConfig"],
|
|
1220
|
+
patch: { supported: true },
|
|
1221
|
+
bulk: {
|
|
1222
|
+
supported: false,
|
|
1223
|
+
maxOperations: 0,
|
|
1224
|
+
maxPayloadSize: 0
|
|
1225
|
+
},
|
|
1226
|
+
filter: {
|
|
1227
|
+
supported: true,
|
|
1228
|
+
maxResults: 100
|
|
1229
|
+
},
|
|
1230
|
+
changePassword: { supported: false },
|
|
1231
|
+
sort: { supported: false },
|
|
1232
|
+
etag: { supported: false },
|
|
1233
|
+
authenticationSchemes: [{
|
|
1234
|
+
type: "oauthbearertoken",
|
|
1235
|
+
name: "Bearer Token",
|
|
1236
|
+
description: "Use the SCIM token generated by Convex Auth connection."
|
|
1237
|
+
}]
|
|
1238
|
+
}) },
|
|
1239
|
+
Schemas: { GET: async (state$1) => handleStaticScimCollection(SCIM_SCHEMAS, state$1.parsedPath.resourceId, {
|
|
1240
|
+
by: "id",
|
|
1241
|
+
notFound: "Schema not found."
|
|
1242
|
+
}) },
|
|
1243
|
+
ResourceTypes: { GET: async (state$1) => handleStaticScimCollection(SCIM_RESOURCE_TYPES, state$1.parsedPath.resourceId, {
|
|
1244
|
+
by: "name",
|
|
1245
|
+
notFound: "Resource type not found."
|
|
1246
|
+
}) },
|
|
1247
|
+
Users: {
|
|
1248
|
+
GET: handleUsersGet,
|
|
1249
|
+
POST: handleUsersPost,
|
|
1250
|
+
PATCH: handleUsersUpsert,
|
|
1251
|
+
PUT: handleUsersUpsert,
|
|
1252
|
+
DELETE: handleUsersDelete
|
|
1253
|
+
},
|
|
1254
|
+
Groups: {
|
|
1255
|
+
GET: handleGroupsGet,
|
|
1256
|
+
POST: handleGroupsPost,
|
|
1257
|
+
PATCH: handleGroupsPatch,
|
|
1258
|
+
DELETE: handleGroupsDelete
|
|
1259
|
+
}
|
|
1260
|
+
}[state.parsedPath.resource]?.[state.request.method];
|
|
1261
|
+
return handler ? await handler(state) : scimError(404, "notFound", "SCIM resource not found.");
|
|
1262
|
+
} catch (error) {
|
|
1263
|
+
if (error instanceof Error && error.message === "Unsupported SCIM filter.") return scimError(400, "invalidFilter", error.message);
|
|
1264
|
+
if (error instanceof Error && error.message === "Invalid SCIM pagination.") return scimError(400, "invalidValue", error.message);
|
|
1265
|
+
if (error instanceof Error && error.message === "Invalid SCIM JSON.") return scimError(400, "invalidSyntax", error.message);
|
|
1266
|
+
if (error instanceof Error && error.message === "Unsupported SCIM content type.") return scimError(415, "invalidSyntax", error.message);
|
|
1267
|
+
if (error instanceof Error && error.message === "Unsupported SCIM PATCH operation.") return scimError(400, "invalidSyntax", error.message);
|
|
1268
|
+
if (error instanceof Error && error.message === "SCIM member set too large to reconcile.") return scimError(413, "tooLarge", error.message);
|
|
1269
|
+
if (error instanceof ConvexError && typeof error.data === "object" && error.data !== null && "code" in error.data && "message" in error.data) {
|
|
1270
|
+
const code = error.data.code;
|
|
1271
|
+
const status = code === "MISSING_BEARER_TOKEN" || code === "INVALID_API_KEY" ? 401 : 400;
|
|
1272
|
+
const response = scimError(status, status === 401 ? "invalidValue" : code, error.data.message);
|
|
1273
|
+
if (status === 401) response.headers.set("WWW-Authenticate", "Bearer");
|
|
1274
|
+
return response;
|
|
1275
|
+
}
|
|
1276
|
+
log("WARN", "[connection.scim] unhandled error surfaced as SCIM 500", { error: error instanceof Error ? error.message : String(error) });
|
|
1277
|
+
return scimError(500, "internalError", "SCIM request failed.");
|
|
1278
|
+
}
|
|
1279
|
+
};
|
|
1280
|
+
const handleOidcCallbackForConnection = async (ctx, request, connectionId) => {
|
|
1281
|
+
const params = await getOidcCallbackParams(request);
|
|
1282
|
+
const { connection, oidc } = await loadConnectionOidcOrThrow(ctx, connectionId);
|
|
1283
|
+
const { providerId, provider, oauthConfig } = await createGroupConnectionOidcRuntime({
|
|
1284
|
+
ctx,
|
|
1285
|
+
componentConnection: config.component.connection,
|
|
1286
|
+
rootUrl: requireEnv("CONVEX_SITE_URL"),
|
|
1287
|
+
connectionId: connection._id,
|
|
1288
|
+
oidc,
|
|
1289
|
+
sharedRedirectURI: sharedOidcRedirectURI
|
|
1290
|
+
});
|
|
1291
|
+
const cookies = getCookies(request);
|
|
1292
|
+
const maybeRedirectTo = useRedirectToParam(providerId, cookies);
|
|
1293
|
+
const destinationUrl = await redirectAbsoluteUrl(ctx, config, { redirectTo: maybeRedirectTo?.redirectTo });
|
|
1294
|
+
let result;
|
|
1295
|
+
try {
|
|
1296
|
+
result = await handleOAuthCallback(providerId, {
|
|
1297
|
+
...oauthConfig,
|
|
1298
|
+
provider
|
|
1299
|
+
}, Object.fromEntries(params.entries()), cookies);
|
|
1300
|
+
} catch (error) {
|
|
1301
|
+
await recordConnectionLoginEvent(ctx, {
|
|
1302
|
+
connection,
|
|
1303
|
+
protocol: "oidc",
|
|
1304
|
+
outcome: "failure",
|
|
1305
|
+
error
|
|
1306
|
+
});
|
|
1307
|
+
throw error;
|
|
1308
|
+
}
|
|
1309
|
+
const extraFields = typeof oidc.profile === "object" && oidc.profile !== null ? oidc.profile.extraFields : void 0;
|
|
1310
|
+
let profile = result.profile;
|
|
1311
|
+
if (extraFields && typeof profile === "object" && profile) {
|
|
1312
|
+
const extend = {};
|
|
1313
|
+
for (const [claimName, fieldName] of Object.entries(extraFields)) if (claimName in profile) extend[fieldName] = profile[claimName];
|
|
1314
|
+
if (Object.keys(extend).length > 0) profile = {
|
|
1315
|
+
...profile,
|
|
1316
|
+
extend
|
|
1317
|
+
};
|
|
1318
|
+
}
|
|
1319
|
+
let verificationCode;
|
|
1320
|
+
try {
|
|
1321
|
+
verificationCode = await callUserOAuth(ctx, {
|
|
1322
|
+
provider: providerId,
|
|
1323
|
+
providerAccountId: result.providerAccountId,
|
|
1324
|
+
profile,
|
|
1325
|
+
signature: result.signature,
|
|
1326
|
+
accountExtend: { identity: {
|
|
1327
|
+
protocol: "oidc",
|
|
1328
|
+
connectionId: connection._id,
|
|
1329
|
+
subject: result.providerAccountId,
|
|
1330
|
+
issuer: typeof oidc.discovery?.issuer === "string" ? oidc.discovery.issuer : void 0,
|
|
1331
|
+
discoveryUrl: typeof oidc.discovery?.discoveryUrl === "string" ? oidc.discovery.discoveryUrl : void 0
|
|
1332
|
+
} }
|
|
1333
|
+
});
|
|
1334
|
+
} catch (error) {
|
|
1335
|
+
await recordConnectionLoginEvent(ctx, {
|
|
1336
|
+
connection,
|
|
1337
|
+
protocol: "oidc",
|
|
1338
|
+
outcome: "failure",
|
|
1339
|
+
error
|
|
1340
|
+
});
|
|
1341
|
+
throw error;
|
|
1342
|
+
}
|
|
1343
|
+
await recordConnectionLoginEvent(ctx, {
|
|
1344
|
+
connection,
|
|
1345
|
+
protocol: "oidc",
|
|
1346
|
+
outcome: "success"
|
|
1347
|
+
});
|
|
1348
|
+
const headers = new Headers({ Location: setURLSearchParam(destinationUrl, "code", verificationCode) });
|
|
1349
|
+
for (const { name, value, options } of result.cookies) headers.append("Set-Cookie", serialize(name, value, options));
|
|
1350
|
+
if (maybeRedirectTo) headers.append("Set-Cookie", serialize(maybeRedirectTo.updatedCookie.name, maybeRedirectTo.updatedCookie.value, maybeRedirectTo.updatedCookie.options));
|
|
1351
|
+
return new Response(null, {
|
|
1352
|
+
status: 302,
|
|
1353
|
+
headers
|
|
1354
|
+
});
|
|
1355
|
+
};
|
|
1356
|
+
addConnectionRoutes(http, {
|
|
1357
|
+
routeBase: GROUP_CONNECTION_ROUTE_BASE,
|
|
1358
|
+
convertErrorsToResponse,
|
|
1359
|
+
handleSamlMetadata: async (ctx, _request, runtimeRoute) => {
|
|
1360
|
+
const { loaded } = await loadActiveConnectionSamlOrThrow(ctx, runtimeRoute.connectionId);
|
|
1361
|
+
return new Response(createGroupConnectionSamlMetadataXml({
|
|
1362
|
+
rootUrl: requireEnv("CONVEX_SITE_URL"),
|
|
1363
|
+
source: loaded.source,
|
|
1364
|
+
config: loaded.config
|
|
1365
|
+
}), {
|
|
1366
|
+
status: 200,
|
|
1367
|
+
headers: { "Content-Type": "application/xml" }
|
|
1368
|
+
});
|
|
1369
|
+
},
|
|
1370
|
+
handleSamlSignIn: async (ctx, request, runtimeRoute) => {
|
|
1371
|
+
const url = new URL(request.url);
|
|
1372
|
+
const verifier = url.searchParams.get("code");
|
|
1373
|
+
if (!verifier) throw convexError(ErrorCode.OAUTH_MISSING_VERIFIER, "Missing sign-in verifier.");
|
|
1374
|
+
const { loaded, connection } = await loadActiveConnectionSamlOrThrow(ctx, runtimeRoute.connectionId);
|
|
1375
|
+
const state = generateRandomString(24, INVITE_TOKEN_ALPHABET);
|
|
1376
|
+
const signInRequest = await createGroupConnectionSamlSignInRequest({
|
|
1377
|
+
rootUrl: requireEnv("CONVEX_SITE_URL"),
|
|
1378
|
+
source: {
|
|
1379
|
+
kind: "connection",
|
|
1380
|
+
id: connection._id
|
|
1381
|
+
},
|
|
1382
|
+
config: loaded.config,
|
|
1383
|
+
state,
|
|
1384
|
+
signature: `saml ${connection._id} pending ${state}`,
|
|
1385
|
+
redirectTo: url.searchParams.get("redirectTo") ?? void 0
|
|
1386
|
+
});
|
|
1387
|
+
const signature = `saml ${connection._id} ${signInRequest.requestId} ${state}`;
|
|
1388
|
+
await callVerifierSignature(ctx, {
|
|
1389
|
+
verifier,
|
|
1390
|
+
signature
|
|
1391
|
+
});
|
|
1392
|
+
const nowMs = Date.now();
|
|
1393
|
+
await ctx.runMutation(config.component.connection.saml.request.create, {
|
|
1394
|
+
connectionId: connection._id,
|
|
1395
|
+
requestId: signInRequest.requestId,
|
|
1396
|
+
createdAt: nowMs,
|
|
1397
|
+
expiresAt: nowMs + SAML_LOGIN_REQUEST_TTL_MS
|
|
1398
|
+
});
|
|
1399
|
+
const redirectTo = url.searchParams.get("redirectTo");
|
|
1400
|
+
const redirectCookies = redirectTo !== null ? [redirectToParamCookie(groupSamlProviderId(connection._id), redirectTo)] : [];
|
|
1401
|
+
const relayState = encodeGroupSamlRelayState({
|
|
1402
|
+
source: {
|
|
1403
|
+
kind: "connection",
|
|
1404
|
+
id: connection._id
|
|
1405
|
+
},
|
|
1406
|
+
signature,
|
|
1407
|
+
requestId: signInRequest.requestId,
|
|
1408
|
+
state,
|
|
1409
|
+
redirectTo: url.searchParams.get("redirectTo") ?? void 0
|
|
1410
|
+
});
|
|
1411
|
+
if (signInRequest.binding === "redirect" && signInRequest.redirectUrl) {
|
|
1412
|
+
const redirectUrl = new URL(signInRequest.redirectUrl);
|
|
1413
|
+
redirectUrl.searchParams.set("RelayState", relayState);
|
|
1414
|
+
const headers = new Headers({ Location: redirectUrl.toString() });
|
|
1415
|
+
for (const { name, value, options } of redirectCookies) headers.append("Set-Cookie", serialize(name, value, options));
|
|
1416
|
+
return new Response(null, {
|
|
1417
|
+
status: 302,
|
|
1418
|
+
headers
|
|
1419
|
+
});
|
|
1420
|
+
}
|
|
1421
|
+
const response = createSamlPostBindingResponse({
|
|
1422
|
+
endpoint: signInRequest.post.endpoint,
|
|
1423
|
+
parameter: "SAMLRequest",
|
|
1424
|
+
value: signInRequest.post.value,
|
|
1425
|
+
relayState
|
|
1426
|
+
});
|
|
1427
|
+
for (const { name, value, options } of redirectCookies) response.headers.append("Set-Cookie", serialize(name, value, options));
|
|
1428
|
+
return response;
|
|
1429
|
+
},
|
|
1430
|
+
handleOidcSignIn: async (ctx, request, runtimeRoute) => {
|
|
1431
|
+
const url = new URL(request.url);
|
|
1432
|
+
const verifier = url.searchParams.get("code");
|
|
1433
|
+
if (!verifier) throw convexError(ErrorCode.OAUTH_MISSING_VERIFIER, "Missing sign-in verifier.");
|
|
1434
|
+
const { connection, oidc } = await loadConnectionOidcOrThrow(ctx, runtimeRoute.connectionId);
|
|
1435
|
+
const { providerId, provider, oauthConfig } = await createGroupConnectionOidcRuntime({
|
|
1436
|
+
ctx,
|
|
1437
|
+
componentConnection: config.component.connection,
|
|
1438
|
+
rootUrl: requireEnv("CONVEX_SITE_URL"),
|
|
1439
|
+
connectionId: connection._id,
|
|
1440
|
+
oidc,
|
|
1441
|
+
sharedRedirectURI: sharedOidcRedirectURI
|
|
1442
|
+
});
|
|
1443
|
+
const { redirect, cookies, signature } = await createOAuthAuthorizationURL(providerId, {
|
|
1444
|
+
...oauthConfig,
|
|
1445
|
+
provider
|
|
1446
|
+
}, {
|
|
1447
|
+
loginHint: url.searchParams.get("loginHint") ?? (typeof oidc.request?.loginHint === "string" ? oidc.request.loginHint : void 0),
|
|
1448
|
+
stateTransform: typeof sharedOidcRedirectURI === "string" ? (state) => encodeGroupOidcState({
|
|
1449
|
+
connectionId: connection._id,
|
|
1450
|
+
state
|
|
1451
|
+
}) : void 0
|
|
1452
|
+
});
|
|
1453
|
+
await callVerifierSignature(ctx, {
|
|
1454
|
+
verifier,
|
|
1455
|
+
signature
|
|
1456
|
+
});
|
|
1457
|
+
const redirectTo = url.searchParams.get("redirectTo");
|
|
1458
|
+
const headers_ = new Headers({ Location: redirect });
|
|
1459
|
+
for (const { name, value, options } of [...cookies, ...redirectTo !== null ? [redirectToParamCookie(providerId, redirectTo)] : []]) headers_.append("Set-Cookie", serialize(name, value, options));
|
|
1460
|
+
return new Response(null, {
|
|
1461
|
+
status: 302,
|
|
1462
|
+
headers: headers_
|
|
1463
|
+
});
|
|
1464
|
+
},
|
|
1465
|
+
handleOidcCallback: async (ctx, request, runtimeRoute) => {
|
|
1466
|
+
return await handleOidcCallbackForConnection(ctx, request, runtimeRoute.connectionId);
|
|
1467
|
+
},
|
|
1468
|
+
handleSamlAcs,
|
|
1469
|
+
handleSamlSlo,
|
|
1470
|
+
handleScimRequest,
|
|
1471
|
+
sharedOidcCallbackPath: sharedOidcRedirectURI,
|
|
1472
|
+
handleOidcSharedCallback: async (ctx, request) => {
|
|
1473
|
+
const url = new URL(request.url);
|
|
1474
|
+
const params = await getOidcCallbackParams(request);
|
|
1475
|
+
const { connectionId } = decodeGroupOidcState(params.get("state"));
|
|
1476
|
+
url.search = params.toString();
|
|
1477
|
+
return await handleOidcCallbackForConnection(ctx, new Request(url, request), connectionId);
|
|
1478
|
+
},
|
|
1479
|
+
scimError
|
|
1480
|
+
});
|
|
1481
|
+
}
|
|
1482
|
+
|
|
1483
|
+
//#endregion
|
|
1484
|
+
export { addGroupHttpRuntime };
|
|
1485
|
+
//# sourceMappingURL=http.js.map
|