@effect-auth/core 0.1.0-alpha.16 → 0.1.0-alpha.19
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/LICENSE +21 -0
- package/README.md +307 -133
- package/dist/AbuseProtection.d.ts +100 -0
- package/dist/AbuseProtection.d.ts.map +1 -0
- package/dist/AbuseProtection.js +71 -0
- package/dist/AbuseProtection.js.map +1 -0
- package/dist/AccessGrant.d.ts +344 -0
- package/dist/AccessGrant.d.ts.map +1 -0
- package/dist/AccessGrant.js +687 -0
- package/dist/AccessGrant.js.map +1 -0
- package/dist/ApiKey.d.ts +0 -12
- package/dist/ApiKey.d.ts.map +1 -1
- package/dist/ApiKey.js +36 -27
- package/dist/ApiKey.js.map +1 -1
- package/dist/Assurance.d.ts +415 -0
- package/dist/Assurance.d.ts.map +1 -0
- package/dist/Assurance.js +764 -0
- package/dist/Assurance.js.map +1 -0
- package/dist/AtomicPlanExecutor.d.ts +28 -0
- package/dist/AtomicPlanExecutor.d.ts.map +1 -0
- package/dist/AtomicPlanExecutor.js +5 -0
- package/dist/AtomicPlanExecutor.js.map +1 -0
- package/dist/AuditLog.d.ts +2314 -52
- package/dist/AuditLog.d.ts.map +1 -1
- package/dist/AuditLog.js +511 -33
- package/dist/AuditLog.js.map +1 -1
- package/dist/AuthFlow.d.ts +128 -38
- package/dist/AuthFlow.d.ts.map +1 -1
- package/dist/AuthFlow.js +611 -263
- package/dist/AuthFlow.js.map +1 -1
- package/dist/AuthRateLimit.d.ts +96 -0
- package/dist/AuthRateLimit.d.ts.map +1 -0
- package/dist/AuthRateLimit.js +212 -0
- package/dist/AuthRateLimit.js.map +1 -0
- package/dist/Challenge.d.ts +0 -3
- package/dist/Challenge.d.ts.map +1 -1
- package/dist/Challenge.js +1 -4
- package/dist/Challenge.js.map +1 -1
- package/dist/Client.d.ts +205 -10
- package/dist/Client.d.ts.map +1 -1
- package/dist/Client.js +397 -16
- package/dist/Client.js.map +1 -1
- package/dist/CloudflareTurnstile.d.ts +28 -0
- package/dist/CloudflareTurnstile.d.ts.map +1 -0
- package/dist/CloudflareTurnstile.js +205 -0
- package/dist/CloudflareTurnstile.js.map +1 -0
- package/dist/Crypto.d.ts +0 -3
- package/dist/Crypto.d.ts.map +1 -1
- package/dist/Crypto.js +1 -4
- package/dist/Crypto.js.map +1 -1
- package/dist/DelegatedAccessStorageMigrations.d.ts +7 -0
- package/dist/DelegatedAccessStorageMigrations.d.ts.map +1 -0
- package/dist/DelegatedAccessStorageMigrations.js +159 -0
- package/dist/DelegatedAccessStorageMigrations.js.map +1 -0
- package/dist/DevEmail.d.ts +44 -0
- package/dist/DevEmail.d.ts.map +1 -0
- package/dist/DevEmail.js +115 -0
- package/dist/DevEmail.js.map +1 -0
- package/dist/DevelopmentSeed.d.ts +47 -0
- package/dist/DevelopmentSeed.d.ts.map +1 -0
- package/dist/DevelopmentSeed.js +337 -0
- package/dist/DevelopmentSeed.js.map +1 -0
- package/dist/DisposableEmailDomains.d.ts +19 -0
- package/dist/DisposableEmailDomains.d.ts.map +1 -0
- package/dist/DisposableEmailDomains.js +85 -0
- package/dist/DisposableEmailDomains.js.map +1 -0
- package/dist/DomainVerification.d.ts +0 -9
- package/dist/DomainVerification.d.ts.map +1 -1
- package/dist/DomainVerification.js +36 -22
- package/dist/DomainVerification.js.map +1 -1
- package/dist/DrizzleBunSqliteStorage.d.ts +18 -0
- package/dist/DrizzleBunSqliteStorage.d.ts.map +1 -0
- package/dist/DrizzleBunSqliteStorage.js +11 -0
- package/dist/DrizzleBunSqliteStorage.js.map +1 -0
- package/dist/DrizzleD1SqliteStorage.d.ts +4 -4
- package/dist/DrizzleD1SqliteStorage.d.ts.map +1 -1
- package/dist/DrizzleD1SqliteStorage.js +5 -5
- package/dist/DrizzleD1SqliteStorage.js.map +1 -1
- package/dist/DrizzleEffectSqliteStorage.d.ts +13 -4
- package/dist/DrizzleEffectSqliteStorage.d.ts.map +1 -1
- package/dist/DrizzleEffectSqliteStorage.js +71 -4
- package/dist/DrizzleEffectSqliteStorage.js.map +1 -1
- package/dist/DrizzleNodeSqliteStorage.d.ts +18 -0
- package/dist/DrizzleNodeSqliteStorage.d.ts.map +1 -0
- package/dist/DrizzleNodeSqliteStorage.js +11 -0
- package/dist/DrizzleNodeSqliteStorage.js.map +1 -0
- package/dist/DrizzlePostgresStorage.d.ts +26 -0
- package/dist/DrizzlePostgresStorage.d.ts.map +1 -0
- package/dist/DrizzlePostgresStorage.js +14 -0
- package/dist/DrizzlePostgresStorage.js.map +1 -0
- package/dist/EffectQbPostgresDelegatedAccessStorage.d.ts +34 -0
- package/dist/EffectQbPostgresDelegatedAccessStorage.d.ts.map +1 -0
- package/dist/EffectQbPostgresDelegatedAccessStorage.js +499 -0
- package/dist/EffectQbPostgresDelegatedAccessStorage.js.map +1 -0
- package/dist/EffectQbPostgresStorage.d.ts +178 -0
- package/dist/EffectQbPostgresStorage.d.ts.map +1 -0
- package/dist/EffectQbPostgresStorage.js +4637 -0
- package/dist/EffectQbPostgresStorage.js.map +1 -0
- package/dist/EffectQbSqliteDelegatedAccessStorage.d.ts +112 -0
- package/dist/EffectQbSqliteDelegatedAccessStorage.d.ts.map +1 -0
- package/dist/EffectQbSqliteDelegatedAccessStorage.js +602 -0
- package/dist/EffectQbSqliteDelegatedAccessStorage.js.map +1 -0
- package/dist/EffectQbSqliteStorage.d.ts +221 -23
- package/dist/EffectQbSqliteStorage.d.ts.map +1 -1
- package/dist/EffectQbSqliteStorage.js +2064 -135
- package/dist/EffectQbSqliteStorage.js.map +1 -1
- package/dist/EmailAuth.d.ts +65 -0
- package/dist/EmailAuth.d.ts.map +1 -0
- package/dist/EmailAuth.js +171 -0
- package/dist/EmailAuth.js.map +1 -0
- package/dist/EmailIdentityAuth.d.ts +30 -0
- package/dist/EmailIdentityAuth.d.ts.map +1 -0
- package/dist/EmailIdentityAuth.js +142 -0
- package/dist/EmailIdentityAuth.js.map +1 -0
- package/dist/EmailOtp.d.ts +10 -11
- package/dist/EmailOtp.d.ts.map +1 -1
- package/dist/EmailOtp.js +44 -81
- package/dist/EmailOtp.js.map +1 -1
- package/dist/EmailRisk.d.ts +48 -0
- package/dist/EmailRisk.d.ts.map +1 -0
- package/dist/EmailRisk.js +33 -0
- package/dist/EmailRisk.js.map +1 -0
- package/dist/EmailVerification.d.ts +10 -16
- package/dist/EmailVerification.d.ts.map +1 -1
- package/dist/EmailVerification.js +85 -42
- package/dist/EmailVerification.js.map +1 -1
- package/dist/Guard.d.ts +11 -0
- package/dist/Guard.d.ts.map +1 -0
- package/dist/Guard.js +11 -0
- package/dist/Guard.js.map +1 -0
- package/dist/HibpPwnedPasswords.d.ts +56 -0
- package/dist/HibpPwnedPasswords.d.ts.map +1 -0
- package/dist/HibpPwnedPasswords.js +232 -0
- package/dist/HibpPwnedPasswords.js.map +1 -0
- package/dist/HttpApi/AdminPermissionDefinition.d.ts +4 -0
- package/dist/HttpApi/AdminPermissionDefinition.d.ts.map +1 -0
- package/dist/HttpApi/AdminPermissionDefinition.js +4 -0
- package/dist/HttpApi/AdminPermissionDefinition.js.map +1 -0
- package/dist/HttpApi/AdminSecurityTimeline.d.ts +4 -0
- package/dist/HttpApi/AdminSecurityTimeline.d.ts.map +1 -0
- package/dist/HttpApi/AdminSecurityTimeline.js +4 -0
- package/dist/HttpApi/AdminSecurityTimeline.js.map +1 -0
- package/dist/HttpApi/AdminSession.d.ts +4 -0
- package/dist/HttpApi/AdminSession.d.ts.map +1 -0
- package/dist/HttpApi/AdminSession.js +4 -0
- package/dist/HttpApi/AdminSession.js.map +1 -0
- package/dist/HttpApi/AdminTrustedDevice.d.ts +4 -0
- package/dist/HttpApi/AdminTrustedDevice.d.ts.map +1 -0
- package/dist/HttpApi/AdminTrustedDevice.js +4 -0
- package/dist/HttpApi/AdminTrustedDevice.js.map +1 -0
- package/dist/HttpApi/Api.d.ts +939 -884
- package/dist/HttpApi/Api.d.ts.map +1 -1
- package/dist/HttpApi/Api.js +2254 -940
- package/dist/HttpApi/Api.js.map +1 -1
- package/dist/HttpApi/ApiKey.d.ts +4 -0
- package/dist/HttpApi/ApiKey.d.ts.map +1 -0
- package/dist/HttpApi/ApiKey.js +4 -0
- package/dist/HttpApi/ApiKey.js.map +1 -0
- package/dist/HttpApi/Audit.d.ts +6 -0
- package/dist/HttpApi/Audit.d.ts.map +1 -0
- package/dist/HttpApi/Audit.js +10 -0
- package/dist/HttpApi/Audit.js.map +1 -0
- package/dist/HttpApi/ClientApi.d.ts +917 -0
- package/dist/HttpApi/ClientApi.d.ts.map +1 -0
- package/dist/HttpApi/ClientApi.js +101 -0
- package/dist/HttpApi/ClientApi.js.map +1 -0
- package/dist/HttpApi/EmailAuth.d.ts +6 -0
- package/dist/HttpApi/EmailAuth.d.ts.map +1 -0
- package/dist/HttpApi/EmailAuth.js +6 -0
- package/dist/HttpApi/EmailAuth.js.map +1 -0
- package/dist/HttpApi/EmailGuards.d.ts +115 -0
- package/dist/HttpApi/EmailGuards.d.ts.map +1 -0
- package/dist/HttpApi/EmailGuards.js +191 -0
- package/dist/HttpApi/EmailGuards.js.map +1 -0
- package/dist/HttpApi/EmailOtp.d.ts +6 -0
- package/dist/HttpApi/EmailOtp.d.ts.map +1 -0
- package/dist/HttpApi/EmailOtp.js +6 -0
- package/dist/HttpApi/EmailOtp.js.map +1 -0
- package/dist/HttpApi/EmailVerification.d.ts +6 -0
- package/dist/HttpApi/EmailVerification.d.ts.map +1 -0
- package/dist/HttpApi/EmailVerification.js +6 -0
- package/dist/HttpApi/EmailVerification.js.map +1 -0
- package/dist/HttpApi/Endpoints.d.ts +661 -301
- package/dist/HttpApi/Endpoints.d.ts.map +1 -1
- package/dist/HttpApi/Endpoints.js +207 -120
- package/dist/HttpApi/Endpoints.js.map +1 -1
- package/dist/HttpApi/Errors.d.ts +37 -10
- package/dist/HttpApi/Errors.d.ts.map +1 -1
- package/dist/HttpApi/Errors.js +42 -4
- package/dist/HttpApi/Errors.js.map +1 -1
- package/dist/HttpApi/Identity.d.ts +6 -0
- package/dist/HttpApi/Identity.d.ts.map +1 -0
- package/dist/HttpApi/Identity.js +6 -0
- package/dist/HttpApi/Identity.js.map +1 -0
- package/dist/HttpApi/IdentityGuards.d.ts +31 -0
- package/dist/HttpApi/IdentityGuards.d.ts.map +1 -0
- package/dist/HttpApi/IdentityGuards.js +33 -0
- package/dist/HttpApi/IdentityGuards.js.map +1 -0
- package/dist/HttpApi/Jwt.d.ts +4 -0
- package/dist/HttpApi/Jwt.d.ts.map +1 -0
- package/dist/HttpApi/Jwt.js +4 -0
- package/dist/HttpApi/Jwt.js.map +1 -0
- package/dist/HttpApi/JwtDiscovery.d.ts +4 -0
- package/dist/HttpApi/JwtDiscovery.d.ts.map +1 -0
- package/dist/HttpApi/JwtDiscovery.js +4 -0
- package/dist/HttpApi/JwtDiscovery.js.map +1 -0
- package/dist/HttpApi/LoginApproval.d.ts +5 -0
- package/dist/HttpApi/LoginApproval.d.ts.map +1 -0
- package/dist/HttpApi/LoginApproval.js +5 -0
- package/dist/HttpApi/LoginApproval.js.map +1 -0
- package/dist/HttpApi/LoginNotification.d.ts +5 -0
- package/dist/HttpApi/LoginNotification.d.ts.map +1 -0
- package/dist/HttpApi/LoginNotification.js +5 -0
- package/dist/HttpApi/LoginNotification.js.map +1 -0
- package/dist/HttpApi/MagicLink.d.ts +6 -0
- package/dist/HttpApi/MagicLink.d.ts.map +1 -0
- package/dist/HttpApi/MagicLink.js +6 -0
- package/dist/HttpApi/MagicLink.js.map +1 -0
- package/dist/HttpApi/Mfa.d.ts +5 -0
- package/dist/HttpApi/Mfa.d.ts.map +1 -0
- package/dist/HttpApi/Mfa.js +5 -0
- package/dist/HttpApi/Mfa.js.map +1 -0
- package/dist/HttpApi/Middleware.d.ts +26 -0
- package/dist/HttpApi/Middleware.d.ts.map +1 -0
- package/dist/HttpApi/Middleware.js +13 -0
- package/dist/HttpApi/Middleware.js.map +1 -0
- package/dist/HttpApi/OAuth.d.ts +4 -0
- package/dist/HttpApi/OAuth.d.ts.map +1 -0
- package/dist/HttpApi/OAuth.js +4 -0
- package/dist/HttpApi/OAuth.js.map +1 -0
- package/dist/HttpApi/OAuthDeviceAuthorization.d.ts +106 -0
- package/dist/HttpApi/OAuthDeviceAuthorization.d.ts.map +1 -0
- package/dist/HttpApi/OAuthDeviceAuthorization.js +415 -0
- package/dist/HttpApi/OAuthDeviceAuthorization.js.map +1 -0
- package/dist/HttpApi/OAuthProviderAuthorization.d.ts +4 -0
- package/dist/HttpApi/OAuthProviderAuthorization.d.ts.map +1 -0
- package/dist/HttpApi/OAuthProviderAuthorization.js +4 -0
- package/dist/HttpApi/OAuthProviderAuthorization.js.map +1 -0
- package/dist/HttpApi/OAuthToken.d.ts +4 -0
- package/dist/HttpApi/OAuthToken.d.ts.map +1 -0
- package/dist/HttpApi/OAuthToken.js +4 -0
- package/dist/HttpApi/OAuthToken.js.map +1 -0
- package/dist/HttpApi/OidcDiscovery.d.ts +4 -0
- package/dist/HttpApi/OidcDiscovery.d.ts.map +1 -0
- package/dist/HttpApi/OidcDiscovery.js +4 -0
- package/dist/HttpApi/OidcDiscovery.js.map +1 -0
- package/dist/HttpApi/Operations/AdminPermissionDefinition.d.ts +28 -0
- package/dist/HttpApi/Operations/AdminPermissionDefinition.d.ts.map +1 -0
- package/dist/HttpApi/Operations/AdminPermissionDefinition.js +5 -0
- package/dist/HttpApi/Operations/AdminPermissionDefinition.js.map +1 -0
- package/dist/HttpApi/Operations/AdminSession.d.ts +16 -0
- package/dist/HttpApi/Operations/AdminSession.d.ts.map +1 -0
- package/dist/HttpApi/Operations/AdminSession.js +5 -0
- package/dist/HttpApi/Operations/AdminSession.js.map +1 -0
- package/dist/HttpApi/Operations/ApiKey.d.ts +16 -0
- package/dist/HttpApi/Operations/ApiKey.d.ts.map +1 -0
- package/dist/HttpApi/Operations/ApiKey.js +5 -0
- package/dist/HttpApi/Operations/ApiKey.js.map +1 -0
- package/dist/HttpApi/Operations/Discovery.d.ts +19 -0
- package/dist/HttpApi/Operations/Discovery.d.ts.map +1 -0
- package/dist/HttpApi/Operations/Discovery.js +7 -0
- package/dist/HttpApi/Operations/Discovery.js.map +1 -0
- package/dist/HttpApi/Operations/EmailAuth.d.ts +12 -0
- package/dist/HttpApi/Operations/EmailAuth.d.ts.map +1 -0
- package/dist/HttpApi/Operations/EmailAuth.js +5 -0
- package/dist/HttpApi/Operations/EmailAuth.js.map +1 -0
- package/dist/HttpApi/Operations/EmailOtp.d.ts +14 -0
- package/dist/HttpApi/Operations/EmailOtp.d.ts.map +1 -0
- package/dist/HttpApi/Operations/EmailOtp.js +5 -0
- package/dist/HttpApi/Operations/EmailOtp.js.map +1 -0
- package/dist/HttpApi/Operations/EmailVerification.d.ts +14 -0
- package/dist/HttpApi/Operations/EmailVerification.d.ts.map +1 -0
- package/dist/HttpApi/Operations/EmailVerification.js +5 -0
- package/dist/HttpApi/Operations/EmailVerification.js.map +1 -0
- package/dist/HttpApi/Operations/HttpOperation.d.ts +4 -0
- package/dist/HttpApi/Operations/HttpOperation.d.ts.map +1 -0
- package/dist/HttpApi/Operations/HttpOperation.js +2 -0
- package/dist/HttpApi/Operations/HttpOperation.js.map +1 -0
- package/dist/HttpApi/Operations/Identity.d.ts +22 -0
- package/dist/HttpApi/Operations/Identity.d.ts.map +1 -0
- package/dist/HttpApi/Operations/Identity.js +5 -0
- package/dist/HttpApi/Operations/Identity.js.map +1 -0
- package/dist/HttpApi/Operations/Jwt.d.ts +14 -0
- package/dist/HttpApi/Operations/Jwt.d.ts.map +1 -0
- package/dist/HttpApi/Operations/Jwt.js +5 -0
- package/dist/HttpApi/Operations/Jwt.js.map +1 -0
- package/dist/HttpApi/Operations/LoginApproval.d.ts +16 -0
- package/dist/HttpApi/Operations/LoginApproval.d.ts.map +1 -0
- package/dist/HttpApi/Operations/LoginApproval.js +5 -0
- package/dist/HttpApi/Operations/LoginApproval.js.map +1 -0
- package/dist/HttpApi/Operations/MagicLink.d.ts +14 -0
- package/dist/HttpApi/Operations/MagicLink.d.ts.map +1 -0
- package/dist/HttpApi/Operations/MagicLink.js +5 -0
- package/dist/HttpApi/Operations/MagicLink.js.map +1 -0
- package/dist/HttpApi/Operations/Mfa.d.ts +24 -0
- package/dist/HttpApi/Operations/Mfa.d.ts.map +1 -0
- package/dist/HttpApi/Operations/Mfa.js +5 -0
- package/dist/HttpApi/Operations/Mfa.js.map +1 -0
- package/dist/HttpApi/Operations/OAuth.d.ts +20 -0
- package/dist/HttpApi/Operations/OAuth.d.ts.map +1 -0
- package/dist/HttpApi/Operations/OAuth.js +5 -0
- package/dist/HttpApi/Operations/OAuth.js.map +1 -0
- package/dist/HttpApi/Operations/OAuthDeviceAuthorization.d.ts +23 -0
- package/dist/HttpApi/Operations/OAuthDeviceAuthorization.d.ts.map +1 -0
- package/dist/HttpApi/Operations/OAuthDeviceAuthorization.js +7 -0
- package/dist/HttpApi/Operations/OAuthDeviceAuthorization.js.map +1 -0
- package/dist/HttpApi/Operations/OAuthProviderAuthorization.d.ts +12 -0
- package/dist/HttpApi/Operations/OAuthProviderAuthorization.d.ts.map +1 -0
- package/dist/HttpApi/Operations/OAuthProviderAuthorization.js +5 -0
- package/dist/HttpApi/Operations/OAuthProviderAuthorization.js.map +1 -0
- package/dist/HttpApi/Operations/OAuthToken.d.ts +26 -0
- package/dist/HttpApi/Operations/OAuthToken.d.ts.map +1 -0
- package/dist/HttpApi/Operations/OAuthToken.js +9 -0
- package/dist/HttpApi/Operations/OAuthToken.js.map +1 -0
- package/dist/HttpApi/Operations/Passkey.d.ts +22 -0
- package/dist/HttpApi/Operations/Passkey.d.ts.map +1 -0
- package/dist/HttpApi/Operations/Passkey.js +5 -0
- package/dist/HttpApi/Operations/Passkey.js.map +1 -0
- package/dist/HttpApi/Operations/Password.d.ts +22 -0
- package/dist/HttpApi/Operations/Password.d.ts.map +1 -0
- package/dist/HttpApi/Operations/Password.js +5 -0
- package/dist/HttpApi/Operations/Password.js.map +1 -0
- package/dist/HttpApi/Operations/RecoveryCodes.d.ts +20 -0
- package/dist/HttpApi/Operations/RecoveryCodes.d.ts.map +1 -0
- package/dist/HttpApi/Operations/RecoveryCodes.js +5 -0
- package/dist/HttpApi/Operations/RecoveryCodes.js.map +1 -0
- package/dist/HttpApi/Operations/RefreshToken.d.ts +12 -0
- package/dist/HttpApi/Operations/RefreshToken.d.ts.map +1 -0
- package/dist/HttpApi/Operations/RefreshToken.js +5 -0
- package/dist/HttpApi/Operations/RefreshToken.js.map +1 -0
- package/dist/HttpApi/Operations/Security.d.ts +12 -0
- package/dist/HttpApi/Operations/Security.d.ts.map +1 -0
- package/dist/HttpApi/Operations/Security.js +5 -0
- package/dist/HttpApi/Operations/Security.js.map +1 -0
- package/dist/HttpApi/Operations/SecurityTimeline.d.ts +19 -0
- package/dist/HttpApi/Operations/SecurityTimeline.d.ts.map +1 -0
- package/dist/HttpApi/Operations/SecurityTimeline.js +7 -0
- package/dist/HttpApi/Operations/SecurityTimeline.js.map +1 -0
- package/dist/HttpApi/Operations/Session.d.ts +22 -0
- package/dist/HttpApi/Operations/Session.d.ts.map +1 -0
- package/dist/HttpApi/Operations/Session.js +5 -0
- package/dist/HttpApi/Operations/Session.js.map +1 -0
- package/dist/HttpApi/Operations/StepUp.d.ts +22 -0
- package/dist/HttpApi/Operations/StepUp.d.ts.map +1 -0
- package/dist/HttpApi/Operations/StepUp.js +5 -0
- package/dist/HttpApi/Operations/StepUp.js.map +1 -0
- package/dist/HttpApi/Operations/Totp.d.ts +20 -0
- package/dist/HttpApi/Operations/Totp.d.ts.map +1 -0
- package/dist/HttpApi/Operations/Totp.js +5 -0
- package/dist/HttpApi/Operations/Totp.js.map +1 -0
- package/dist/HttpApi/Operations/TrustedDevice.d.ts +23 -0
- package/dist/HttpApi/Operations/TrustedDevice.d.ts.map +1 -0
- package/dist/HttpApi/Operations/TrustedDevice.js +7 -0
- package/dist/HttpApi/Operations/TrustedDevice.js.map +1 -0
- package/dist/HttpApi/Operations/index.d.ts +28 -0
- package/dist/HttpApi/Operations/index.d.ts.map +1 -0
- package/dist/HttpApi/Operations/index.js +28 -0
- package/dist/HttpApi/Operations/index.js.map +1 -0
- package/dist/HttpApi/Passkey.d.ts +5 -0
- package/dist/HttpApi/Passkey.d.ts.map +1 -0
- package/dist/HttpApi/Passkey.js +5 -0
- package/dist/HttpApi/Passkey.js.map +1 -0
- package/dist/HttpApi/Password.d.ts +220 -0
- package/dist/HttpApi/Password.d.ts.map +1 -0
- package/dist/HttpApi/Password.js +237 -0
- package/dist/HttpApi/Password.js.map +1 -0
- package/dist/HttpApi/PasswordContract.d.ts +307 -0
- package/dist/HttpApi/PasswordContract.d.ts.map +1 -0
- package/dist/HttpApi/PasswordContract.js +63 -0
- package/dist/HttpApi/PasswordContract.js.map +1 -0
- package/dist/HttpApi/PasswordGuards.d.ts +82 -0
- package/dist/HttpApi/PasswordGuards.d.ts.map +1 -0
- package/dist/HttpApi/PasswordGuards.js +179 -0
- package/dist/HttpApi/PasswordGuards.js.map +1 -0
- package/dist/HttpApi/RecoveryCodes.d.ts +5 -0
- package/dist/HttpApi/RecoveryCodes.d.ts.map +1 -0
- package/dist/HttpApi/RecoveryCodes.js +5 -0
- package/dist/HttpApi/RecoveryCodes.js.map +1 -0
- package/dist/HttpApi/RefreshToken.d.ts +4 -0
- package/dist/HttpApi/RefreshToken.d.ts.map +1 -0
- package/dist/HttpApi/RefreshToken.js +4 -0
- package/dist/HttpApi/RefreshToken.js.map +1 -0
- package/dist/HttpApi/RequestGuards.d.ts +42 -0
- package/dist/HttpApi/RequestGuards.d.ts.map +1 -0
- package/dist/HttpApi/RequestGuards.js +194 -0
- package/dist/HttpApi/RequestGuards.js.map +1 -0
- package/dist/HttpApi/Schemas.d.ts +399 -84
- package/dist/HttpApi/Schemas.d.ts.map +1 -1
- package/dist/HttpApi/Schemas.js +225 -27
- package/dist/HttpApi/Schemas.js.map +1 -1
- package/dist/HttpApi/Security.d.ts +12 -93
- package/dist/HttpApi/Security.d.ts.map +1 -1
- package/dist/HttpApi/Security.js +65 -356
- package/dist/HttpApi/Security.js.map +1 -1
- package/dist/HttpApi/SecurityTimeline.d.ts +4 -0
- package/dist/HttpApi/SecurityTimeline.d.ts.map +1 -0
- package/dist/HttpApi/SecurityTimeline.js +4 -0
- package/dist/HttpApi/SecurityTimeline.js.map +1 -0
- package/dist/HttpApi/Session.d.ts +5 -0
- package/dist/HttpApi/Session.d.ts.map +1 -0
- package/dist/HttpApi/Session.js +5 -0
- package/dist/HttpApi/Session.js.map +1 -0
- package/dist/HttpApi/SessionGuards.d.ts +15 -0
- package/dist/HttpApi/SessionGuards.d.ts.map +1 -0
- package/dist/HttpApi/SessionGuards.js +37 -0
- package/dist/HttpApi/SessionGuards.js.map +1 -0
- package/dist/HttpApi/StepUp.d.ts +5 -0
- package/dist/HttpApi/StepUp.d.ts.map +1 -0
- package/dist/HttpApi/StepUp.js +5 -0
- package/dist/HttpApi/StepUp.js.map +1 -0
- package/dist/HttpApi/Totp.d.ts +5 -0
- package/dist/HttpApi/Totp.d.ts.map +1 -0
- package/dist/HttpApi/Totp.js +5 -0
- package/dist/HttpApi/Totp.js.map +1 -0
- package/dist/HttpApi/Transport.d.ts +4 -6
- package/dist/HttpApi/Transport.d.ts.map +1 -1
- package/dist/HttpApi/Transport.js +62 -36
- package/dist/HttpApi/Transport.js.map +1 -1
- package/dist/HttpApi/TrustedDevice.d.ts +4 -0
- package/dist/HttpApi/TrustedDevice.d.ts.map +1 -0
- package/dist/HttpApi/TrustedDevice.js +4 -0
- package/dist/HttpApi/TrustedDevice.js.map +1 -0
- package/dist/HttpApi/index.d.ts +11 -3
- package/dist/HttpApi/index.d.ts.map +1 -1
- package/dist/HttpApi/index.js +10 -2
- package/dist/HttpApi/index.js.map +1 -1
- package/dist/Identity.d.ts +138 -0
- package/dist/Identity.d.ts.map +1 -0
- package/dist/Identity.js +105 -0
- package/dist/Identity.js.map +1 -0
- package/dist/IdentityManagement.d.ts +189 -0
- package/dist/IdentityManagement.d.ts.map +1 -0
- package/dist/IdentityManagement.js +317 -0
- package/dist/IdentityManagement.js.map +1 -0
- package/dist/IncidentAction.d.ts +1 -4
- package/dist/IncidentAction.d.ts.map +1 -1
- package/dist/IncidentAction.js +15 -9
- package/dist/IncidentAction.js.map +1 -1
- package/dist/Internal.d.ts +2 -0
- package/dist/Internal.d.ts.map +1 -1
- package/dist/Internal.js +30 -0
- package/dist/Internal.js.map +1 -1
- package/dist/Invitation.d.ts +362 -0
- package/dist/Invitation.d.ts.map +1 -0
- package/dist/Invitation.js +633 -0
- package/dist/Invitation.js.map +1 -0
- package/dist/IpQualityScore.d.ts +38 -0
- package/dist/IpQualityScore.d.ts.map +1 -0
- package/dist/IpQualityScore.js +215 -0
- package/dist/IpQualityScore.js.map +1 -0
- package/dist/Jwt.d.ts +8 -29
- package/dist/Jwt.d.ts.map +1 -1
- package/dist/Jwt.js +67 -56
- package/dist/Jwt.js.map +1 -1
- package/dist/LoginApproval.d.ts +15 -30
- package/dist/LoginApproval.d.ts.map +1 -1
- package/dist/LoginApproval.js +47 -41
- package/dist/LoginApproval.js.map +1 -1
- package/dist/LoginNotification.d.ts +7 -11
- package/dist/LoginNotification.d.ts.map +1 -1
- package/dist/LoginNotification.js +30 -17
- package/dist/LoginNotification.js.map +1 -1
- package/dist/LoginRisk.d.ts +11 -13
- package/dist/LoginRisk.d.ts.map +1 -1
- package/dist/LoginRisk.js +66 -26
- package/dist/LoginRisk.js.map +1 -1
- package/dist/LoginRiskEnrichment.d.ts +145 -0
- package/dist/LoginRiskEnrichment.d.ts.map +1 -0
- package/dist/LoginRiskEnrichment.js +220 -0
- package/dist/LoginRiskEnrichment.js.map +1 -0
- package/dist/MagicLink.d.ts +9 -8
- package/dist/MagicLink.d.ts.map +1 -1
- package/dist/MagicLink.js +40 -73
- package/dist/MagicLink.js.map +1 -1
- package/dist/Mailer.d.ts +19 -12
- package/dist/Mailer.d.ts.map +1 -1
- package/dist/Mailer.js +10 -12
- package/dist/Mailer.js.map +1 -1
- package/dist/OAuth.d.ts +138 -96
- package/dist/OAuth.d.ts.map +1 -1
- package/dist/OAuth.js +522 -221
- package/dist/OAuth.js.map +1 -1
- package/dist/OAuthDeviceAuthorization.d.ts +378 -0
- package/dist/OAuthDeviceAuthorization.d.ts.map +1 -0
- package/dist/OAuthDeviceAuthorization.js +860 -0
- package/dist/OAuthDeviceAuthorization.js.map +1 -0
- package/dist/OAuthDeviceClient.d.ts +76 -0
- package/dist/OAuthDeviceClient.d.ts.map +1 -0
- package/dist/OAuthDeviceClient.js +362 -0
- package/dist/OAuthDeviceClient.js.map +1 -0
- package/dist/Passkey.d.ts +15 -17
- package/dist/Passkey.d.ts.map +1 -1
- package/dist/Passkey.js +86 -39
- package/dist/Passkey.js.map +1 -1
- package/dist/PasskeyBrowser.d.ts +39 -0
- package/dist/PasskeyBrowser.d.ts.map +1 -0
- package/dist/PasskeyBrowser.js +206 -0
- package/dist/PasskeyBrowser.js.map +1 -0
- package/dist/PasskeySimpleWebAuthn.d.ts.map +1 -1
- package/dist/PasskeySimpleWebAuthn.js +19 -7
- package/dist/PasskeySimpleWebAuthn.js.map +1 -1
- package/dist/Password.d.ts +71 -37
- package/dist/Password.d.ts.map +1 -1
- package/dist/Password.js +295 -81
- package/dist/Password.js.map +1 -1
- package/dist/PasswordRisk.d.ts +63 -0
- package/dist/PasswordRisk.d.ts.map +1 -0
- package/dist/PasswordRisk.js +37 -0
- package/dist/PasswordRisk.js.map +1 -0
- package/dist/Permission.d.ts +308 -0
- package/dist/Permission.d.ts.map +1 -0
- package/dist/Permission.js +827 -0
- package/dist/Permission.js.map +1 -0
- package/dist/Policy.d.ts +31 -18
- package/dist/Policy.d.ts.map +1 -1
- package/dist/Policy.js +58 -14
- package/dist/Policy.js.map +1 -1
- package/dist/PostgresDelegatedAccessStorageMigrations.d.ts +7 -0
- package/dist/PostgresDelegatedAccessStorageMigrations.d.ts.map +1 -0
- package/dist/PostgresDelegatedAccessStorageMigrations.js +119 -0
- package/dist/PostgresDelegatedAccessStorageMigrations.js.map +1 -0
- package/dist/PostgresStorageMigrations.d.ts +16 -0
- package/dist/PostgresStorageMigrations.d.ts.map +1 -0
- package/dist/PostgresStorageMigrations.js +674 -0
- package/dist/PostgresStorageMigrations.js.map +1 -0
- package/dist/Privacy.d.ts +0 -3
- package/dist/Privacy.d.ts.map +1 -1
- package/dist/Privacy.js +2 -5
- package/dist/Privacy.js.map +1 -1
- package/dist/RateLimiter.d.ts +0 -3
- package/dist/RateLimiter.d.ts.map +1 -1
- package/dist/RateLimiter.js +1 -4
- package/dist/RateLimiter.js.map +1 -1
- package/dist/RecoveryCode.d.ts +83 -11
- package/dist/RecoveryCode.d.ts.map +1 -1
- package/dist/RecoveryCode.js +273 -75
- package/dist/RecoveryCode.js.map +1 -1
- package/dist/RecoveryPolicy.d.ts +81 -0
- package/dist/RecoveryPolicy.d.ts.map +1 -0
- package/dist/RecoveryPolicy.js +119 -0
- package/dist/RecoveryPolicy.js.map +1 -0
- package/dist/RefreshToken.d.ts +0 -9
- package/dist/RefreshToken.d.ts.map +1 -1
- package/dist/RefreshToken.js +31 -22
- package/dist/RefreshToken.js.map +1 -1
- package/dist/Retention.d.ts +6 -1
- package/dist/Retention.d.ts.map +1 -1
- package/dist/Retention.js +49 -12
- package/dist/Retention.js.map +1 -1
- package/dist/SecurityTimeline.d.ts +1 -4
- package/dist/SecurityTimeline.d.ts.map +1 -1
- package/dist/SecurityTimeline.js +110 -17
- package/dist/SecurityTimeline.js.map +1 -1
- package/dist/Sessions.d.ts +124 -29
- package/dist/Sessions.d.ts.map +1 -1
- package/dist/Sessions.js +626 -94
- package/dist/Sessions.js.map +1 -1
- package/dist/SqliteStorageSchemaData.d.ts +2 -0
- package/dist/SqliteStorageSchemaData.d.ts.map +1 -0
- package/dist/SqliteStorageSchemaData.js +508 -0
- package/dist/SqliteStorageSchemaData.js.map +1 -0
- package/dist/StepUp.d.ts +132 -11
- package/dist/StepUp.d.ts.map +1 -1
- package/dist/StepUp.js +387 -19
- package/dist/StepUp.js.map +1 -1
- package/dist/Storage.d.ts +89 -23
- package/dist/Storage.d.ts.map +1 -1
- package/dist/Storage.js +10 -12
- package/dist/Storage.js.map +1 -1
- package/dist/StorageMigrations.d.ts +7 -1
- package/dist/StorageMigrations.d.ts.map +1 -1
- package/dist/StorageMigrations.js +256 -0
- package/dist/StorageMigrations.js.map +1 -1
- package/dist/StorageSchemaGenerator.d.ts +544 -0
- package/dist/StorageSchemaGenerator.d.ts.map +1 -0
- package/dist/StorageSchemaGenerator.js +1418 -0
- package/dist/StorageSchemaGenerator.js.map +1 -0
- package/dist/StrongFactor.d.ts +64 -0
- package/dist/StrongFactor.d.ts.map +1 -0
- package/dist/StrongFactor.js +100 -0
- package/dist/StrongFactor.js.map +1 -0
- package/dist/Testing.js +2 -2
- package/dist/Testing.js.map +1 -1
- package/dist/Totp.d.ts +88 -13
- package/dist/Totp.d.ts.map +1 -1
- package/dist/Totp.js +192 -34
- package/dist/Totp.js.map +1 -1
- package/dist/TrustedDevice.d.ts +0 -9
- package/dist/TrustedDevice.d.ts.map +1 -1
- package/dist/TrustedDevice.js +15 -17
- package/dist/TrustedDevice.js.map +1 -1
- package/dist/WaitUntil.d.ts +0 -3
- package/dist/WaitUntil.d.ts.map +1 -1
- package/dist/WaitUntil.js +1 -4
- package/dist/WaitUntil.js.map +1 -1
- package/dist/Webhook.d.ts +42 -12
- package/dist/Webhook.d.ts.map +1 -1
- package/dist/Webhook.js +165 -26
- package/dist/Webhook.js.map +1 -1
- package/dist/alchemy/cloudflare/Email.d.ts.map +1 -1
- package/dist/alchemy/cloudflare/Email.js +9 -4
- package/dist/alchemy/cloudflare/Email.js.map +1 -1
- package/dist/cloudflare/Email.js +1 -1
- package/dist/cloudflare/Email.js.map +1 -1
- package/dist/cloudflare/RequestMetadata.d.ts +49 -0
- package/dist/cloudflare/RequestMetadata.d.ts.map +1 -0
- package/dist/cloudflare/RequestMetadata.js +71 -0
- package/dist/cloudflare/RequestMetadata.js.map +1 -0
- package/dist/index.d.ts +0 -35
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -35
- package/dist/index.js.map +1 -1
- package/dist/internal/AuthFlowFinalizer.d.ts +31 -0
- package/dist/internal/AuthFlowFinalizer.d.ts.map +1 -0
- package/dist/internal/AuthFlowFinalizer.js +182 -0
- package/dist/internal/AuthFlowFinalizer.js.map +1 -0
- package/migrations/0001_auth_storage.sql +1 -0
- package/migrations/0006_auth_totp_factor.sql +1 -0
- package/migrations/0024_auth_permission.sql +39 -0
- package/migrations/0025_auth_permission_definition.sql +19 -0
- package/migrations/0026_auth_user_identity.sql +59 -0
- package/migrations/0027_auth_audit_log_storage_order.sql +46 -0
- package/migrations/0028_auth_oauth_client_secret_key.sql +39 -0
- package/migrations/0029_auth_oauth_device_authorization.sql +28 -0
- package/migrations/delegated-access/0001_auth_delegated_access.sql +152 -0
- package/migrations/postgres/0001_auth_core.sql +77 -0
- package/migrations/postgres/0002_auth_security_oauth.sql +65 -0
- package/migrations/postgres/0003_auth_credentials_tokens.sql +43 -0
- package/migrations/postgres/0004_auth_security_history.sql +103 -0
- package/migrations/postgres/0005_auth_webhooks.sql +29 -0
- package/migrations/postgres/0006_auth_domain_timeline.sql +50 -0
- package/migrations/postgres/0007_auth_oauth_clients.sql +85 -0
- package/migrations/postgres/0008_auth_oauth_tokens.sql +63 -0
- package/migrations/postgres/0009_auth_permissions.sql +66 -0
- package/migrations/postgres/0010_auth_oauth_device_authorization.sql +50 -0
- package/migrations/postgres/delegated-access/0001_auth_delegated_access.sql +112 -0
- package/package.json +309 -2
package/dist/OAuth.js
CHANGED
|
@@ -2,6 +2,7 @@ import { Brand, Context, Data, Duration, Effect, Encoding, Layer, Option, Redact
|
|
|
2
2
|
import { Challenge } from "./Challenge.js";
|
|
3
3
|
import { Crypto } from "./Crypto.js";
|
|
4
4
|
import { ChallengeId, Email, OAuthAccountId, OAuthClientId, OAuthProviderId, UnixMillis, UserId, } from "./Identifiers.js";
|
|
5
|
+
import { globalIdentityScope, normalizeEmail } from "./Identity.js";
|
|
5
6
|
import { currentUnixMillis } from "./Internal.js";
|
|
6
7
|
import { JwtAlgorithms, JwtError, JwtKeyId, JwtKeys, JwtVerifier, } from "./Jwt.js";
|
|
7
8
|
export const OAuthStateToken = Brand.nominal();
|
|
@@ -61,7 +62,11 @@ export const googleOidcOfflineAccessAuthorizationParams = {
|
|
|
61
62
|
export const microsoftOidcProviderId = OAuthProviderId("microsoft");
|
|
62
63
|
export const microsoftOidcLoginBaseUrl = "https://login.microsoftonline.com";
|
|
63
64
|
export const microsoftOidcUserInfoEndpoint = "https://graph.microsoft.com/oidc/userinfo";
|
|
64
|
-
export const microsoftOidcDefaultScopes = [
|
|
65
|
+
export const microsoftOidcDefaultScopes = [
|
|
66
|
+
"openid",
|
|
67
|
+
"email",
|
|
68
|
+
"profile",
|
|
69
|
+
];
|
|
65
70
|
export const microsoftOidcOfflineAccessScopes = [
|
|
66
71
|
"openid",
|
|
67
72
|
"email",
|
|
@@ -85,226 +90,146 @@ export class OAuthClientRegistryError extends Data.TaggedError("OAuthClientRegis
|
|
|
85
90
|
}
|
|
86
91
|
export class OAuthClientRegistry extends Context.Service()("auth/OAuthClientRegistry") {
|
|
87
92
|
}
|
|
88
|
-
(function (OAuthClientRegistry) {
|
|
89
|
-
OAuthClientRegistry.make = (service) => OAuthClientRegistry.of(service);
|
|
90
|
-
})(OAuthClientRegistry || (OAuthClientRegistry = {}));
|
|
91
93
|
export class OAuthClientStoreError extends Data.TaggedError("OAuthClientStoreError") {
|
|
92
94
|
}
|
|
93
95
|
export class OAuthClientStore extends Context.Service()("auth/OAuthClientStore") {
|
|
94
96
|
}
|
|
95
|
-
(function (OAuthClientStore) {
|
|
96
|
-
OAuthClientStore.make = (service) => OAuthClientStore.of(service);
|
|
97
|
-
})(OAuthClientStore || (OAuthClientStore = {}));
|
|
98
97
|
export class OAuthConsentStoreError extends Data.TaggedError("OAuthConsentStoreError") {
|
|
99
98
|
}
|
|
100
99
|
export class OAuthConsentStore extends Context.Service()("auth/OAuthConsentStore") {
|
|
101
100
|
}
|
|
102
|
-
(function (OAuthConsentStore) {
|
|
103
|
-
OAuthConsentStore.make = (service) => OAuthConsentStore.of(service);
|
|
104
|
-
})(OAuthConsentStore || (OAuthConsentStore = {}));
|
|
105
101
|
export class OAuthClientSecretError extends Data.TaggedError("OAuthClientSecretError") {
|
|
106
102
|
}
|
|
107
103
|
export class OAuthClientSecrets extends Context.Service()("auth/OAuthClientSecrets") {
|
|
108
104
|
}
|
|
109
|
-
(function (OAuthClientSecrets) {
|
|
110
|
-
OAuthClientSecrets.make = (service) => OAuthClientSecrets.of(service);
|
|
111
|
-
})(OAuthClientSecrets || (OAuthClientSecrets = {}));
|
|
112
105
|
export class OAuthClientSecretStoreError extends Data.TaggedError("OAuthClientSecretStoreError") {
|
|
113
106
|
}
|
|
114
107
|
export class OAuthClientSecretStore extends Context.Service()("auth/OAuthClientSecretStore") {
|
|
115
108
|
}
|
|
116
|
-
(function (OAuthClientSecretStore) {
|
|
117
|
-
OAuthClientSecretStore.make = (service) => OAuthClientSecretStore.of(service);
|
|
118
|
-
})(OAuthClientSecretStore || (OAuthClientSecretStore = {}));
|
|
119
109
|
export class OAuthClientSecretVerificationError extends Data.TaggedError("OAuthClientSecretVerificationError") {
|
|
120
110
|
}
|
|
121
111
|
export class OAuthClientSecretVerification extends Context.Service()("auth/OAuthClientSecretVerification") {
|
|
122
112
|
}
|
|
123
|
-
(function (OAuthClientSecretVerification) {
|
|
124
|
-
OAuthClientSecretVerification.make = (service) => OAuthClientSecretVerification.of(service);
|
|
125
|
-
})(OAuthClientSecretVerification || (OAuthClientSecretVerification = {}));
|
|
126
113
|
export class OAuthAuthorizationCodeStoreError extends Data.TaggedError("OAuthAuthorizationCodeStoreError") {
|
|
127
114
|
}
|
|
128
115
|
export class OAuthAuthorizationCodeStore extends Context.Service()("auth/OAuthAuthorizationCodeStore") {
|
|
129
116
|
}
|
|
130
|
-
(function (OAuthAuthorizationCodeStore) {
|
|
131
|
-
OAuthAuthorizationCodeStore.make = (service) => OAuthAuthorizationCodeStore.of(service);
|
|
132
|
-
})(OAuthAuthorizationCodeStore || (OAuthAuthorizationCodeStore = {}));
|
|
133
117
|
export class OAuthAuthorizationCodeGrantError extends Data.TaggedError("OAuthAuthorizationCodeGrantError") {
|
|
134
118
|
}
|
|
135
119
|
export class OAuthAuthorizationCodeGrant extends Context.Service()("auth/OAuthAuthorizationCodeGrant") {
|
|
136
120
|
}
|
|
137
|
-
(function (OAuthAuthorizationCodeGrant) {
|
|
138
|
-
OAuthAuthorizationCodeGrant.make = (service) => OAuthAuthorizationCodeGrant.of(service);
|
|
139
|
-
})(OAuthAuthorizationCodeGrant || (OAuthAuthorizationCodeGrant = {}));
|
|
140
121
|
export class OAuthAuthorizationCodeTokenIssuerError extends Data.TaggedError("OAuthAuthorizationCodeTokenIssuerError") {
|
|
141
122
|
}
|
|
142
123
|
export class OAuthAuthorizationCodeTokenIssuer extends Context.Service()("auth/OAuthAuthorizationCodeTokenIssuer") {
|
|
143
124
|
}
|
|
144
|
-
(function (OAuthAuthorizationCodeTokenIssuer) {
|
|
145
|
-
OAuthAuthorizationCodeTokenIssuer.make = (service) => OAuthAuthorizationCodeTokenIssuer.of(service);
|
|
146
|
-
})(OAuthAuthorizationCodeTokenIssuer || (OAuthAuthorizationCodeTokenIssuer = {}));
|
|
147
125
|
export class OAuthAuthorizationCodeTokenGrantError extends Data.TaggedError("OAuthAuthorizationCodeTokenGrantError") {
|
|
148
126
|
}
|
|
149
127
|
export class OAuthAuthorizationCodeTokenGrant extends Context.Service()("auth/OAuthAuthorizationCodeTokenGrant") {
|
|
150
128
|
}
|
|
151
|
-
(function (OAuthAuthorizationCodeTokenGrant) {
|
|
152
|
-
OAuthAuthorizationCodeTokenGrant.make = (service) => OAuthAuthorizationCodeTokenGrant.of(service);
|
|
153
|
-
})(OAuthAuthorizationCodeTokenGrant || (OAuthAuthorizationCodeTokenGrant = {}));
|
|
154
129
|
export class OAuthRefreshTokenIssuerError extends Data.TaggedError("OAuthRefreshTokenIssuerError") {
|
|
155
130
|
}
|
|
156
131
|
export class OAuthRefreshTokenIssuer extends Context.Service()("auth/OAuthRefreshTokenIssuer") {
|
|
157
132
|
}
|
|
158
|
-
(function (OAuthRefreshTokenIssuer) {
|
|
159
|
-
OAuthRefreshTokenIssuer.make = (service) => OAuthRefreshTokenIssuer.of(service);
|
|
160
|
-
})(OAuthRefreshTokenIssuer || (OAuthRefreshTokenIssuer = {}));
|
|
161
133
|
export class OAuthRefreshTokenGrantError extends Data.TaggedError("OAuthRefreshTokenGrantError") {
|
|
162
134
|
}
|
|
163
135
|
export class OAuthRefreshTokenGrant extends Context.Service()("auth/OAuthRefreshTokenGrant") {
|
|
164
136
|
}
|
|
165
|
-
(function (OAuthRefreshTokenGrant) {
|
|
166
|
-
OAuthRefreshTokenGrant.make = (service) => OAuthRefreshTokenGrant.of(service);
|
|
167
|
-
})(OAuthRefreshTokenGrant || (OAuthRefreshTokenGrant = {}));
|
|
168
137
|
export class OAuthClientCredentialsTokenIssuerError extends Data.TaggedError("OAuthClientCredentialsTokenIssuerError") {
|
|
169
138
|
}
|
|
170
139
|
export class OAuthClientCredentialsTokenIssuer extends Context.Service()("auth/OAuthClientCredentialsTokenIssuer") {
|
|
171
140
|
}
|
|
172
|
-
(function (OAuthClientCredentialsTokenIssuer) {
|
|
173
|
-
OAuthClientCredentialsTokenIssuer.make = (service) => OAuthClientCredentialsTokenIssuer.of(service);
|
|
174
|
-
})(OAuthClientCredentialsTokenIssuer || (OAuthClientCredentialsTokenIssuer = {}));
|
|
175
141
|
export class OAuthClientCredentialsGrantError extends Data.TaggedError("OAuthClientCredentialsGrantError") {
|
|
176
142
|
}
|
|
177
143
|
export class OAuthClientCredentialsGrant extends Context.Service()("auth/OAuthClientCredentialsGrant") {
|
|
178
144
|
}
|
|
179
|
-
(function (OAuthClientCredentialsGrant) {
|
|
180
|
-
OAuthClientCredentialsGrant.make = (service) => OAuthClientCredentialsGrant.of(service);
|
|
181
|
-
})(OAuthClientCredentialsGrant || (OAuthClientCredentialsGrant = {}));
|
|
182
145
|
export class OAuthTokenRevokerError extends Data.TaggedError("OAuthTokenRevokerError") {
|
|
183
146
|
}
|
|
184
147
|
export class OAuthTokenRevoker extends Context.Service()("auth/OAuthTokenRevoker") {
|
|
185
148
|
}
|
|
186
|
-
(function (OAuthTokenRevoker) {
|
|
187
|
-
OAuthTokenRevoker.make = (service) => OAuthTokenRevoker.of(service);
|
|
188
|
-
})(OAuthTokenRevoker || (OAuthTokenRevoker = {}));
|
|
189
149
|
export class OAuthTokenRevocationError extends Data.TaggedError("OAuthTokenRevocationError") {
|
|
190
150
|
}
|
|
191
151
|
export class OAuthTokenRevocation extends Context.Service()("auth/OAuthTokenRevocation") {
|
|
192
152
|
}
|
|
193
|
-
(function (OAuthTokenRevocation) {
|
|
194
|
-
OAuthTokenRevocation.make = (service) => OAuthTokenRevocation.of(service);
|
|
195
|
-
})(OAuthTokenRevocation || (OAuthTokenRevocation = {}));
|
|
196
153
|
export class OAuthTokenIntrospectorError extends Data.TaggedError("OAuthTokenIntrospectorError") {
|
|
197
154
|
}
|
|
198
155
|
export class OAuthTokenIntrospector extends Context.Service()("auth/OAuthTokenIntrospector") {
|
|
199
156
|
}
|
|
200
|
-
(function (OAuthTokenIntrospector) {
|
|
201
|
-
OAuthTokenIntrospector.make = (service) => OAuthTokenIntrospector.of(service);
|
|
202
|
-
})(OAuthTokenIntrospector || (OAuthTokenIntrospector = {}));
|
|
203
157
|
export class OAuthTokenIntrospectionError extends Data.TaggedError("OAuthTokenIntrospectionError") {
|
|
204
158
|
}
|
|
205
159
|
export class OAuthTokenIntrospection extends Context.Service()("auth/OAuthTokenIntrospection") {
|
|
206
160
|
}
|
|
207
|
-
(function (OAuthTokenIntrospection) {
|
|
208
|
-
OAuthTokenIntrospection.make = (service) => OAuthTokenIntrospection.of(service);
|
|
209
|
-
})(OAuthTokenIntrospection || (OAuthTokenIntrospection = {}));
|
|
210
161
|
export class OAuthProviderAuthorizationPolicyError extends Data.TaggedError("OAuthProviderAuthorizationPolicyError") {
|
|
211
162
|
}
|
|
212
163
|
export class OAuthProviderAuthorizationPolicy extends Context.Service()("auth/OAuthProviderAuthorizationPolicy") {
|
|
213
164
|
}
|
|
214
|
-
(function (OAuthProviderAuthorizationPolicy) {
|
|
215
|
-
OAuthProviderAuthorizationPolicy.make = (service) => OAuthProviderAuthorizationPolicy.of(service);
|
|
216
|
-
})(OAuthProviderAuthorizationPolicy || (OAuthProviderAuthorizationPolicy = {}));
|
|
217
165
|
export class OAuthProviderAuthorizationError extends Data.TaggedError("OAuthProviderAuthorizationError") {
|
|
218
166
|
}
|
|
219
167
|
export class OAuthProviderAuthorization extends Context.Service()("auth/OAuthProviderAuthorization") {
|
|
220
168
|
}
|
|
221
|
-
(function (OAuthProviderAuthorization) {
|
|
222
|
-
OAuthProviderAuthorization.make = (service) => OAuthProviderAuthorization.of(service);
|
|
223
|
-
})(OAuthProviderAuthorization || (OAuthProviderAuthorization = {}));
|
|
224
169
|
export class OAuthUserInfoError extends Data.TaggedError("OAuthUserInfoError") {
|
|
225
170
|
}
|
|
226
171
|
export class OAuthProviderModeTokenStoreError extends Data.TaggedError("OAuthProviderModeTokenStoreError") {
|
|
227
172
|
}
|
|
228
173
|
export class OAuthProviderModeTokenStore extends Context.Service()("auth/OAuthProviderModeTokenStore") {
|
|
229
174
|
}
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
175
|
+
export class OAuthProviderModeAccessTokenVerifierError extends Data.TaggedError("OAuthProviderModeAccessTokenVerifierError") {
|
|
176
|
+
}
|
|
177
|
+
export class OAuthProviderModeAccessTokenVerifier extends Context.Service()("auth/OAuthProviderModeAccessTokenVerifier") {
|
|
178
|
+
}
|
|
233
179
|
export class OAuthProviderTokenVaultError extends Data.TaggedError("OAuthProviderTokenVaultError") {
|
|
234
180
|
}
|
|
235
181
|
export class OAuthProviderTokenVault extends Context.Service()("auth/OAuthProviderTokenVault") {
|
|
236
182
|
}
|
|
237
|
-
(function (OAuthProviderTokenVault) {
|
|
238
|
-
OAuthProviderTokenVault.make = (service) => OAuthProviderTokenVault.of(service);
|
|
239
|
-
})(OAuthProviderTokenVault || (OAuthProviderTokenVault = {}));
|
|
240
183
|
export class OAuthProviderTokenLifecycleError extends Data.TaggedError("OAuthProviderTokenLifecycleError") {
|
|
241
184
|
}
|
|
242
185
|
export class OAuthProviderTokenLifecycle extends Context.Service()("auth/OAuthProviderTokenLifecycle") {
|
|
243
186
|
}
|
|
244
|
-
(function (OAuthProviderTokenLifecycle) {
|
|
245
|
-
OAuthProviderTokenLifecycle.make = (service) => OAuthProviderTokenLifecycle.of(service);
|
|
246
|
-
})(OAuthProviderTokenLifecycle || (OAuthProviderTokenLifecycle = {}));
|
|
247
187
|
export class OidcIdTokenVerifierError extends Data.TaggedError("OidcIdTokenVerifierError") {
|
|
248
188
|
}
|
|
249
189
|
export class OidcIdTokenVerifier extends Context.Service()("auth/OidcIdTokenVerifier") {
|
|
250
190
|
}
|
|
251
|
-
(function (OidcIdTokenVerifier) {
|
|
252
|
-
OidcIdTokenVerifier.make = (service) => OidcIdTokenVerifier.of(service);
|
|
253
|
-
})(OidcIdTokenVerifier || (OidcIdTokenVerifier = {}));
|
|
254
191
|
export class OAuthProfileNormalizationError extends Data.TaggedError("OAuthProfileNormalizationError") {
|
|
255
192
|
}
|
|
256
193
|
export class OAuthProfileNormalizer extends Context.Service()("auth/OAuthProfileNormalizer") {
|
|
257
194
|
}
|
|
258
|
-
(function (OAuthProfileNormalizer) {
|
|
259
|
-
OAuthProfileNormalizer.make = (service) => OAuthProfileNormalizer.of(service);
|
|
260
|
-
})(OAuthProfileNormalizer || (OAuthProfileNormalizer = {}));
|
|
261
195
|
export class OAuthTokenExchangeError extends Data.TaggedError("OAuthTokenExchangeError") {
|
|
262
196
|
}
|
|
263
197
|
export class OAuthTokenExchange extends Context.Service()("auth/OAuthTokenExchange") {
|
|
264
198
|
}
|
|
265
|
-
(function (OAuthTokenExchange) {
|
|
266
|
-
OAuthTokenExchange.make = (service) => OAuthTokenExchange.of(service);
|
|
267
|
-
})(OAuthTokenExchange || (OAuthTokenExchange = {}));
|
|
268
199
|
export class OAuthProviders extends Context.Service()("auth/OAuthProviders") {
|
|
269
200
|
}
|
|
270
|
-
(function (OAuthProviders) {
|
|
271
|
-
OAuthProviders.make = (service) => OAuthProviders.of(service);
|
|
272
|
-
})(OAuthProviders || (OAuthProviders = {}));
|
|
273
201
|
export class OAuthStateError extends Data.TaggedError("OAuthStateError") {
|
|
274
202
|
}
|
|
275
203
|
export class OAuthState extends Context.Service()("auth/OAuthState") {
|
|
276
204
|
}
|
|
277
|
-
(function (OAuthState) {
|
|
278
|
-
OAuthState.make = (service) => OAuthState.of(service);
|
|
279
|
-
})(OAuthState || (OAuthState = {}));
|
|
280
205
|
export class OAuthAccountStoreError extends Data.TaggedError("OAuthAccountStoreError") {
|
|
281
206
|
}
|
|
207
|
+
export class OAuthIdentityBridgeConflictError extends Data.TaggedError("OAuthIdentityBridgeConflictError") {
|
|
208
|
+
}
|
|
209
|
+
export class OAuthIdentityBridgeStoreError extends Data.TaggedError("OAuthIdentityBridgeStoreError") {
|
|
210
|
+
}
|
|
211
|
+
export class OAuthIdentityBridgeStore extends Context.Service()("auth/OAuthIdentityBridgeStore") {
|
|
212
|
+
}
|
|
282
213
|
export class OAuthAccountStore extends Context.Service()("auth/OAuthAccountStore") {
|
|
283
214
|
}
|
|
284
|
-
(function (OAuthAccountStore) {
|
|
285
|
-
OAuthAccountStore.make = (service) => OAuthAccountStore.of(service);
|
|
286
|
-
})(OAuthAccountStore || (OAuthAccountStore = {}));
|
|
287
215
|
export class OAuthAccountLinkingError extends Data.TaggedError("OAuthAccountLinkingError") {
|
|
288
216
|
}
|
|
289
217
|
export class OAuthAccountLinking extends Context.Service()("auth/OAuthAccountLinking") {
|
|
290
218
|
}
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
219
|
+
export class OAuthIdentityBridgePolicy extends Context.Service()("auth/OAuthIdentityBridgePolicy") {
|
|
220
|
+
}
|
|
221
|
+
export class OAuthIdentityBridgeError extends Data.TaggedError("OAuthIdentityBridgeError") {
|
|
222
|
+
}
|
|
223
|
+
export class OAuthIdentityBridge extends Context.Service()("auth/OAuthIdentityBridge") {
|
|
224
|
+
}
|
|
294
225
|
export class OAuthAccountUnlinkingError extends Data.TaggedError("OAuthAccountUnlinkingError") {
|
|
295
226
|
}
|
|
296
227
|
export class OAuthAccountUnlinking extends Context.Service()("auth/OAuthAccountUnlinking") {
|
|
297
228
|
}
|
|
298
|
-
(function (OAuthAccountUnlinking) {
|
|
299
|
-
OAuthAccountUnlinking.make = (service) => OAuthAccountUnlinking.of(service);
|
|
300
|
-
})(OAuthAccountUnlinking || (OAuthAccountUnlinking = {}));
|
|
301
229
|
export class OAuthLinkConfirmationError extends Data.TaggedError("OAuthLinkConfirmationError") {
|
|
302
230
|
}
|
|
303
231
|
export class OAuthLinkConfirmation extends Context.Service()("auth/OAuthLinkConfirmation") {
|
|
304
232
|
}
|
|
305
|
-
(function (OAuthLinkConfirmation) {
|
|
306
|
-
OAuthLinkConfirmation.make = (service) => OAuthLinkConfirmation.of(service);
|
|
307
|
-
})(OAuthLinkConfirmation || (OAuthLinkConfirmation = {}));
|
|
308
233
|
const oauthStateError = (operation, message, cause) => new OAuthStateError({ operation, message, cause });
|
|
309
234
|
const oauthAuthorizationCodeGrantError = (operation, message, cause) => new OAuthAuthorizationCodeGrantError({ operation, message, cause });
|
|
310
235
|
const oauthAuthorizationCodeTokenGrantError = (operation, message, cause) => new OAuthAuthorizationCodeTokenGrantError({ operation, message, cause });
|
|
@@ -330,6 +255,10 @@ const oauthClientRegistryError = (operation, message, cause) => new OAuthClientR
|
|
|
330
255
|
message,
|
|
331
256
|
...(cause === undefined ? {} : { cause }),
|
|
332
257
|
});
|
|
258
|
+
const oauthProviderModeAccessTokenVerifierError = (message) => new OAuthProviderModeAccessTokenVerifierError({
|
|
259
|
+
operation: "verify",
|
|
260
|
+
message,
|
|
261
|
+
});
|
|
333
262
|
const oauthClientSecretError = (operation, message, cause) => new OAuthClientSecretError({
|
|
334
263
|
operation,
|
|
335
264
|
message,
|
|
@@ -397,8 +326,10 @@ const parseOAuthClientSecretValue = (secret) => {
|
|
|
397
326
|
}
|
|
398
327
|
return Effect.succeed(OAuthClientSecretPrefix(parts[0]));
|
|
399
328
|
};
|
|
400
|
-
const hashOAuthClientSecretValue = (dependencies, secret, operation) => dependencies.crypto
|
|
401
|
-
|
|
329
|
+
const hashOAuthClientSecretValue = (dependencies, secret, operation) => dependencies.crypto
|
|
330
|
+
.digestSha256({ data: `oauth-client-secret:${secret}` })
|
|
331
|
+
.pipe(Effect.map((hash) => OAuthClientSecretHash(`sha256:${hash}`)), Effect.mapError((cause) => oauthClientSecretError(operation, "Failed to hash OAuth client secret", cause)));
|
|
332
|
+
export const makeOAuthClientSecrets = (dependencies) => OAuthClientSecrets.of({
|
|
402
333
|
generate: Effect.fn("auth.oauth.client_secret.generate")(function* (input) {
|
|
403
334
|
const prefixBytes = yield* validateOAuthClientSecretByteLength(input?.prefixBytes ?? defaultOAuthClientSecretPrefixBytes, "generate", "OAuth client secret prefix");
|
|
404
335
|
const secretBytes = yield* validateOAuthClientSecretByteLength(input?.secretBytes ?? defaultOAuthClientSecretBytes, "generate", "OAuth client secret");
|
|
@@ -446,7 +377,9 @@ export const makeAppleSignInProvider = (input) => ({
|
|
|
446
377
|
...appleSignInDefaultAuthorizationParams,
|
|
447
378
|
...input.authorizationParams,
|
|
448
379
|
},
|
|
449
|
-
...(input.metadata === undefined
|
|
380
|
+
...(input.metadata === undefined
|
|
381
|
+
? {}
|
|
382
|
+
: { metadata: metadataValue(input.metadata) }),
|
|
450
383
|
});
|
|
451
384
|
export const makeGithubOAuthProvider = (input) => ({
|
|
452
385
|
id: input.id ?? githubOAuthProviderId,
|
|
@@ -459,7 +392,9 @@ export const makeGithubOAuthProvider = (input) => ({
|
|
|
459
392
|
...(input.authorizationParams === undefined
|
|
460
393
|
? {}
|
|
461
394
|
: { authorizationParams: { ...input.authorizationParams } }),
|
|
462
|
-
...(input.metadata === undefined
|
|
395
|
+
...(input.metadata === undefined
|
|
396
|
+
? {}
|
|
397
|
+
: { metadata: metadataValue(input.metadata) }),
|
|
463
398
|
});
|
|
464
399
|
export const makeGoogleOidcProvider = (input) => ({
|
|
465
400
|
id: input.id ?? googleOidcProviderId,
|
|
@@ -475,7 +410,9 @@ export const makeGoogleOidcProvider = (input) => ({
|
|
|
475
410
|
...(input.authorizationParams === undefined
|
|
476
411
|
? {}
|
|
477
412
|
: { authorizationParams: { ...input.authorizationParams } }),
|
|
478
|
-
...(input.metadata === undefined
|
|
413
|
+
...(input.metadata === undefined
|
|
414
|
+
? {}
|
|
415
|
+
: { metadata: metadataValue(input.metadata) }),
|
|
479
416
|
});
|
|
480
417
|
export const makeMicrosoftOidcProvider = (input) => ({
|
|
481
418
|
id: input.id ?? microsoftOidcProviderId,
|
|
@@ -490,7 +427,9 @@ export const makeMicrosoftOidcProvider = (input) => ({
|
|
|
490
427
|
...(input.authorizationParams === undefined
|
|
491
428
|
? {}
|
|
492
429
|
: { authorizationParams: { ...input.authorizationParams } }),
|
|
493
|
-
...(input.metadata === undefined
|
|
430
|
+
...(input.metadata === undefined
|
|
431
|
+
? {}
|
|
432
|
+
: { metadata: metadataValue(input.metadata) }),
|
|
494
433
|
});
|
|
495
434
|
export const makeGenericOidcProvider = (input) => ({
|
|
496
435
|
id: input.id,
|
|
@@ -510,7 +449,9 @@ export const makeGenericOidcProvider = (input) => ({
|
|
|
510
449
|
...(input.authorizationParams === undefined
|
|
511
450
|
? {}
|
|
512
451
|
: { authorizationParams: { ...input.authorizationParams } }),
|
|
513
|
-
...(input.metadata === undefined
|
|
452
|
+
...(input.metadata === undefined
|
|
453
|
+
? {}
|
|
454
|
+
: { metadata: metadataValue(input.metadata) }),
|
|
514
455
|
});
|
|
515
456
|
const oauthClientSecretPost = (clientSecret) => ({
|
|
516
457
|
method: "client_secret_post",
|
|
@@ -577,7 +518,9 @@ const cloneProviderConfig = (provider) => ({
|
|
|
577
518
|
...(provider.authorizationParams === undefined
|
|
578
519
|
? {}
|
|
579
520
|
: { authorizationParams: { ...provider.authorizationParams } }),
|
|
580
|
-
...(provider.metadata === undefined
|
|
521
|
+
...(provider.metadata === undefined
|
|
522
|
+
? {}
|
|
523
|
+
: { metadata: metadataValue(provider.metadata) }),
|
|
581
524
|
});
|
|
582
525
|
const cloneOAuthClientRecord = (client) => ({
|
|
583
526
|
...client,
|
|
@@ -587,7 +530,9 @@ const cloneOAuthClientRecord = (client) => ({
|
|
|
587
530
|
...(client.allowedScopes === undefined
|
|
588
531
|
? {}
|
|
589
532
|
: { allowedScopes: [...client.allowedScopes] }),
|
|
590
|
-
...(client.metadata === undefined
|
|
533
|
+
...(client.metadata === undefined
|
|
534
|
+
? {}
|
|
535
|
+
: { metadata: metadataValue(client.metadata) }),
|
|
591
536
|
});
|
|
592
537
|
const validateOAuthClientRedirectUriRecord = (client, input) => {
|
|
593
538
|
if (client === undefined) {
|
|
@@ -630,18 +575,24 @@ const isOAuthConsentActive = (record, now, scopes = []) => record.revokedAt ===
|
|
|
630
575
|
const cloneOAuthClientSecretRecord = (record) => ({
|
|
631
576
|
...record,
|
|
632
577
|
authenticationMethods: [...record.authenticationMethods],
|
|
633
|
-
...(record.metadata === undefined
|
|
578
|
+
...(record.metadata === undefined
|
|
579
|
+
? {}
|
|
580
|
+
: { metadata: metadataValue(record.metadata) }),
|
|
634
581
|
});
|
|
635
582
|
const cloneAuthorizationCodeRecord = (record) => ({
|
|
636
583
|
...record,
|
|
637
584
|
scopes: [...record.scopes],
|
|
638
|
-
...(record.metadata === undefined
|
|
585
|
+
...(record.metadata === undefined
|
|
586
|
+
? {}
|
|
587
|
+
: { metadata: metadataValue(record.metadata) }),
|
|
639
588
|
});
|
|
640
589
|
const cloneOAuthTokenResponse = (tokens) => ({
|
|
641
590
|
accessToken: tokens.accessToken,
|
|
642
591
|
tokenType: tokens.tokenType,
|
|
643
592
|
...(tokens.expiresIn === undefined ? {} : { expiresIn: tokens.expiresIn }),
|
|
644
|
-
...(tokens.refreshToken === undefined
|
|
593
|
+
...(tokens.refreshToken === undefined
|
|
594
|
+
? {}
|
|
595
|
+
: { refreshToken: tokens.refreshToken }),
|
|
645
596
|
...(tokens.idToken === undefined ? {} : { idToken: tokens.idToken }),
|
|
646
597
|
...(tokens.scopes === undefined ? {} : { scopes: [...tokens.scopes] }),
|
|
647
598
|
...(tokens.extra === undefined ? {} : { extra: metadataValue(tokens.extra) }),
|
|
@@ -649,14 +600,30 @@ const cloneOAuthTokenResponse = (tokens) => ({
|
|
|
649
600
|
const cloneOAuthTokenIntrospectionResponse = (response) => response.active
|
|
650
601
|
? {
|
|
651
602
|
active: true,
|
|
652
|
-
...(response.scopes === undefined
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
...(response.
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
...(response.
|
|
659
|
-
|
|
603
|
+
...(response.scopes === undefined
|
|
604
|
+
? {}
|
|
605
|
+
: { scopes: [...response.scopes] }),
|
|
606
|
+
...(response.clientId === undefined
|
|
607
|
+
? {}
|
|
608
|
+
: { clientId: response.clientId }),
|
|
609
|
+
...(response.username === undefined
|
|
610
|
+
? {}
|
|
611
|
+
: { username: response.username }),
|
|
612
|
+
...(response.tokenType === undefined
|
|
613
|
+
? {}
|
|
614
|
+
: { tokenType: response.tokenType }),
|
|
615
|
+
...(response.expiresAt === undefined
|
|
616
|
+
? {}
|
|
617
|
+
: { expiresAt: response.expiresAt }),
|
|
618
|
+
...(response.issuedAt === undefined
|
|
619
|
+
? {}
|
|
620
|
+
: { issuedAt: response.issuedAt }),
|
|
621
|
+
...(response.notBefore === undefined
|
|
622
|
+
? {}
|
|
623
|
+
: { notBefore: response.notBefore }),
|
|
624
|
+
...(response.subject === undefined
|
|
625
|
+
? {}
|
|
626
|
+
: { subject: response.subject }),
|
|
660
627
|
...(response.audience === undefined
|
|
661
628
|
? {}
|
|
662
629
|
: {
|
|
@@ -666,7 +633,9 @@ const cloneOAuthTokenIntrospectionResponse = (response) => response.active
|
|
|
666
633
|
}),
|
|
667
634
|
...(response.issuer === undefined ? {} : { issuer: response.issuer }),
|
|
668
635
|
...(response.jwtId === undefined ? {} : { jwtId: response.jwtId }),
|
|
669
|
-
...(response.extra === undefined
|
|
636
|
+
...(response.extra === undefined
|
|
637
|
+
? {}
|
|
638
|
+
: { extra: metadataValue(response.extra) }),
|
|
670
639
|
}
|
|
671
640
|
: { active: false };
|
|
672
641
|
const cloneOAuthProviderModeTokenRecord = (record) => ({
|
|
@@ -679,7 +648,29 @@ const cloneOAuthProviderModeTokenRecord = (record) => ({
|
|
|
679
648
|
? [...record.audience]
|
|
680
649
|
: record.audience,
|
|
681
650
|
}),
|
|
682
|
-
...(record.metadata === undefined
|
|
651
|
+
...(record.metadata === undefined
|
|
652
|
+
? {}
|
|
653
|
+
: { metadata: metadataValue(record.metadata) }),
|
|
654
|
+
});
|
|
655
|
+
const activeOAuthProviderModeAccessTokenRecord = (record) => ({
|
|
656
|
+
clientId: record.clientId,
|
|
657
|
+
subject: record.subject,
|
|
658
|
+
scopes: [...record.scopes],
|
|
659
|
+
issuedAt: record.issuedAt,
|
|
660
|
+
expiresAt: record.expiresAt,
|
|
661
|
+
tokenType: "access_token",
|
|
662
|
+
...(record.issuer === undefined ? {} : { issuer: record.issuer }),
|
|
663
|
+
...(record.audience === undefined
|
|
664
|
+
? {}
|
|
665
|
+
: {
|
|
666
|
+
audience: Array.isArray(record.audience)
|
|
667
|
+
? [...record.audience]
|
|
668
|
+
: record.audience,
|
|
669
|
+
}),
|
|
670
|
+
...(record.jwtId === undefined ? {} : { jwtId: record.jwtId }),
|
|
671
|
+
...(record.metadata === undefined
|
|
672
|
+
? {}
|
|
673
|
+
: { metadata: metadataValue(record.metadata) }),
|
|
683
674
|
});
|
|
684
675
|
const consumedAuthorizationCode = (record, consumedAt) => ({
|
|
685
676
|
clientId: record.clientId,
|
|
@@ -695,7 +686,9 @@ const consumedAuthorizationCode = (record, consumedAt) => ({
|
|
|
695
686
|
issuedAt: record.issuedAt,
|
|
696
687
|
expiresAt: record.expiresAt,
|
|
697
688
|
consumedAt,
|
|
698
|
-
...(record.metadata === undefined
|
|
689
|
+
...(record.metadata === undefined
|
|
690
|
+
? {}
|
|
691
|
+
: { metadata: metadataValue(record.metadata) }),
|
|
699
692
|
});
|
|
700
693
|
const issuedAuthorizationCode = (input) => ({
|
|
701
694
|
code: Redacted.make(input.code),
|
|
@@ -914,7 +907,9 @@ const oauthLinkConfirmationMetadata = (input) => ({
|
|
|
914
907
|
userId: input.userId,
|
|
915
908
|
providerId: input.identity.providerId,
|
|
916
909
|
providerAccountId: input.identity.providerAccountId,
|
|
917
|
-
...(input.identity.email === undefined
|
|
910
|
+
...(input.identity.email === undefined
|
|
911
|
+
? {}
|
|
912
|
+
: { email: input.identity.email }),
|
|
918
913
|
...(input.identity.emailVerified === undefined
|
|
919
914
|
? {}
|
|
920
915
|
: { emailVerified: input.identity.emailVerified }),
|
|
@@ -922,7 +917,9 @@ const oauthLinkConfirmationMetadata = (input) => ({
|
|
|
922
917
|
? {}
|
|
923
918
|
: { identityMetadata: metadataValue(input.identity.metadata) }),
|
|
924
919
|
reason: input.reason,
|
|
925
|
-
...(input.metadata === undefined
|
|
920
|
+
...(input.metadata === undefined
|
|
921
|
+
? {}
|
|
922
|
+
: { metadata: metadataValue(input.metadata) }),
|
|
926
923
|
});
|
|
927
924
|
const pendingOAuthLinkConfirmationFromChallenge = (challenge, operation) => {
|
|
928
925
|
const metadata = challenge.metadata ?? {};
|
|
@@ -951,10 +948,11 @@ const pendingOAuthLinkConfirmationFromChallenge = (challenge, operation) => {
|
|
|
951
948
|
? {}
|
|
952
949
|
: { metadata: metadataValue(identityMetadata) }),
|
|
953
950
|
},
|
|
954
|
-
reason: stringFromUnknown(metadata.reason) ??
|
|
955
|
-
"manual",
|
|
951
|
+
reason: stringFromUnknown(metadata.reason) ?? "manual",
|
|
956
952
|
expiresAt: challenge.expiresAt,
|
|
957
|
-
...(appMetadata === undefined
|
|
953
|
+
...(appMetadata === undefined
|
|
954
|
+
? {}
|
|
955
|
+
: { metadata: metadataValue(appMetadata) }),
|
|
958
956
|
});
|
|
959
957
|
};
|
|
960
958
|
const confirmedOAuthLinkConfirmationFromPending = (input) => ({
|
|
@@ -988,7 +986,9 @@ const makeOAuthProfile = (input) => ({
|
|
|
988
986
|
...(input.name === undefined ? {} : { name: input.name }),
|
|
989
987
|
...(input.username === undefined ? {} : { username: input.username }),
|
|
990
988
|
...(input.avatarUrl === undefined ? {} : { avatarUrl: input.avatarUrl }),
|
|
991
|
-
...(input.metadata === undefined
|
|
989
|
+
...(input.metadata === undefined
|
|
990
|
+
? {}
|
|
991
|
+
: { metadata: metadataValue(input.metadata) }),
|
|
992
992
|
});
|
|
993
993
|
const oauthJwksPublicJwkFromUnknown = (value) => {
|
|
994
994
|
const record = recordFromUnknown(value);
|
|
@@ -1061,7 +1061,9 @@ const oauthJwksRecordsFromDocument = (provider, document, allowedAlgorithms) =>
|
|
|
1061
1061
|
},
|
|
1062
1062
|
}));
|
|
1063
1063
|
});
|
|
1064
|
-
const oauthJwksKeyUsableAt = (key, now) => now === undefined ||
|
|
1064
|
+
const oauthJwksKeyUsableAt = (key, now) => now === undefined ||
|
|
1065
|
+
key.expiresAt === undefined ||
|
|
1066
|
+
Number(now) < Number(key.expiresAt);
|
|
1065
1067
|
const oauthJwksVerificationKeyMatches = (key, input) => key.id === input.kid &&
|
|
1066
1068
|
key.status !== "disabled" &&
|
|
1067
1069
|
key.publicJwk !== undefined &&
|
|
@@ -1231,7 +1233,7 @@ export const decodeOAuthTokenResponse = (value) => Effect.gen(function* () {
|
|
|
1231
1233
|
extra: tokenResponseExtra(value),
|
|
1232
1234
|
};
|
|
1233
1235
|
});
|
|
1234
|
-
export const makeOidcIdTokenVerifier = (dependencies) => OidcIdTokenVerifier.
|
|
1236
|
+
export const makeOidcIdTokenVerifier = (dependencies) => OidcIdTokenVerifier.of({
|
|
1235
1237
|
verify: Effect.fn("auth.oidc_id_token.verify")(function* (input) {
|
|
1236
1238
|
const { provider } = input;
|
|
1237
1239
|
const { issuer } = provider;
|
|
@@ -1255,7 +1257,10 @@ export const makeOidcIdTokenVerifier = (dependencies) => OidcIdTokenVerifier.mak
|
|
|
1255
1257
|
}
|
|
1256
1258
|
const claims = oidcIdTokenClaims(verified.claims, input);
|
|
1257
1259
|
if (typeof claims === "string") {
|
|
1258
|
-
return {
|
|
1260
|
+
return {
|
|
1261
|
+
valid: false,
|
|
1262
|
+
reason: claims,
|
|
1263
|
+
};
|
|
1259
1264
|
}
|
|
1260
1265
|
return {
|
|
1261
1266
|
valid: true,
|
|
@@ -1305,7 +1310,7 @@ export const makeOAuthJwksJwtKeys = (dependencies) => {
|
|
|
1305
1310
|
};
|
|
1306
1311
|
return records;
|
|
1307
1312
|
});
|
|
1308
|
-
return JwtKeys.
|
|
1313
|
+
return JwtKeys.of({
|
|
1309
1314
|
selectSigningKey: () => Effect.succeed(Option.none()),
|
|
1310
1315
|
findVerificationKey: Effect.fn("auth.oauth_jwks.find_verification_key")(function* (input) {
|
|
1311
1316
|
const now = yield* oauthJwksNow(input.now);
|
|
@@ -1332,7 +1337,9 @@ export const normalizeOidcProfile = (input) => Effect.gen(function* () {
|
|
|
1332
1337
|
return yield* oauthProfileNormalizationError("missing_subject", "OIDC profile is missing subject");
|
|
1333
1338
|
}
|
|
1334
1339
|
const userInfo = yield* userInfoRecord(input.userInfo);
|
|
1335
|
-
const userInfoSubject = userInfo === undefined
|
|
1340
|
+
const userInfoSubject = userInfo === undefined
|
|
1341
|
+
? undefined
|
|
1342
|
+
: nonEmptyStringFromUnknown(userInfo.sub);
|
|
1336
1343
|
if (userInfoSubject !== undefined && userInfoSubject !== subject) {
|
|
1337
1344
|
return yield* oauthProfileNormalizationError("subject_mismatch", "OIDC userinfo subject does not match ID token subject");
|
|
1338
1345
|
}
|
|
@@ -1353,7 +1360,7 @@ export const normalizeOidcProfile = (input) => Effect.gen(function* () {
|
|
|
1353
1360
|
metadata,
|
|
1354
1361
|
});
|
|
1355
1362
|
});
|
|
1356
|
-
export const makeOidcOAuthProfileNormalizer = () => OAuthProfileNormalizer.
|
|
1363
|
+
export const makeOidcOAuthProfileNormalizer = () => OAuthProfileNormalizer.of({
|
|
1357
1364
|
normalize: Effect.fn("auth.oauth_profile.normalize_oidc")(normalizeOidcProfile),
|
|
1358
1365
|
});
|
|
1359
1366
|
export const normalizeOAuthProfile = (input) => OAuthProfileNormalizer.use((normalizer) => normalizer.normalize(input));
|
|
@@ -1361,7 +1368,9 @@ export const verifiedOAuthIdentityFromProfile = (profile) => {
|
|
|
1361
1368
|
const metadata = optionalRecord({
|
|
1362
1369
|
...(profile.name === undefined ? {} : { name: profile.name }),
|
|
1363
1370
|
...(profile.username === undefined ? {} : { username: profile.username }),
|
|
1364
|
-
...(profile.avatarUrl === undefined
|
|
1371
|
+
...(profile.avatarUrl === undefined
|
|
1372
|
+
? {}
|
|
1373
|
+
: { avatarUrl: profile.avatarUrl }),
|
|
1365
1374
|
...(profile.metadata === undefined ? {} : profile.metadata),
|
|
1366
1375
|
});
|
|
1367
1376
|
return {
|
|
@@ -1374,7 +1383,7 @@ export const verifiedOAuthIdentityFromProfile = (profile) => {
|
|
|
1374
1383
|
...(metadata === undefined ? {} : { metadata: metadataValue(metadata) }),
|
|
1375
1384
|
};
|
|
1376
1385
|
};
|
|
1377
|
-
export const makeOAuthTokenExchange = (dependencies) => OAuthTokenExchange.
|
|
1386
|
+
export const makeOAuthTokenExchange = (dependencies) => OAuthTokenExchange.of({
|
|
1378
1387
|
exchangeAuthorizationCode: Effect.fn("auth.oauth_token.exchange_code")(function* (input) {
|
|
1379
1388
|
const request = yield* makeOAuthTokenRequest(input);
|
|
1380
1389
|
const response = yield* dependencies.request(request);
|
|
@@ -1413,9 +1422,13 @@ const storeOAuthProviderTokenResponse = (dependencies, input, operation) => Effe
|
|
|
1413
1422
|
accessTokenCiphertext,
|
|
1414
1423
|
tokenType: input.tokens.tokenType,
|
|
1415
1424
|
updatedAt: now,
|
|
1416
|
-
...(refreshTokenCiphertext === undefined
|
|
1425
|
+
...(refreshTokenCiphertext === undefined
|
|
1426
|
+
? {}
|
|
1427
|
+
: { refreshTokenCiphertext }),
|
|
1417
1428
|
...(idTokenCiphertext === undefined ? {} : { idTokenCiphertext }),
|
|
1418
|
-
...(input.tokens.scopes === undefined
|
|
1429
|
+
...(input.tokens.scopes === undefined
|
|
1430
|
+
? {}
|
|
1431
|
+
: { scopes: input.tokens.scopes }),
|
|
1419
1432
|
...(expiresAt === undefined ? {} : { expiresAt }),
|
|
1420
1433
|
})
|
|
1421
1434
|
.pipe(Effect.mapError((cause) => oauthProviderTokenLifecycleError(operation, "Failed to store OAuth provider token ciphertext", cause)));
|
|
@@ -1427,7 +1440,9 @@ const storeOAuthProviderTokenResponse = (dependencies, input, operation) => Effe
|
|
|
1427
1440
|
};
|
|
1428
1441
|
});
|
|
1429
1442
|
const revokeOAuthProviderTokenCiphertext = (dependencies, input, tokenCiphertext, tokenTypeHint) => Effect.gen(function* () {
|
|
1430
|
-
const token = yield* dependencies
|
|
1443
|
+
const token = yield* dependencies
|
|
1444
|
+
.decryptToken(tokenCiphertext)
|
|
1445
|
+
.pipe(Effect.mapError((cause) => oauthProviderTokenLifecycleError("revoke", `Failed to decrypt OAuth provider ${tokenTypeHint}`, cause)));
|
|
1431
1446
|
const request = yield* makeOAuthTokenRevocationRequest({
|
|
1432
1447
|
provider: input.provider,
|
|
1433
1448
|
token,
|
|
@@ -1437,9 +1452,11 @@ const revokeOAuthProviderTokenCiphertext = (dependencies, input, tokenCiphertext
|
|
|
1437
1452
|
: { clientAuthentication: input.clientAuthentication }),
|
|
1438
1453
|
...(input.params === undefined ? {} : { params: input.params }),
|
|
1439
1454
|
}).pipe(Effect.mapError((cause) => oauthProviderTokenLifecycleError("revoke", "Failed to build OAuth provider token revocation request", cause)));
|
|
1440
|
-
yield* dependencies
|
|
1455
|
+
yield* dependencies
|
|
1456
|
+
.request(request)
|
|
1457
|
+
.pipe(Effect.mapError((cause) => oauthProviderTokenLifecycleError("revoke", "Failed to execute OAuth provider token revocation request", cause)));
|
|
1441
1458
|
});
|
|
1442
|
-
export const makeOAuthProviderTokenLifecycle = (dependencies) => OAuthProviderTokenLifecycle.
|
|
1459
|
+
export const makeOAuthProviderTokenLifecycle = (dependencies) => OAuthProviderTokenLifecycle.of({
|
|
1443
1460
|
store: Effect.fn("auth.oauth_provider_token_lifecycle.store")(function* (input) {
|
|
1444
1461
|
return yield* storeOAuthProviderTokenResponse(dependencies, input, "store");
|
|
1445
1462
|
}),
|
|
@@ -1465,7 +1482,9 @@ export const makeOAuthProviderTokenLifecycle = (dependencies) => OAuthProviderTo
|
|
|
1465
1482
|
: { clientAuthentication: input.clientAuthentication }),
|
|
1466
1483
|
...(input.params === undefined ? {} : { params: input.params }),
|
|
1467
1484
|
}).pipe(Effect.mapError((cause) => oauthProviderTokenLifecycleError("refresh", "Failed to build OAuth provider token refresh request", cause)));
|
|
1468
|
-
const rawResponse = yield* dependencies
|
|
1485
|
+
const rawResponse = yield* dependencies
|
|
1486
|
+
.request(request)
|
|
1487
|
+
.pipe(Effect.mapError((cause) => oauthProviderTokenLifecycleError("refresh", "Failed to execute OAuth provider token refresh request", cause)));
|
|
1469
1488
|
const tokens = yield* decodeOAuthTokenResponse(rawResponse).pipe(Effect.mapError((cause) => oauthProviderTokenLifecycleError("refresh", "Failed to decode OAuth provider token refresh response", cause)));
|
|
1470
1489
|
const stored = yield* storeOAuthProviderTokenResponse(dependencies, {
|
|
1471
1490
|
accountId: input.accountId,
|
|
@@ -1531,13 +1550,15 @@ export const completeOAuthCallback = (input) => Effect.gen(function* () {
|
|
|
1531
1550
|
provider: input.provider,
|
|
1532
1551
|
code: input.code,
|
|
1533
1552
|
codeVerifier: input.codeVerifier,
|
|
1534
|
-
redirectUri: input.redirectUri ??
|
|
1553
|
+
redirectUri: input.redirectUri ??
|
|
1554
|
+
verifiedState.redirectUri ??
|
|
1555
|
+
input.provider.redirectUri,
|
|
1535
1556
|
clientAuthentication: input.clientAuthentication,
|
|
1536
1557
|
params: input.tokenParams,
|
|
1537
1558
|
});
|
|
1538
1559
|
return { state: verifiedState, tokens };
|
|
1539
1560
|
});
|
|
1540
|
-
export const makeOAuthAccountLinkingPolicy = (dependencies) => OAuthAccountLinking.
|
|
1561
|
+
export const makeOAuthAccountLinkingPolicy = (dependencies) => OAuthAccountLinking.of({
|
|
1541
1562
|
resolve: Effect.fn("auth.oauth_account_linking.resolve")(function* (input) {
|
|
1542
1563
|
const identity = cloneVerifiedOAuthIdentity(input.identity);
|
|
1543
1564
|
const linked = yield* dependencies.accounts
|
|
@@ -1585,7 +1606,9 @@ export const makeOAuthAccountLinkingPolicy = (dependencies) => OAuthAccountLinki
|
|
|
1585
1606
|
}
|
|
1586
1607
|
return {
|
|
1587
1608
|
type: "require-explicit-linking",
|
|
1588
|
-
reason: identity.emailVerified === true
|
|
1609
|
+
reason: identity.emailVerified === true
|
|
1610
|
+
? "matched-email"
|
|
1611
|
+
: "unverified-email",
|
|
1589
1612
|
identity,
|
|
1590
1613
|
matchedUserId: input.matchedUserId,
|
|
1591
1614
|
};
|
|
@@ -1598,7 +1621,119 @@ export const makeOAuthAccountLinkingPolicy = (dependencies) => OAuthAccountLinki
|
|
|
1598
1621
|
}),
|
|
1599
1622
|
});
|
|
1600
1623
|
export const resolveOAuthAccountLinking = (input) => OAuthAccountLinking.use((linking) => linking.resolve(input));
|
|
1601
|
-
export const
|
|
1624
|
+
export const makeOAuthIdentityBridge = (dependencies) => OAuthIdentityBridge.of({
|
|
1625
|
+
resolve: Effect.fn("auth.oauth_identity_bridge.resolve")(function* (input) {
|
|
1626
|
+
const identity = cloneVerifiedOAuthIdentity(input.identity);
|
|
1627
|
+
const mapError = (message) => (cause) => new OAuthIdentityBridgeError({ message, cause });
|
|
1628
|
+
const initial = yield* dependencies.linking
|
|
1629
|
+
.resolve({ identity, currentUserId: input.currentUserId })
|
|
1630
|
+
.pipe(Effect.mapError(mapError("Failed to resolve OAuth account")));
|
|
1631
|
+
if (initial.type !== "require-explicit-linking") {
|
|
1632
|
+
return initial;
|
|
1633
|
+
}
|
|
1634
|
+
const decision = yield* dependencies.policy.decide({
|
|
1635
|
+
identity,
|
|
1636
|
+
currentUserId: input.currentUserId,
|
|
1637
|
+
});
|
|
1638
|
+
if (decision.type === "deny") {
|
|
1639
|
+
return { type: "deny", reason: decision.reason, identity };
|
|
1640
|
+
}
|
|
1641
|
+
const trustedVerifiedEmail = decision.trustVerifiedEmail === true &&
|
|
1642
|
+
identity.emailVerified === true &&
|
|
1643
|
+
identity.email !== undefined;
|
|
1644
|
+
const normalizedEmail = trustedVerifiedEmail
|
|
1645
|
+
? yield* normalizeEmail(identity.email).pipe(Effect.mapError(mapError("Provider returned an invalid email claim")))
|
|
1646
|
+
: undefined;
|
|
1647
|
+
const matched = normalizedEmail === undefined
|
|
1648
|
+
? Option.none()
|
|
1649
|
+
: yield* dependencies.identities
|
|
1650
|
+
.findByKindAndNormalizedValue({
|
|
1651
|
+
scope: globalIdentityScope,
|
|
1652
|
+
kind: "email",
|
|
1653
|
+
normalizedValue: normalizedEmail,
|
|
1654
|
+
})
|
|
1655
|
+
.pipe(Effect.mapError(mapError("Failed to resolve provider email")));
|
|
1656
|
+
const linking = Option.isNone(matched)
|
|
1657
|
+
? initial
|
|
1658
|
+
: yield* dependencies.linking
|
|
1659
|
+
.resolve({
|
|
1660
|
+
identity,
|
|
1661
|
+
currentUserId: input.currentUserId,
|
|
1662
|
+
matchedUserId: matched.value.userId,
|
|
1663
|
+
})
|
|
1664
|
+
.pipe(Effect.mapError(mapError("Failed to resolve OAuth linking")));
|
|
1665
|
+
if (linking.type !== "require-explicit-linking") {
|
|
1666
|
+
return linking;
|
|
1667
|
+
}
|
|
1668
|
+
if (Option.isSome(matched)) {
|
|
1669
|
+
return linking;
|
|
1670
|
+
}
|
|
1671
|
+
if (!decision.createUser) {
|
|
1672
|
+
return {
|
|
1673
|
+
type: "deny",
|
|
1674
|
+
reason: "user-creation-not-permitted",
|
|
1675
|
+
identity,
|
|
1676
|
+
};
|
|
1677
|
+
}
|
|
1678
|
+
const user = input.makeUser();
|
|
1679
|
+
const account = input.makeAccount(user.id);
|
|
1680
|
+
if (account.userId !== user.id) {
|
|
1681
|
+
return yield* new OAuthIdentityBridgeError({
|
|
1682
|
+
message: "OAuth account user does not match the new user",
|
|
1683
|
+
});
|
|
1684
|
+
}
|
|
1685
|
+
const emailIdentity = decision.createEmailIdentity === true && normalizedEmail !== undefined
|
|
1686
|
+
? input.makeEmailIdentity(user.id, identity.email, normalizedEmail)
|
|
1687
|
+
: undefined;
|
|
1688
|
+
if (emailIdentity !== undefined && emailIdentity.userId !== user.id) {
|
|
1689
|
+
return yield* new OAuthIdentityBridgeError({
|
|
1690
|
+
message: "Email identity user does not match the new user",
|
|
1691
|
+
});
|
|
1692
|
+
}
|
|
1693
|
+
const created = yield* dependencies.store
|
|
1694
|
+
.create({ user, account, identity: emailIdentity })
|
|
1695
|
+
.pipe(Effect.catchTag("OAuthIdentityBridgeConflictError", (conflict) => {
|
|
1696
|
+
if (conflict.reason === "provider-account" ||
|
|
1697
|
+
conflict.reason === "oauth-account-id") {
|
|
1698
|
+
return dependencies.linking
|
|
1699
|
+
.resolve({ identity, currentUserId: input.currentUserId })
|
|
1700
|
+
.pipe(Effect.mapError(mapError("Failed to resolve OAuth race")));
|
|
1701
|
+
}
|
|
1702
|
+
if (conflict.reason === "identity-value") {
|
|
1703
|
+
return dependencies.identities
|
|
1704
|
+
.findByKindAndNormalizedValue({
|
|
1705
|
+
scope: globalIdentityScope,
|
|
1706
|
+
kind: "email",
|
|
1707
|
+
normalizedValue: normalizedEmail,
|
|
1708
|
+
})
|
|
1709
|
+
.pipe(Effect.mapError(mapError("Failed to resolve email collision")), Effect.map((collision) => ({
|
|
1710
|
+
type: "require-explicit-linking",
|
|
1711
|
+
reason: "matched-email",
|
|
1712
|
+
identity,
|
|
1713
|
+
...(Option.isSome(collision)
|
|
1714
|
+
? { matchedUserId: collision.value.userId }
|
|
1715
|
+
: {}),
|
|
1716
|
+
})));
|
|
1717
|
+
}
|
|
1718
|
+
return Effect.fail(new OAuthIdentityBridgeError({
|
|
1719
|
+
message: `OAuth identity creation conflicted on ${conflict.reason}`,
|
|
1720
|
+
cause: conflict,
|
|
1721
|
+
}));
|
|
1722
|
+
}), Effect.mapError((cause) => cause instanceof OAuthIdentityBridgeError
|
|
1723
|
+
? cause
|
|
1724
|
+
: mapError("Failed to create OAuth identity")(cause)));
|
|
1725
|
+
if ("type" in created) {
|
|
1726
|
+
return created;
|
|
1727
|
+
}
|
|
1728
|
+
return {
|
|
1729
|
+
type: "created",
|
|
1730
|
+
reason: "new-provider-account",
|
|
1731
|
+
...created,
|
|
1732
|
+
};
|
|
1733
|
+
}),
|
|
1734
|
+
});
|
|
1735
|
+
export const resolveOAuthIdentityBridge = (input) => OAuthIdentityBridge.use((bridge) => bridge.resolve(input));
|
|
1736
|
+
export const makeOAuthAccountUnlinkingPolicy = (dependencies) => OAuthAccountUnlinking.of({
|
|
1602
1737
|
resolve: Effect.fn("auth.oauth_account_unlinking.resolve")(function* (input) {
|
|
1603
1738
|
const account = yield* dependencies.accounts
|
|
1604
1739
|
.findByProviderAccount({
|
|
@@ -1627,7 +1762,8 @@ export const makeOAuthAccountUnlinkingPolicy = (dependencies) => OAuthAccountUnl
|
|
|
1627
1762
|
const remainingAccounts = yield* dependencies.accounts
|
|
1628
1763
|
.listByUser({ userId: input.userId })
|
|
1629
1764
|
.pipe(Effect.map((accounts) => accounts.filter((linked) => linked.id !== linkedAccount.id)), Effect.mapError((cause) => oauthAccountUnlinkingError("resolve", "Failed to list OAuth provider accounts for user", cause)));
|
|
1630
|
-
if (dependencies.allowLastAccount !== true &&
|
|
1765
|
+
if (dependencies.allowLastAccount !== true &&
|
|
1766
|
+
remainingAccounts.length === 0) {
|
|
1631
1767
|
return {
|
|
1632
1768
|
type: "deny-last-account",
|
|
1633
1769
|
reason: "last-linked-account",
|
|
@@ -1635,7 +1771,8 @@ export const makeOAuthAccountUnlinkingPolicy = (dependencies) => OAuthAccountUnl
|
|
|
1635
1771
|
account: linkedAccount,
|
|
1636
1772
|
};
|
|
1637
1773
|
}
|
|
1638
|
-
if (dependencies.requireStepUp === true &&
|
|
1774
|
+
if (dependencies.requireStepUp === true &&
|
|
1775
|
+
input.stepUpSatisfied !== true) {
|
|
1639
1776
|
return {
|
|
1640
1777
|
type: "requires-step-up",
|
|
1641
1778
|
reason: "step-up-required",
|
|
@@ -1668,7 +1805,7 @@ const findOAuthLinkConfirmationExistingAccount = (dependencies, input) => depend
|
|
|
1668
1805
|
}
|
|
1669
1806
|
return Effect.succeed(account);
|
|
1670
1807
|
}));
|
|
1671
|
-
export const makeOAuthLinkConfirmation = (dependencies) => OAuthLinkConfirmation.
|
|
1808
|
+
export const makeOAuthLinkConfirmation = (dependencies) => OAuthLinkConfirmation.of({
|
|
1672
1809
|
start: Effect.fn("auth.oauth_link_confirmation.start")(function* (input) {
|
|
1673
1810
|
const identity = cloneVerifiedOAuthIdentity(input.identity);
|
|
1674
1811
|
const reason = input.reason ?? "manual";
|
|
@@ -1682,7 +1819,8 @@ export const makeOAuthLinkConfirmation = (dependencies) => OAuthLinkConfirmation
|
|
|
1682
1819
|
}
|
|
1683
1820
|
const secret = input.secret ??
|
|
1684
1821
|
(yield* dependencies.crypto
|
|
1685
|
-
.randomToken(yield* validateOAuthLinkConfirmationSecretBytes(dependencies.secretBytes ??
|
|
1822
|
+
.randomToken(yield* validateOAuthLinkConfirmationSecretBytes(dependencies.secretBytes ??
|
|
1823
|
+
defaultOAuthLinkConfirmationSecretBytes))
|
|
1686
1824
|
.pipe(Effect.map(Redacted.make), Effect.mapError((cause) => oauthLinkConfirmationError("start", "Failed to generate OAuth link confirmation secret", cause))));
|
|
1687
1825
|
const issued = yield* dependencies.challenge
|
|
1688
1826
|
.issue({
|
|
@@ -1735,7 +1873,8 @@ export const makeOAuthLinkConfirmation = (dependencies) => OAuthLinkConfirmation
|
|
|
1735
1873
|
})
|
|
1736
1874
|
.pipe(Effect.mapError((cause) => oauthLinkConfirmationError("confirm", "Invalid OAuth link confirmation challenge", cause)));
|
|
1737
1875
|
const pending = yield* pendingOAuthLinkConfirmationFromChallenge(inspected, "confirm");
|
|
1738
|
-
if (input.currentUserId !== undefined &&
|
|
1876
|
+
if (input.currentUserId !== undefined &&
|
|
1877
|
+
input.currentUserId !== pending.userId) {
|
|
1739
1878
|
return yield* oauthLinkConfirmationError("confirm", "OAuth link confirmation does not match current user");
|
|
1740
1879
|
}
|
|
1741
1880
|
if (input.expectedProviderId !== undefined &&
|
|
@@ -1760,7 +1899,9 @@ export const makeOAuthLinkConfirmation = (dependencies) => OAuthLinkConfirmation
|
|
|
1760
1899
|
.pipe(Effect.mapError((cause) => oauthLinkConfirmationError("confirm", "Failed to consume OAuth link confirmation challenge", cause)));
|
|
1761
1900
|
return confirmedOAuthLinkConfirmationFromPending({
|
|
1762
1901
|
pending,
|
|
1763
|
-
...(Option.isSome(existing)
|
|
1902
|
+
...(Option.isSome(existing)
|
|
1903
|
+
? { existingAccount: existing.value }
|
|
1904
|
+
: {}),
|
|
1764
1905
|
});
|
|
1765
1906
|
}),
|
|
1766
1907
|
});
|
|
@@ -1784,7 +1925,9 @@ const makeOAuthPkceWithCrypto = (dependencies, input) => Effect.gen(function* ()
|
|
|
1784
1925
|
codeChallengeMethod: "S256",
|
|
1785
1926
|
};
|
|
1786
1927
|
});
|
|
1787
|
-
const authorizationCodeHash = (crypto, code, operation) => crypto
|
|
1928
|
+
const authorizationCodeHash = (crypto, code, operation) => crypto
|
|
1929
|
+
.digestSha256({ data: String(code) })
|
|
1930
|
+
.pipe(Effect.mapError((cause) => oauthAuthorizationCodeGrantError(operation, "Failed to hash OAuth authorization code", cause)));
|
|
1788
1931
|
const pkceChallengeForVerifier = (crypto, verifier) => crypto.digestSha256({ data: Redacted.value(verifier) }).pipe(Effect.map(OAuthCodeChallenge), Effect.mapError((cause) => oauthAuthorizationCodeGrantError("consume", "Failed to calculate OAuth PKCE challenge", cause)));
|
|
1789
1932
|
const timingSafeEqualString = (crypto, left, right) => crypto
|
|
1790
1933
|
.timingSafeEqual({
|
|
@@ -1798,7 +1941,7 @@ const authorizationCodeExpiresAt = (input, issuedAt, defaultTtl) => input.expire
|
|
|
1798
1941
|
export const makeOAuthAuthorizationCodeGrant = (dependencies) => {
|
|
1799
1942
|
const codeBytes = dependencies.codeBytes ?? defaultOAuthAuthorizationCodeBytes;
|
|
1800
1943
|
const codeTtl = dependencies.codeTtl ?? defaultOAuthAuthorizationCodeTtl;
|
|
1801
|
-
return OAuthAuthorizationCodeGrant.
|
|
1944
|
+
return OAuthAuthorizationCodeGrant.of({
|
|
1802
1945
|
issue: Effect.fn("auth.oauth.authorization_code.issue")(function* (input) {
|
|
1803
1946
|
const issuedAt = input.issuedAt ?? (yield* currentUnixMillis);
|
|
1804
1947
|
const expiresAt = authorizationCodeExpiresAt(input, issuedAt, codeTtl);
|
|
@@ -1832,13 +1975,17 @@ export const makeOAuthAuthorizationCodeGrant = (dependencies) => {
|
|
|
1832
1975
|
? {}
|
|
1833
1976
|
: { metadata: metadataValue(input.metadata) }),
|
|
1834
1977
|
};
|
|
1835
|
-
yield* dependencies.store
|
|
1978
|
+
yield* dependencies.store
|
|
1979
|
+
.upsert(record)
|
|
1980
|
+
.pipe(Effect.mapError((cause) => oauthAuthorizationCodeGrantError("issue", "Failed to store OAuth authorization code", cause)));
|
|
1836
1981
|
return issuedAuthorizationCode({ code, record });
|
|
1837
1982
|
}),
|
|
1838
1983
|
consume: Effect.fn("auth.oauth.authorization_code.consume")(function* (input) {
|
|
1839
1984
|
const now = input.now ?? (yield* currentUnixMillis);
|
|
1840
1985
|
const codeHash = yield* authorizationCodeHash(dependencies.crypto, authorizationCodeValue(input.code), "consume");
|
|
1841
|
-
const recordOption = yield* dependencies.store
|
|
1986
|
+
const recordOption = yield* dependencies.store
|
|
1987
|
+
.findByHash({ codeHash })
|
|
1988
|
+
.pipe(Effect.mapError((cause) => oauthAuthorizationCodeGrantError("consume", "Failed to load OAuth authorization code", cause)));
|
|
1842
1989
|
if (Option.isNone(recordOption)) {
|
|
1843
1990
|
return { valid: false, reason: "unknown_code" };
|
|
1844
1991
|
}
|
|
@@ -1893,7 +2040,7 @@ const oauthTokenGrantString = (value) => {
|
|
|
1893
2040
|
return trimmed === undefined || trimmed === "" ? undefined : trimmed;
|
|
1894
2041
|
};
|
|
1895
2042
|
const oauthTokenGrantScopes = (scopes) => {
|
|
1896
|
-
const values = typeof scopes === "string" ? scopes.split(/\s+/) : scopes ?? [];
|
|
2043
|
+
const values = typeof scopes === "string" ? scopes.split(/\s+/) : (scopes ?? []);
|
|
1897
2044
|
const unique = new Set();
|
|
1898
2045
|
for (const value of values) {
|
|
1899
2046
|
const scope = value.trim();
|
|
@@ -1903,17 +2050,24 @@ const oauthTokenGrantScopes = (scopes) => {
|
|
|
1903
2050
|
}
|
|
1904
2051
|
return [...unique];
|
|
1905
2052
|
};
|
|
1906
|
-
const oauthTokenGrantScopesAllowed = (scopes, allowedScopes) => allowedScopes === undefined ||
|
|
2053
|
+
const oauthTokenGrantScopesAllowed = (scopes, allowedScopes) => allowedScopes === undefined ||
|
|
2054
|
+
scopes.every((scope) => allowedScopes.includes(scope));
|
|
1907
2055
|
const validateOAuthProviderModeOpaqueTokenBytes = (value, label, error) => Number.isInteger(value) && value >= 16 && value <= 128
|
|
1908
2056
|
? Effect.succeed(value)
|
|
1909
2057
|
: Effect.fail(error(`${label} byte length must be an integer between 16 and 128`));
|
|
1910
2058
|
const generateOAuthProviderModeOpaqueToken = (crypto, byteLength, brand, label, error) => Effect.gen(function* () {
|
|
1911
2059
|
const validByteLength = yield* validateOAuthProviderModeOpaqueTokenBytes(byteLength, label, error);
|
|
1912
|
-
const token = yield* crypto
|
|
2060
|
+
const token = yield* crypto
|
|
2061
|
+
.randomToken(validByteLength)
|
|
2062
|
+
.pipe(Effect.mapError((cause) => error(`Failed to generate OAuth ${label} token`, cause)));
|
|
1913
2063
|
return Redacted.make(brand(token));
|
|
1914
2064
|
});
|
|
1915
2065
|
const oauthProviderModeOpaqueTokenHash = (crypto, token, error) => crypto.digestSha256({ data: Redacted.value(token) }).pipe(Effect.map((digest) => `sha256:${digest}`), Effect.mapError((cause) => error("Failed to hash OAuth provider-mode token", cause)));
|
|
1916
|
-
const oauthProviderModeOpaqueTokenAudience = (audience) => audience === undefined
|
|
2066
|
+
const oauthProviderModeOpaqueTokenAudience = (audience) => audience === undefined
|
|
2067
|
+
? undefined
|
|
2068
|
+
: Array.isArray(audience)
|
|
2069
|
+
? [...audience]
|
|
2070
|
+
: audience;
|
|
1917
2071
|
const oauthProviderModeOpaqueTokenRecord = (dependencies, input) => ({
|
|
1918
2072
|
tokenHash: input.tokenHash,
|
|
1919
2073
|
tokenType: input.tokenType,
|
|
@@ -1925,10 +2079,12 @@ const oauthProviderModeOpaqueTokenRecord = (dependencies, input) => ({
|
|
|
1925
2079
|
...(dependencies.issuer === undefined ? {} : { issuer: dependencies.issuer }),
|
|
1926
2080
|
...(dependencies.audience === undefined
|
|
1927
2081
|
? {}
|
|
1928
|
-
: {
|
|
1929
|
-
|
|
2082
|
+
: {
|
|
2083
|
+
audience: oauthProviderModeOpaqueTokenAudience(dependencies.audience),
|
|
2084
|
+
}),
|
|
2085
|
+
...(input.metadata === undefined && dependencies.metadata === undefined
|
|
1930
2086
|
? {}
|
|
1931
|
-
: { metadata: metadataValue(dependencies.metadata) }),
|
|
2087
|
+
: { metadata: metadataValue(input.metadata ?? dependencies.metadata) }),
|
|
1932
2088
|
});
|
|
1933
2089
|
const oauthProviderModeOpaqueExpiresAt = (issuedAt, ttl) => UnixMillis(Number(issuedAt) + Duration.toMillis(ttl));
|
|
1934
2090
|
const oauthProviderModeOpaqueExpiresInSeconds = (issuedAt, expiresAt) => Math.max(0, Math.floor((Number(expiresAt) - Number(issuedAt)) / 1000));
|
|
@@ -1941,8 +2097,16 @@ const oauthProviderModeOpaqueTokenResponse = (input) => ({
|
|
|
1941
2097
|
: { refreshToken: input.refreshToken }),
|
|
1942
2098
|
...(input.scopes.length === 0 ? {} : { scopes: [...input.scopes] }),
|
|
1943
2099
|
});
|
|
1944
|
-
const oauthProviderModeOpaqueStoreToken = (store, record, error) => store
|
|
2100
|
+
const oauthProviderModeOpaqueStoreToken = (store, record, error) => store
|
|
2101
|
+
.upsert(record)
|
|
2102
|
+
.pipe(Effect.mapError((cause) => error("Failed to store OAuth provider-mode token", cause)));
|
|
1945
2103
|
const oauthProviderModeScopesSubset = (scopes, grantedScopes) => scopes.every((scope) => grantedScopes.includes(scope));
|
|
2104
|
+
const oauthProviderModeAudienceValues = (audience) => audience === undefined
|
|
2105
|
+
? []
|
|
2106
|
+
: Array.isArray(audience)
|
|
2107
|
+
? audience
|
|
2108
|
+
: [audience];
|
|
2109
|
+
const oauthProviderModeAccessTokenInvalid = (reason) => ({ valid: false, reason });
|
|
1946
2110
|
const oauthTokenGrantClientId = (value) => {
|
|
1947
2111
|
const clientId = oauthTokenGrantString(value === undefined ? undefined : String(value));
|
|
1948
2112
|
return clientId === undefined ? undefined : OAuthClientId(clientId);
|
|
@@ -1960,7 +2124,7 @@ const oauthAuthorizationCodeConsumeFailureToTokenFailure = (reason) => {
|
|
|
1960
2124
|
}
|
|
1961
2125
|
}
|
|
1962
2126
|
};
|
|
1963
|
-
export const makeOAuthAuthorizationCodeTokenGrant = (dependencies) => OAuthAuthorizationCodeTokenGrant.
|
|
2127
|
+
export const makeOAuthAuthorizationCodeTokenGrant = (dependencies) => OAuthAuthorizationCodeTokenGrant.of({
|
|
1964
2128
|
exchange: Effect.fn("auth.oauth.authorization_code_token.exchange")(function* (input) {
|
|
1965
2129
|
if (input.grantType !== "authorization_code") {
|
|
1966
2130
|
return oauthAuthorizationCodeTokenInvalid("unsupported_grant_type");
|
|
@@ -1968,18 +2132,24 @@ export const makeOAuthAuthorizationCodeTokenGrant = (dependencies) => OAuthAutho
|
|
|
1968
2132
|
const { code } = input;
|
|
1969
2133
|
const clientId = oauthTokenGrantClientId(input.clientId);
|
|
1970
2134
|
const redirectUri = oauthTokenGrantString(input.redirectUri);
|
|
1971
|
-
if (code === undefined ||
|
|
2135
|
+
if (code === undefined ||
|
|
2136
|
+
clientId === undefined ||
|
|
2137
|
+
redirectUri === undefined) {
|
|
1972
2138
|
return oauthAuthorizationCodeTokenInvalid("invalid_request");
|
|
1973
2139
|
}
|
|
1974
|
-
const clientOption = yield* dependencies.clients
|
|
1975
|
-
|
|
2140
|
+
const clientOption = yield* dependencies.clients
|
|
2141
|
+
.find({ clientId })
|
|
2142
|
+
.pipe(Effect.mapError((cause) => oauthAuthorizationCodeTokenGrantError("exchange", "Failed to load OAuth client", cause)));
|
|
2143
|
+
if (Option.isNone(clientOption) ||
|
|
2144
|
+
clientOption.value.status !== "active") {
|
|
1976
2145
|
return oauthAuthorizationCodeTokenInvalid("invalid_client");
|
|
1977
2146
|
}
|
|
1978
2147
|
const client = clientOption.value;
|
|
1979
2148
|
if (!client.allowedGrantTypes.includes("authorization_code")) {
|
|
1980
2149
|
return oauthAuthorizationCodeTokenInvalid("unauthorized_client");
|
|
1981
2150
|
}
|
|
1982
|
-
if (client.type === "confidential" &&
|
|
2151
|
+
if (client.type === "confidential" &&
|
|
2152
|
+
input.clientAuthenticated !== true) {
|
|
1983
2153
|
return oauthAuthorizationCodeTokenInvalid("invalid_client");
|
|
1984
2154
|
}
|
|
1985
2155
|
const now = input.now ?? (yield* currentUnixMillis);
|
|
@@ -2008,7 +2178,7 @@ export const makeOAuthAuthorizationCodeTokenGrant = (dependencies) => OAuthAutho
|
|
|
2008
2178
|
};
|
|
2009
2179
|
}),
|
|
2010
2180
|
});
|
|
2011
|
-
export const makeOAuthRefreshTokenGrant = (dependencies) => OAuthRefreshTokenGrant.
|
|
2181
|
+
export const makeOAuthRefreshTokenGrant = (dependencies) => OAuthRefreshTokenGrant.of({
|
|
2012
2182
|
exchange: Effect.fn("auth.oauth.refresh_token.exchange")(function* (input) {
|
|
2013
2183
|
if (input.grantType !== "refresh_token") {
|
|
2014
2184
|
return oauthRefreshTokenInvalid("unsupported_grant_type");
|
|
@@ -2018,15 +2188,19 @@ export const makeOAuthRefreshTokenGrant = (dependencies) => OAuthRefreshTokenGra
|
|
|
2018
2188
|
if (refreshToken === undefined || clientId === undefined) {
|
|
2019
2189
|
return oauthRefreshTokenInvalid("invalid_request");
|
|
2020
2190
|
}
|
|
2021
|
-
const clientOption = yield* dependencies.clients
|
|
2022
|
-
|
|
2191
|
+
const clientOption = yield* dependencies.clients
|
|
2192
|
+
.find({ clientId })
|
|
2193
|
+
.pipe(Effect.mapError((cause) => oauthRefreshTokenGrantError("exchange", "Failed to load OAuth client", cause)));
|
|
2194
|
+
if (Option.isNone(clientOption) ||
|
|
2195
|
+
clientOption.value.status !== "active") {
|
|
2023
2196
|
return oauthRefreshTokenInvalid("invalid_client");
|
|
2024
2197
|
}
|
|
2025
2198
|
const client = clientOption.value;
|
|
2026
2199
|
if (!client.allowedGrantTypes.includes("refresh_token")) {
|
|
2027
2200
|
return oauthRefreshTokenInvalid("unauthorized_client");
|
|
2028
2201
|
}
|
|
2029
|
-
if (client.type === "confidential" &&
|
|
2202
|
+
if (client.type === "confidential" &&
|
|
2203
|
+
input.clientAuthenticated !== true) {
|
|
2030
2204
|
return oauthRefreshTokenInvalid("invalid_client");
|
|
2031
2205
|
}
|
|
2032
2206
|
const scopes = oauthTokenGrantScopes(input.scopes);
|
|
@@ -2052,7 +2226,7 @@ export const makeOAuthRefreshTokenGrant = (dependencies) => OAuthRefreshTokenGra
|
|
|
2052
2226
|
};
|
|
2053
2227
|
}),
|
|
2054
2228
|
});
|
|
2055
|
-
export const makeOAuthClientCredentialsGrant = (dependencies) => OAuthClientCredentialsGrant.
|
|
2229
|
+
export const makeOAuthClientCredentialsGrant = (dependencies) => OAuthClientCredentialsGrant.of({
|
|
2056
2230
|
exchange: Effect.fn("auth.oauth.client_credentials.exchange")(function* (input) {
|
|
2057
2231
|
if (input.grantType !== "client_credentials") {
|
|
2058
2232
|
return oauthClientCredentialsInvalid("unsupported_grant_type");
|
|
@@ -2061,8 +2235,11 @@ export const makeOAuthClientCredentialsGrant = (dependencies) => OAuthClientCred
|
|
|
2061
2235
|
if (clientId === undefined) {
|
|
2062
2236
|
return oauthClientCredentialsInvalid("invalid_request");
|
|
2063
2237
|
}
|
|
2064
|
-
const clientOption = yield* dependencies.clients
|
|
2065
|
-
|
|
2238
|
+
const clientOption = yield* dependencies.clients
|
|
2239
|
+
.find({ clientId })
|
|
2240
|
+
.pipe(Effect.mapError((cause) => oauthClientCredentialsGrantError("exchange", "Failed to load OAuth client", cause)));
|
|
2241
|
+
if (Option.isNone(clientOption) ||
|
|
2242
|
+
clientOption.value.status !== "active") {
|
|
2066
2243
|
return oauthClientCredentialsInvalid("invalid_client");
|
|
2067
2244
|
}
|
|
2068
2245
|
const client = clientOption.value;
|
|
@@ -2103,7 +2280,7 @@ export const makeOAuthProviderModeOpaqueTokenIssuer = (dependencies) => {
|
|
|
2103
2280
|
const accessTokenTtl = dependencies.accessTokenTtl ?? defaultOAuthProviderModeAccessTokenTtl;
|
|
2104
2281
|
const refreshTokenTtl = dependencies.refreshTokenTtl ?? defaultOAuthProviderModeRefreshTokenTtl;
|
|
2105
2282
|
return {
|
|
2106
|
-
authorizationCode: OAuthAuthorizationCodeTokenIssuer.
|
|
2283
|
+
authorizationCode: OAuthAuthorizationCodeTokenIssuer.of({
|
|
2107
2284
|
issue: Effect.fn("auth.oauth.provider_mode_opaque.authorization_code.issue")(function* (input) {
|
|
2108
2285
|
const scopes = [...input.code.scopes];
|
|
2109
2286
|
const accessToken = yield* generateOAuthProviderModeOpaqueToken(dependencies.crypto, accessTokenBytes, OAuthAccessToken, "access", oauthAuthorizationCodeTokenIssuerError);
|
|
@@ -2148,7 +2325,7 @@ export const makeOAuthProviderModeOpaqueTokenIssuer = (dependencies) => {
|
|
|
2148
2325
|
});
|
|
2149
2326
|
}),
|
|
2150
2327
|
}),
|
|
2151
|
-
refreshToken: OAuthRefreshTokenIssuer.
|
|
2328
|
+
refreshToken: OAuthRefreshTokenIssuer.of({
|
|
2152
2329
|
issue: Effect.fn("auth.oauth.provider_mode_opaque.refresh_token.issue")(function* (input) {
|
|
2153
2330
|
const tokenHash = yield* oauthProviderModeOpaqueTokenHash(dependencies.crypto, input.refreshToken, oauthRefreshTokenIssuerError);
|
|
2154
2331
|
const recordOption = yield* dependencies.tokenStore
|
|
@@ -2175,7 +2352,7 @@ export const makeOAuthProviderModeOpaqueTokenIssuer = (dependencies) => {
|
|
|
2175
2352
|
const accessTokenHash = yield* oauthProviderModeOpaqueTokenHash(dependencies.crypto, accessToken, oauthRefreshTokenIssuerError);
|
|
2176
2353
|
const refreshToken = yield* generateOAuthProviderModeOpaqueToken(dependencies.crypto, refreshTokenBytes, OAuthRefreshToken, "refresh", oauthRefreshTokenIssuerError);
|
|
2177
2354
|
const refreshTokenHash = yield* oauthProviderModeOpaqueTokenHash(dependencies.crypto, refreshToken, oauthRefreshTokenIssuerError);
|
|
2178
|
-
const accessTokenExpiresAt = oauthProviderModeOpaqueExpiresAt(input.now, accessTokenTtl);
|
|
2355
|
+
const accessTokenExpiresAt = UnixMillis(Math.min(Number(oauthProviderModeOpaqueExpiresAt(input.now, accessTokenTtl)), Number(record.expiresAt)));
|
|
2179
2356
|
yield* oauthProviderModeOpaqueStoreToken(dependencies.tokenStore, oauthProviderModeOpaqueTokenRecord(dependencies, {
|
|
2180
2357
|
tokenHash: accessTokenHash,
|
|
2181
2358
|
tokenType: "access_token",
|
|
@@ -2184,6 +2361,9 @@ export const makeOAuthProviderModeOpaqueTokenIssuer = (dependencies) => {
|
|
|
2184
2361
|
scopes,
|
|
2185
2362
|
issuedAt: input.now,
|
|
2186
2363
|
expiresAt: accessTokenExpiresAt,
|
|
2364
|
+
...(record.metadata === undefined
|
|
2365
|
+
? {}
|
|
2366
|
+
: { metadata: record.metadata }),
|
|
2187
2367
|
}), oauthRefreshTokenIssuerError);
|
|
2188
2368
|
yield* oauthProviderModeOpaqueStoreToken(dependencies.tokenStore, oauthProviderModeOpaqueTokenRecord(dependencies, {
|
|
2189
2369
|
tokenHash: refreshTokenHash,
|
|
@@ -2192,7 +2372,10 @@ export const makeOAuthProviderModeOpaqueTokenIssuer = (dependencies) => {
|
|
|
2192
2372
|
subject: record.subject,
|
|
2193
2373
|
scopes,
|
|
2194
2374
|
issuedAt: input.now,
|
|
2195
|
-
expiresAt:
|
|
2375
|
+
expiresAt: record.expiresAt,
|
|
2376
|
+
...(record.metadata === undefined
|
|
2377
|
+
? {}
|
|
2378
|
+
: { metadata: record.metadata }),
|
|
2196
2379
|
}), oauthRefreshTokenIssuerError);
|
|
2197
2380
|
const rotated = yield* dependencies.tokenStore
|
|
2198
2381
|
.rotateRefreshToken({
|
|
@@ -2216,7 +2399,7 @@ export const makeOAuthProviderModeOpaqueTokenIssuer = (dependencies) => {
|
|
|
2216
2399
|
};
|
|
2217
2400
|
}),
|
|
2218
2401
|
}),
|
|
2219
|
-
clientCredentials: OAuthClientCredentialsTokenIssuer.
|
|
2402
|
+
clientCredentials: OAuthClientCredentialsTokenIssuer.of({
|
|
2220
2403
|
issue: Effect.fn("auth.oauth.provider_mode_opaque.client_credentials.issue")(function* (input) {
|
|
2221
2404
|
const scopes = [...(input.scopes ?? [])];
|
|
2222
2405
|
if (!oauthTokenGrantScopesAllowed(scopes, input.client.allowedScopes)) {
|
|
@@ -2258,9 +2441,74 @@ export const makeOAuthProviderModeOpaqueTokenIssuer = (dependencies) => {
|
|
|
2258
2441
|
}),
|
|
2259
2442
|
};
|
|
2260
2443
|
};
|
|
2261
|
-
export const
|
|
2444
|
+
export const makeOAuthProviderModeAccessTokenVerifier = (dependencies) => OAuthProviderModeAccessTokenVerifier.of({
|
|
2445
|
+
verify: Effect.fn("auth.oauth.provider_mode_access_token.verify")(function* (input) {
|
|
2446
|
+
const accessToken = input?.accessToken;
|
|
2447
|
+
if (accessToken === undefined) {
|
|
2448
|
+
return oauthProviderModeAccessTokenInvalid("unknown_token");
|
|
2449
|
+
}
|
|
2450
|
+
const tokenValue = Redacted.value(accessToken);
|
|
2451
|
+
if (typeof tokenValue !== "string" || tokenValue.trim() === "") {
|
|
2452
|
+
return oauthProviderModeAccessTokenInvalid("unknown_token");
|
|
2453
|
+
}
|
|
2454
|
+
const tokenHash = yield* oauthProviderModeOpaqueTokenHash(dependencies.crypto, accessToken, () => oauthProviderModeAccessTokenVerifierError("Failed to hash OAuth provider-mode access token"));
|
|
2455
|
+
const recordOption = yield* dependencies.tokenStore
|
|
2456
|
+
.findByHash({ tokenHash })
|
|
2457
|
+
.pipe(Effect.mapError(() => oauthProviderModeAccessTokenVerifierError("Failed to load OAuth provider-mode access token")));
|
|
2458
|
+
if (Option.isNone(recordOption)) {
|
|
2459
|
+
return oauthProviderModeAccessTokenInvalid("unknown_token");
|
|
2460
|
+
}
|
|
2461
|
+
const record = recordOption.value;
|
|
2462
|
+
if (record.tokenType !== "access_token") {
|
|
2463
|
+
return oauthProviderModeAccessTokenInvalid("wrong_token_type");
|
|
2464
|
+
}
|
|
2465
|
+
const now = input.now ?? (yield* currentUnixMillis);
|
|
2466
|
+
if (Number(now) >= Number(record.expiresAt)) {
|
|
2467
|
+
return oauthProviderModeAccessTokenInvalid("expired");
|
|
2468
|
+
}
|
|
2469
|
+
if (record.revokedAt !== undefined) {
|
|
2470
|
+
return oauthProviderModeAccessTokenInvalid("revoked");
|
|
2471
|
+
}
|
|
2472
|
+
if (record.rotatedAt !== undefined) {
|
|
2473
|
+
return oauthProviderModeAccessTokenInvalid("rotated");
|
|
2474
|
+
}
|
|
2475
|
+
const clientOption = yield* dependencies.clients
|
|
2476
|
+
.find({ clientId: record.clientId })
|
|
2477
|
+
.pipe(Effect.mapError(() => oauthProviderModeAccessTokenVerifierError("Failed to load OAuth access token client")));
|
|
2478
|
+
if (Option.isNone(clientOption)) {
|
|
2479
|
+
return oauthProviderModeAccessTokenInvalid("unknown_client");
|
|
2480
|
+
}
|
|
2481
|
+
if (clientOption.value.status !== "active") {
|
|
2482
|
+
return oauthProviderModeAccessTokenInvalid("disabled_client");
|
|
2483
|
+
}
|
|
2484
|
+
if (input.issuer !== undefined && record.issuer !== input.issuer) {
|
|
2485
|
+
return oauthProviderModeAccessTokenInvalid("issuer_mismatch");
|
|
2486
|
+
}
|
|
2487
|
+
if (input.audience !== undefined) {
|
|
2488
|
+
const recordAudience = oauthProviderModeAudienceValues(record.audience);
|
|
2489
|
+
const requiredAudience = oauthProviderModeAudienceValues(input.audience);
|
|
2490
|
+
if (!requiredAudience.every((audience) => recordAudience.includes(audience))) {
|
|
2491
|
+
return oauthProviderModeAccessTokenInvalid("audience_mismatch");
|
|
2492
|
+
}
|
|
2493
|
+
}
|
|
2494
|
+
if (!oauthProviderModeScopesSubset(input.requiredScopes ?? [], record.scopes)) {
|
|
2495
|
+
return oauthProviderModeAccessTokenInvalid("missing_scope");
|
|
2496
|
+
}
|
|
2497
|
+
const activeRecord = activeOAuthProviderModeAccessTokenRecord(record);
|
|
2498
|
+
return {
|
|
2499
|
+
valid: true,
|
|
2500
|
+
record: activeRecord,
|
|
2501
|
+
client: cloneOAuthClientRecord(clientOption.value),
|
|
2502
|
+
subject: activeRecord.subject,
|
|
2503
|
+
scopes: [...activeRecord.scopes],
|
|
2504
|
+
};
|
|
2505
|
+
}),
|
|
2506
|
+
});
|
|
2507
|
+
export const makeOAuthClientSecretVerification = (dependencies) => OAuthClientSecretVerification.of({
|
|
2262
2508
|
authenticateClient: Effect.fn("auth.oauth.client_secret.authenticate_client")(function* (input) {
|
|
2263
|
-
const prefix = yield* dependencies.clientSecrets
|
|
2509
|
+
const prefix = yield* dependencies.clientSecrets
|
|
2510
|
+
.parse(input.clientSecret)
|
|
2511
|
+
.pipe(Effect.catchTag("OAuthClientSecretError", () => Effect.succeed(undefined)));
|
|
2264
2512
|
if (prefix === undefined) {
|
|
2265
2513
|
return false;
|
|
2266
2514
|
}
|
|
@@ -2295,13 +2543,15 @@ export const makeOAuthClientSecretVerification = (dependencies) => OAuthClientSe
|
|
|
2295
2543
|
return Option.isSome(updated);
|
|
2296
2544
|
}),
|
|
2297
2545
|
});
|
|
2298
|
-
export const makeOAuthTokenRevocation = (dependencies) => OAuthTokenRevocation.
|
|
2546
|
+
export const makeOAuthTokenRevocation = (dependencies) => OAuthTokenRevocation.of({
|
|
2299
2547
|
revoke: Effect.fn("auth.oauth.token_revocation.revoke")(function* (input) {
|
|
2300
2548
|
const { token } = input;
|
|
2301
2549
|
const tokenValue = token === undefined ? undefined : String(Redacted.value(token)).trim();
|
|
2302
2550
|
const clientId = oauthTokenGrantClientId(input.clientId);
|
|
2303
2551
|
const tokenTypeHint = oauthTokenGrantString(input.tokenTypeHint);
|
|
2304
|
-
if (token === undefined ||
|
|
2552
|
+
if (token === undefined ||
|
|
2553
|
+
tokenValue === undefined ||
|
|
2554
|
+
clientId === undefined) {
|
|
2305
2555
|
return oauthTokenRevocationInvalid("invalid_request");
|
|
2306
2556
|
}
|
|
2307
2557
|
if (tokenTypeHint !== undefined &&
|
|
@@ -2309,12 +2559,16 @@ export const makeOAuthTokenRevocation = (dependencies) => OAuthTokenRevocation.m
|
|
|
2309
2559
|
tokenTypeHint !== "refresh_token") {
|
|
2310
2560
|
return oauthTokenRevocationInvalid("unsupported_token_type");
|
|
2311
2561
|
}
|
|
2312
|
-
const clientOption = yield* dependencies.clients
|
|
2313
|
-
|
|
2562
|
+
const clientOption = yield* dependencies.clients
|
|
2563
|
+
.find({ clientId })
|
|
2564
|
+
.pipe(Effect.mapError((cause) => oauthTokenRevocationError("revoke", "Failed to load OAuth client", cause)));
|
|
2565
|
+
if (Option.isNone(clientOption) ||
|
|
2566
|
+
clientOption.value.status !== "active") {
|
|
2314
2567
|
return oauthTokenRevocationInvalid("invalid_client");
|
|
2315
2568
|
}
|
|
2316
2569
|
const client = clientOption.value;
|
|
2317
|
-
if (client.type !== "confidential" ||
|
|
2570
|
+
if (client.type !== "confidential" ||
|
|
2571
|
+
input.clientAuthenticated !== true) {
|
|
2318
2572
|
return oauthTokenRevocationInvalid("invalid_client");
|
|
2319
2573
|
}
|
|
2320
2574
|
const now = input.now ?? (yield* currentUnixMillis);
|
|
@@ -2332,21 +2586,29 @@ export const makeOAuthTokenRevocation = (dependencies) => OAuthTokenRevocation.m
|
|
|
2332
2586
|
};
|
|
2333
2587
|
}),
|
|
2334
2588
|
});
|
|
2335
|
-
export const makeOAuthTokenIntrospection = (dependencies) => OAuthTokenIntrospection.
|
|
2589
|
+
export const makeOAuthTokenIntrospection = (dependencies) => OAuthTokenIntrospection.of({
|
|
2336
2590
|
introspect: Effect.fn("auth.oauth.token_introspection.introspect")(function* (input) {
|
|
2337
2591
|
const { token } = input;
|
|
2338
|
-
const tokenValue = token === undefined
|
|
2592
|
+
const tokenValue = token === undefined
|
|
2593
|
+
? undefined
|
|
2594
|
+
: String(Redacted.value(token)).trim();
|
|
2339
2595
|
const clientId = oauthTokenGrantClientId(input.clientId);
|
|
2340
2596
|
const tokenTypeHint = oauthTokenGrantString(input.tokenTypeHint);
|
|
2341
|
-
if (token === undefined ||
|
|
2597
|
+
if (token === undefined ||
|
|
2598
|
+
tokenValue === undefined ||
|
|
2599
|
+
clientId === undefined) {
|
|
2342
2600
|
return oauthTokenIntrospectionInvalid("invalid_request");
|
|
2343
2601
|
}
|
|
2344
|
-
const clientOption = yield* dependencies.clients
|
|
2345
|
-
|
|
2602
|
+
const clientOption = yield* dependencies.clients
|
|
2603
|
+
.find({ clientId })
|
|
2604
|
+
.pipe(Effect.mapError((cause) => oauthTokenIntrospectionError("introspect", "Failed to load OAuth client", cause)));
|
|
2605
|
+
if (Option.isNone(clientOption) ||
|
|
2606
|
+
clientOption.value.status !== "active") {
|
|
2346
2607
|
return oauthTokenIntrospectionInvalid("invalid_client");
|
|
2347
2608
|
}
|
|
2348
2609
|
const client = clientOption.value;
|
|
2349
|
-
if (client.type !== "confidential" ||
|
|
2610
|
+
if (client.type !== "confidential" ||
|
|
2611
|
+
input.clientAuthenticated !== true) {
|
|
2350
2612
|
return oauthTokenIntrospectionInvalid("invalid_client");
|
|
2351
2613
|
}
|
|
2352
2614
|
const now = input.now ?? (yield* currentUnixMillis);
|
|
@@ -2368,7 +2630,9 @@ export const makeOAuthTokenIntrospection = (dependencies) => OAuthTokenIntrospec
|
|
|
2368
2630
|
const oauthProviderAuthorizationInvalid = (reason, input) => ({
|
|
2369
2631
|
valid: false,
|
|
2370
2632
|
reason,
|
|
2371
|
-
...(input?.redirectUri === undefined
|
|
2633
|
+
...(input?.redirectUri === undefined
|
|
2634
|
+
? {}
|
|
2635
|
+
: { redirectUri: input.redirectUri }),
|
|
2372
2636
|
...(input?.state === undefined ? {} : { state: input.state }),
|
|
2373
2637
|
...(input?.client === undefined
|
|
2374
2638
|
? {}
|
|
@@ -2386,7 +2650,7 @@ const oauthProviderAuthorizationClientId = (value) => {
|
|
|
2386
2650
|
return clientId === undefined ? undefined : OAuthClientId(clientId);
|
|
2387
2651
|
};
|
|
2388
2652
|
const oauthProviderAuthorizationScopes = (scopes) => {
|
|
2389
|
-
const values = typeof scopes === "string" ? scopes.split(/\s+/) : scopes ?? [];
|
|
2653
|
+
const values = typeof scopes === "string" ? scopes.split(/\s+/) : (scopes ?? []);
|
|
2390
2654
|
const unique = new Set();
|
|
2391
2655
|
for (const value of values) {
|
|
2392
2656
|
const scope = value.trim();
|
|
@@ -2396,13 +2660,14 @@ const oauthProviderAuthorizationScopes = (scopes) => {
|
|
|
2396
2660
|
}
|
|
2397
2661
|
return [...unique];
|
|
2398
2662
|
};
|
|
2399
|
-
const oauthProviderAuthorizationScopeAllowed = (scopes, allowedScopes) => allowedScopes === undefined ||
|
|
2663
|
+
const oauthProviderAuthorizationScopeAllowed = (scopes, allowedScopes) => allowedScopes === undefined ||
|
|
2664
|
+
scopes.every((scope) => allowedScopes.includes(scope));
|
|
2400
2665
|
const oauthProviderAuthorizationScopeSubset = (scopes, requestedScopes) => scopes.every((scope) => requestedScopes.includes(scope));
|
|
2401
2666
|
const oauthProviderAuthorizationClientAllowsCode = (client) => client.allowedResponseTypes.includes("code") &&
|
|
2402
2667
|
client.allowedGrantTypes.includes("authorization_code");
|
|
2403
2668
|
const oauthProviderAuthorizationGrantedScopesValid = (scopes, requestedScopes, allowedScopes) => oauthProviderAuthorizationScopeSubset(scopes, requestedScopes) &&
|
|
2404
2669
|
oauthProviderAuthorizationScopeAllowed(scopes, allowedScopes);
|
|
2405
|
-
export const makeOAuthProviderAuthorization = (dependencies) => OAuthProviderAuthorization.
|
|
2670
|
+
export const makeOAuthProviderAuthorization = (dependencies) => OAuthProviderAuthorization.of({
|
|
2406
2671
|
authorize: Effect.fn("auth.oauth.provider_authorization.authorize")(function* (input) {
|
|
2407
2672
|
const state = oauthProviderAuthorizationString(input.state);
|
|
2408
2673
|
const clientId = oauthProviderAuthorizationClientId(input.clientId);
|
|
@@ -2410,8 +2675,11 @@ export const makeOAuthProviderAuthorization = (dependencies) => OAuthProviderAut
|
|
|
2410
2675
|
if (clientId === undefined || redirectUri === undefined) {
|
|
2411
2676
|
return oauthProviderAuthorizationInvalid("invalid_request");
|
|
2412
2677
|
}
|
|
2413
|
-
const clientOption = yield* dependencies.clients
|
|
2414
|
-
|
|
2678
|
+
const clientOption = yield* dependencies.clients
|
|
2679
|
+
.find({ clientId })
|
|
2680
|
+
.pipe(Effect.mapError((cause) => oauthProviderAuthorizationError("authorize", "Failed to load OAuth client", cause)));
|
|
2681
|
+
if (Option.isNone(clientOption) ||
|
|
2682
|
+
clientOption.value.status !== "active") {
|
|
2415
2683
|
return oauthProviderAuthorizationInvalid("invalid_request");
|
|
2416
2684
|
}
|
|
2417
2685
|
const client = clientOption.value;
|
|
@@ -2430,7 +2698,9 @@ export const makeOAuthProviderAuthorization = (dependencies) => OAuthProviderAut
|
|
|
2430
2698
|
if (!oauthProviderAuthorizationClientAllowsCode(client)) {
|
|
2431
2699
|
return redirectError("unauthorized_client");
|
|
2432
2700
|
}
|
|
2433
|
-
const codeChallenge = oauthProviderAuthorizationString(input.codeChallenge === undefined
|
|
2701
|
+
const codeChallenge = oauthProviderAuthorizationString(input.codeChallenge === undefined
|
|
2702
|
+
? undefined
|
|
2703
|
+
: String(input.codeChallenge));
|
|
2434
2704
|
if (codeChallenge === undefined ||
|
|
2435
2705
|
oauthProviderAuthorizationString(input.codeChallengeMethod) !== "S256") {
|
|
2436
2706
|
return redirectError("invalid_request");
|
|
@@ -2484,6 +2754,7 @@ export const exchangeOAuthRefreshToken = (input) => OAuthRefreshTokenGrant.use((
|
|
|
2484
2754
|
export const exchangeOAuthClientCredentialsToken = (input) => OAuthClientCredentialsGrant.use((grant) => grant.exchange(input));
|
|
2485
2755
|
export const revokeOAuthToken = (input) => OAuthTokenRevocation.use((revocation) => revocation.revoke(input));
|
|
2486
2756
|
export const introspectOAuthToken = (input) => OAuthTokenIntrospection.use((introspection) => introspection.introspect(input));
|
|
2757
|
+
export const verifyOAuthProviderModeAccessToken = (input) => OAuthProviderModeAccessTokenVerifier.use((verifier) => verifier.verify(input));
|
|
2487
2758
|
export const authorizeOAuthProviderAuthorization = (input) => OAuthProviderAuthorization.use((authorization) => authorization.authorize(input));
|
|
2488
2759
|
export const makeOAuthPkce = (input) => Effect.gen(function* () {
|
|
2489
2760
|
const crypto = yield* Crypto;
|
|
@@ -2518,10 +2789,12 @@ const makeAuthorizationUrl = (input) => Effect.try({
|
|
|
2518
2789
|
},
|
|
2519
2790
|
catch: (cause) => oauthStateError("authorization-url", "Failed to build OAuth authorization URL", cause),
|
|
2520
2791
|
});
|
|
2521
|
-
export const makeOAuthState = (dependencies) => OAuthState.
|
|
2792
|
+
export const makeOAuthState = (dependencies) => OAuthState.of({
|
|
2522
2793
|
start: Effect.fn("auth.oauth_state.start")(function* (input) {
|
|
2523
2794
|
const stateSecretBytes = yield* validateByteLength(dependencies.stateSecretBytes ?? defaultOAuthStateSecretBytes, "start", "OAuth state secret");
|
|
2524
|
-
const stateSecret = yield* dependencies.crypto
|
|
2795
|
+
const stateSecret = yield* dependencies.crypto
|
|
2796
|
+
.randomToken(stateSecretBytes)
|
|
2797
|
+
.pipe(Effect.map(Redacted.make), Effect.mapError((cause) => oauthStateError("start", "Failed to generate OAuth state secret", cause)));
|
|
2525
2798
|
const pkce = yield* makeOAuthPkceWithCrypto(dependencies, {
|
|
2526
2799
|
codeVerifier: input.codeVerifier,
|
|
2527
2800
|
verifierBytes: dependencies.codeVerifierBytes,
|
|
@@ -2548,11 +2821,16 @@ export const makeOAuthState = (dependencies) => OAuthState.make({
|
|
|
2548
2821
|
scopes,
|
|
2549
2822
|
codeChallenge: pkce.codeChallenge,
|
|
2550
2823
|
...(nonce === undefined ? {} : { nonce }),
|
|
2551
|
-
...(input.metadata === undefined
|
|
2824
|
+
...(input.metadata === undefined
|
|
2825
|
+
? {}
|
|
2826
|
+
: { metadata: input.metadata }),
|
|
2552
2827
|
},
|
|
2553
2828
|
})
|
|
2554
2829
|
.pipe(Effect.mapError((cause) => oauthStateError("start", "Failed to issue OAuth state challenge", cause)));
|
|
2555
|
-
const state = encodeOAuthState({
|
|
2830
|
+
const state = encodeOAuthState({
|
|
2831
|
+
challengeId: issued.id,
|
|
2832
|
+
secret: stateSecret,
|
|
2833
|
+
});
|
|
2556
2834
|
const authorizationUrl = yield* makeAuthorizationUrl({
|
|
2557
2835
|
provider: input.provider,
|
|
2558
2836
|
redirectUri,
|
|
@@ -2659,6 +2937,16 @@ export const OAuthProviderModeOpaqueTokenIssuerLive = (options = {}) => Layer.me
|
|
|
2659
2937
|
tokenStore,
|
|
2660
2938
|
}).clientCredentials;
|
|
2661
2939
|
})));
|
|
2940
|
+
export const OAuthProviderModeAccessTokenVerifierLive = Layer.effect(OAuthProviderModeAccessTokenVerifier)(Effect.gen(function* () {
|
|
2941
|
+
const crypto = yield* Crypto;
|
|
2942
|
+
const tokenStore = yield* OAuthProviderModeTokenStore;
|
|
2943
|
+
const clients = yield* OAuthClientRegistry;
|
|
2944
|
+
return makeOAuthProviderModeAccessTokenVerifier({
|
|
2945
|
+
crypto,
|
|
2946
|
+
tokenStore,
|
|
2947
|
+
clients,
|
|
2948
|
+
});
|
|
2949
|
+
}));
|
|
2662
2950
|
export const OAuthTokenRevocationLive = Layer.effect(OAuthTokenRevocation)(Effect.gen(function* () {
|
|
2663
2951
|
const clients = yield* OAuthClientRegistry;
|
|
2664
2952
|
const revoker = yield* OAuthTokenRevoker;
|
|
@@ -2673,11 +2961,15 @@ export const OAuthProviderAuthorizationLive = Layer.effect(OAuthProviderAuthoriz
|
|
|
2673
2961
|
const clients = yield* OAuthClientRegistry;
|
|
2674
2962
|
const authorizationCodes = yield* OAuthAuthorizationCodeGrant;
|
|
2675
2963
|
const policy = yield* OAuthProviderAuthorizationPolicy;
|
|
2676
|
-
return makeOAuthProviderAuthorization({
|
|
2964
|
+
return makeOAuthProviderAuthorization({
|
|
2965
|
+
clients,
|
|
2966
|
+
authorizationCodes,
|
|
2967
|
+
policy,
|
|
2968
|
+
});
|
|
2677
2969
|
}));
|
|
2678
2970
|
export const makeOAuthProviders = (providers) => {
|
|
2679
2971
|
const providersById = new Map(providers.map((provider) => [provider.id, cloneProviderConfig(provider)]));
|
|
2680
|
-
return OAuthProviders.
|
|
2972
|
+
return OAuthProviders.of({
|
|
2681
2973
|
get: (id) => Effect.sync(() => {
|
|
2682
2974
|
const provider = providersById.get(id);
|
|
2683
2975
|
return provider === undefined
|
|
@@ -2696,9 +2988,13 @@ export const OAuthClientSecretVerificationLive = Layer.effect(OAuthClientSecretV
|
|
|
2696
2988
|
const secretStore = yield* OAuthClientSecretStore;
|
|
2697
2989
|
return makeOAuthClientSecretVerification({ clientSecrets, secretStore });
|
|
2698
2990
|
}));
|
|
2699
|
-
export const makeOAuthClientRegistryFromStore = (store) => OAuthClientRegistry.
|
|
2700
|
-
find: (input) => store
|
|
2701
|
-
|
|
2991
|
+
export const makeOAuthClientRegistryFromStore = (store) => OAuthClientRegistry.of({
|
|
2992
|
+
find: (input) => store
|
|
2993
|
+
.find(input)
|
|
2994
|
+
.pipe(Effect.mapError((cause) => oauthClientRegistryError("find", "Failed to load OAuth client", cause))),
|
|
2995
|
+
validateRedirectUri: (input) => store
|
|
2996
|
+
.validateRedirectUri(input)
|
|
2997
|
+
.pipe(Effect.mapError((cause) => oauthClientRegistryError("validate-redirect-uri", "Failed to validate OAuth client redirect URI", cause))),
|
|
2702
2998
|
});
|
|
2703
2999
|
export const OAuthClientRegistryFromStoreLive = Layer.effect(OAuthClientRegistry)(Effect.gen(function* () {
|
|
2704
3000
|
const store = yield* OAuthClientStore;
|
|
@@ -2706,7 +3002,7 @@ export const OAuthClientRegistryFromStoreLive = Layer.effect(OAuthClientRegistry
|
|
|
2706
3002
|
}));
|
|
2707
3003
|
export const makeOAuthClientRegistryMemory = (clients = []) => {
|
|
2708
3004
|
const clientsById = new Map(clients.map((client) => [client.id, cloneOAuthClientRecord(client)]));
|
|
2709
|
-
return OAuthClientRegistry.
|
|
3005
|
+
return OAuthClientRegistry.of({
|
|
2710
3006
|
find: (input) => Effect.sync(() => {
|
|
2711
3007
|
const client = clientsById.get(input.clientId);
|
|
2712
3008
|
return client === undefined
|
|
@@ -2722,7 +3018,7 @@ export const makeOAuthClientRegistryMemory = (clients = []) => {
|
|
|
2722
3018
|
export const OAuthClientRegistryMemoryLive = (clients = []) => Layer.succeed(OAuthClientRegistry)(makeOAuthClientRegistryMemory(clients));
|
|
2723
3019
|
export const makeOAuthClientStoreMemory = (clients = []) => {
|
|
2724
3020
|
const clientsById = new Map(clients.map((client) => [client.id, cloneOAuthClientRecord(client)]));
|
|
2725
|
-
return OAuthClientStore.
|
|
3021
|
+
return OAuthClientStore.of({
|
|
2726
3022
|
upsert: (record) => Effect.sync(() => {
|
|
2727
3023
|
clientsById.set(record.id, cloneOAuthClientRecord(record));
|
|
2728
3024
|
}),
|
|
@@ -2738,14 +3034,14 @@ export const makeOAuthClientStoreMemory = (clients = []) => {
|
|
|
2738
3034
|
validateRedirectUri: (input) => Effect.sync(() => validateOAuthClientRedirectUriRecord(clientsById.get(input.clientId), input)),
|
|
2739
3035
|
});
|
|
2740
3036
|
};
|
|
2741
|
-
export const OAuthClientStoreMemoryLive = (clients = []) => Layer.
|
|
3037
|
+
export const OAuthClientStoreMemoryLive = (clients = []) => Layer.sync(OAuthClientStore)(() => makeOAuthClientStoreMemory(clients));
|
|
2742
3038
|
const oauthConsentMemoryKey = (input) => `${input.userId}\u0000${input.clientId}`;
|
|
2743
3039
|
export const makeOAuthConsentStoreMemory = (records = []) => {
|
|
2744
3040
|
const recordsByKey = new Map(records.map((record) => [
|
|
2745
3041
|
oauthConsentMemoryKey(record),
|
|
2746
3042
|
cloneOAuthConsentRecord(record),
|
|
2747
3043
|
]));
|
|
2748
|
-
return OAuthConsentStore.
|
|
3044
|
+
return OAuthConsentStore.of({
|
|
2749
3045
|
upsert: (record) => Effect.sync(() => {
|
|
2750
3046
|
recordsByKey.set(oauthConsentMemoryKey(record), cloneOAuthConsentRecord(record));
|
|
2751
3047
|
}),
|
|
@@ -2795,11 +3091,11 @@ export const makeOAuthConsentStoreMemory = (records = []) => {
|
|
|
2795
3091
|
}),
|
|
2796
3092
|
});
|
|
2797
3093
|
};
|
|
2798
|
-
export const OAuthConsentStoreMemoryLive = (records = []) => Layer.
|
|
3094
|
+
export const OAuthConsentStoreMemoryLive = (records = []) => Layer.sync(OAuthConsentStore)(() => makeOAuthConsentStoreMemory(records));
|
|
2799
3095
|
const oauthClientSecretMemoryKey = (input) => `${input.clientId}\u0000${input.prefix}`;
|
|
2800
3096
|
export const makeOAuthClientSecretStoreMemory = () => {
|
|
2801
3097
|
const recordsByKey = new Map();
|
|
2802
|
-
return OAuthClientSecretStore.
|
|
3098
|
+
return OAuthClientSecretStore.of({
|
|
2803
3099
|
upsert: (record) => Effect.sync(() => {
|
|
2804
3100
|
recordsByKey.set(oauthClientSecretMemoryKey(record), cloneOAuthClientSecretRecord(record));
|
|
2805
3101
|
}),
|
|
@@ -2844,7 +3140,7 @@ export const makeOAuthClientSecretStoreMemory = () => {
|
|
|
2844
3140
|
export const OAuthClientSecretStoreMemoryLive = Layer.sync(OAuthClientSecretStore)(makeOAuthClientSecretStoreMemory);
|
|
2845
3141
|
export const makeOAuthAuthorizationCodeStoreMemory = () => {
|
|
2846
3142
|
const recordsByHash = new Map();
|
|
2847
|
-
return OAuthAuthorizationCodeStore.
|
|
3143
|
+
return OAuthAuthorizationCodeStore.of({
|
|
2848
3144
|
upsert: (record) => Effect.sync(() => {
|
|
2849
3145
|
recordsByHash.set(record.codeHash, cloneAuthorizationCodeRecord(record));
|
|
2850
3146
|
}),
|
|
@@ -2880,7 +3176,7 @@ export const makeOAuthAuthorizationCodeStoreMemory = () => {
|
|
|
2880
3176
|
export const OAuthAuthorizationCodeStoreMemoryLive = Layer.sync(OAuthAuthorizationCodeStore)(makeOAuthAuthorizationCodeStoreMemory);
|
|
2881
3177
|
export const makeOAuthProviderModeTokenStoreMemory = () => {
|
|
2882
3178
|
const recordsByHash = new Map();
|
|
2883
|
-
return OAuthProviderModeTokenStore.
|
|
3179
|
+
return OAuthProviderModeTokenStore.of({
|
|
2884
3180
|
upsert: (record) => Effect.sync(() => {
|
|
2885
3181
|
recordsByHash.set(record.tokenHash, cloneOAuthProviderModeTokenRecord(record));
|
|
2886
3182
|
}),
|
|
@@ -2964,7 +3260,9 @@ export const OAuthLinkConfirmationLive = Layer.effect(OAuthLinkConfirmation)(Eff
|
|
|
2964
3260
|
const accountKey = (input) => `${input.providerId}:${input.providerAccountId}`;
|
|
2965
3261
|
const cloneOAuthAccountRecord = (record) => ({
|
|
2966
3262
|
...record,
|
|
2967
|
-
...(record.metadata === undefined
|
|
3263
|
+
...(record.metadata === undefined
|
|
3264
|
+
? {}
|
|
3265
|
+
: { metadata: metadataValue(record.metadata) }),
|
|
2968
3266
|
});
|
|
2969
3267
|
const cloneProviderTokenVaultRecord = (record) => ({
|
|
2970
3268
|
...record,
|
|
@@ -2986,7 +3284,7 @@ const activeProviderTokenRecord = (record) => record === undefined || record.rev
|
|
|
2986
3284
|
const includeAccount = (record, includeUnlinked) => includeUnlinked === true || record.unlinkedAt === undefined;
|
|
2987
3285
|
export const makeOAuthProviderTokenVaultMemory = () => {
|
|
2988
3286
|
const recordsByAccountId = new Map();
|
|
2989
|
-
return OAuthProviderTokenVault.
|
|
3287
|
+
return OAuthProviderTokenVault.of({
|
|
2990
3288
|
upsert: (record) => Effect.sync(() => {
|
|
2991
3289
|
recordsByAccountId.set(record.accountId, cloneProviderTokenVaultRecord(record));
|
|
2992
3290
|
}),
|
|
@@ -3021,7 +3319,7 @@ export const OAuthProviderTokenVaultMemoryLive = Layer.sync(OAuthProviderTokenVa
|
|
|
3021
3319
|
export const makeOAuthAccountStoreMemory = () => {
|
|
3022
3320
|
const accountsById = new Map();
|
|
3023
3321
|
const idByProviderAccount = new Map();
|
|
3024
|
-
return OAuthAccountStore.
|
|
3322
|
+
return OAuthAccountStore.of({
|
|
3025
3323
|
insert: (row) => Effect.sync(() => {
|
|
3026
3324
|
const cloned = cloneOAuthAccountRecord(row);
|
|
3027
3325
|
accountsById.set(row.id, cloned);
|
|
@@ -3029,7 +3327,9 @@ export const makeOAuthAccountStoreMemory = () => {
|
|
|
3029
3327
|
}),
|
|
3030
3328
|
findById: (id) => Effect.sync(() => {
|
|
3031
3329
|
const row = accountsById.get(id);
|
|
3032
|
-
return row === undefined
|
|
3330
|
+
return row === undefined
|
|
3331
|
+
? Option.none()
|
|
3332
|
+
: Option.some(cloneOAuthAccountRecord(row));
|
|
3033
3333
|
}),
|
|
3034
3334
|
findByProviderAccount: (input) => Effect.sync(() => {
|
|
3035
3335
|
const id = idByProviderAccount.get(accountKey(input));
|
|
@@ -3039,7 +3339,8 @@ export const makeOAuthAccountStoreMemory = () => {
|
|
|
3039
3339
|
: Option.some(cloneOAuthAccountRecord(row));
|
|
3040
3340
|
}),
|
|
3041
3341
|
listByUser: (input) => Effect.sync(() => [...accountsById.values()]
|
|
3042
|
-
.filter((row) => row.userId === input.userId &&
|
|
3342
|
+
.filter((row) => row.userId === input.userId &&
|
|
3343
|
+
includeAccount(row, input.includeUnlinked))
|
|
3043
3344
|
.map(cloneOAuthAccountRecord)),
|
|
3044
3345
|
unlink: (input) => Effect.sync(() => {
|
|
3045
3346
|
const id = idByProviderAccount.get(accountKey(input));
|