@_mustachio/openauth 0.9.2 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/esm/adapters/d1/audit-log.js +15 -0
- package/dist/esm/adapters/d1/config-store.js +45 -0
- package/dist/esm/adapters/d1/index.js +12 -0
- package/dist/esm/adapters/d1/key-store.js +116 -0
- package/dist/esm/adapters/d1/method-store.js +52 -0
- package/dist/esm/adapters/d1/migrations.js +77 -0
- package/dist/esm/adapters/d1/session-store.js +134 -0
- package/dist/esm/adapters/d1/session.js +18 -0
- package/dist/esm/adapters/d1/token-store.js +140 -0
- package/dist/esm/adapters/durable-object/index.js +3 -0
- package/dist/esm/adapters/durable-object/session-store.js +139 -0
- package/dist/esm/adapters/durable-object/types.js +0 -0
- package/dist/esm/adapters/dynamo/audit-log.js +23 -0
- package/dist/esm/adapters/dynamo/client.js +0 -0
- package/dist/esm/adapters/dynamo/config-store.js +57 -0
- package/dist/esm/adapters/dynamo/index.js +10 -0
- package/dist/esm/adapters/dynamo/key-store.js +188 -0
- package/dist/esm/adapters/dynamo/method-store.js +72 -0
- package/dist/esm/adapters/dynamo/passkey-credential-store.js +83 -0
- package/dist/esm/adapters/dynamo/sdk.js +128 -0
- package/dist/esm/adapters/dynamo/session-store.js +173 -0
- package/dist/esm/adapters/dynamo/token-store.js +178 -0
- package/dist/esm/adapters/kms/in-memory-backing.js +28 -0
- package/dist/esm/adapters/kms/index.js +5 -0
- package/dist/esm/adapters/kms/key-store.js +129 -0
- package/dist/esm/adapters/kms/sdk.js +23 -0
- package/dist/esm/adapters/kms/types.js +0 -0
- package/dist/esm/adapters/kv/audit-log.js +21 -0
- package/dist/esm/adapters/kv/config-store.js +43 -0
- package/dist/esm/adapters/kv/index.js +5 -0
- package/dist/esm/adapters/kv/method-store.js +63 -0
- package/dist/esm/adapters/kv/types.js +0 -0
- package/dist/esm/adapters/memory/audit-log.js +16 -0
- package/dist/esm/adapters/memory/clock.js +5 -0
- package/dist/esm/adapters/memory/config-store.js +31 -0
- package/dist/esm/adapters/memory/index.js +10 -0
- package/dist/esm/adapters/memory/key-store.js +78 -0
- package/dist/esm/adapters/memory/method-store.js +43 -0
- package/dist/esm/adapters/memory/passkey-credential-store.js +53 -0
- package/dist/esm/adapters/memory/session-store.js +82 -0
- package/dist/esm/adapters/memory/token-store.js +91 -0
- package/dist/esm/adapters/postgres/audit-log.js +16 -0
- package/dist/esm/adapters/postgres/config-store.js +48 -0
- package/dist/esm/adapters/postgres/executor.js +21 -0
- package/dist/esm/adapters/postgres/index.js +13 -0
- package/dist/esm/adapters/postgres/key-store.js +191 -0
- package/dist/esm/adapters/postgres/method-store.js +61 -0
- package/dist/esm/adapters/postgres/migrations.js +111 -0
- package/dist/esm/adapters/postgres/passkey-credential-store.js +80 -0
- package/dist/esm/adapters/postgres/session-store.js +135 -0
- package/dist/esm/adapters/postgres/token-store.js +151 -0
- package/dist/esm/client.js +26 -10
- package/dist/esm/domain/audit.js +13 -0
- package/dist/esm/domain/authorize.js +212 -0
- package/dist/esm/domain/callback.js +173 -0
- package/dist/esm/domain/client-auth.js +61 -0
- package/dist/esm/domain/client-credentials.js +91 -0
- package/dist/esm/domain/crypto.js +97 -0
- package/dist/esm/domain/discovery.js +41 -0
- package/dist/esm/domain/introspect.js +51 -0
- package/dist/esm/domain/jwt.js +43 -0
- package/dist/esm/domain/method-cache.js +136 -0
- package/dist/esm/domain/method-dispatch.js +36 -0
- package/dist/esm/domain/method-route.js +108 -0
- package/dist/esm/domain/pkce.js +16 -0
- package/dist/esm/domain/refresh.js +91 -0
- package/dist/esm/domain/revoke.js +81 -0
- package/dist/esm/domain/state-envelope.js +80 -0
- package/dist/esm/domain/token-exchange.js +101 -0
- package/dist/esm/domain/token.js +205 -0
- package/dist/esm/domain/userinfo.js +27 -0
- package/dist/esm/http/context.js +7 -0
- package/dist/esm/http/cookies.js +98 -0
- package/dist/esm/http/errors.js +71 -0
- package/dist/esm/http/handlers/authorize.js +163 -0
- package/dist/esm/http/handlers/callback.js +53 -0
- package/dist/esm/http/handlers/metadata.js +34 -0
- package/dist/esm/http/handlers/method-route.js +87 -0
- package/dist/esm/http/handlers/revocation.js +98 -0
- package/dist/esm/http/handlers/token.js +167 -0
- package/dist/esm/http/handlers/userinfo.js +54 -0
- package/dist/esm/http/middleware/error.js +15 -0
- package/dist/esm/http/middleware/tenant.js +102 -0
- package/dist/esm/http/resolver.js +15 -0
- package/dist/esm/http/router.js +35 -0
- package/dist/esm/http/schemas/authorize.js +24 -0
- package/dist/esm/http/schemas/revocation.js +18 -0
- package/dist/esm/http/schemas/token.js +57 -0
- package/dist/esm/index.js +121 -9
- package/dist/esm/methods/code.js +221 -0
- package/dist/esm/methods/m2m.js +41 -0
- package/dist/esm/methods/oauth2-factory.js +84 -0
- package/dist/esm/methods/oauth2-generic.js +196 -0
- package/dist/esm/methods/oidc-generic.js +53 -0
- package/dist/esm/methods/passkey.js +275 -0
- package/dist/esm/methods/password-hash.js +79 -0
- package/dist/esm/methods/password.js +166 -0
- package/dist/esm/methods/providers/apple.js +29 -0
- package/dist/esm/methods/providers/cognito.js +37 -0
- package/dist/esm/methods/providers/discord.js +28 -0
- package/dist/esm/methods/providers/facebook.js +42 -0
- package/dist/esm/methods/providers/github.js +29 -0
- package/dist/esm/methods/providers/google.js +29 -0
- package/dist/esm/methods/providers/index.js +17 -0
- package/dist/esm/methods/providers/jumpcloud.js +27 -0
- package/dist/esm/methods/providers/keycloak.js +32 -0
- package/dist/esm/methods/providers/linkedin.js +28 -0
- package/dist/esm/methods/providers/microsoft.js +28 -0
- package/dist/esm/methods/providers/slack.js +30 -0
- package/dist/esm/methods/providers/spotify.js +28 -0
- package/dist/esm/methods/providers/twitch.js +28 -0
- package/dist/esm/methods/providers/x.js +28 -0
- package/dist/esm/methods/providers/yahoo.js +27 -0
- package/dist/esm/pkce.js +4 -16
- package/dist/esm/ports/audit-log.js +0 -0
- package/dist/esm/ports/config-store.js +0 -0
- package/dist/esm/ports/key-store.js +0 -0
- package/dist/esm/ports/method-store.js +0 -0
- package/dist/esm/ports/session-store.js +0 -0
- package/dist/esm/ports/token-store.js +0 -0
- package/dist/esm/types/authorization.js +0 -0
- package/dist/esm/types/error.js +65 -0
- package/dist/esm/types/flow.js +0 -0
- package/dist/esm/types/idp.js +0 -0
- package/dist/esm/types/method.js +0 -0
- package/dist/esm/types/picker.js +0 -0
- package/dist/esm/types/result.js +11 -0
- package/dist/esm/types/subject.js +0 -0
- package/dist/esm/types/tenant.js +5 -0
- package/dist/esm/types/token.js +0 -0
- package/dist/esm/ui/forms.js +253 -0
- package/dist/esm/ui/index.js +8 -0
- package/dist/esm/ui/picker.js +49 -0
- package/dist/types/adapters/d1/audit-log.d.ts +19 -0
- package/dist/types/adapters/d1/audit-log.d.ts.map +1 -0
- package/dist/types/adapters/d1/config-store.d.ts +20 -0
- package/dist/types/adapters/d1/config-store.d.ts.map +1 -0
- package/dist/types/adapters/d1/index.d.ts +35 -0
- package/dist/types/adapters/d1/index.d.ts.map +1 -0
- package/dist/types/adapters/d1/key-store.d.ts +17 -0
- package/dist/types/adapters/d1/key-store.d.ts.map +1 -0
- package/dist/types/adapters/d1/method-store.d.ts +21 -0
- package/dist/types/adapters/d1/method-store.d.ts.map +1 -0
- package/dist/types/adapters/d1/migrations.d.ts +18 -0
- package/dist/types/adapters/d1/migrations.d.ts.map +1 -0
- package/dist/types/adapters/d1/session-store.d.ts +20 -0
- package/dist/types/adapters/d1/session-store.d.ts.map +1 -0
- package/dist/types/adapters/d1/session.d.ts +18 -0
- package/dist/types/adapters/d1/session.d.ts.map +1 -0
- package/dist/types/adapters/d1/token-store.d.ts +29 -0
- package/dist/types/adapters/d1/token-store.d.ts.map +1 -0
- package/dist/types/adapters/d1/types.d.ts +43 -0
- package/dist/types/adapters/d1/types.d.ts.map +1 -0
- package/dist/types/adapters/durable-object/index.d.ts +17 -0
- package/dist/types/adapters/durable-object/index.d.ts.map +1 -0
- package/dist/types/adapters/durable-object/session-store.d.ts +21 -0
- package/dist/types/adapters/durable-object/session-store.d.ts.map +1 -0
- package/dist/types/adapters/durable-object/types.d.ts +23 -0
- package/dist/types/adapters/durable-object/types.d.ts.map +1 -0
- package/dist/types/adapters/dynamo/audit-log.d.ts +19 -0
- package/dist/types/adapters/dynamo/audit-log.d.ts.map +1 -0
- package/dist/types/adapters/dynamo/client.d.ts +111 -0
- package/dist/types/adapters/dynamo/client.d.ts.map +1 -0
- package/dist/types/adapters/dynamo/config-store.d.ts +21 -0
- package/dist/types/adapters/dynamo/config-store.d.ts.map +1 -0
- package/dist/types/adapters/dynamo/index.d.ts +60 -0
- package/dist/types/adapters/dynamo/index.d.ts.map +1 -0
- package/dist/types/adapters/dynamo/key-store.d.ts +23 -0
- package/dist/types/adapters/dynamo/key-store.d.ts.map +1 -0
- package/dist/types/adapters/dynamo/method-store.d.ts +20 -0
- package/dist/types/adapters/dynamo/method-store.d.ts.map +1 -0
- package/dist/types/adapters/dynamo/passkey-credential-store.d.ts +47 -0
- package/dist/types/adapters/dynamo/passkey-credential-store.d.ts.map +1 -0
- package/dist/types/adapters/dynamo/sdk.d.ts +23 -0
- package/dist/types/adapters/dynamo/sdk.d.ts.map +1 -0
- package/dist/types/adapters/dynamo/session-store.d.ts +20 -0
- package/dist/types/adapters/dynamo/session-store.d.ts.map +1 -0
- package/dist/types/adapters/dynamo/token-store.d.ts +29 -0
- package/dist/types/adapters/dynamo/token-store.d.ts.map +1 -0
- package/dist/types/adapters/kms/in-memory-backing.d.ts +9 -0
- package/dist/types/adapters/kms/in-memory-backing.d.ts.map +1 -0
- package/dist/types/adapters/kms/index.d.ts +35 -0
- package/dist/types/adapters/kms/index.d.ts.map +1 -0
- package/dist/types/adapters/kms/key-store.d.ts +20 -0
- package/dist/types/adapters/kms/key-store.d.ts.map +1 -0
- package/dist/types/adapters/kms/sdk.d.ts +16 -0
- package/dist/types/adapters/kms/sdk.d.ts.map +1 -0
- package/dist/types/adapters/kms/types.d.ts +58 -0
- package/dist/types/adapters/kms/types.d.ts.map +1 -0
- package/dist/types/adapters/kv/audit-log.d.ts +22 -0
- package/dist/types/adapters/kv/audit-log.d.ts.map +1 -0
- package/dist/types/adapters/kv/config-store.d.ts +25 -0
- package/dist/types/adapters/kv/config-store.d.ts.map +1 -0
- package/dist/types/adapters/kv/index.d.ts +21 -0
- package/dist/types/adapters/kv/index.d.ts.map +1 -0
- package/dist/types/adapters/kv/method-store.d.ts +23 -0
- package/dist/types/adapters/kv/method-store.d.ts.map +1 -0
- package/dist/types/adapters/kv/types.d.ts +28 -0
- package/dist/types/adapters/kv/types.d.ts.map +1 -0
- package/dist/types/adapters/memory/audit-log.d.ts +18 -0
- package/dist/types/adapters/memory/audit-log.d.ts.map +1 -0
- package/dist/types/adapters/memory/clock.d.ts +7 -0
- package/dist/types/adapters/memory/clock.d.ts.map +1 -0
- package/dist/types/adapters/memory/config-store.d.ts +19 -0
- package/dist/types/adapters/memory/config-store.d.ts.map +1 -0
- package/dist/types/adapters/memory/index.d.ts +15 -0
- package/dist/types/adapters/memory/index.d.ts.map +1 -0
- package/dist/types/adapters/memory/key-store.d.ts +17 -0
- package/dist/types/adapters/memory/key-store.d.ts.map +1 -0
- package/dist/types/adapters/memory/method-store.d.ts +26 -0
- package/dist/types/adapters/memory/method-store.d.ts.map +1 -0
- package/dist/types/adapters/memory/passkey-credential-store.d.ts +43 -0
- package/dist/types/adapters/memory/passkey-credential-store.d.ts.map +1 -0
- package/dist/types/adapters/memory/session-store.d.ts +19 -0
- package/dist/types/adapters/memory/session-store.d.ts.map +1 -0
- package/dist/types/adapters/memory/token-store.d.ts +28 -0
- package/dist/types/adapters/memory/token-store.d.ts.map +1 -0
- package/dist/types/adapters/postgres/audit-log.d.ts +18 -0
- package/dist/types/adapters/postgres/audit-log.d.ts.map +1 -0
- package/dist/types/adapters/postgres/config-store.d.ts +21 -0
- package/dist/types/adapters/postgres/config-store.d.ts.map +1 -0
- package/dist/types/adapters/postgres/executor.d.ts +48 -0
- package/dist/types/adapters/postgres/executor.d.ts.map +1 -0
- package/dist/types/adapters/postgres/index.d.ts +39 -0
- package/dist/types/adapters/postgres/index.d.ts.map +1 -0
- package/dist/types/adapters/postgres/key-store.d.ts +23 -0
- package/dist/types/adapters/postgres/key-store.d.ts.map +1 -0
- package/dist/types/adapters/postgres/method-store.d.ts +21 -0
- package/dist/types/adapters/postgres/method-store.d.ts.map +1 -0
- package/dist/types/adapters/postgres/migrations.d.ts +22 -0
- package/dist/types/adapters/postgres/migrations.d.ts.map +1 -0
- package/dist/types/adapters/postgres/passkey-credential-store.d.ts +48 -0
- package/dist/types/adapters/postgres/passkey-credential-store.d.ts.map +1 -0
- package/dist/types/adapters/postgres/session-store.d.ts +20 -0
- package/dist/types/adapters/postgres/session-store.d.ts.map +1 -0
- package/dist/types/adapters/postgres/token-store.d.ts +30 -0
- package/dist/types/adapters/postgres/token-store.d.ts.map +1 -0
- package/dist/types/client.d.ts +1 -1
- package/dist/types/client.d.ts.map +1 -1
- package/dist/types/domain/audit.d.ts +17 -0
- package/dist/types/domain/audit.d.ts.map +1 -0
- package/dist/types/domain/authorize.d.ts +125 -0
- package/dist/types/domain/authorize.d.ts.map +1 -0
- package/dist/types/domain/callback.d.ts +70 -0
- package/dist/types/domain/callback.d.ts.map +1 -0
- package/dist/types/domain/client-auth.d.ts +57 -0
- package/dist/types/domain/client-auth.d.ts.map +1 -0
- package/dist/types/domain/client-credentials.d.ts +52 -0
- package/dist/types/domain/client-credentials.d.ts.map +1 -0
- package/dist/types/domain/crypto.d.ts +53 -0
- package/dist/types/domain/crypto.d.ts.map +1 -0
- package/dist/types/domain/discovery.d.ts +44 -0
- package/dist/types/domain/discovery.d.ts.map +1 -0
- package/dist/types/domain/introspect.d.ts +71 -0
- package/dist/types/domain/introspect.d.ts.map +1 -0
- package/dist/types/domain/jwt.d.ts +48 -0
- package/dist/types/domain/jwt.d.ts.map +1 -0
- package/dist/types/domain/method-cache.d.ts +42 -0
- package/dist/types/domain/method-cache.d.ts.map +1 -0
- package/dist/types/domain/method-dispatch.d.ts +37 -0
- package/dist/types/domain/method-dispatch.d.ts.map +1 -0
- package/dist/types/domain/method-route.d.ts +77 -0
- package/dist/types/domain/method-route.d.ts.map +1 -0
- package/dist/types/domain/pkce.d.ts +15 -0
- package/dist/types/domain/pkce.d.ts.map +1 -0
- package/dist/types/domain/refresh.d.ts +43 -0
- package/dist/types/domain/refresh.d.ts.map +1 -0
- package/dist/types/domain/revoke.d.ts +61 -0
- package/dist/types/domain/revoke.d.ts.map +1 -0
- package/dist/types/domain/state-envelope.d.ts +30 -0
- package/dist/types/domain/state-envelope.d.ts.map +1 -0
- package/dist/types/domain/token-exchange.d.ts +67 -0
- package/dist/types/domain/token-exchange.d.ts.map +1 -0
- package/dist/types/domain/token.d.ts +100 -0
- package/dist/types/domain/token.d.ts.map +1 -0
- package/dist/types/domain/userinfo.d.ts +22 -0
- package/dist/types/domain/userinfo.d.ts.map +1 -0
- package/dist/types/http/context.d.ts +63 -0
- package/dist/types/http/context.d.ts.map +1 -0
- package/dist/types/http/cookies.d.ts +45 -0
- package/dist/types/http/cookies.d.ts.map +1 -0
- package/dist/types/http/errors.d.ts +36 -0
- package/dist/types/http/errors.d.ts.map +1 -0
- package/dist/types/http/handlers/authorize.d.ts +3 -0
- package/dist/types/http/handlers/authorize.d.ts.map +1 -0
- package/dist/types/http/handlers/callback.d.ts +3 -0
- package/dist/types/http/handlers/callback.d.ts.map +1 -0
- package/dist/types/http/handlers/metadata.d.ts +4 -0
- package/dist/types/http/handlers/metadata.d.ts.map +1 -0
- package/dist/types/http/handlers/method-route.d.ts +3 -0
- package/dist/types/http/handlers/method-route.d.ts.map +1 -0
- package/dist/types/http/handlers/revocation.d.ts +4 -0
- package/dist/types/http/handlers/revocation.d.ts.map +1 -0
- package/dist/types/http/handlers/token.d.ts +3 -0
- package/dist/types/http/handlers/token.d.ts.map +1 -0
- package/dist/types/http/handlers/userinfo.d.ts +3 -0
- package/dist/types/http/handlers/userinfo.d.ts.map +1 -0
- package/dist/types/http/middleware/error.d.ts +9 -0
- package/dist/types/http/middleware/error.d.ts.map +1 -0
- package/dist/types/http/middleware/tenant.d.ts +30 -0
- package/dist/types/http/middleware/tenant.d.ts.map +1 -0
- package/dist/types/http/resolver.d.ts +22 -0
- package/dist/types/http/resolver.d.ts.map +1 -0
- package/dist/types/http/router.d.ts +21 -0
- package/dist/types/http/router.d.ts.map +1 -0
- package/dist/types/http/schemas/authorize.d.ts +52 -0
- package/dist/types/http/schemas/authorize.d.ts.map +1 -0
- package/dist/types/http/schemas/revocation.d.ts +41 -0
- package/dist/types/http/schemas/revocation.d.ts.map +1 -0
- package/dist/types/http/schemas/token.d.ts +227 -0
- package/dist/types/http/schemas/token.d.ts.map +1 -0
- package/dist/types/index.d.ts +63 -13
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/methods/code.d.ts +96 -0
- package/dist/types/methods/code.d.ts.map +1 -0
- package/dist/types/methods/m2m.d.ts +41 -0
- package/dist/types/methods/m2m.d.ts.map +1 -0
- package/dist/types/methods/oauth2-factory.d.ts +133 -0
- package/dist/types/methods/oauth2-factory.d.ts.map +1 -0
- package/dist/types/methods/oauth2-generic.d.ts +75 -0
- package/dist/types/methods/oauth2-generic.d.ts.map +1 -0
- package/dist/types/methods/oidc-generic.d.ts +26 -0
- package/dist/types/methods/oidc-generic.d.ts.map +1 -0
- package/dist/types/methods/passkey.d.ts +106 -0
- package/dist/types/methods/passkey.d.ts.map +1 -0
- package/dist/types/methods/password-hash.d.ts +25 -0
- package/dist/types/methods/password-hash.d.ts.map +1 -0
- package/dist/types/methods/password.d.ts +70 -0
- package/dist/types/methods/password.d.ts.map +1 -0
- package/dist/types/methods/providers/apple.d.ts +29 -0
- package/dist/types/methods/providers/apple.d.ts.map +1 -0
- package/dist/types/methods/providers/cognito.d.ts +36 -0
- package/dist/types/methods/providers/cognito.d.ts.map +1 -0
- package/dist/types/methods/providers/discord.d.ts +22 -0
- package/dist/types/methods/providers/discord.d.ts.map +1 -0
- package/dist/types/methods/providers/facebook.d.ts +29 -0
- package/dist/types/methods/providers/facebook.d.ts.map +1 -0
- package/dist/types/methods/providers/github.d.ts +25 -0
- package/dist/types/methods/providers/github.d.ts.map +1 -0
- package/dist/types/methods/providers/google.d.ts +28 -0
- package/dist/types/methods/providers/google.d.ts.map +1 -0
- package/dist/types/methods/providers/index.d.ts +24 -0
- package/dist/types/methods/providers/index.d.ts.map +1 -0
- package/dist/types/methods/providers/jumpcloud.d.ts +22 -0
- package/dist/types/methods/providers/jumpcloud.d.ts.map +1 -0
- package/dist/types/methods/providers/keycloak.d.ts +30 -0
- package/dist/types/methods/providers/keycloak.d.ts.map +1 -0
- package/dist/types/methods/providers/linkedin.d.ts +22 -0
- package/dist/types/methods/providers/linkedin.d.ts.map +1 -0
- package/dist/types/methods/providers/microsoft.d.ts +30 -0
- package/dist/types/methods/providers/microsoft.d.ts.map +1 -0
- package/dist/types/methods/providers/slack.d.ts +25 -0
- package/dist/types/methods/providers/slack.d.ts.map +1 -0
- package/dist/types/methods/providers/spotify.d.ts +22 -0
- package/dist/types/methods/providers/spotify.d.ts.map +1 -0
- package/dist/types/methods/providers/twitch.d.ts +23 -0
- package/dist/types/methods/providers/twitch.d.ts.map +1 -0
- package/dist/types/methods/providers/x.d.ts +25 -0
- package/dist/types/methods/providers/x.d.ts.map +1 -0
- package/dist/types/methods/providers/yahoo.d.ts +22 -0
- package/dist/types/methods/providers/yahoo.d.ts.map +1 -0
- package/dist/types/pkce.d.ts +1 -2
- package/dist/types/pkce.d.ts.map +1 -1
- package/dist/types/ports/audit-log.d.ts +139 -0
- package/dist/types/ports/audit-log.d.ts.map +1 -0
- package/dist/types/ports/config-store.d.ts +32 -0
- package/dist/types/ports/config-store.d.ts.map +1 -0
- package/dist/types/ports/key-store.d.ts +98 -0
- package/dist/types/ports/key-store.d.ts.map +1 -0
- package/dist/types/ports/method-store.d.ts +29 -0
- package/dist/types/ports/method-store.d.ts.map +1 -0
- package/dist/types/ports/session-store.d.ts +82 -0
- package/dist/types/ports/session-store.d.ts.map +1 -0
- package/dist/types/ports/token-store.d.ts +93 -0
- package/dist/types/ports/token-store.d.ts.map +1 -0
- package/dist/types/types/authorization.d.ts +52 -0
- package/dist/types/types/authorization.d.ts.map +1 -0
- package/dist/types/types/error.d.ts +92 -0
- package/dist/types/types/error.d.ts.map +1 -0
- package/dist/types/types/flow.d.ts +87 -0
- package/dist/types/types/flow.d.ts.map +1 -0
- package/dist/types/types/idp.d.ts +234 -0
- package/dist/types/types/idp.d.ts.map +1 -0
- package/dist/types/types/method.d.ts +256 -0
- package/dist/types/types/method.d.ts.map +1 -0
- package/dist/types/types/picker.d.ts +31 -0
- package/dist/types/types/picker.d.ts.map +1 -0
- package/dist/types/types/result.d.ts +29 -0
- package/dist/types/types/result.d.ts.map +1 -0
- package/dist/types/types/subject.d.ts +47 -0
- package/dist/types/types/subject.d.ts.map +1 -0
- package/dist/types/types/tenant.d.ts +239 -0
- package/dist/types/types/tenant.d.ts.map +1 -0
- package/dist/types/types/token.d.ts +103 -0
- package/dist/types/types/token.d.ts.map +1 -0
- package/dist/types/ui/forms.d.ts +35 -0
- package/dist/types/ui/forms.d.ts.map +1 -0
- package/dist/types/ui/index.d.ts +14 -0
- package/dist/types/ui/index.d.ts.map +1 -0
- package/dist/types/ui/picker.d.ts +18 -0
- package/dist/types/ui/picker.d.ts.map +1 -0
- package/package.json +41 -6
- package/src/adapters/d1/audit-log.ts +32 -0
- package/src/adapters/d1/config-store.ts +67 -0
- package/src/adapters/d1/index.ts +41 -0
- package/src/adapters/d1/key-store.ts +218 -0
- package/src/adapters/d1/method-store.ts +103 -0
- package/src/adapters/d1/migrations.ts +89 -0
- package/src/adapters/d1/session-store.ts +230 -0
- package/src/adapters/d1/session.ts +38 -0
- package/src/adapters/d1/token-store.ts +251 -0
- package/src/adapters/d1/types.ts +53 -0
- package/src/adapters/durable-object/index.ts +23 -0
- package/src/adapters/durable-object/session-store.ts +227 -0
- package/src/adapters/durable-object/types.ts +25 -0
- package/src/adapters/dynamo/audit-log.ts +35 -0
- package/src/adapters/dynamo/client.ts +118 -0
- package/src/adapters/dynamo/config-store.ts +72 -0
- package/src/adapters/dynamo/index.ts +81 -0
- package/src/adapters/dynamo/key-store.ts +267 -0
- package/src/adapters/dynamo/method-store.ts +105 -0
- package/src/adapters/dynamo/passkey-credential-store.ts +132 -0
- package/src/adapters/dynamo/sdk.ts +189 -0
- package/src/adapters/dynamo/session-store.ts +229 -0
- package/src/adapters/dynamo/token-store.ts +248 -0
- package/src/adapters/kms/in-memory-backing.ts +36 -0
- package/src/adapters/kms/index.ts +39 -0
- package/src/adapters/kms/key-store.ts +176 -0
- package/src/adapters/kms/sdk.ts +39 -0
- package/src/adapters/kms/types.ts +61 -0
- package/src/adapters/kv/audit-log.ts +40 -0
- package/src/adapters/kv/config-store.ts +63 -0
- package/src/adapters/kv/index.ts +20 -0
- package/src/adapters/kv/method-store.ts +98 -0
- package/src/adapters/kv/types.ts +26 -0
- package/src/adapters/memory/audit-log.ts +28 -0
- package/src/adapters/memory/clock.ts +7 -0
- package/src/adapters/memory/config-store.ts +41 -0
- package/src/adapters/memory/index.ts +26 -0
- package/src/adapters/memory/key-store.ts +102 -0
- package/src/adapters/memory/method-store.ts +75 -0
- package/src/adapters/memory/passkey-credential-store.ts +97 -0
- package/src/adapters/memory/session-store.ts +128 -0
- package/src/adapters/memory/token-store.ts +165 -0
- package/src/adapters/postgres/audit-log.ts +34 -0
- package/src/adapters/postgres/config-store.ts +72 -0
- package/src/adapters/postgres/executor.ts +76 -0
- package/src/adapters/postgres/index.ts +60 -0
- package/src/adapters/postgres/key-store.ts +334 -0
- package/src/adapters/postgres/method-store.ts +104 -0
- package/src/adapters/postgres/migrations.ts +131 -0
- package/src/adapters/postgres/passkey-credential-store.ts +150 -0
- package/src/adapters/postgres/session-store.ts +216 -0
- package/src/adapters/postgres/token-store.ts +263 -0
- package/src/client.ts +50 -16
- package/src/domain/audit.ts +28 -0
- package/src/domain/authorize.ts +405 -0
- package/src/domain/callback.ts +263 -0
- package/src/domain/client-auth.ts +116 -0
- package/src/domain/client-credentials.ts +178 -0
- package/src/domain/crypto.ts +168 -0
- package/src/domain/discovery.ts +83 -0
- package/src/domain/introspect.ts +145 -0
- package/src/domain/jwt.ts +106 -0
- package/src/domain/method-cache.ts +220 -0
- package/src/domain/method-dispatch.ts +95 -0
- package/src/domain/method-route.ts +208 -0
- package/src/domain/pkce.ts +37 -0
- package/src/domain/refresh.ts +169 -0
- package/src/domain/revoke.ts +161 -0
- package/src/domain/state-envelope.ts +142 -0
- package/src/domain/token-exchange.ts +232 -0
- package/src/domain/token.ts +357 -0
- package/src/domain/userinfo.ts +56 -0
- package/src/http/context.ts +86 -0
- package/src/http/cookies.ts +167 -0
- package/src/http/errors.ts +98 -0
- package/src/http/handlers/authorize.ts +221 -0
- package/src/http/handlers/callback.ts +77 -0
- package/src/http/handlers/metadata.ts +44 -0
- package/src/http/handlers/method-route.ts +115 -0
- package/src/http/handlers/revocation.ts +151 -0
- package/src/http/handlers/token.ts +244 -0
- package/src/http/handlers/userinfo.ts +66 -0
- package/src/http/middleware/error.ts +26 -0
- package/src/http/middleware/tenant.ts +165 -0
- package/src/http/resolver.ts +34 -0
- package/src/http/router.ts +66 -0
- package/src/http/schemas/authorize.ts +58 -0
- package/src/http/schemas/revocation.ts +23 -0
- package/src/http/schemas/token.ts +85 -0
- package/src/index.ts +266 -20
- package/src/methods/code.ts +359 -0
- package/src/methods/m2m.ts +82 -0
- package/src/methods/oauth2-factory.ts +151 -0
- package/src/methods/oauth2-generic.ts +360 -0
- package/src/methods/oidc-generic.ts +109 -0
- package/src/methods/passkey.ts +419 -0
- package/src/methods/password-hash.ts +134 -0
- package/src/methods/password.ts +298 -0
- package/src/methods/providers/apple.ts +42 -0
- package/src/methods/providers/cognito.ts +55 -0
- package/src/methods/providers/discord.ts +37 -0
- package/src/methods/providers/facebook.ts +54 -0
- package/src/methods/providers/github.ts +42 -0
- package/src/methods/providers/google.ts +43 -0
- package/src/methods/providers/index.ts +23 -0
- package/src/methods/providers/jumpcloud.ts +36 -0
- package/src/methods/providers/keycloak.ts +42 -0
- package/src/methods/providers/linkedin.ts +37 -0
- package/src/methods/providers/microsoft.ts +42 -0
- package/src/methods/providers/slack.ts +42 -0
- package/src/methods/providers/spotify.ts +37 -0
- package/src/methods/providers/twitch.ts +38 -0
- package/src/methods/providers/x.ts +40 -0
- package/src/methods/providers/yahoo.ts +36 -0
- package/src/pkce.ts +20 -21
- package/src/ports/CONSISTENCY.md +88 -0
- package/src/ports/audit-log.ts +148 -0
- package/src/ports/config-store.ts +34 -0
- package/src/ports/key-store.ts +106 -0
- package/src/ports/method-store.ts +41 -0
- package/src/ports/session-store.ts +98 -0
- package/src/ports/token-store.ts +103 -0
- package/src/types/authorization.ts +53 -0
- package/src/types/error.ts +123 -0
- package/src/types/flow.ts +89 -0
- package/src/types/idp.ts +269 -0
- package/src/types/method.ts +270 -0
- package/src/types/picker.ts +32 -0
- package/src/types/result.ts +23 -0
- package/src/types/subject.ts +50 -0
- package/src/types/tenant.ts +248 -0
- package/src/types/token.ts +101 -0
- package/src/ui/forms.ts +289 -0
- package/src/ui/index.ts +14 -0
- package/src/ui/picker.ts +63 -0
- package/dist/esm/issuer.js +0 -691
- package/dist/esm/jwt.js +0 -16
- package/dist/esm/keys.js +0 -113
- package/dist/esm/provider/apple.js +0 -28
- package/dist/esm/provider/arctic.js +0 -43
- package/dist/esm/provider/code.js +0 -58
- package/dist/esm/provider/cognito.js +0 -16
- package/dist/esm/provider/discord.js +0 -15
- package/dist/esm/provider/facebook.js +0 -24
- package/dist/esm/provider/github.js +0 -15
- package/dist/esm/provider/google.js +0 -25
- package/dist/esm/provider/index.js +0 -3
- package/dist/esm/provider/jumpcloud.js +0 -15
- package/dist/esm/provider/keycloak.js +0 -15
- package/dist/esm/provider/linkedin.js +0 -15
- package/dist/esm/provider/m2m.js +0 -16
- package/dist/esm/provider/microsoft.js +0 -24
- package/dist/esm/provider/oauth2.js +0 -119
- package/dist/esm/provider/oidc.js +0 -69
- package/dist/esm/provider/passkey.js +0 -315
- package/dist/esm/provider/password.js +0 -306
- package/dist/esm/provider/provider.js +0 -10
- package/dist/esm/provider/slack.js +0 -15
- package/dist/esm/provider/spotify.js +0 -15
- package/dist/esm/provider/twitch.js +0 -15
- package/dist/esm/provider/x.js +0 -16
- package/dist/esm/provider/yahoo.js +0 -15
- package/dist/esm/random.js +0 -27
- package/dist/esm/storage/aws.js +0 -39
- package/dist/esm/storage/cloudflare.js +0 -42
- package/dist/esm/storage/dynamo.js +0 -116
- package/dist/esm/storage/memory.js +0 -88
- package/dist/esm/storage/storage.js +0 -36
- package/dist/esm/subject.js +0 -7
- package/dist/esm/ui/base.js +0 -407
- package/dist/esm/ui/code.js +0 -151
- package/dist/esm/ui/form.js +0 -43
- package/dist/esm/ui/icon.js +0 -92
- package/dist/esm/ui/passkey.js +0 -329
- package/dist/esm/ui/password.js +0 -338
- package/dist/esm/ui/select.js +0 -187
- package/dist/esm/ui/theme.js +0 -115
- package/dist/esm/util.js +0 -54
- package/dist/types/issuer.d.ts +0 -607
- package/dist/types/issuer.d.ts.map +0 -1
- package/dist/types/jwt.d.ts +0 -6
- package/dist/types/jwt.d.ts.map +0 -1
- package/dist/types/keys.d.ts +0 -18
- package/dist/types/keys.d.ts.map +0 -1
- package/dist/types/provider/apple.d.ts +0 -108
- package/dist/types/provider/apple.d.ts.map +0 -1
- package/dist/types/provider/arctic.d.ts +0 -16
- package/dist/types/provider/arctic.d.ts.map +0 -1
- package/dist/types/provider/code.d.ts +0 -74
- package/dist/types/provider/code.d.ts.map +0 -1
- package/dist/types/provider/cognito.d.ts +0 -64
- package/dist/types/provider/cognito.d.ts.map +0 -1
- package/dist/types/provider/discord.d.ts +0 -38
- package/dist/types/provider/discord.d.ts.map +0 -1
- package/dist/types/provider/facebook.d.ts +0 -74
- package/dist/types/provider/facebook.d.ts.map +0 -1
- package/dist/types/provider/github.d.ts +0 -38
- package/dist/types/provider/github.d.ts.map +0 -1
- package/dist/types/provider/google.d.ts +0 -74
- package/dist/types/provider/google.d.ts.map +0 -1
- package/dist/types/provider/index.d.ts +0 -4
- package/dist/types/provider/index.d.ts.map +0 -1
- package/dist/types/provider/jumpcloud.d.ts +0 -38
- package/dist/types/provider/jumpcloud.d.ts.map +0 -1
- package/dist/types/provider/keycloak.d.ts +0 -67
- package/dist/types/provider/keycloak.d.ts.map +0 -1
- package/dist/types/provider/linkedin.d.ts +0 -6
- package/dist/types/provider/linkedin.d.ts.map +0 -1
- package/dist/types/provider/m2m.d.ts +0 -34
- package/dist/types/provider/m2m.d.ts.map +0 -1
- package/dist/types/provider/microsoft.d.ts +0 -89
- package/dist/types/provider/microsoft.d.ts.map +0 -1
- package/dist/types/provider/oauth2.d.ts +0 -133
- package/dist/types/provider/oauth2.d.ts.map +0 -1
- package/dist/types/provider/oidc.d.ts +0 -91
- package/dist/types/provider/oidc.d.ts.map +0 -1
- package/dist/types/provider/passkey.d.ts +0 -143
- package/dist/types/provider/passkey.d.ts.map +0 -1
- package/dist/types/provider/password.d.ts +0 -210
- package/dist/types/provider/password.d.ts.map +0 -1
- package/dist/types/provider/provider.d.ts +0 -29
- package/dist/types/provider/provider.d.ts.map +0 -1
- package/dist/types/provider/slack.d.ts +0 -59
- package/dist/types/provider/slack.d.ts.map +0 -1
- package/dist/types/provider/spotify.d.ts +0 -38
- package/dist/types/provider/spotify.d.ts.map +0 -1
- package/dist/types/provider/twitch.d.ts +0 -38
- package/dist/types/provider/twitch.d.ts.map +0 -1
- package/dist/types/provider/x.d.ts +0 -38
- package/dist/types/provider/x.d.ts.map +0 -1
- package/dist/types/provider/yahoo.d.ts +0 -38
- package/dist/types/provider/yahoo.d.ts.map +0 -1
- package/dist/types/random.d.ts +0 -3
- package/dist/types/random.d.ts.map +0 -1
- package/dist/types/storage/aws.d.ts +0 -4
- package/dist/types/storage/aws.d.ts.map +0 -1
- package/dist/types/storage/cloudflare.d.ts +0 -34
- package/dist/types/storage/cloudflare.d.ts.map +0 -1
- package/dist/types/storage/dynamo.d.ts +0 -65
- package/dist/types/storage/dynamo.d.ts.map +0 -1
- package/dist/types/storage/memory.d.ts +0 -49
- package/dist/types/storage/memory.d.ts.map +0 -1
- package/dist/types/storage/storage.d.ts +0 -15
- package/dist/types/storage/storage.d.ts.map +0 -1
- package/dist/types/subject.d.ts +0 -122
- package/dist/types/subject.d.ts.map +0 -1
- package/dist/types/ui/base.d.ts +0 -5
- package/dist/types/ui/base.d.ts.map +0 -1
- package/dist/types/ui/code.d.ts +0 -104
- package/dist/types/ui/code.d.ts.map +0 -1
- package/dist/types/ui/form.d.ts +0 -6
- package/dist/types/ui/form.d.ts.map +0 -1
- package/dist/types/ui/icon.d.ts +0 -6
- package/dist/types/ui/icon.d.ts.map +0 -1
- package/dist/types/ui/passkey.d.ts +0 -5
- package/dist/types/ui/passkey.d.ts.map +0 -1
- package/dist/types/ui/password.d.ts +0 -139
- package/dist/types/ui/password.d.ts.map +0 -1
- package/dist/types/ui/select.d.ts +0 -55
- package/dist/types/ui/select.d.ts.map +0 -1
- package/dist/types/ui/theme.d.ts +0 -207
- package/dist/types/ui/theme.d.ts.map +0 -1
- package/dist/types/util.d.ts +0 -8
- package/dist/types/util.d.ts.map +0 -1
- package/src/css.d.ts +0 -4
- package/src/issuer.ts +0 -1628
- package/src/jwt.ts +0 -17
- package/src/keys.ts +0 -139
- package/src/provider/apple.ts +0 -127
- package/src/provider/arctic.ts +0 -66
- package/src/provider/code.ts +0 -227
- package/src/provider/cognito.ts +0 -74
- package/src/provider/discord.ts +0 -45
- package/src/provider/facebook.ts +0 -84
- package/src/provider/github.ts +0 -45
- package/src/provider/google.ts +0 -85
- package/src/provider/index.ts +0 -3
- package/src/provider/jumpcloud.ts +0 -45
- package/src/provider/keycloak.ts +0 -75
- package/src/provider/linkedin.ts +0 -12
- package/src/provider/m2m.ts +0 -56
- package/src/provider/microsoft.ts +0 -100
- package/src/provider/oauth2.ts +0 -297
- package/src/provider/oidc.ts +0 -179
- package/src/provider/passkey.ts +0 -655
- package/src/provider/password.ts +0 -672
- package/src/provider/provider.ts +0 -33
- package/src/provider/slack.ts +0 -67
- package/src/provider/spotify.ts +0 -45
- package/src/provider/twitch.ts +0 -45
- package/src/provider/x.ts +0 -46
- package/src/provider/yahoo.ts +0 -45
- package/src/random.ts +0 -24
- package/src/storage/aws.ts +0 -59
- package/src/storage/cloudflare.ts +0 -77
- package/src/storage/dynamo.ts +0 -193
- package/src/storage/memory.ts +0 -135
- package/src/storage/storage.ts +0 -46
- package/src/subject.ts +0 -130
- package/src/ui/base.tsx +0 -118
- package/src/ui/code.tsx +0 -215
- package/src/ui/form.tsx +0 -40
- package/src/ui/icon.tsx +0 -95
- package/src/ui/passkey.tsx +0 -321
- package/src/ui/password.tsx +0 -405
- package/src/ui/select.tsx +0 -221
- package/src/ui/theme.ts +0 -319
- package/src/ui/ui.css +0 -252
- package/src/util.ts +0 -58
- /package/dist/esm/{css.d.js → adapters/d1/types.js} +0 -0
|
@@ -0,0 +1,359 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `codeMethod` — magic-code (email / SMS) credential factory.
|
|
3
|
+
*
|
|
4
|
+
* Routes:
|
|
5
|
+
* GET /authorize → render destination form (email or phone input).
|
|
6
|
+
* POST /send → mint code, call `sendCode(destination, code)` hook,
|
|
7
|
+
* stash hashed code in `methodState`, render verify form.
|
|
8
|
+
* POST /verify → compare submitted code against stored hash; on match,
|
|
9
|
+
* return `success` with the destination as provider
|
|
10
|
+
* subject.
|
|
11
|
+
*
|
|
12
|
+
* The framework's flow record TTL (10 minutes) doubles as the code TTL —
|
|
13
|
+
* the methodState rolls off when the flow does.
|
|
14
|
+
*
|
|
15
|
+
* Anti-enumeration: the `/send` route always renders the verify form,
|
|
16
|
+
* whether or not the destination is valid. The user-supplied `sendCode`
|
|
17
|
+
* hook can silently no-op for unknown destinations.
|
|
18
|
+
*/
|
|
19
|
+
import { z } from "zod"
|
|
20
|
+
|
|
21
|
+
import {
|
|
22
|
+
base64url,
|
|
23
|
+
randomBytes,
|
|
24
|
+
sha256,
|
|
25
|
+
timingSafeEqualStr,
|
|
26
|
+
utf8,
|
|
27
|
+
} from "../domain/crypto"
|
|
28
|
+
import type {
|
|
29
|
+
AuthMethod,
|
|
30
|
+
AuthMethodFactory,
|
|
31
|
+
MethodContext,
|
|
32
|
+
MethodResult,
|
|
33
|
+
} from "../types/method"
|
|
34
|
+
import { renderForm } from "../ui/forms"
|
|
35
|
+
|
|
36
|
+
export type CodeProperties = {
|
|
37
|
+
destination: string
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export type CodeState = {
|
|
41
|
+
destination: string
|
|
42
|
+
/** Base64url SHA-256 hash of the code; the plain code never persists. */
|
|
43
|
+
codeHash: string
|
|
44
|
+
/** Failed-verify counter. After 5 attempts the flow is denied. */
|
|
45
|
+
attempts: number
|
|
46
|
+
error?: string
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export type CodeMethodOptions = {
|
|
50
|
+
/**
|
|
51
|
+
* Called when the user submits a destination. The hook receives the
|
|
52
|
+
* generated code and is responsible for delivering it (email, SMS,
|
|
53
|
+
* etc.). Returning normally means "delivery attempted"; the framework
|
|
54
|
+
* does not inspect the outcome.
|
|
55
|
+
*/
|
|
56
|
+
sendCode: (input: {
|
|
57
|
+
destination: string
|
|
58
|
+
code: string
|
|
59
|
+
tenantId: string
|
|
60
|
+
}) => Promise<void>
|
|
61
|
+
/**
|
|
62
|
+
* Override code generation. Default: 6-digit numeric.
|
|
63
|
+
*
|
|
64
|
+
* Kept on the factory closure (not per-tenant) because the generation
|
|
65
|
+
* algorithm is part of the host's overall deliverability + UX
|
|
66
|
+
* decisions, not something that should be reconfigured per tenant.
|
|
67
|
+
*/
|
|
68
|
+
generateCode?: () => string
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Per-tenant config. Host supplies these via `MethodConfig.config` so
|
|
73
|
+
* each tenant can ship its own code length, attempt cap, channel kind,
|
|
74
|
+
* and copy without instantiating a new factory.
|
|
75
|
+
*/
|
|
76
|
+
const configSchema = z.object({
|
|
77
|
+
/** Default 6. Range 4–10. */
|
|
78
|
+
codeLength: z.number().int().min(4).max(10).optional(),
|
|
79
|
+
/** Default 5. After this many failed verifies the flow is denied. */
|
|
80
|
+
maxAttempts: z.number().int().min(1).max(20).optional(),
|
|
81
|
+
/** Default "email". */
|
|
82
|
+
destinationKind: z.enum(["email", "tel", "any"]).optional(),
|
|
83
|
+
/** Form copy overrides. */
|
|
84
|
+
titles: z
|
|
85
|
+
.object({
|
|
86
|
+
request: z.string().optional(),
|
|
87
|
+
verify: z.string().optional(),
|
|
88
|
+
})
|
|
89
|
+
.optional(),
|
|
90
|
+
})
|
|
91
|
+
type CodeConfig = z.infer<typeof configSchema>
|
|
92
|
+
|
|
93
|
+
const sendBody = z.object({
|
|
94
|
+
destination: z.string().min(1),
|
|
95
|
+
})
|
|
96
|
+
const verifyBody = z.object({
|
|
97
|
+
code: z.string().min(1),
|
|
98
|
+
})
|
|
99
|
+
|
|
100
|
+
export function codeMethod(
|
|
101
|
+
opts: CodeMethodOptions,
|
|
102
|
+
): AuthMethodFactory<CodeProperties, CodeState, CodeConfig> {
|
|
103
|
+
const customGenerator = opts.generateCode
|
|
104
|
+
return {
|
|
105
|
+
kind: "code",
|
|
106
|
+
configSchema,
|
|
107
|
+
build: async ({
|
|
108
|
+
id,
|
|
109
|
+
kind,
|
|
110
|
+
config,
|
|
111
|
+
}): Promise<AuthMethod<CodeProperties, CodeState>> => {
|
|
112
|
+
const titleRequest = config.titles?.request ?? "Sign in"
|
|
113
|
+
const titleVerify = config.titles?.verify ?? "Enter your code"
|
|
114
|
+
const maxAttempts = config.maxAttempts ?? 5
|
|
115
|
+
const destinationKind = config.destinationKind ?? "email"
|
|
116
|
+
const codeLength = config.codeLength ?? 6
|
|
117
|
+
const generateCode = customGenerator ?? (() => defaultCode(codeLength))
|
|
118
|
+
return {
|
|
119
|
+
id,
|
|
120
|
+
kind,
|
|
121
|
+
type: "code",
|
|
122
|
+
routes: {
|
|
123
|
+
"GET /authorize": async (_ctx) => ({
|
|
124
|
+
kind: "challenge",
|
|
125
|
+
response: htmlResponse(
|
|
126
|
+
renderForm({
|
|
127
|
+
title: titleRequest,
|
|
128
|
+
action: `/m/${id}/send`,
|
|
129
|
+
fields: destinationField(destinationKind),
|
|
130
|
+
submit: "Send code",
|
|
131
|
+
}),
|
|
132
|
+
),
|
|
133
|
+
}),
|
|
134
|
+
"POST /send": async (ctx) =>
|
|
135
|
+
handleSend(
|
|
136
|
+
ctx,
|
|
137
|
+
id,
|
|
138
|
+
titleRequest,
|
|
139
|
+
titleVerify,
|
|
140
|
+
destinationKind,
|
|
141
|
+
generateCode,
|
|
142
|
+
opts.sendCode,
|
|
143
|
+
),
|
|
144
|
+
"POST /verify": async (ctx) =>
|
|
145
|
+
handleVerify(ctx, id, titleVerify, maxAttempts),
|
|
146
|
+
},
|
|
147
|
+
}
|
|
148
|
+
},
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
async function handleSend(
|
|
153
|
+
ctx: MethodContext<CodeState>,
|
|
154
|
+
methodId: string,
|
|
155
|
+
titleRequest: string,
|
|
156
|
+
titleVerify: string,
|
|
157
|
+
destinationKind: "email" | "tel" | "any",
|
|
158
|
+
generateCode: () => string,
|
|
159
|
+
sendCode: CodeMethodOptions["sendCode"],
|
|
160
|
+
): Promise<MethodResult<CodeProperties, CodeState>> {
|
|
161
|
+
const form = await safeForm(ctx.request)
|
|
162
|
+
const parsed = sendBody.safeParse(form)
|
|
163
|
+
if (
|
|
164
|
+
!parsed.success ||
|
|
165
|
+
!validateDestination(parsed.data?.destination, destinationKind)
|
|
166
|
+
) {
|
|
167
|
+
return {
|
|
168
|
+
kind: "challenge",
|
|
169
|
+
response: htmlResponse(
|
|
170
|
+
renderForm({
|
|
171
|
+
title: titleRequest,
|
|
172
|
+
action: `/m/${methodId}/send`,
|
|
173
|
+
fields: destinationField(destinationKind),
|
|
174
|
+
submit: "Send code",
|
|
175
|
+
error: "Please enter a valid destination.",
|
|
176
|
+
}),
|
|
177
|
+
400,
|
|
178
|
+
),
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
const destination = parsed.data.destination
|
|
182
|
+
const code = generateCode()
|
|
183
|
+
// Side effect best-effort: deliveries can fail but we still render the
|
|
184
|
+
// verify form so we never leak whether the destination exists.
|
|
185
|
+
try {
|
|
186
|
+
await sendCode({ destination, code, tenantId: ctx.tenant.id })
|
|
187
|
+
} catch {
|
|
188
|
+
/* swallow — the user retries via the resend control. */
|
|
189
|
+
}
|
|
190
|
+
const hash = base64url.encode(await sha256(utf8.encode(code)))
|
|
191
|
+
return {
|
|
192
|
+
kind: "challenge",
|
|
193
|
+
response: htmlResponse(
|
|
194
|
+
renderForm({
|
|
195
|
+
title: titleVerify,
|
|
196
|
+
action: `/m/${methodId}/verify`,
|
|
197
|
+
fields: [
|
|
198
|
+
{
|
|
199
|
+
name: "code",
|
|
200
|
+
label: "Code",
|
|
201
|
+
required: true,
|
|
202
|
+
inputmode: "numeric",
|
|
203
|
+
autocomplete: "one-time-code",
|
|
204
|
+
},
|
|
205
|
+
],
|
|
206
|
+
submit: "Verify",
|
|
207
|
+
hidden: { destination },
|
|
208
|
+
}),
|
|
209
|
+
),
|
|
210
|
+
saveMethodState: {
|
|
211
|
+
destination,
|
|
212
|
+
codeHash: hash,
|
|
213
|
+
attempts: 0,
|
|
214
|
+
},
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
async function handleVerify(
|
|
219
|
+
ctx: MethodContext<CodeState>,
|
|
220
|
+
methodId: string,
|
|
221
|
+
titleVerify: string,
|
|
222
|
+
maxAttempts: number,
|
|
223
|
+
): Promise<MethodResult<CodeProperties, CodeState>> {
|
|
224
|
+
if (!ctx.methodState) {
|
|
225
|
+
return {
|
|
226
|
+
kind: "error",
|
|
227
|
+
error: {
|
|
228
|
+
code: "invalid_request",
|
|
229
|
+
description: "verify without prior /send",
|
|
230
|
+
},
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
const state = ctx.methodState
|
|
234
|
+
if (state.attempts >= maxAttempts) {
|
|
235
|
+
return { kind: "denied", reason: "too_many_attempts" }
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
const form = await safeForm(ctx.request)
|
|
239
|
+
const parsed = verifyBody.safeParse(form)
|
|
240
|
+
if (!parsed.success) {
|
|
241
|
+
return verifyError(methodId, state, titleVerify, "Please enter the code.")
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
const submittedHash = base64url.encode(
|
|
245
|
+
await sha256(utf8.encode(parsed.data.code)),
|
|
246
|
+
)
|
|
247
|
+
if (!timingSafeEqualStr(submittedHash, state.codeHash)) {
|
|
248
|
+
return verifyError(
|
|
249
|
+
methodId,
|
|
250
|
+
{ ...state, attempts: state.attempts + 1 },
|
|
251
|
+
titleVerify,
|
|
252
|
+
"Incorrect code. Please try again.",
|
|
253
|
+
)
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
return {
|
|
257
|
+
kind: "success",
|
|
258
|
+
providerSubject: state.destination,
|
|
259
|
+
properties: { destination: state.destination },
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
function verifyError(
|
|
264
|
+
methodId: string,
|
|
265
|
+
next: CodeState,
|
|
266
|
+
titleVerify: string,
|
|
267
|
+
error: string,
|
|
268
|
+
): MethodResult<CodeProperties, CodeState> {
|
|
269
|
+
return {
|
|
270
|
+
kind: "challenge",
|
|
271
|
+
response: htmlResponse(
|
|
272
|
+
renderForm({
|
|
273
|
+
title: titleVerify,
|
|
274
|
+
action: `/m/${methodId}/verify`,
|
|
275
|
+
fields: [
|
|
276
|
+
{
|
|
277
|
+
name: "code",
|
|
278
|
+
label: "Code",
|
|
279
|
+
required: true,
|
|
280
|
+
inputmode: "numeric",
|
|
281
|
+
autocomplete: "one-time-code",
|
|
282
|
+
},
|
|
283
|
+
],
|
|
284
|
+
submit: "Verify",
|
|
285
|
+
error,
|
|
286
|
+
}),
|
|
287
|
+
400,
|
|
288
|
+
),
|
|
289
|
+
saveMethodState: { ...next, error },
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
function destinationField(kind: "email" | "tel" | "any") {
|
|
294
|
+
if (kind === "email") {
|
|
295
|
+
return [
|
|
296
|
+
{
|
|
297
|
+
name: "destination",
|
|
298
|
+
label: "Email",
|
|
299
|
+
type: "email" as const,
|
|
300
|
+
required: true,
|
|
301
|
+
autocomplete: "email",
|
|
302
|
+
},
|
|
303
|
+
]
|
|
304
|
+
}
|
|
305
|
+
if (kind === "tel") {
|
|
306
|
+
return [
|
|
307
|
+
{
|
|
308
|
+
name: "destination",
|
|
309
|
+
label: "Phone",
|
|
310
|
+
type: "tel" as const,
|
|
311
|
+
required: true,
|
|
312
|
+
autocomplete: "tel",
|
|
313
|
+
},
|
|
314
|
+
]
|
|
315
|
+
}
|
|
316
|
+
return [
|
|
317
|
+
{
|
|
318
|
+
name: "destination",
|
|
319
|
+
label: "Destination",
|
|
320
|
+
type: "text" as const,
|
|
321
|
+
required: true,
|
|
322
|
+
},
|
|
323
|
+
]
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
function validateDestination(
|
|
327
|
+
destination: string | undefined,
|
|
328
|
+
kind: "email" | "tel" | "any",
|
|
329
|
+
): destination is string {
|
|
330
|
+
if (!destination) return false
|
|
331
|
+
if (kind === "email") return /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(destination)
|
|
332
|
+
if (kind === "tel") return /^[+\d][\d\s\-()]{6,}$/.test(destination)
|
|
333
|
+
return destination.length > 0
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
function defaultCode(length: number): string {
|
|
337
|
+
// Modulo over a uniform 32-bit draw — small skew on the high end of the
|
|
338
|
+
// range, fine for codes gated by rate limiting + max-attempts.
|
|
339
|
+
const buf = randomBytes(4)
|
|
340
|
+
const view = new DataView(buf.buffer, buf.byteOffset, 4)
|
|
341
|
+
const max = 10 ** length
|
|
342
|
+
const n = view.getUint32(0) % max
|
|
343
|
+
return n.toString().padStart(length, "0")
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
async function safeForm(req: Request): Promise<Record<string, string>> {
|
|
347
|
+
const ct = req.headers.get("content-type") ?? ""
|
|
348
|
+
if (!ct.toLowerCase().startsWith("application/x-www-form-urlencoded")) {
|
|
349
|
+
return {}
|
|
350
|
+
}
|
|
351
|
+
return Object.fromEntries(new URLSearchParams(await req.text()).entries())
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
function htmlResponse(body: string, status = 200): Response {
|
|
355
|
+
return new Response(body, {
|
|
356
|
+
status,
|
|
357
|
+
headers: { "content-type": "text/html; charset=utf-8" },
|
|
358
|
+
})
|
|
359
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `m2mMethod` — machine-to-machine factory (RFC 6749 §4.4 client_credentials).
|
|
3
|
+
*
|
|
4
|
+
* No URL routes. The factory ships only a `client` fn the framework invokes
|
|
5
|
+
* from `/token` after standard client authentication has succeeded. The
|
|
6
|
+
* fn validates and returns the `P` properties the success callback will
|
|
7
|
+
* map into the issued subject claim.
|
|
8
|
+
*
|
|
9
|
+
* Typical use: a tenant configures one m2m method instance per tenant.
|
|
10
|
+
* The user-supplied `verify` hook decides whether the (already
|
|
11
|
+
* authenticated) client is allowed to use this method and what claims it
|
|
12
|
+
* carries (org id, service tier, etc.).
|
|
13
|
+
*/
|
|
14
|
+
import { z } from "zod"
|
|
15
|
+
|
|
16
|
+
import { authError } from "../types/error"
|
|
17
|
+
import { err, ok, type Result } from "../types/result"
|
|
18
|
+
import type { AuthMethod, AuthMethodFactory, ClientFn } from "../types/method"
|
|
19
|
+
|
|
20
|
+
export type M2MProperties = {
|
|
21
|
+
/** The client's stable id (echoed back from the request). */
|
|
22
|
+
clientId: string
|
|
23
|
+
/** Tenant-supplied extra claims. */
|
|
24
|
+
claims?: Record<string, unknown>
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export type M2MMethodOptions = {
|
|
28
|
+
/**
|
|
29
|
+
* Look up the client's per-client metadata. Return `null` for unauthorized
|
|
30
|
+
* (the framework already authenticated the secret; this is for
|
|
31
|
+
* application-level authorization — e.g. "is this client allowed to use
|
|
32
|
+
* this method?", "what claims should we attach?").
|
|
33
|
+
*/
|
|
34
|
+
verify: (input: {
|
|
35
|
+
clientID: string
|
|
36
|
+
params: Record<string, string>
|
|
37
|
+
tenantId: string
|
|
38
|
+
}) => Promise<{ claims?: Record<string, unknown> } | null>
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const configSchema = z.object({}).strict()
|
|
42
|
+
type M2MConfig = z.infer<typeof configSchema>
|
|
43
|
+
|
|
44
|
+
export function m2mMethod(
|
|
45
|
+
opts: M2MMethodOptions,
|
|
46
|
+
): AuthMethodFactory<M2MProperties, never, M2MConfig> {
|
|
47
|
+
return {
|
|
48
|
+
kind: "m2m",
|
|
49
|
+
configSchema,
|
|
50
|
+
build: async ({
|
|
51
|
+
id,
|
|
52
|
+
kind,
|
|
53
|
+
tenantId,
|
|
54
|
+
}): Promise<AuthMethod<M2MProperties, never>> => {
|
|
55
|
+
const clientFn: ClientFn<M2MProperties> = async (
|
|
56
|
+
input,
|
|
57
|
+
): Promise<
|
|
58
|
+
Result<M2MProperties, ReturnType<typeof authError.invalidClient>>
|
|
59
|
+
> => {
|
|
60
|
+
const verified = await opts.verify({
|
|
61
|
+
clientID: input.clientID,
|
|
62
|
+
params: input.params,
|
|
63
|
+
tenantId,
|
|
64
|
+
})
|
|
65
|
+
if (!verified) {
|
|
66
|
+
return err(authError.invalidClient("client not authorized for m2m"))
|
|
67
|
+
}
|
|
68
|
+
return ok({
|
|
69
|
+
clientId: input.clientID,
|
|
70
|
+
...(verified.claims ? { claims: verified.claims } : {}),
|
|
71
|
+
})
|
|
72
|
+
}
|
|
73
|
+
return {
|
|
74
|
+
id,
|
|
75
|
+
kind,
|
|
76
|
+
type: "m2m",
|
|
77
|
+
routes: {},
|
|
78
|
+
client: clientFn,
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
}
|
|
82
|
+
}
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `oauth2Factory` and `oidcFactory` — generic multi-tenant factories.
|
|
3
|
+
*
|
|
4
|
+
* Use these when each tenant brings its own OAuth 2.0 / OIDC issuer,
|
|
5
|
+
* client credentials, scopes, and endpoint URLs. The factory's
|
|
6
|
+
* `configSchema` accepts a per-tenant blob and `build()` delegates to
|
|
7
|
+
* `buildOauth2Method` / `buildOidcMethod` to produce the actual
|
|
8
|
+
* `AuthMethod`.
|
|
9
|
+
*
|
|
10
|
+
* For built-in vendor wrappers (Google, GitHub, Apple, etc.) see
|
|
11
|
+
* `./providers/*` — those bake in the issuer URL and provider quirks.
|
|
12
|
+
*
|
|
13
|
+
* For single-tenant deployments where the issuer / endpoints are
|
|
14
|
+
* compile-time constants, you can still call `buildOauth2Method` /
|
|
15
|
+
* `buildOidcMethod` directly inside your own `AuthMethodFactory` —
|
|
16
|
+
* those entry points are the underlying "build a static AuthMethod"
|
|
17
|
+
* primitives; this file just wraps them in the multi-tenant factory
|
|
18
|
+
* shape.
|
|
19
|
+
*/
|
|
20
|
+
import { z } from "zod"
|
|
21
|
+
|
|
22
|
+
import { buildOauth2Method } from "./oauth2-generic"
|
|
23
|
+
import { buildOidcMethod } from "./oidc-generic"
|
|
24
|
+
import type { Oauth2Properties, Oauth2State } from "./oauth2-generic"
|
|
25
|
+
import type { AuthMethod, AuthMethodFactory } from "../types/method"
|
|
26
|
+
|
|
27
|
+
const oauth2ConfigSchema = z.object({
|
|
28
|
+
clientId: z.string().min(1),
|
|
29
|
+
clientSecret: z.string().min(1).optional(),
|
|
30
|
+
scopes: z.array(z.string()).min(1),
|
|
31
|
+
authorizationUrl: z.string().url(),
|
|
32
|
+
tokenUrl: z.string().url(),
|
|
33
|
+
jwksUri: z.string().url().optional(),
|
|
34
|
+
expectedIssuer: z.string().optional(),
|
|
35
|
+
extraAuthorizeParams: z.record(z.string()).optional(),
|
|
36
|
+
pkce: z.enum(["S256", "none"]).optional(),
|
|
37
|
+
responseMode: z.enum(["query", "form_post"]).optional(),
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
export type Oauth2FactoryConfig = z.infer<typeof oauth2ConfigSchema>
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Generic OAuth 2.0 factory.
|
|
44
|
+
*
|
|
45
|
+
* `kind: "oauth2"`. Use a different `MethodConfig.id` per instance to
|
|
46
|
+
* register multiple OAuth 2.0 upstreams against a single tenant.
|
|
47
|
+
*/
|
|
48
|
+
export const oauth2Factory: AuthMethodFactory<
|
|
49
|
+
Oauth2Properties,
|
|
50
|
+
Oauth2State,
|
|
51
|
+
Oauth2FactoryConfig
|
|
52
|
+
> = {
|
|
53
|
+
kind: "oauth2",
|
|
54
|
+
configSchema: oauth2ConfigSchema,
|
|
55
|
+
build: async ({
|
|
56
|
+
id,
|
|
57
|
+
kind,
|
|
58
|
+
config,
|
|
59
|
+
}): Promise<AuthMethod<Oauth2Properties, Oauth2State>> =>
|
|
60
|
+
buildOauth2Method({
|
|
61
|
+
id,
|
|
62
|
+
kind,
|
|
63
|
+
clientId: config.clientId,
|
|
64
|
+
...(config.clientSecret !== undefined
|
|
65
|
+
? { clientSecret: config.clientSecret }
|
|
66
|
+
: {}),
|
|
67
|
+
scopes: config.scopes,
|
|
68
|
+
authorizationUrl: config.authorizationUrl,
|
|
69
|
+
tokenUrl: config.tokenUrl,
|
|
70
|
+
...(config.jwksUri ? { jwksUri: config.jwksUri } : {}),
|
|
71
|
+
...(config.expectedIssuer
|
|
72
|
+
? { expectedIssuer: config.expectedIssuer }
|
|
73
|
+
: {}),
|
|
74
|
+
...(config.extraAuthorizeParams
|
|
75
|
+
? { extraAuthorizeParams: config.extraAuthorizeParams }
|
|
76
|
+
: {}),
|
|
77
|
+
...(config.pkce ? { pkce: config.pkce } : {}),
|
|
78
|
+
...(config.responseMode ? { responseMode: config.responseMode } : {}),
|
|
79
|
+
}),
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const oidcConfigSchema = z.object({
|
|
83
|
+
issuer: z.string().url(),
|
|
84
|
+
clientId: z.string().min(1),
|
|
85
|
+
clientSecret: z.string().min(1).optional(),
|
|
86
|
+
scopes: z.array(z.string()).optional(),
|
|
87
|
+
extraAuthorizeParams: z.record(z.string()).optional(),
|
|
88
|
+
pkce: z.enum(["S256", "none"]).optional(),
|
|
89
|
+
responseMode: z.enum(["query", "form_post"]).optional(),
|
|
90
|
+
/**
|
|
91
|
+
* Skip discovery and use these endpoints directly. Useful for
|
|
92
|
+
* providers with non-standard or fragmented discovery
|
|
93
|
+
* (Microsoft tenant-templated, legacy stacks).
|
|
94
|
+
*/
|
|
95
|
+
endpoints: z
|
|
96
|
+
.object({
|
|
97
|
+
authorization_endpoint: z.string().url(),
|
|
98
|
+
token_endpoint: z.string().url(),
|
|
99
|
+
jwks_uri: z.string().url(),
|
|
100
|
+
issuer: z.string(),
|
|
101
|
+
})
|
|
102
|
+
.optional(),
|
|
103
|
+
})
|
|
104
|
+
|
|
105
|
+
export type OidcFactoryConfig = z.infer<typeof oidcConfigSchema>
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Generic OIDC factory. Auto-discovers `<issuer>/.well-known/openid-
|
|
109
|
+
* configuration` unless `endpoints` is supplied.
|
|
110
|
+
*
|
|
111
|
+
* `kind: "oidc"`. Use a different `MethodConfig.id` per instance to
|
|
112
|
+
* register multiple OIDC upstreams against a single tenant.
|
|
113
|
+
*/
|
|
114
|
+
export const oidcFactory: AuthMethodFactory<
|
|
115
|
+
Oauth2Properties,
|
|
116
|
+
Oauth2State,
|
|
117
|
+
OidcFactoryConfig
|
|
118
|
+
> = {
|
|
119
|
+
kind: "oidc",
|
|
120
|
+
configSchema: oidcConfigSchema,
|
|
121
|
+
build: async ({
|
|
122
|
+
id,
|
|
123
|
+
kind,
|
|
124
|
+
config,
|
|
125
|
+
}): Promise<AuthMethod<Oauth2Properties, Oauth2State>> =>
|
|
126
|
+
buildOidcMethod({
|
|
127
|
+
id,
|
|
128
|
+
kind,
|
|
129
|
+
issuer: config.issuer,
|
|
130
|
+
clientId: config.clientId,
|
|
131
|
+
...(config.clientSecret !== undefined
|
|
132
|
+
? { clientSecret: config.clientSecret }
|
|
133
|
+
: {}),
|
|
134
|
+
scopes: config.scopes ?? ["openid", "email", "profile"],
|
|
135
|
+
...(config.extraAuthorizeParams
|
|
136
|
+
? { extraAuthorizeParams: config.extraAuthorizeParams }
|
|
137
|
+
: {}),
|
|
138
|
+
...(config.pkce ? { pkce: config.pkce } : {}),
|
|
139
|
+
...(config.responseMode ? { responseMode: config.responseMode } : {}),
|
|
140
|
+
...(config.endpoints
|
|
141
|
+
? {
|
|
142
|
+
endpoints: {
|
|
143
|
+
authorization_endpoint: config.endpoints.authorization_endpoint,
|
|
144
|
+
token_endpoint: config.endpoints.token_endpoint,
|
|
145
|
+
jwks_uri: config.endpoints.jwks_uri,
|
|
146
|
+
issuer: config.endpoints.issuer,
|
|
147
|
+
},
|
|
148
|
+
}
|
|
149
|
+
: {}),
|
|
150
|
+
}),
|
|
151
|
+
}
|