@entro314labs/entro-auth 0.0.0-stage → 1.8.0-beta.12
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.md +20 -0
- package/README.md +31 -2
- package/dist/_virtual/_rolldown/runtime.mjs +26 -0
- package/dist/adapters/drizzle-adapter/index.d.mts +1 -0
- package/dist/adapters/drizzle-adapter/index.mjs +2 -0
- package/dist/adapters/index.d.mts +19 -0
- package/dist/adapters/index.mjs +8 -0
- package/dist/adapters/kysely-adapter/index.d.mts +1 -0
- package/dist/adapters/kysely-adapter/index.mjs +2 -0
- package/dist/adapters/memory-adapter/index.d.mts +1 -0
- package/dist/adapters/memory-adapter/index.mjs +2 -0
- package/dist/api/dispatch.d.mts +31 -0
- package/dist/api/dispatch.mjs +318 -0
- package/dist/api/index.d.mts +4117 -0
- package/dist/api/index.mjs +227 -0
- package/dist/api/middlewares/authorization.d.mts +70 -0
- package/dist/api/middlewares/authorization.mjs +78 -0
- package/dist/api/middlewares/index.d.mts +3 -0
- package/dist/api/middlewares/origin-check.d.mts +12 -0
- package/dist/api/middlewares/origin-check.mjs +154 -0
- package/dist/api/rate-limiter/index.mjs +322 -0
- package/dist/api/routes/account.d.mts +407 -0
- package/dist/api/routes/account.mjs +642 -0
- package/dist/api/routes/callback.d.mts +27 -0
- package/dist/api/routes/callback.mjs +184 -0
- package/dist/api/routes/email-verification.d.mts +153 -0
- package/dist/api/routes/email-verification.mjs +315 -0
- package/dist/api/routes/error.d.mts +22 -0
- package/dist/api/routes/error.mjs +386 -0
- package/dist/api/routes/id-token-nonce.d.mts +83 -0
- package/dist/api/routes/id-token-nonce.mjs +79 -0
- package/dist/api/routes/index.d.mts +14 -0
- package/dist/api/routes/ok.d.mts +30 -0
- package/dist/api/routes/ok.mjs +26 -0
- package/dist/api/routes/password.d.mts +177 -0
- package/dist/api/routes/password.mjs +198 -0
- package/dist/api/routes/session.d.mts +446 -0
- package/dist/api/routes/session.mjs +488 -0
- package/dist/api/routes/sign-in.d.mts +182 -0
- package/dist/api/routes/sign-in.mjs +374 -0
- package/dist/api/routes/sign-out.d.mts +46 -0
- package/dist/api/routes/sign-out.mjs +101 -0
- package/dist/api/routes/sign-up.d.mts +155 -0
- package/dist/api/routes/sign-up.mjs +279 -0
- package/dist/api/routes/update-session.d.mts +70 -0
- package/dist/api/routes/update-session.mjs +56 -0
- package/dist/api/routes/update-user.d.mts +424 -0
- package/dist/api/routes/update-user.mjs +524 -0
- package/dist/api/state/oauth.d.mts +48 -0
- package/dist/api/state/oauth.mjs +38 -0
- package/dist/api/state/should-session-refresh.d.mts +10 -0
- package/dist/api/state/should-session-refresh.mjs +12 -0
- package/dist/api/to-auth-endpoints.mjs +59 -0
- package/dist/auth/base.mjs +60 -0
- package/dist/auth/full.d.mts +25 -0
- package/dist/auth/full.mjs +28 -0
- package/dist/auth/minimal.d.mts +8 -0
- package/dist/auth/minimal.mjs +10 -0
- package/dist/auth/trusted-origins.mjs +130 -0
- package/dist/client/broadcast-channel.d.mts +16 -0
- package/dist/client/broadcast-channel.mjs +44 -0
- package/dist/client/config.d.mts +84 -0
- package/dist/client/config.mjs +111 -0
- package/dist/client/equality.d.mts +15 -0
- package/dist/client/equality.mjs +41 -0
- package/dist/client/fetch-plugins.mjs +16 -0
- package/dist/client/focus-manager.d.mts +7 -0
- package/dist/client/focus-manager.mjs +30 -0
- package/dist/client/index.d.mts +35 -0
- package/dist/client/index.mjs +21 -0
- package/dist/client/lynx/index.d.mts +40 -0
- package/dist/client/lynx/index.mjs +22 -0
- package/dist/client/lynx/lynx-store.d.mts +43 -0
- package/dist/client/lynx/lynx-store.mjs +43 -0
- package/dist/client/online-manager.d.mts +8 -0
- package/dist/client/online-manager.mjs +33 -0
- package/dist/client/parser.d.mts +12 -0
- package/dist/client/parser.mjs +59 -0
- package/dist/client/path-to-object.d.mts +110 -0
- package/dist/client/plugins/index.d.mts +44 -0
- package/dist/client/plugins/index.mjs +30 -0
- package/dist/client/plugins/infer-plugin.d.mts +12 -0
- package/dist/client/plugins/infer-plugin.mjs +10 -0
- package/dist/client/proxy.mjs +70 -0
- package/dist/client/query-atom.mjs +12 -0
- package/dist/client/query.d.mts +19 -0
- package/dist/client/query.mjs +133 -0
- package/dist/client/react/index.d.mts +41 -0
- package/dist/client/react/index.mjs +22 -0
- package/dist/client/react/react-store.d.mts +43 -0
- package/dist/client/react/react-store.mjs +44 -0
- package/dist/client/session-atom.d.mts +9 -0
- package/dist/client/session-atom.mjs +179 -0
- package/dist/client/session-refresh.d.mts +16 -0
- package/dist/client/session-refresh.mjs +131 -0
- package/dist/client/solid/index.d.mts +41 -0
- package/dist/client/solid/index.mjs +22 -0
- package/dist/client/solid/solid-store.mjs +20 -0
- package/dist/client/svelte/index.d.mts +41 -0
- package/dist/client/svelte/index.mjs +18 -0
- package/dist/client/types.d.mts +49 -0
- package/dist/client/vanilla.d.mts +39 -0
- package/dist/client/vanilla.mjs +18 -0
- package/dist/client/vue/index.d.mts +64 -0
- package/dist/client/vue/index.mjs +60 -0
- package/dist/client/vue/vue-store.mjs +22 -0
- package/dist/context/create-context.mjs +229 -0
- package/dist/context/helpers.mjs +159 -0
- package/dist/context/init-minimal.mjs +15 -0
- package/dist/context/init.mjs +16 -0
- package/dist/context/secret-utils.mjs +52 -0
- package/dist/context/store-capabilities.mjs +11 -0
- package/dist/cookies/cache.mjs +33 -0
- package/dist/cookies/cookie-utils.d.mts +70 -0
- package/dist/cookies/cookie-utils.mjs +200 -0
- package/dist/cookies/index.d.mts +121 -0
- package/dist/cookies/index.mjs +356 -0
- package/dist/cookies/jwt.mjs +44 -0
- package/dist/cookies/session-store.d.mts +31 -0
- package/dist/cookies/session-store.mjs +183 -0
- package/dist/crypto/buffer.d.mts +4 -0
- package/dist/crypto/buffer.mjs +15 -0
- package/dist/crypto/index.d.mts +24 -0
- package/dist/crypto/index.mjs +70 -0
- package/dist/crypto/jwt.d.mts +5 -0
- package/dist/crypto/jwt.mjs +141 -0
- package/dist/crypto/password.d.mts +7 -0
- package/dist/crypto/password.mjs +13 -0
- package/dist/crypto/purpose.d.mts +12 -0
- package/dist/crypto/purpose.mjs +27 -0
- package/dist/crypto/random.d.mts +1 -0
- package/dist/crypto/random.mjs +4 -0
- package/dist/db/adapter-base.d.mts +3 -0
- package/dist/db/adapter-base.mjs +24 -0
- package/dist/db/adapter-kysely.d.mts +3 -0
- package/dist/db/adapter-kysely.mjs +16 -0
- package/dist/db/field-converter.d.mts +3 -0
- package/dist/db/field-converter.mjs +18 -0
- package/dist/db/field.d.mts +38 -0
- package/dist/db/get-migration.d.mts +50 -0
- package/dist/db/get-migration.mjs +685 -0
- package/dist/db/get-schema.d.mts +9 -0
- package/dist/db/get-schema.mjs +54 -0
- package/dist/db/index.d.mts +10 -0
- package/dist/db/index.mjs +34 -0
- package/dist/db/internal-adapter.d.mts +10 -0
- package/dist/db/internal-adapter.mjs +1083 -0
- package/dist/db/revoke-unproven-account-access.d.mts +18 -0
- package/dist/db/revoke-unproven-account-access.mjs +57 -0
- package/dist/db/schema.d.mts +59 -0
- package/dist/db/schema.mjs +172 -0
- package/dist/db/to-zod.d.mts +31 -0
- package/dist/db/to-zod.mjs +32 -0
- package/dist/db/verification-token-storage.mjs +24 -0
- package/dist/db/with-hooks.d.mts +33 -0
- package/dist/db/with-hooks.mjs +248 -0
- package/dist/index.d.mts +30 -0
- package/dist/index.mjs +16 -0
- package/dist/integrations/cookie-plugin-guard.mjs +17 -0
- package/dist/integrations/next-js.d.mts +23 -0
- package/dist/integrations/next-js.mjs +104 -0
- package/dist/integrations/node.d.mts +7 -0
- package/dist/integrations/node.mjs +14 -0
- package/dist/integrations/solid-start.d.mts +19 -0
- package/dist/integrations/solid-start.mjs +14 -0
- package/dist/integrations/svelte-kit.d.mts +28 -0
- package/dist/integrations/svelte-kit.mjs +56 -0
- package/dist/integrations/tanstack-start-solid.d.mts +27 -0
- package/dist/integrations/tanstack-start-solid.mjs +56 -0
- package/dist/integrations/tanstack-start.d.mts +27 -0
- package/dist/integrations/tanstack-start.mjs +56 -0
- package/dist/oauth2/account-fields.mjs +51 -0
- package/dist/oauth2/account-key.mjs +42 -0
- package/dist/oauth2/callback.mjs +67 -0
- package/dist/oauth2/dpop-client.d.mts +1 -0
- package/dist/oauth2/dpop-client.mjs +2 -0
- package/dist/oauth2/errors.mjs +48 -0
- package/dist/oauth2/index.d.mts +5 -0
- package/dist/oauth2/index.mjs +5 -0
- package/dist/oauth2/link-account.d.mts +126 -0
- package/dist/oauth2/link-account.mjs +429 -0
- package/dist/oauth2/state.d.mts +49 -0
- package/dist/oauth2/state.mjs +66 -0
- package/dist/oauth2/utils.d.mts +21 -0
- package/dist/oauth2/utils.mjs +44 -0
- package/dist/package.mjs +3 -0
- package/dist/plugins/access/access.d.mts +13 -0
- package/dist/plugins/access/access.mjs +77 -0
- package/dist/plugins/access/index.d.mts +3 -0
- package/dist/plugins/access/index.mjs +1 -0
- package/dist/plugins/access/types.d.mts +20 -0
- package/dist/plugins/additional-fields/client.d.mts +96 -0
- package/dist/plugins/additional-fields/client.mjs +10 -0
- package/dist/plugins/admin/access/index.d.mts +2 -0
- package/dist/plugins/admin/access/index.mjs +1 -0
- package/dist/plugins/admin/access/statement.d.mts +49 -0
- package/dist/plugins/admin/access/statement.mjs +53 -0
- package/dist/plugins/admin/admin.d.mts +908 -0
- package/dist/plugins/admin/admin.mjs +90 -0
- package/dist/plugins/admin/client.d.mts +84 -0
- package/dist/plugins/admin/client.mjs +38 -0
- package/dist/plugins/admin/error-codes.d.mts +30 -0
- package/dist/plugins/admin/error-codes.mjs +33 -0
- package/dist/plugins/admin/has-permission.mjs +11 -0
- package/dist/plugins/admin/index.d.mts +3 -0
- package/dist/plugins/admin/index.mjs +1 -0
- package/dist/plugins/admin/routes.mjs +940 -0
- package/dist/plugins/admin/schema.d.mts +37 -0
- package/dist/plugins/admin/schema.mjs +32 -0
- package/dist/plugins/admin/types.d.mts +89 -0
- package/dist/plugins/anonymous/client.d.mts +28 -0
- package/dist/plugins/anonymous/client.mjs +20 -0
- package/dist/plugins/anonymous/error-codes.d.mts +10 -0
- package/dist/plugins/anonymous/error-codes.mjs +13 -0
- package/dist/plugins/anonymous/index.d.mts +170 -0
- package/dist/plugins/anonymous/index.mjs +220 -0
- package/dist/plugins/anonymous/schema.d.mts +12 -0
- package/dist/plugins/anonymous/schema.mjs +8 -0
- package/dist/plugins/anonymous/types.d.mts +62 -0
- package/dist/plugins/bearer/index.d.mts +39 -0
- package/dist/plugins/bearer/index.mjs +73 -0
- package/dist/plugins/captcha/constants.d.mts +7 -0
- package/dist/plugins/captcha/constants.mjs +27 -0
- package/dist/plugins/captcha/error-codes.mjs +12 -0
- package/dist/plugins/captcha/index.d.mts +22 -0
- package/dist/plugins/captcha/index.mjs +93 -0
- package/dist/plugins/captcha/types.d.mts +90 -0
- package/dist/plugins/captcha/utils.mjs +18 -0
- package/dist/plugins/captcha/verify-handlers/captchafox.mjs +26 -0
- package/dist/plugins/captcha/verify-handlers/cloudflare-turnstile.mjs +46 -0
- package/dist/plugins/captcha/verify-handlers/google-recaptcha.mjs +31 -0
- package/dist/plugins/captcha/verify-handlers/h-captcha.mjs +26 -0
- package/dist/plugins/captcha/verify-handlers/vercel-botid.mjs +26 -0
- package/dist/plugins/custom-session/client.d.mts +13 -0
- package/dist/plugins/custom-session/client.mjs +6 -0
- package/dist/plugins/custom-session/index.d.mts +65 -0
- package/dist/plugins/custom-session/index.mjs +57 -0
- package/dist/plugins/device-authorization/client.d.mts +13 -0
- package/dist/plugins/device-authorization/client.mjs +17 -0
- package/dist/plugins/device-authorization/error-codes.mjs +18 -0
- package/dist/plugins/device-authorization/index.d.mts +550 -0
- package/dist/plugins/device-authorization/index.mjs +79 -0
- package/dist/plugins/device-authorization/routes.d.mts +96 -0
- package/dist/plugins/device-authorization/routes.mjs +734 -0
- package/dist/plugins/device-authorization/schema.d.mts +15 -0
- package/dist/plugins/device-authorization/schema.mjs +62 -0
- package/dist/plugins/email-otp/client.d.mts +17 -0
- package/dist/plugins/email-otp/client.mjs +16 -0
- package/dist/plugins/email-otp/error-codes.d.mts +5 -0
- package/dist/plugins/email-otp/error-codes.mjs +8 -0
- package/dist/plugins/email-otp/index.d.mts +542 -0
- package/dist/plugins/email-otp/index.mjs +144 -0
- package/dist/plugins/email-otp/otp-token.mjs +66 -0
- package/dist/plugins/email-otp/routes.mjs +774 -0
- package/dist/plugins/email-otp/types.d.mts +105 -0
- package/dist/plugins/email-otp/utils.mjs +16 -0
- package/dist/plugins/generic-oauth/error-codes.mjs +8 -0
- package/dist/plugins/generic-oauth/index.d.mts +57 -0
- package/dist/plugins/generic-oauth/index.mjs +459 -0
- package/dist/plugins/generic-oauth/providers/auth0.d.mts +32 -0
- package/dist/plugins/generic-oauth/providers/auth0.mjs +48 -0
- package/dist/plugins/generic-oauth/providers/gumroad.d.mts +27 -0
- package/dist/plugins/generic-oauth/providers/gumroad.mjs +61 -0
- package/dist/plugins/generic-oauth/providers/hubspot.d.mts +32 -0
- package/dist/plugins/generic-oauth/providers/hubspot.mjs +65 -0
- package/dist/plugins/generic-oauth/providers/index.d.mts +11 -0
- package/dist/plugins/generic-oauth/providers/keycloak.d.mts +32 -0
- package/dist/plugins/generic-oauth/providers/keycloak.mjs +46 -0
- package/dist/plugins/generic-oauth/providers/line.d.mts +50 -0
- package/dist/plugins/generic-oauth/providers/line.mjs +92 -0
- package/dist/plugins/generic-oauth/providers/microsoft-entra-id.d.mts +35 -0
- package/dist/plugins/generic-oauth/providers/microsoft-entra-id.mjs +104 -0
- package/dist/plugins/generic-oauth/providers/okta.d.mts +32 -0
- package/dist/plugins/generic-oauth/providers/okta.mjs +47 -0
- package/dist/plugins/generic-oauth/providers/patreon.d.mts +25 -0
- package/dist/plugins/generic-oauth/providers/patreon.mjs +60 -0
- package/dist/plugins/generic-oauth/providers/slack.d.mts +25 -0
- package/dist/plugins/generic-oauth/providers/slack.mjs +65 -0
- package/dist/plugins/generic-oauth/providers/token-endpoint-audience.mjs +15 -0
- package/dist/plugins/generic-oauth/providers/yandex.d.mts +25 -0
- package/dist/plugins/generic-oauth/providers/yandex.mjs +66 -0
- package/dist/plugins/generic-oauth/types.d.mts +328 -0
- package/dist/plugins/haveibeenpwned/index.d.mts +57 -0
- package/dist/plugins/haveibeenpwned/index.mjs +80 -0
- package/dist/plugins/index.d.mts +76 -0
- package/dist/plugins/index.mjs +53 -0
- package/dist/plugins/jwt/adapter.mjs +78 -0
- package/dist/plugins/jwt/client.d.mts +38 -0
- package/dist/plugins/jwt/client.mjs +18 -0
- package/dist/plugins/jwt/cookie-cache.mjs +71 -0
- package/dist/plugins/jwt/index.d.mts +241 -0
- package/dist/plugins/jwt/index.mjs +213 -0
- package/dist/plugins/jwt/schema.d.mts +30 -0
- package/dist/plugins/jwt/schema.mjs +28 -0
- package/dist/plugins/jwt/sign.d.mts +127 -0
- package/dist/plugins/jwt/sign.mjs +134 -0
- package/dist/plugins/jwt/types.d.mts +255 -0
- package/dist/plugins/jwt/utils.d.mts +36 -0
- package/dist/plugins/jwt/utils.mjs +63 -0
- package/dist/plugins/jwt/verify.d.mts +7 -0
- package/dist/plugins/jwt/verify.mjs +50 -0
- package/dist/plugins/last-login-method/client.d.mts +45 -0
- package/dist/plugins/last-login-method/client.mjs +47 -0
- package/dist/plugins/last-login-method/index.d.mts +121 -0
- package/dist/plugins/last-login-method/index.mjs +98 -0
- package/dist/plugins/magic-link/client.d.mts +6 -0
- package/dist/plugins/magic-link/client.mjs +10 -0
- package/dist/plugins/magic-link/index.d.mts +208 -0
- package/dist/plugins/magic-link/index.mjs +223 -0
- package/dist/plugins/magic-link/utils.mjs +8 -0
- package/dist/plugins/multi-session/client.d.mts +15 -0
- package/dist/plugins/multi-session/client.mjs +18 -0
- package/dist/plugins/multi-session/error-codes.d.mts +3 -0
- package/dist/plugins/multi-session/error-codes.mjs +4 -0
- package/dist/plugins/multi-session/index.d.mts +206 -0
- package/dist/plugins/multi-session/index.mjs +216 -0
- package/dist/plugins/oauth-popup/client.d.mts +74 -0
- package/dist/plugins/oauth-popup/client.mjs +204 -0
- package/dist/plugins/oauth-popup/constants.d.mts +8 -0
- package/dist/plugins/oauth-popup/constants.mjs +10 -0
- package/dist/plugins/oauth-popup/error-codes.d.mts +6 -0
- package/dist/plugins/oauth-popup/error-codes.mjs +9 -0
- package/dist/plugins/oauth-popup/index.d.mts +61 -0
- package/dist/plugins/oauth-popup/index.mjs +232 -0
- package/dist/plugins/oauth-popup/types.d.mts +26 -0
- package/dist/plugins/oauth-proxy/index.d.mts +123 -0
- package/dist/plugins/oauth-proxy/index.mjs +397 -0
- package/dist/plugins/oauth-proxy/utils.mjs +54 -0
- package/dist/plugins/one-tap/client.d.mts +187 -0
- package/dist/plugins/one-tap/client.mjs +208 -0
- package/dist/plugins/one-tap/index.d.mts +117 -0
- package/dist/plugins/one-tap/index.mjs +146 -0
- package/dist/plugins/one-time-token/client.d.mts +7 -0
- package/dist/plugins/one-time-token/client.mjs +10 -0
- package/dist/plugins/one-time-token/index.d.mts +128 -0
- package/dist/plugins/one-time-token/index.mjs +106 -0
- package/dist/plugins/one-time-token/utils.mjs +8 -0
- package/dist/plugins/open-api/generator.d.mts +124 -0
- package/dist/plugins/open-api/generator.mjs +557 -0
- package/dist/plugins/open-api/index.d.mts +93 -0
- package/dist/plugins/open-api/index.mjs +64 -0
- package/dist/plugins/open-api/logo.mjs +12 -0
- package/dist/plugins/organization/access/index.d.mts +2 -0
- package/dist/plugins/organization/access/index.mjs +1 -0
- package/dist/plugins/organization/access/statement.d.mts +111 -0
- package/dist/plugins/organization/access/statement.mjs +76 -0
- package/dist/plugins/organization/adapter.d.mts +786 -0
- package/dist/plugins/organization/adapter.mjs +821 -0
- package/dist/plugins/organization/call.mjs +14 -0
- package/dist/plugins/organization/client.d.mts +375 -0
- package/dist/plugins/organization/client.mjs +108 -0
- package/dist/plugins/organization/error-codes.d.mts +62 -0
- package/dist/plugins/organization/error-codes.mjs +65 -0
- package/dist/plugins/organization/has-permission.d.mts +12 -0
- package/dist/plugins/organization/has-permission.mjs +72 -0
- package/dist/plugins/organization/index.d.mts +7 -0
- package/dist/plugins/organization/index.mjs +5 -0
- package/dist/plugins/organization/organization.d.mts +418 -0
- package/dist/plugins/organization/organization.mjs +888 -0
- package/dist/plugins/organization/permission.d.mts +12 -0
- package/dist/plugins/organization/permission.mjs +13 -0
- package/dist/plugins/organization/roles.d.mts +6 -0
- package/dist/plugins/organization/roles.mjs +25 -0
- package/dist/plugins/organization/routes/crud-access-control.d.mts +509 -0
- package/dist/plugins/organization/routes/crud-access-control.mjs +674 -0
- package/dist/plugins/organization/routes/crud-invites.d.mts +1173 -0
- package/dist/plugins/organization/routes/crud-invites.mjs +619 -0
- package/dist/plugins/organization/routes/crud-members.d.mts +1010 -0
- package/dist/plugins/organization/routes/crud-members.mjs +515 -0
- package/dist/plugins/organization/routes/crud-org.d.mts +914 -0
- package/dist/plugins/organization/routes/crud-org.mjs +465 -0
- package/dist/plugins/organization/routes/crud-team.d.mts +1235 -0
- package/dist/plugins/organization/routes/crud-team.mjs +767 -0
- package/dist/plugins/organization/schema.d.mts +388 -0
- package/dist/plugins/organization/schema.mjs +64 -0
- package/dist/plugins/organization/types.d.mts +688 -0
- package/dist/plugins/phone-number/client.d.mts +29 -0
- package/dist/plugins/phone-number/client.mjs +18 -0
- package/dist/plugins/phone-number/error-codes.d.mts +16 -0
- package/dist/plugins/phone-number/error-codes.mjs +19 -0
- package/dist/plugins/phone-number/index.d.mts +376 -0
- package/dist/plugins/phone-number/index.mjs +72 -0
- package/dist/plugins/phone-number/routes.mjs +612 -0
- package/dist/plugins/phone-number/schema.d.mts +19 -0
- package/dist/plugins/phone-number/schema.mjs +17 -0
- package/dist/plugins/phone-number/types.d.mts +119 -0
- package/dist/plugins/siwe/client.d.mts +10 -0
- package/dist/plugins/siwe/client.mjs +14 -0
- package/dist/plugins/siwe/index.d.mts +58 -0
- package/dist/plugins/siwe/index.mjs +288 -0
- package/dist/plugins/siwe/parse-message.mjs +57 -0
- package/dist/plugins/siwe/schema.d.mts +32 -0
- package/dist/plugins/siwe/schema.mjs +29 -0
- package/dist/plugins/siwe/types.d.mts +41 -0
- package/dist/plugins/test-utils/auth-helpers.mjs +34 -0
- package/dist/plugins/test-utils/cookie-builder.mjs +54 -0
- package/dist/plugins/test-utils/db-helpers.mjs +64 -0
- package/dist/plugins/test-utils/factories.mjs +37 -0
- package/dist/plugins/test-utils/index.d.mts +69 -0
- package/dist/plugins/test-utils/index.mjs +96 -0
- package/dist/plugins/test-utils/otp-sink.mjs +20 -0
- package/dist/plugins/test-utils/types.d.mts +49 -0
- package/dist/plugins/two-factor/backup-codes/index.d.mts +286 -0
- package/dist/plugins/two-factor/backup-codes/index.mjs +354 -0
- package/dist/plugins/two-factor/claim.d.mts +86 -0
- package/dist/plugins/two-factor/claim.mjs +171 -0
- package/dist/plugins/two-factor/client.d.mts +76 -0
- package/dist/plugins/two-factor/client.mjs +40 -0
- package/dist/plugins/two-factor/constant.d.mts +7 -0
- package/dist/plugins/two-factor/constant.mjs +12 -0
- package/dist/plugins/two-factor/error-code.d.mts +20 -0
- package/dist/plugins/two-factor/error-code.mjs +23 -0
- package/dist/plugins/two-factor/index.d.mts +746 -0
- package/dist/plugins/two-factor/index.mjs +493 -0
- package/dist/plugins/two-factor/otp/index.d.mts +211 -0
- package/dist/plugins/two-factor/otp/index.mjs +262 -0
- package/dist/plugins/two-factor/passkey.mjs +47 -0
- package/dist/plugins/two-factor/schema.d.mts +66 -0
- package/dist/plugins/two-factor/schema.mjs +66 -0
- package/dist/plugins/two-factor/totp/index.d.mts +214 -0
- package/dist/plugins/two-factor/totp/index.mjs +295 -0
- package/dist/plugins/two-factor/types.d.mts +112 -0
- package/dist/plugins/two-factor/utils.mjs +8 -0
- package/dist/plugins/two-factor/verify-two-factor.d.mts +121 -0
- package/dist/plugins/two-factor/verify-two-factor.mjs +314 -0
- package/dist/plugins/username/client.d.mts +34 -0
- package/dist/plugins/username/client.mjs +16 -0
- package/dist/plugins/username/error-codes.d.mts +11 -0
- package/dist/plugins/username/error-codes.mjs +14 -0
- package/dist/plugins/username/index.d.mts +319 -0
- package/dist/plugins/username/index.mjs +304 -0
- package/dist/plugins/username/schema.d.mts +45 -0
- package/dist/plugins/username/schema.mjs +24 -0
- package/dist/social-providers/index.d.mts +1 -0
- package/dist/social-providers/index.mjs +2 -0
- package/dist/state.d.mts +48 -0
- package/dist/state.mjs +153 -0
- package/dist/test-utils/headers.d.mts +5 -0
- package/dist/test-utils/headers.mjs +16 -0
- package/dist/test-utils/http-test-instance.d.mts +420 -0
- package/dist/test-utils/http-test-instance.mjs +106 -0
- package/dist/test-utils/index.d.mts +4 -0
- package/dist/test-utils/index.mjs +4 -0
- package/dist/test-utils/test-instance.d.mts +55 -0
- package/dist/test-utils/test-instance.mjs +252 -0
- package/dist/types/adapter.d.mts +2 -0
- package/dist/types/api.d.mts +24 -0
- package/dist/types/auth.d.mts +28 -0
- package/dist/types/helper.d.mts +23 -0
- package/dist/types/index.d.mts +10 -0
- package/dist/types/index.mjs +1 -0
- package/dist/types/models.d.mts +7 -0
- package/dist/types/plugins.d.mts +16 -0
- package/dist/utils/constants.mjs +3 -0
- package/dist/utils/date.mjs +5 -0
- package/dist/utils/hashing.mjs +17 -0
- package/dist/utils/hide-metadata.d.mts +2 -0
- package/dist/utils/hide-metadata.mjs +1 -0
- package/dist/utils/index.d.mts +5 -0
- package/dist/utils/is-api-error.d.mts +2 -0
- package/dist/utils/is-api-error.mjs +1 -0
- package/dist/utils/is-atom.mjs +5 -0
- package/dist/utils/is-promise.mjs +5 -0
- package/dist/utils/middleware-response.mjs +9 -0
- package/dist/utils/password.mjs +90 -0
- package/dist/utils/plugin-helper.mjs +13 -0
- package/dist/utils/request.mjs +22 -0
- package/dist/utils/shim.mjs +21 -0
- package/dist/utils/time.d.mts +46 -0
- package/dist/utils/time.mjs +97 -0
- package/dist/utils/url.d.mts +74 -0
- package/dist/utils/url.mjs +237 -0
- package/dist/utils/validate-user-info.mjs +43 -0
- package/dist/utils/wildcard.mjs +107 -0
- package/dist/version.mjs +4 -0
- package/package.json +601 -3
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { GenericEndpointContext } from "@entro314labs/entro-auth-core";
|
|
2
|
+
export interface EmailOTPOptions {
|
|
3
|
+
/**
|
|
4
|
+
* Function to send email verification.
|
|
5
|
+
*
|
|
6
|
+
* It is recommended to not await the email sending to avoid timing attacks.
|
|
7
|
+
* On serverless platforms, use `waitUntil` or similar to ensure the email is sent.
|
|
8
|
+
*/
|
|
9
|
+
sendVerificationOTP: (data: {
|
|
10
|
+
email: string;
|
|
11
|
+
otp: string;
|
|
12
|
+
type: "sign-in" | "email-verification" | "forget-password" | "change-email";
|
|
13
|
+
}, ctx?: GenericEndpointContext | undefined) => Promise<void>;
|
|
14
|
+
/**
|
|
15
|
+
* Length of the OTP
|
|
16
|
+
*
|
|
17
|
+
* @default 6
|
|
18
|
+
*/
|
|
19
|
+
otpLength?: number | undefined;
|
|
20
|
+
/**
|
|
21
|
+
* Expiry time of the OTP in seconds
|
|
22
|
+
*
|
|
23
|
+
* @default 300 (5 minutes)
|
|
24
|
+
*/
|
|
25
|
+
expiresIn?: number | undefined;
|
|
26
|
+
/**
|
|
27
|
+
* Custom function to generate otp
|
|
28
|
+
*/
|
|
29
|
+
generateOTP?: (data: {
|
|
30
|
+
email: string;
|
|
31
|
+
type: "sign-in" | "email-verification" | "forget-password" | "change-email";
|
|
32
|
+
}, ctx?: GenericEndpointContext) => string | undefined;
|
|
33
|
+
/**
|
|
34
|
+
* Send email verification on sign-up
|
|
35
|
+
*
|
|
36
|
+
* @Default false
|
|
37
|
+
*/
|
|
38
|
+
sendVerificationOnSignUp?: boolean | undefined;
|
|
39
|
+
/**
|
|
40
|
+
* A boolean value that determines whether to prevent
|
|
41
|
+
* automatic sign-up when the user is not registered.
|
|
42
|
+
*
|
|
43
|
+
* @Default false
|
|
44
|
+
*/
|
|
45
|
+
disableSignUp?: boolean | undefined;
|
|
46
|
+
/**
|
|
47
|
+
* Allowed attempts for the OTP code
|
|
48
|
+
* @default 3
|
|
49
|
+
*/
|
|
50
|
+
allowedAttempts?: number | undefined;
|
|
51
|
+
/**
|
|
52
|
+
* Store the OTP in your database in a secure way
|
|
53
|
+
* Note: This will not affect the OTP sent to the user, it will only affect the OTP stored in your database
|
|
54
|
+
*
|
|
55
|
+
* @default "plain"
|
|
56
|
+
*/
|
|
57
|
+
storeOTP?: ("hashed" | "plain" | "encrypted" | {
|
|
58
|
+
hash: (otp: string) => Promise<string>;
|
|
59
|
+
} | {
|
|
60
|
+
encrypt: (otp: string) => Promise<string>;
|
|
61
|
+
decrypt: (otp: string) => Promise<string>;
|
|
62
|
+
}) | undefined;
|
|
63
|
+
/**
|
|
64
|
+
* Strategy for handling OTP when the user requests a new OTP
|
|
65
|
+
* while an existing one is still valid.
|
|
66
|
+
*
|
|
67
|
+
* - `"rotate"`: Always generates a new OTP (default behavior).
|
|
68
|
+
* - `"reuse"`: Resends the same OTP and extends its expiry.
|
|
69
|
+
* Only works when the OTP is recoverable (plain, encrypted, or custom encrypt/decrypt).
|
|
70
|
+
* Falls back to `"rotate"` when OTP is hashed.
|
|
71
|
+
*
|
|
72
|
+
* @default "rotate"
|
|
73
|
+
*/
|
|
74
|
+
resendStrategy?: "rotate" | "reuse" | undefined;
|
|
75
|
+
/**
|
|
76
|
+
* Change email configuration for the change email with OTP flow
|
|
77
|
+
*
|
|
78
|
+
* @default {
|
|
79
|
+
* enabled: false,
|
|
80
|
+
* verifyCurrentEmail: false,
|
|
81
|
+
* }
|
|
82
|
+
*/
|
|
83
|
+
changeEmail?: {
|
|
84
|
+
enabled?: boolean;
|
|
85
|
+
verifyCurrentEmail?: boolean;
|
|
86
|
+
};
|
|
87
|
+
/**
|
|
88
|
+
* Override the default email verification to use email otp instead
|
|
89
|
+
*
|
|
90
|
+
* @default false
|
|
91
|
+
*/
|
|
92
|
+
overrideDefaultEmailVerification?: boolean | undefined;
|
|
93
|
+
/**
|
|
94
|
+
* Rate limit configuration
|
|
95
|
+
*
|
|
96
|
+
* @default {
|
|
97
|
+
* window: 60,
|
|
98
|
+
* max: 3,
|
|
99
|
+
* }
|
|
100
|
+
*/
|
|
101
|
+
rateLimit?: {
|
|
102
|
+
window: number;
|
|
103
|
+
max: number;
|
|
104
|
+
};
|
|
105
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { base64Url } from "@better-auth/utils/base64";
|
|
2
|
+
import { createHash } from "@better-auth/utils/hash";
|
|
3
|
+
// src/plugins/email-otp/utils.ts
|
|
4
|
+
function toOTPIdentifier(type, email) {
|
|
5
|
+
return `${type}-otp-${email}`;
|
|
6
|
+
}
|
|
7
|
+
const defaultKeyHasher = async (otp) => {
|
|
8
|
+
const hash = await createHash("SHA-256").digest(new TextEncoder().encode(otp));
|
|
9
|
+
return base64Url.encode(new Uint8Array(hash), { padding: false });
|
|
10
|
+
};
|
|
11
|
+
function splitAtLastColon(input) {
|
|
12
|
+
const idx = input.lastIndexOf(":");
|
|
13
|
+
if (idx === -1) return [input, ""];
|
|
14
|
+
return [input.slice(0, idx), input.slice(idx + 1)];
|
|
15
|
+
}
|
|
16
|
+
export { defaultKeyHasher, splitAtLastColon, toOTPIdentifier };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { defineErrorCodes } from "@entro314labs/entro-auth-core/utils/error-codes";
|
|
2
|
+
// src/plugins/generic-oauth/error-codes.ts
|
|
3
|
+
const GENERIC_OAUTH_ERROR_CODES = defineErrorCodes({
|
|
4
|
+
INVALID_OAUTH_CONFIGURATION: "Invalid OAuth configuration",
|
|
5
|
+
TOKEN_URL_NOT_FOUND: "Invalid OAuth configuration. Token URL not found.",
|
|
6
|
+
PUSHED_AUTHORIZATION_REQUEST_FAILED: "The pushed authorization request failed"
|
|
7
|
+
});
|
|
8
|
+
export { GENERIC_OAUTH_ERROR_CODES };
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { GenericOAuthConfig, GenericOAuthOptions, GenericOAuthUserInfo } from "./types.mjs";
|
|
2
|
+
import { Auth0Options, auth0 } from "./providers/auth0.mjs";
|
|
3
|
+
import { GumroadOptions, gumroad } from "./providers/gumroad.mjs";
|
|
4
|
+
import { HubSpotOptions, hubspot } from "./providers/hubspot.mjs";
|
|
5
|
+
import { KeycloakOptions, keycloak } from "./providers/keycloak.mjs";
|
|
6
|
+
import { LineOptions, line } from "./providers/line.mjs";
|
|
7
|
+
import { MicrosoftEntraIdOptions, microsoftEntraId } from "./providers/microsoft-entra-id.mjs";
|
|
8
|
+
import { OktaOptions, okta } from "./providers/okta.mjs";
|
|
9
|
+
import { PatreonOptions, patreon } from "./providers/patreon.mjs";
|
|
10
|
+
import { SlackOptions, slack } from "./providers/slack.mjs";
|
|
11
|
+
import { YandexOptions, yandex } from "./providers/yandex.mjs";
|
|
12
|
+
import "./providers/index.mjs";
|
|
13
|
+
import { AuthContext } from "@entro314labs/entro-auth-core";
|
|
14
|
+
import { OAuthProvider } from "@entro314labs/entro-auth-core/oauth2";
|
|
15
|
+
declare module "@entro314labs/entro-auth-core" {
|
|
16
|
+
interface EntroAuthPluginRegistry<AuthOptions, Options> {
|
|
17
|
+
"generic-oauth": {
|
|
18
|
+
creator: typeof genericOAuth;
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Base type for OAuth provider options.
|
|
24
|
+
* Extracts common fields from GenericOAuthConfig for provider helpers.
|
|
25
|
+
*/
|
|
26
|
+
export type BaseOAuthProviderOptions = Pick<GenericOAuthConfig, "clientId" | "clientSecret" | "tokenEndpointAuth" | "scopes" | "redirectURI" | "endSessionEndpoint" | "postLogoutRedirectURI" | "disableProviderLogout" | "pkce" | "disableImplicitSignUp" | "disableSignUp" | "overrideUserInfo">;
|
|
27
|
+
type PendingDiscovery = Map<string, GenericOAuthConfig>;
|
|
28
|
+
/**
|
|
29
|
+
* A generic OAuth plugin that registers any OAuth/OIDC provider
|
|
30
|
+
* as a first-class social provider.
|
|
31
|
+
*
|
|
32
|
+
* Providers are used through the standard `signIn.social` and
|
|
33
|
+
* `callback/:id` core endpoints — no plugin-specific endpoints needed.
|
|
34
|
+
*/
|
|
35
|
+
export declare const genericOAuth: <const ID extends string>(options: GenericOAuthOptions<ID>) => {
|
|
36
|
+
id: "generic-oauth";
|
|
37
|
+
version: string;
|
|
38
|
+
init: (ctx: AuthContext) => Promise<{
|
|
39
|
+
context: {
|
|
40
|
+
socialProviders: OAuthProvider<object, Partial<import("@entro314labs/entro-auth-core/oauth2").ProviderOptions<object>>>[];
|
|
41
|
+
genericOAuthPendingDiscovery: PendingDiscovery;
|
|
42
|
+
};
|
|
43
|
+
}>;
|
|
44
|
+
hooks: {
|
|
45
|
+
before: {
|
|
46
|
+
matcher: (context: import("@entro314labs/entro-auth-core").HookEndpointContext) => boolean;
|
|
47
|
+
handler: import("better-call").Middleware<import("better-call").MiddlewareOptions, (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<void>>;
|
|
48
|
+
}[];
|
|
49
|
+
};
|
|
50
|
+
options: GenericOAuthOptions<ID>;
|
|
51
|
+
$ERROR_CODES: {
|
|
52
|
+
INVALID_OAUTH_CONFIGURATION: import("@entro314labs/entro-auth-core/utils/error-codes").RawError<"INVALID_OAUTH_CONFIGURATION">;
|
|
53
|
+
TOKEN_URL_NOT_FOUND: import("@entro314labs/entro-auth-core/utils/error-codes").RawError<"TOKEN_URL_NOT_FOUND">;
|
|
54
|
+
PUSHED_AUTHORIZATION_REQUEST_FAILED: import("@entro314labs/entro-auth-core/utils/error-codes").RawError<"PUSHED_AUTHORIZATION_REQUEST_FAILED">;
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
export { type Auth0Options, type GenericOAuthConfig, type GenericOAuthOptions, type GenericOAuthUserInfo, type GumroadOptions, type HubSpotOptions, type KeycloakOptions, type LineOptions, type MicrosoftEntraIdOptions, type OktaOptions, type PatreonOptions, type SlackOptions, type YandexOptions, auth0, gumroad, hubspot, keycloak, line, microsoftEntraId, okta, patreon, slack, yandex };
|
|
@@ -0,0 +1,459 @@
|
|
|
1
|
+
import { PACKAGE_VERSION } from "../../version.mjs";
|
|
2
|
+
import { GENERIC_OAUTH_ERROR_CODES } from "./error-codes.mjs";
|
|
3
|
+
import { auth0 } from "./providers/auth0.mjs";
|
|
4
|
+
import { gumroad } from "./providers/gumroad.mjs";
|
|
5
|
+
import { hubspot } from "./providers/hubspot.mjs";
|
|
6
|
+
import { keycloak } from "./providers/keycloak.mjs";
|
|
7
|
+
import { line } from "./providers/line.mjs";
|
|
8
|
+
import { microsoftEntraId } from "./providers/microsoft-entra-id.mjs";
|
|
9
|
+
import { okta } from "./providers/okta.mjs";
|
|
10
|
+
import { patreon } from "./providers/patreon.mjs";
|
|
11
|
+
import { slack } from "./providers/slack.mjs";
|
|
12
|
+
import { yandex } from "./providers/yandex.mjs";
|
|
13
|
+
import { APIError } from "@entro314labs/entro-auth-core/error";
|
|
14
|
+
import { applyDefaultAccessTokenExpiry, createAuthorizationURL, parseStringBoolean, pushAuthorizationRequest, refreshAccessToken, validateAuthorizationCode, verifyProviderIdToken } from "@entro314labs/entro-auth-core/oauth2";
|
|
15
|
+
import { createAuthMiddleware } from "@entro314labs/entro-auth-core/api";
|
|
16
|
+
import { createRemoteJWKSet, decodeJwt } from "jose";
|
|
17
|
+
import { betterFetch } from "@better-fetch/fetch";
|
|
18
|
+
import { createDpopFetch, deriveDpopKeyJkt } from "@entro314labs/entro-auth-core/oauth2/dpop-client";
|
|
19
|
+
// src/plugins/generic-oauth/index.ts
|
|
20
|
+
function isSecretlessTokenEndpointAuth(tokenEndpointAuth) {
|
|
21
|
+
return tokenEndpointAuth?.method === "private_key_jwt" || tokenEndpointAuth?.method === "none";
|
|
22
|
+
}
|
|
23
|
+
function isClientSecretTokenEndpointAuth(tokenEndpointAuth) {
|
|
24
|
+
return tokenEndpointAuth?.method === "client_secret_basic" || tokenEndpointAuth?.method === "client_secret_post";
|
|
25
|
+
}
|
|
26
|
+
const WELL_KNOWN_DOCUMENTS = ["openid-configuration", "oauth-authorization-server"];
|
|
27
|
+
/**
|
|
28
|
+
* The issuer identifiers `discoveryUrl` can be built from, or `undefined` when
|
|
29
|
+
* it is not a well-known URL.
|
|
30
|
+
*
|
|
31
|
+
* OpenID Connect Discovery 1.0 §4 appends the well-known path to the issuer,
|
|
32
|
+
* and RFC 8414 §3.1 inserts it between the host and the issuer's path. Both
|
|
33
|
+
* remove a terminating `/` from the issuer first.
|
|
34
|
+
*/
|
|
35
|
+
function issuersOfDiscoveryUrl(discoveryUrl) {
|
|
36
|
+
const { origin, pathname } = new URL(discoveryUrl);
|
|
37
|
+
const issuers = [];
|
|
38
|
+
const add = (path) => issuers.push(`${origin}${path.endsWith("/") ? path.slice(0, -1) : path}`);
|
|
39
|
+
for (const document of WELL_KNOWN_DOCUMENTS) {
|
|
40
|
+
const wellKnown = `/.well-known/${document}`;
|
|
41
|
+
if (pathname.endsWith(wellKnown)) add(pathname.slice(0, -wellKnown.length));
|
|
42
|
+
if (pathname.startsWith(`${wellKnown}/`)) add(pathname.slice(wellKnown.length));
|
|
43
|
+
}
|
|
44
|
+
return issuers.length > 0 ? issuers : void 0;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Returns why a discovered issuer must not be used, or `undefined` when it can.
|
|
48
|
+
* RFC 8414 §3.3: a document published for another issuer must not be used.
|
|
49
|
+
*/
|
|
50
|
+
function checkDiscoveredIssuer(config, discoveryUrl, discoveredIssuer) {
|
|
51
|
+
if (discoveredIssuer === void 0) return "the discovery document has no issuer, so it cannot be checked. Configure authorizationUrl, tokenUrl, and userInfoUrl instead of discoveryUrl.";
|
|
52
|
+
if (config.issuer) return discoveredIssuer === config.issuer ? void 0 : `discovery issuer "${discoveredIssuer}" does not match the configured issuer "${config.issuer}".`;
|
|
53
|
+
const expected = issuersOfDiscoveryUrl(discoveryUrl);
|
|
54
|
+
if (!expected) return `discoveryUrl "${discoveryUrl}" is not a well-known URL, so its issuer cannot be checked. Set issuer to the issuer identifier the provider documents.`;
|
|
55
|
+
return expected.some((issuer) => discoveredIssuer === issuer || discoveredIssuer === `${issuer}/`) ? void 0 : `discovery issuer "${discoveredIssuer}" is not the issuer of discoveryUrl "${discoveryUrl}". If the provider publishes its document under another name for the same issuer, set issuer to the issuer identifier the provider documents.`;
|
|
56
|
+
}
|
|
57
|
+
/** A request waits on a discovery retry, so bound it (the SSO plugin uses 10s too). */
|
|
58
|
+
const DISCOVERY_RETRY_TIMEOUT_MS = 1e4;
|
|
59
|
+
const MAX_DISCOVERY_REDIRECTS = 5;
|
|
60
|
+
/**
|
|
61
|
+
* Providers skipped because startup discovery failed. Init stores them on each auth
|
|
62
|
+
* instance's context, so one plugin object can serve several instances. It is a context
|
|
63
|
+
* field rather than a WeakMap because requests see copies of the context, and a later
|
|
64
|
+
* plugin may replace `socialProviders`.
|
|
65
|
+
*/
|
|
66
|
+
const getPendingDiscovery = (ctx) => ctx.genericOAuthPendingDiscovery;
|
|
67
|
+
/**
|
|
68
|
+
* Reads ID token claims, or null for a token that is not a JWS, so a
|
|
69
|
+
* malformed token fails the sign-in instead of throwing.
|
|
70
|
+
*/
|
|
71
|
+
const readIdTokenClaims = (idToken) => {
|
|
72
|
+
try {
|
|
73
|
+
return decodeJwt(idToken);
|
|
74
|
+
} catch {
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
async function fetchDiscovery(url, headers, timeout) {
|
|
79
|
+
const signal = timeout ? AbortSignal.timeout(timeout) : void 0;
|
|
80
|
+
let target = url;
|
|
81
|
+
for (let hop = 0;; hop++) {
|
|
82
|
+
const redirect = {};
|
|
83
|
+
const result = await betterFetch(target, {
|
|
84
|
+
method: "GET",
|
|
85
|
+
headers,
|
|
86
|
+
redirect: headers ? "manual" : void 0,
|
|
87
|
+
signal,
|
|
88
|
+
onError: ({ response }) => {
|
|
89
|
+
if (response.status >= 300 && response.status < 400) redirect.location = response.headers.get("location");
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
if (headers && redirect.location) {
|
|
93
|
+
const next = new URL(redirect.location, target);
|
|
94
|
+
if (next.origin !== new URL(url).origin) throw new Error(`discovery redirected to ${next.origin}; with discoveryHeaders set, only same-origin redirects are followed. Set discoveryUrl to the final URL.`);
|
|
95
|
+
if (hop >= MAX_DISCOVERY_REDIRECTS) throw new Error(`discovery redirected more than ${MAX_DISCOVERY_REDIRECTS} times. Set discoveryUrl to the final URL.`);
|
|
96
|
+
target = next.href;
|
|
97
|
+
continue;
|
|
98
|
+
}
|
|
99
|
+
if (headers && result.error?.status === 0) throw new Error("discovery redirected; with discoveryHeaders set, set discoveryUrl to the final URL.");
|
|
100
|
+
if (result.error || !result.data) return null;
|
|
101
|
+
if (result.data.issuer) try {
|
|
102
|
+
new URL(result.data.issuer);
|
|
103
|
+
} catch {
|
|
104
|
+
return null;
|
|
105
|
+
}
|
|
106
|
+
return result.data;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
async function fetchUserInfo(tokens, userInfoUrl, idTokenClaims, dpopFetch) {
|
|
110
|
+
if (tokens.idToken) {
|
|
111
|
+
const decoded = idTokenClaims ?? readIdTokenClaims(tokens.idToken);
|
|
112
|
+
if (decoded?.sub && decoded?.email) return {
|
|
113
|
+
id: decoded.sub,
|
|
114
|
+
emailVerified: parseStringBoolean(decoded.email_verified) ?? false,
|
|
115
|
+
image: decoded.picture,
|
|
116
|
+
...decoded
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
if (!userInfoUrl || !tokens.accessToken) return null;
|
|
120
|
+
const requestUserInfo = (scheme) => betterFetch(userInfoUrl, {
|
|
121
|
+
method: "GET",
|
|
122
|
+
headers: { Authorization: `${scheme} ${tokens.accessToken}` },
|
|
123
|
+
customFetchImpl: scheme === "DPoP" ? dpopFetch : void 0
|
|
124
|
+
});
|
|
125
|
+
const tokenType = tokens.tokenType?.toLowerCase();
|
|
126
|
+
const tryDpop = !!dpopFetch && (!tokenType || tokenType === "dpop");
|
|
127
|
+
let userInfo = await requestUserInfo(tryDpop ? "DPoP" : "Bearer");
|
|
128
|
+
if (tryDpop && !tokenType && userInfo.error?.status === 401) userInfo = await requestUserInfo("Bearer");
|
|
129
|
+
if (userInfo.error || !userInfo.data) return null;
|
|
130
|
+
return {
|
|
131
|
+
...userInfo.data,
|
|
132
|
+
email: userInfo.data.email,
|
|
133
|
+
emailVerified: parseStringBoolean(userInfo.data.email_verified) ?? false,
|
|
134
|
+
image: userInfo.data.picture,
|
|
135
|
+
name: userInfo.data.name
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* A generic OAuth plugin that registers any OAuth/OIDC provider
|
|
140
|
+
* as a first-class social provider.
|
|
141
|
+
*
|
|
142
|
+
* Providers are used through the standard `signIn.social` and
|
|
143
|
+
* `callback/:id` core endpoints — no plugin-specific endpoints needed.
|
|
144
|
+
*/
|
|
145
|
+
const genericOAuth = (options) => {
|
|
146
|
+
const seenIds = /* @__PURE__ */ new Set();
|
|
147
|
+
const nonUniqueIds = /* @__PURE__ */ new Set();
|
|
148
|
+
for (const config of options.config) {
|
|
149
|
+
const id = config.providerId;
|
|
150
|
+
if (seenIds.has(id)) nonUniqueIds.add(id);
|
|
151
|
+
seenIds.add(id);
|
|
152
|
+
}
|
|
153
|
+
if (nonUniqueIds.size > 0) console.warn(`Duplicate provider IDs found: ${Array.from(nonUniqueIds).join(", ")}`);
|
|
154
|
+
const dpopClients = /* @__PURE__ */ new WeakMap();
|
|
155
|
+
const getDpopClient = (keyPair) => {
|
|
156
|
+
let client = dpopClients.get(keyPair);
|
|
157
|
+
if (!client) {
|
|
158
|
+
client = deriveDpopKeyJkt(keyPair).then((jkt) => ({
|
|
159
|
+
fetch: createDpopFetch({ keyPair }),
|
|
160
|
+
jkt
|
|
161
|
+
}));
|
|
162
|
+
dpopClients.set(keyPair, client);
|
|
163
|
+
}
|
|
164
|
+
return client;
|
|
165
|
+
};
|
|
166
|
+
const buildProviders = async (configs, ctx, discoveryTimeout) => {
|
|
167
|
+
const genericProviders = [];
|
|
168
|
+
for (const c of configs) {
|
|
169
|
+
if (Object.keys(c.authorizationHeaders ?? {}).some((name) => name.toLowerCase() === "authorization")) throw new Error(`Provider "${c.providerId}": authorizationHeaders cannot set "Authorization". Use tokenEndpointAuth: { method: "custom", customizeRequest } instead.`);
|
|
170
|
+
let authorizationUrl = c.authorizationUrl;
|
|
171
|
+
let tokenUrl = c.tokenUrl;
|
|
172
|
+
let userInfoUrl = c.userInfoUrl;
|
|
173
|
+
let endSessionEndpoint = c.endSessionEndpoint;
|
|
174
|
+
let pushedAuthorizationRequestUrl = c.pushedAuthorizationRequestUrl;
|
|
175
|
+
let requiresPushedAuthorizationRequest = false;
|
|
176
|
+
let issuer;
|
|
177
|
+
let isOidc = false;
|
|
178
|
+
let idTokenConfig;
|
|
179
|
+
if (c.discoveryUrl) {
|
|
180
|
+
const discovered = await fetchDiscovery(c.discoveryUrl, c.discoveryHeaders, discoveryTimeout).catch((err) => {
|
|
181
|
+
ctx.logger.error(`Discovery fetch failed for "${c.providerId}": ${err}`);
|
|
182
|
+
return null;
|
|
183
|
+
});
|
|
184
|
+
const issuerError = discovered && checkDiscoveredIssuer(c, c.discoveryUrl, discovered.issuer);
|
|
185
|
+
if (issuerError) {
|
|
186
|
+
ctx.logger.error(`Provider "${c.providerId}": ${issuerError} Provider skipped.`);
|
|
187
|
+
continue;
|
|
188
|
+
}
|
|
189
|
+
if (discovered) {
|
|
190
|
+
authorizationUrl ??= discovered.authorization_endpoint;
|
|
191
|
+
tokenUrl ??= discovered.token_endpoint;
|
|
192
|
+
userInfoUrl ??= discovered.userinfo_endpoint;
|
|
193
|
+
endSessionEndpoint ??= discovered.end_session_endpoint;
|
|
194
|
+
pushedAuthorizationRequestUrl ??= discovered.pushed_authorization_request_endpoint;
|
|
195
|
+
requiresPushedAuthorizationRequest = discovered.require_pushed_authorization_requests === true;
|
|
196
|
+
issuer = discovered.issuer;
|
|
197
|
+
const signingAlgs = discovered.id_token_signing_alg_values_supported;
|
|
198
|
+
isOidc = Array.isArray(signingAlgs) && signingAlgs.length > 0;
|
|
199
|
+
if (discovered.jwks_uri && discovered.issuer) {
|
|
200
|
+
let jwksUrl;
|
|
201
|
+
try {
|
|
202
|
+
jwksUrl = new URL(discovered.jwks_uri, c.discoveryUrl);
|
|
203
|
+
} catch {
|
|
204
|
+
ctx.logger.error(`Provider "${c.providerId}": invalid jwks_uri "${discovered.jwks_uri}" in discovery document. Provider skipped.`);
|
|
205
|
+
continue;
|
|
206
|
+
}
|
|
207
|
+
const jwksHeaders = jwksUrl.origin === new URL(c.discoveryUrl).origin ? c.discoveryHeaders : void 0;
|
|
208
|
+
idTokenConfig = {
|
|
209
|
+
jwks: createRemoteJWKSet(jwksUrl, jwksHeaders && { headers: jwksHeaders }),
|
|
210
|
+
issuer: discovered.issuer,
|
|
211
|
+
audience: c.clientId,
|
|
212
|
+
algorithms: isOidc ? signingAlgs : void 0
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
if (!authorizationUrl || !tokenUrl && !c.getToken) {
|
|
217
|
+
ctx.logger.error(`Provider "${c.providerId}": discovery left no usable authorization endpoint or token exchange. Provider skipped.`);
|
|
218
|
+
continue;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
if (c.requireIdTokenVerification && !idTokenConfig) {
|
|
222
|
+
if (c.discoveryUrl) {
|
|
223
|
+
ctx.logger.error(`Provider "${c.providerId}": requires verified ID tokens, but discovery did not provide a usable issuer and jwks_uri. Provider skipped.`);
|
|
224
|
+
continue;
|
|
225
|
+
}
|
|
226
|
+
throw new Error(`Provider "${c.providerId}": requires verified ID tokens, but discovery did not provide a usable issuer and jwks_uri.`);
|
|
227
|
+
}
|
|
228
|
+
const pushedAuthorizationRequest = c.pushedAuthorizationRequest ?? "auto";
|
|
229
|
+
const usePushedAuthorizationRequest = pushedAuthorizationRequest === true || pushedAuthorizationRequest === "auto" && requiresPushedAuthorizationRequest;
|
|
230
|
+
if (usePushedAuthorizationRequest && !pushedAuthorizationRequestUrl) {
|
|
231
|
+
const reason = requiresPushedAuthorizationRequest ? "discovery requires pushed authorization requests but has no pushed_authorization_request_endpoint" : "pushedAuthorizationRequest is true but no pushed authorization request endpoint is configured. Set pushedAuthorizationRequestUrl or use a discoveryUrl that publishes pushed_authorization_request_endpoint";
|
|
232
|
+
if (c.discoveryUrl) {
|
|
233
|
+
ctx.logger.error(`Provider "${c.providerId}": ${reason}. Provider skipped.`);
|
|
234
|
+
continue;
|
|
235
|
+
}
|
|
236
|
+
throw new Error(`Provider "${c.providerId}": ${reason}.`);
|
|
237
|
+
}
|
|
238
|
+
if (pushedAuthorizationRequest === false && requiresPushedAuthorizationRequest) ctx.logger.warn(`Provider "${c.providerId}": discovery sets require_pushed_authorization_requests, but pushedAuthorizationRequest is false. The provider will likely reject sign-in requests.`);
|
|
239
|
+
const pushedAuthorizationRequestEndpoint = usePushedAuthorizationRequest ? pushedAuthorizationRequestUrl : void 0;
|
|
240
|
+
const { tokenEndpointAuth } = c;
|
|
241
|
+
const { fetch: dpopFetch, jkt: dpopJkt } = c.dpop ? await getDpopClient(c.dpop.keyPair) : {};
|
|
242
|
+
if (c.clientSecret && isSecretlessTokenEndpointAuth(tokenEndpointAuth)) throw new Error(`Provider "${c.providerId}": tokenEndpointAuth.method "${tokenEndpointAuth?.method}" cannot be combined with clientSecret`);
|
|
243
|
+
if (!c.clientSecret && isClientSecretTokenEndpointAuth(tokenEndpointAuth)) throw new Error(`Provider "${c.providerId}": tokenEndpointAuth.method "${tokenEndpointAuth?.method}" requires clientSecret`);
|
|
244
|
+
if (!c.clientSecret && !tokenEndpointAuth && c.authentication === "basic") throw new Error(`Provider "${c.providerId}": authentication "basic" requires clientSecret`);
|
|
245
|
+
const resolveUserInfo = async (tokens, idTokenClaims) => {
|
|
246
|
+
const raw = c.getUserInfo ? await c.getUserInfo(tokens) : await fetchUserInfo(tokens, userInfoUrl, idTokenClaims, dpopFetch);
|
|
247
|
+
if (!raw) return null;
|
|
248
|
+
const requiresSubjectMatch = !c.getUserInfo || raw.sub != null;
|
|
249
|
+
if (idTokenClaims?.sub !== void 0 && requiresSubjectMatch && String(raw.sub) !== idTokenClaims.sub) return null;
|
|
250
|
+
const mapped = c.mapProfileToUser ? await c.mapProfileToUser(raw) : {};
|
|
251
|
+
const user = {
|
|
252
|
+
email: raw.email,
|
|
253
|
+
emailVerified: parseStringBoolean(raw.emailVerified) ?? false,
|
|
254
|
+
image: raw.image,
|
|
255
|
+
name: raw.name,
|
|
256
|
+
...mapped
|
|
257
|
+
};
|
|
258
|
+
return {
|
|
259
|
+
user: {
|
|
260
|
+
...user,
|
|
261
|
+
image: user.image ?? void 0
|
|
262
|
+
},
|
|
263
|
+
data: raw
|
|
264
|
+
};
|
|
265
|
+
};
|
|
266
|
+
const accountSubject = c.accountSubject;
|
|
267
|
+
const provider = {
|
|
268
|
+
id: c.providerId,
|
|
269
|
+
name: c.name ?? c.providerId,
|
|
270
|
+
issuer,
|
|
271
|
+
accountSubject: ({ tokens, profile }) => {
|
|
272
|
+
const genericProfile = profile;
|
|
273
|
+
if (accountSubject) return accountSubject({
|
|
274
|
+
tokens,
|
|
275
|
+
profile: genericProfile
|
|
276
|
+
});
|
|
277
|
+
if (!isOidc) return genericProfile.id ?? "";
|
|
278
|
+
if (idTokenConfig && tokens.idToken) return readIdTokenClaims(tokens.idToken)?.sub ?? "";
|
|
279
|
+
return genericProfile.sub ?? "";
|
|
280
|
+
},
|
|
281
|
+
idToken: idTokenConfig,
|
|
282
|
+
requiresIdTokenNonce: idTokenConfig !== void 0 && c.disableIdTokenNonceBinding !== true,
|
|
283
|
+
allowIdpInitiated: c.allowIdpInitiated,
|
|
284
|
+
async createEndSessionURL(data) {
|
|
285
|
+
if (c.disableProviderLogout) return null;
|
|
286
|
+
if (!endSessionEndpoint) return null;
|
|
287
|
+
let url;
|
|
288
|
+
try {
|
|
289
|
+
url = new URL(endSessionEndpoint);
|
|
290
|
+
} catch {
|
|
291
|
+
return null;
|
|
292
|
+
}
|
|
293
|
+
if (data.idToken) url.searchParams.set("id_token_hint", data.idToken);
|
|
294
|
+
const configuredRedirectURI = data.postLogoutRedirectURI ?? c.postLogoutRedirectURI;
|
|
295
|
+
const postLogoutRedirectURI = configuredRedirectURI ? new URL(configuredRedirectURI, ctx.baseURL).toString() : void 0;
|
|
296
|
+
if (postLogoutRedirectURI) {
|
|
297
|
+
url.searchParams.set("post_logout_redirect_uri", postLogoutRedirectURI);
|
|
298
|
+
url.searchParams.set("client_id", c.clientId);
|
|
299
|
+
if (data.state) url.searchParams.set("state", data.state);
|
|
300
|
+
} else if (!data.idToken) url.searchParams.set("client_id", c.clientId);
|
|
301
|
+
return url;
|
|
302
|
+
},
|
|
303
|
+
async createAuthorizationURL(data) {
|
|
304
|
+
if (!authorizationUrl) throw APIError.from("BAD_REQUEST", GENERIC_OAUTH_ERROR_CODES.INVALID_OAUTH_CONFIGURATION);
|
|
305
|
+
const url = await createAuthorizationURL({
|
|
306
|
+
id: c.providerId,
|
|
307
|
+
options: {
|
|
308
|
+
clientId: c.clientId,
|
|
309
|
+
clientSecret: c.clientSecret,
|
|
310
|
+
redirectURI: c.redirectURI
|
|
311
|
+
},
|
|
312
|
+
authorizationEndpoint: authorizationUrl,
|
|
313
|
+
state: data.state,
|
|
314
|
+
codeVerifier: c.pkce ?? true ? data.codeVerifier : void 0,
|
|
315
|
+
scopes: (() => {
|
|
316
|
+
const merged = [...data.scopes ?? [], ...c.scopes ?? []];
|
|
317
|
+
if (isOidc && !merged.includes("openid")) merged.unshift("openid");
|
|
318
|
+
return merged;
|
|
319
|
+
})(),
|
|
320
|
+
redirectURI: data.redirectURI,
|
|
321
|
+
prompt: c.prompt,
|
|
322
|
+
accessType: c.accessType,
|
|
323
|
+
responseType: c.responseType,
|
|
324
|
+
responseMode: c.responseMode,
|
|
325
|
+
nonce: data.idTokenNonce,
|
|
326
|
+
additionalParams: {
|
|
327
|
+
...c.authorizationUrlParams ?? {},
|
|
328
|
+
...data.additionalParams ?? {},
|
|
329
|
+
...dpopJkt && { dpop_jkt: dpopJkt }
|
|
330
|
+
},
|
|
331
|
+
loginHint: data.loginHint
|
|
332
|
+
});
|
|
333
|
+
if (!pushedAuthorizationRequestEndpoint) return url;
|
|
334
|
+
try {
|
|
335
|
+
return await pushAuthorizationRequest({
|
|
336
|
+
authorizationURL: url,
|
|
337
|
+
authorizationEndpoint: authorizationUrl,
|
|
338
|
+
pushedAuthorizationRequestEndpoint,
|
|
339
|
+
options: {
|
|
340
|
+
clientId: c.clientId,
|
|
341
|
+
clientSecret: c.clientSecret
|
|
342
|
+
},
|
|
343
|
+
tokenEndpoint: tokenUrl,
|
|
344
|
+
issuer,
|
|
345
|
+
authentication: c.authentication,
|
|
346
|
+
tokenEndpointAuth,
|
|
347
|
+
headers: c.authorizationHeaders,
|
|
348
|
+
fetch: dpopFetch
|
|
349
|
+
});
|
|
350
|
+
} catch (error) {
|
|
351
|
+
ctx.logger.error(`Provider "${c.providerId}": pushed authorization request failed: ${error}`);
|
|
352
|
+
throw APIError.from("BAD_GATEWAY", GENERIC_OAUTH_ERROR_CODES.PUSHED_AUTHORIZATION_REQUEST_FAILED);
|
|
353
|
+
}
|
|
354
|
+
},
|
|
355
|
+
async validateAuthorizationCode(data) {
|
|
356
|
+
if (c.getToken) return applyDefaultAccessTokenExpiry(await c.getToken(data), c.accessTokenExpiresIn);
|
|
357
|
+
if (!tokenUrl) throw APIError.from("BAD_REQUEST", GENERIC_OAUTH_ERROR_CODES.TOKEN_URL_NOT_FOUND);
|
|
358
|
+
const tokens = await validateAuthorizationCode({
|
|
359
|
+
headers: c.authorizationHeaders,
|
|
360
|
+
code: data.code,
|
|
361
|
+
codeVerifier: c.pkce ?? true ? data.codeVerifier : void 0,
|
|
362
|
+
redirectURI: data.redirectURI,
|
|
363
|
+
options: {
|
|
364
|
+
clientId: c.clientId,
|
|
365
|
+
clientSecret: c.clientSecret,
|
|
366
|
+
redirectURI: c.redirectURI
|
|
367
|
+
},
|
|
368
|
+
tokenEndpoint: tokenUrl,
|
|
369
|
+
issuer,
|
|
370
|
+
authentication: c.authentication,
|
|
371
|
+
tokenEndpointAuth,
|
|
372
|
+
additionalParams: c.tokenUrlParams,
|
|
373
|
+
fetch: dpopFetch
|
|
374
|
+
});
|
|
375
|
+
return applyDefaultAccessTokenExpiry(tokens, c.accessTokenExpiresIn);
|
|
376
|
+
},
|
|
377
|
+
async getUserInfoFromIdToken(idToken) {
|
|
378
|
+
const claims = provider.idToken ? readIdTokenClaims(idToken) : void 0;
|
|
379
|
+
if (claims === null) return null;
|
|
380
|
+
return resolveUserInfo({ idToken }, claims);
|
|
381
|
+
},
|
|
382
|
+
async getUserInfo(tokens) {
|
|
383
|
+
const { expectedIdTokenNonce, ...oauthTokens } = tokens;
|
|
384
|
+
if (!oauthTokens.idToken || !provider.idToken) return resolveUserInfo(oauthTokens);
|
|
385
|
+
const claims = await verifyProviderIdToken(provider, oauthTokens.idToken, expectedIdTokenNonce) ? readIdTokenClaims(oauthTokens.idToken) : null;
|
|
386
|
+
if (!claims) {
|
|
387
|
+
ctx.logger.error(`Provider "${c.providerId}": id_token failed verification against the discovery JWKS or expected nonce`);
|
|
388
|
+
return null;
|
|
389
|
+
}
|
|
390
|
+
return resolveUserInfo(oauthTokens, claims);
|
|
391
|
+
},
|
|
392
|
+
async refreshAccessToken(refreshToken, refreshCtx) {
|
|
393
|
+
if (!tokenUrl) throw APIError.from("BAD_REQUEST", GENERIC_OAUTH_ERROR_CODES.TOKEN_URL_NOT_FOUND);
|
|
394
|
+
const resolvedRefreshParams = typeof c.refreshTokenParams === "function" ? await c.refreshTokenParams(refreshCtx) : c.refreshTokenParams;
|
|
395
|
+
const tokens = await refreshAccessToken({
|
|
396
|
+
refreshToken,
|
|
397
|
+
options: {
|
|
398
|
+
clientId: c.clientId,
|
|
399
|
+
clientSecret: c.clientSecret
|
|
400
|
+
},
|
|
401
|
+
authentication: c.authentication,
|
|
402
|
+
tokenEndpointAuth,
|
|
403
|
+
tokenEndpoint: tokenUrl,
|
|
404
|
+
issuer,
|
|
405
|
+
extraParams: resolvedRefreshParams,
|
|
406
|
+
headers: c.authorizationHeaders,
|
|
407
|
+
fetch: dpopFetch
|
|
408
|
+
});
|
|
409
|
+
return applyDefaultAccessTokenExpiry(tokens, c.accessTokenExpiresIn);
|
|
410
|
+
},
|
|
411
|
+
disableImplicitSignUp: c.disableImplicitSignUp,
|
|
412
|
+
disableSignUp: c.disableSignUp,
|
|
413
|
+
options: {
|
|
414
|
+
disableSignUp: c.disableSignUp,
|
|
415
|
+
overrideUserInfoOnSignIn: c.overrideUserInfo,
|
|
416
|
+
requireEmailVerification: c.requireEmailVerification
|
|
417
|
+
}
|
|
418
|
+
};
|
|
419
|
+
genericProviders.push(provider);
|
|
420
|
+
}
|
|
421
|
+
return genericProviders;
|
|
422
|
+
};
|
|
423
|
+
const retryDiscovery = async (ctx, providerId) => {
|
|
424
|
+
const pendingDiscovery = getPendingDiscovery(ctx);
|
|
425
|
+
const pending = pendingDiscovery?.get(providerId);
|
|
426
|
+
if (!pending) return;
|
|
427
|
+
const [provider] = await buildProviders([pending], ctx, DISCOVERY_RETRY_TIMEOUT_MS);
|
|
428
|
+
if (!provider || !pendingDiscovery?.delete(providerId)) return;
|
|
429
|
+
ctx.socialProviders.unshift(provider);
|
|
430
|
+
};
|
|
431
|
+
const requestedProviderId = (context) => {
|
|
432
|
+
const id = context.body?.provider ?? context.body?.providerId ?? context.query?.provider ?? context.params?.id;
|
|
433
|
+
return typeof id === "string" ? id : void 0;
|
|
434
|
+
};
|
|
435
|
+
return {
|
|
436
|
+
id: "generic-oauth",
|
|
437
|
+
version: PACKAGE_VERSION,
|
|
438
|
+
init: async (ctx) => {
|
|
439
|
+
const genericProviders = await buildProviders(options.config, ctx);
|
|
440
|
+
const built = new Set(genericProviders.map((p) => p.id));
|
|
441
|
+
const genericOAuthPendingDiscovery = new Map(options.config.filter((c) => !built.has(c.providerId)).map((c) => [c.providerId, c]));
|
|
442
|
+
const existingIds = new Set(ctx.socialProviders.map((p) => p.id));
|
|
443
|
+
for (const gp of genericProviders) if (existingIds.has(gp.id)) ctx.logger.warn(`Generic OAuth provider "${gp.id}" shadows a built-in social provider with the same ID`);
|
|
444
|
+
return { context: {
|
|
445
|
+
socialProviders: genericProviders.concat(ctx.socialProviders),
|
|
446
|
+
genericOAuthPendingDiscovery
|
|
447
|
+
} };
|
|
448
|
+
},
|
|
449
|
+
hooks: { before: [{
|
|
450
|
+
matcher: (context) => getPendingDiscovery(context.context)?.has(requestedProviderId(context) ?? "") === true,
|
|
451
|
+
handler: createAuthMiddleware(async (ctx) => {
|
|
452
|
+
await retryDiscovery(ctx.context, requestedProviderId(ctx) ?? "");
|
|
453
|
+
})
|
|
454
|
+
}] },
|
|
455
|
+
options,
|
|
456
|
+
$ERROR_CODES: GENERIC_OAUTH_ERROR_CODES
|
|
457
|
+
};
|
|
458
|
+
};
|
|
459
|
+
export { auth0, genericOAuth, gumroad, hubspot, keycloak, line, microsoftEntraId, okta, patreon, slack, yandex };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { GenericOAuthConfig } from "../types.mjs";
|
|
2
|
+
import { BaseOAuthProviderOptions } from "../index.mjs";
|
|
3
|
+
export interface Auth0Options extends BaseOAuthProviderOptions {
|
|
4
|
+
/**
|
|
5
|
+
* Auth0 domain (e.g., dev-xxx.eu.auth0.com)
|
|
6
|
+
* This will be used to construct the discovery URL.
|
|
7
|
+
*/
|
|
8
|
+
domain: string;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Auth0 OAuth provider helper
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* import { genericOAuth, auth0 } from "@entro314labs/entro-auth/plugins/generic-oauth";
|
|
16
|
+
*
|
|
17
|
+
* export const auth = entroAuth({
|
|
18
|
+
* plugins: [
|
|
19
|
+
* genericOAuth({
|
|
20
|
+
* config: [
|
|
21
|
+
* auth0({
|
|
22
|
+
* clientId: process.env.AUTH0_CLIENT_ID,
|
|
23
|
+
* clientSecret: process.env.AUTH0_CLIENT_SECRET,
|
|
24
|
+
* domain: process.env.AUTH0_DOMAIN,
|
|
25
|
+
* }),
|
|
26
|
+
* ],
|
|
27
|
+
* }),
|
|
28
|
+
* ],
|
|
29
|
+
* });
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export declare function auth0(options: Auth0Options): GenericOAuthConfig<"auth0">;
|