@hammadj/better-auth 1.5.0-beta.9
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 +33 -0
- package/dist/_virtual/rolldown_runtime.mjs +36 -0
- package/dist/adapters/drizzle-adapter/index.d.mts +1 -0
- package/dist/adapters/drizzle-adapter/index.mjs +3 -0
- package/dist/adapters/index.d.mts +23 -0
- package/dist/adapters/index.mjs +13 -0
- package/dist/adapters/index.mjs.map +1 -0
- package/dist/adapters/kysely-adapter/index.d.mts +1 -0
- package/dist/adapters/kysely-adapter/index.mjs +3 -0
- package/dist/adapters/memory-adapter/index.d.mts +1 -0
- package/dist/adapters/memory-adapter/index.mjs +3 -0
- package/dist/adapters/mongodb-adapter/index.d.mts +1 -0
- package/dist/adapters/mongodb-adapter/index.mjs +3 -0
- package/dist/adapters/prisma-adapter/index.d.mts +1 -0
- package/dist/adapters/prisma-adapter/index.mjs +3 -0
- package/dist/api/index.d.mts +40 -0
- package/dist/api/index.mjs +205 -0
- package/dist/api/index.mjs.map +1 -0
- package/dist/api/middlewares/index.d.mts +1 -0
- package/dist/api/middlewares/index.mjs +3 -0
- package/dist/api/middlewares/origin-check.d.mts +17 -0
- package/dist/api/middlewares/origin-check.mjs +140 -0
- package/dist/api/middlewares/origin-check.mjs.map +1 -0
- package/dist/api/rate-limiter/index.mjs +177 -0
- package/dist/api/rate-limiter/index.mjs.map +1 -0
- package/dist/api/routes/account.d.mts +10 -0
- package/dist/api/routes/account.mjs +493 -0
- package/dist/api/routes/account.mjs.map +1 -0
- package/dist/api/routes/callback.d.mts +5 -0
- package/dist/api/routes/callback.mjs +178 -0
- package/dist/api/routes/callback.mjs.map +1 -0
- package/dist/api/routes/email-verification.d.mts +29 -0
- package/dist/api/routes/email-verification.mjs +301 -0
- package/dist/api/routes/email-verification.mjs.map +1 -0
- package/dist/api/routes/error.d.mts +5 -0
- package/dist/api/routes/error.mjs +386 -0
- package/dist/api/routes/error.mjs.map +1 -0
- package/dist/api/routes/index.d.mts +11 -0
- package/dist/api/routes/index.mjs +13 -0
- package/dist/api/routes/ok.d.mts +5 -0
- package/dist/api/routes/ok.mjs +30 -0
- package/dist/api/routes/ok.mjs.map +1 -0
- package/dist/api/routes/password.d.mts +8 -0
- package/dist/api/routes/password.mjs +198 -0
- package/dist/api/routes/password.mjs.map +1 -0
- package/dist/api/routes/session.d.mts +52 -0
- package/dist/api/routes/session.mjs +478 -0
- package/dist/api/routes/session.mjs.map +1 -0
- package/dist/api/routes/sign-in.d.mts +8 -0
- package/dist/api/routes/sign-in.mjs +262 -0
- package/dist/api/routes/sign-in.mjs.map +1 -0
- package/dist/api/routes/sign-out.d.mts +5 -0
- package/dist/api/routes/sign-out.mjs +33 -0
- package/dist/api/routes/sign-out.mjs.map +1 -0
- package/dist/api/routes/sign-up.d.mts +7 -0
- package/dist/api/routes/sign-up.mjs +227 -0
- package/dist/api/routes/sign-up.mjs.map +1 -0
- package/dist/api/routes/update-user.d.mts +12 -0
- package/dist/api/routes/update-user.mjs +493 -0
- package/dist/api/routes/update-user.mjs.map +1 -0
- package/dist/api/state/oauth.d.mts +5 -0
- package/dist/api/state/oauth.mjs +8 -0
- package/dist/api/state/oauth.mjs.map +1 -0
- package/dist/api/state/should-session-refresh.d.mts +13 -0
- package/dist/api/state/should-session-refresh.mjs +16 -0
- package/dist/api/state/should-session-refresh.mjs.map +1 -0
- package/dist/api/to-auth-endpoints.mjs +197 -0
- package/dist/api/to-auth-endpoints.mjs.map +1 -0
- package/dist/auth/base.mjs +44 -0
- package/dist/auth/base.mjs.map +1 -0
- package/dist/auth/full.d.mts +30 -0
- package/dist/auth/full.mjs +32 -0
- package/dist/auth/full.mjs.map +1 -0
- package/dist/auth/minimal.d.mts +12 -0
- package/dist/auth/minimal.mjs +14 -0
- package/dist/auth/minimal.mjs.map +1 -0
- package/dist/auth/trusted-origins.mjs +31 -0
- package/dist/auth/trusted-origins.mjs.map +1 -0
- package/dist/client/broadcast-channel.d.mts +20 -0
- package/dist/client/broadcast-channel.mjs +46 -0
- package/dist/client/broadcast-channel.mjs.map +1 -0
- package/dist/client/config.mjs +90 -0
- package/dist/client/config.mjs.map +1 -0
- package/dist/client/fetch-plugins.mjs +18 -0
- package/dist/client/fetch-plugins.mjs.map +1 -0
- package/dist/client/focus-manager.d.mts +11 -0
- package/dist/client/focus-manager.mjs +32 -0
- package/dist/client/focus-manager.mjs.map +1 -0
- package/dist/client/index.d.mts +30 -0
- package/dist/client/index.mjs +21 -0
- package/dist/client/index.mjs.map +1 -0
- package/dist/client/lynx/index.d.mts +62 -0
- package/dist/client/lynx/index.mjs +24 -0
- package/dist/client/lynx/index.mjs.map +1 -0
- package/dist/client/lynx/lynx-store.d.mts +47 -0
- package/dist/client/lynx/lynx-store.mjs +47 -0
- package/dist/client/lynx/lynx-store.mjs.map +1 -0
- package/dist/client/online-manager.d.mts +12 -0
- package/dist/client/online-manager.mjs +35 -0
- package/dist/client/online-manager.mjs.map +1 -0
- package/dist/client/parser.mjs +73 -0
- package/dist/client/parser.mjs.map +1 -0
- package/dist/client/path-to-object.d.mts +57 -0
- package/dist/client/plugins/index.d.mts +58 -0
- package/dist/client/plugins/index.mjs +33 -0
- package/dist/client/plugins/infer-plugin.d.mts +9 -0
- package/dist/client/plugins/infer-plugin.mjs +11 -0
- package/dist/client/plugins/infer-plugin.mjs.map +1 -0
- package/dist/client/proxy.mjs +79 -0
- package/dist/client/proxy.mjs.map +1 -0
- package/dist/client/query.d.mts +23 -0
- package/dist/client/query.mjs +98 -0
- package/dist/client/query.mjs.map +1 -0
- package/dist/client/react/index.d.mts +63 -0
- package/dist/client/react/index.mjs +24 -0
- package/dist/client/react/index.mjs.map +1 -0
- package/dist/client/react/react-store.d.mts +47 -0
- package/dist/client/react/react-store.mjs +47 -0
- package/dist/client/react/react-store.mjs.map +1 -0
- package/dist/client/session-atom.mjs +29 -0
- package/dist/client/session-atom.mjs.map +1 -0
- package/dist/client/session-refresh.d.mts +28 -0
- package/dist/client/session-refresh.mjs +140 -0
- package/dist/client/session-refresh.mjs.map +1 -0
- package/dist/client/solid/index.d.mts +57 -0
- package/dist/client/solid/index.mjs +22 -0
- package/dist/client/solid/index.mjs.map +1 -0
- package/dist/client/solid/solid-store.mjs +24 -0
- package/dist/client/solid/solid-store.mjs.map +1 -0
- package/dist/client/svelte/index.d.mts +63 -0
- package/dist/client/svelte/index.mjs +20 -0
- package/dist/client/svelte/index.mjs.map +1 -0
- package/dist/client/types.d.mts +58 -0
- package/dist/client/vanilla.d.mts +62 -0
- package/dist/client/vanilla.mjs +20 -0
- package/dist/client/vanilla.mjs.map +1 -0
- package/dist/client/vue/index.d.mts +86 -0
- package/dist/client/vue/index.mjs +38 -0
- package/dist/client/vue/index.mjs.map +1 -0
- package/dist/client/vue/vue-store.mjs +26 -0
- package/dist/client/vue/vue-store.mjs.map +1 -0
- package/dist/context/create-context.mjs +211 -0
- package/dist/context/create-context.mjs.map +1 -0
- package/dist/context/helpers.mjs +62 -0
- package/dist/context/helpers.mjs.map +1 -0
- package/dist/context/init-minimal.mjs +20 -0
- package/dist/context/init-minimal.mjs.map +1 -0
- package/dist/context/init.mjs +22 -0
- package/dist/context/init.mjs.map +1 -0
- package/dist/cookies/cookie-utils.d.mts +29 -0
- package/dist/cookies/cookie-utils.mjs +105 -0
- package/dist/cookies/cookie-utils.mjs.map +1 -0
- package/dist/cookies/index.d.mts +67 -0
- package/dist/cookies/index.mjs +264 -0
- package/dist/cookies/index.mjs.map +1 -0
- package/dist/cookies/session-store.d.mts +36 -0
- package/dist/cookies/session-store.mjs +200 -0
- package/dist/cookies/session-store.mjs.map +1 -0
- package/dist/crypto/buffer.d.mts +8 -0
- package/dist/crypto/buffer.mjs +18 -0
- package/dist/crypto/buffer.mjs.map +1 -0
- package/dist/crypto/index.d.mts +27 -0
- package/dist/crypto/index.mjs +38 -0
- package/dist/crypto/index.mjs.map +1 -0
- package/dist/crypto/jwt.d.mts +8 -0
- package/dist/crypto/jwt.mjs +95 -0
- package/dist/crypto/jwt.mjs.map +1 -0
- package/dist/crypto/password.d.mts +12 -0
- package/dist/crypto/password.mjs +36 -0
- package/dist/crypto/password.mjs.map +1 -0
- package/dist/crypto/random.d.mts +5 -0
- package/dist/crypto/random.mjs +8 -0
- package/dist/crypto/random.mjs.map +1 -0
- package/dist/db/adapter-base.d.mts +8 -0
- package/dist/db/adapter-base.mjs +28 -0
- package/dist/db/adapter-base.mjs.map +1 -0
- package/dist/db/adapter-kysely.d.mts +8 -0
- package/dist/db/adapter-kysely.mjs +21 -0
- package/dist/db/adapter-kysely.mjs.map +1 -0
- package/dist/db/field-converter.d.mts +8 -0
- package/dist/db/field-converter.mjs +21 -0
- package/dist/db/field-converter.mjs.map +1 -0
- package/dist/db/field.d.mts +55 -0
- package/dist/db/field.mjs +11 -0
- package/dist/db/field.mjs.map +1 -0
- package/dist/db/get-migration.d.mts +23 -0
- package/dist/db/get-migration.mjs +339 -0
- package/dist/db/get-migration.mjs.map +1 -0
- package/dist/db/get-schema.d.mts +11 -0
- package/dist/db/get-schema.mjs +39 -0
- package/dist/db/get-schema.mjs.map +1 -0
- package/dist/db/index.d.mts +9 -0
- package/dist/db/index.mjs +36 -0
- package/dist/db/index.mjs.map +1 -0
- package/dist/db/internal-adapter.d.mts +14 -0
- package/dist/db/internal-adapter.mjs +616 -0
- package/dist/db/internal-adapter.mjs.map +1 -0
- package/dist/db/schema.d.mts +26 -0
- package/dist/db/schema.mjs +118 -0
- package/dist/db/schema.mjs.map +1 -0
- package/dist/db/to-zod.d.mts +36 -0
- package/dist/db/to-zod.mjs +26 -0
- package/dist/db/to-zod.mjs.map +1 -0
- package/dist/db/verification-token-storage.mjs +28 -0
- package/dist/db/verification-token-storage.mjs.map +1 -0
- package/dist/db/with-hooks.d.mts +33 -0
- package/dist/db/with-hooks.mjs +159 -0
- package/dist/db/with-hooks.mjs.map +1 -0
- package/dist/index.d.mts +52 -0
- package/dist/index.mjs +26 -0
- package/dist/integrations/next-js.d.mts +14 -0
- package/dist/integrations/next-js.mjs +78 -0
- package/dist/integrations/next-js.mjs.map +1 -0
- package/dist/integrations/node.d.mts +13 -0
- package/dist/integrations/node.mjs +16 -0
- package/dist/integrations/node.mjs.map +1 -0
- package/dist/integrations/solid-start.d.mts +23 -0
- package/dist/integrations/solid-start.mjs +17 -0
- package/dist/integrations/solid-start.mjs.map +1 -0
- package/dist/integrations/svelte-kit.d.mts +29 -0
- package/dist/integrations/svelte-kit.mjs +57 -0
- package/dist/integrations/svelte-kit.mjs.map +1 -0
- package/dist/integrations/tanstack-start-solid.d.mts +22 -0
- package/dist/integrations/tanstack-start-solid.mjs +61 -0
- package/dist/integrations/tanstack-start-solid.mjs.map +1 -0
- package/dist/integrations/tanstack-start.d.mts +22 -0
- package/dist/integrations/tanstack-start.mjs +61 -0
- package/dist/integrations/tanstack-start.mjs.map +1 -0
- package/dist/oauth2/index.d.mts +5 -0
- package/dist/oauth2/index.mjs +7 -0
- package/dist/oauth2/link-account.d.mts +31 -0
- package/dist/oauth2/link-account.mjs +144 -0
- package/dist/oauth2/link-account.mjs.map +1 -0
- package/dist/oauth2/state.d.mts +26 -0
- package/dist/oauth2/state.mjs +51 -0
- package/dist/oauth2/state.mjs.map +1 -0
- package/dist/oauth2/utils.d.mts +8 -0
- package/dist/oauth2/utils.mjs +31 -0
- package/dist/oauth2/utils.mjs.map +1 -0
- package/dist/plugins/access/access.d.mts +30 -0
- package/dist/plugins/access/access.mjs +46 -0
- package/dist/plugins/access/access.mjs.map +1 -0
- package/dist/plugins/access/index.d.mts +3 -0
- package/dist/plugins/access/index.mjs +3 -0
- package/dist/plugins/access/types.d.mts +17 -0
- package/dist/plugins/additional-fields/client.d.mts +14 -0
- package/dist/plugins/additional-fields/client.mjs +11 -0
- package/dist/plugins/additional-fields/client.mjs.map +1 -0
- package/dist/plugins/admin/access/index.d.mts +2 -0
- package/dist/plugins/admin/access/index.mjs +3 -0
- package/dist/plugins/admin/access/statement.d.mts +118 -0
- package/dist/plugins/admin/access/statement.mjs +53 -0
- package/dist/plugins/admin/access/statement.mjs.map +1 -0
- package/dist/plugins/admin/admin.d.mts +14 -0
- package/dist/plugins/admin/admin.mjs +95 -0
- package/dist/plugins/admin/admin.mjs.map +1 -0
- package/dist/plugins/admin/client.d.mts +14 -0
- package/dist/plugins/admin/client.mjs +36 -0
- package/dist/plugins/admin/client.mjs.map +1 -0
- package/dist/plugins/admin/error-codes.d.mts +5 -0
- package/dist/plugins/admin/error-codes.mjs +30 -0
- package/dist/plugins/admin/error-codes.mjs.map +1 -0
- package/dist/plugins/admin/has-permission.mjs +16 -0
- package/dist/plugins/admin/has-permission.mjs.map +1 -0
- package/dist/plugins/admin/index.d.mts +3 -0
- package/dist/plugins/admin/index.mjs +3 -0
- package/dist/plugins/admin/routes.mjs +855 -0
- package/dist/plugins/admin/routes.mjs.map +1 -0
- package/dist/plugins/admin/schema.d.mts +6 -0
- package/dist/plugins/admin/schema.mjs +34 -0
- package/dist/plugins/admin/schema.mjs.map +1 -0
- package/dist/plugins/admin/types.d.mts +89 -0
- package/dist/plugins/anonymous/client.d.mts +9 -0
- package/dist/plugins/anonymous/client.mjs +22 -0
- package/dist/plugins/anonymous/client.mjs.map +1 -0
- package/dist/plugins/anonymous/error-codes.d.mts +5 -0
- package/dist/plugins/anonymous/error-codes.mjs +16 -0
- package/dist/plugins/anonymous/error-codes.mjs.map +1 -0
- package/dist/plugins/anonymous/index.d.mts +14 -0
- package/dist/plugins/anonymous/index.mjs +163 -0
- package/dist/plugins/anonymous/index.mjs.map +1 -0
- package/dist/plugins/anonymous/schema.d.mts +5 -0
- package/dist/plugins/anonymous/schema.mjs +11 -0
- package/dist/plugins/anonymous/schema.mjs.map +1 -0
- package/dist/plugins/anonymous/types.d.mts +68 -0
- package/dist/plugins/api-key/adapter.mjs +468 -0
- package/dist/plugins/api-key/adapter.mjs.map +1 -0
- package/dist/plugins/api-key/client.d.mts +9 -0
- package/dist/plugins/api-key/client.mjs +19 -0
- package/dist/plugins/api-key/client.mjs.map +1 -0
- package/dist/plugins/api-key/error-codes.d.mts +5 -0
- package/dist/plugins/api-key/error-codes.mjs +34 -0
- package/dist/plugins/api-key/error-codes.mjs.map +1 -0
- package/dist/plugins/api-key/index.d.mts +17 -0
- package/dist/plugins/api-key/index.mjs +134 -0
- package/dist/plugins/api-key/index.mjs.map +1 -0
- package/dist/plugins/api-key/rate-limit.mjs +74 -0
- package/dist/plugins/api-key/rate-limit.mjs.map +1 -0
- package/dist/plugins/api-key/routes/create-api-key.mjs +252 -0
- package/dist/plugins/api-key/routes/create-api-key.mjs.map +1 -0
- package/dist/plugins/api-key/routes/delete-all-expired-api-keys.mjs +24 -0
- package/dist/plugins/api-key/routes/delete-all-expired-api-keys.mjs.map +1 -0
- package/dist/plugins/api-key/routes/delete-api-key.mjs +74 -0
- package/dist/plugins/api-key/routes/delete-api-key.mjs.map +1 -0
- package/dist/plugins/api-key/routes/get-api-key.mjs +158 -0
- package/dist/plugins/api-key/routes/get-api-key.mjs.map +1 -0
- package/dist/plugins/api-key/routes/index.mjs +71 -0
- package/dist/plugins/api-key/routes/index.mjs.map +1 -0
- package/dist/plugins/api-key/routes/list-api-keys.mjs +194 -0
- package/dist/plugins/api-key/routes/list-api-keys.mjs.map +1 -0
- package/dist/plugins/api-key/routes/update-api-key.mjs +248 -0
- package/dist/plugins/api-key/routes/update-api-key.mjs.map +1 -0
- package/dist/plugins/api-key/routes/verify-api-key.mjs +223 -0
- package/dist/plugins/api-key/routes/verify-api-key.mjs.map +1 -0
- package/dist/plugins/api-key/schema.d.mts +11 -0
- package/dist/plugins/api-key/schema.mjs +130 -0
- package/dist/plugins/api-key/schema.mjs.map +1 -0
- package/dist/plugins/api-key/types.d.mts +346 -0
- package/dist/plugins/bearer/index.d.mts +25 -0
- package/dist/plugins/bearer/index.mjs +66 -0
- package/dist/plugins/bearer/index.mjs.map +1 -0
- package/dist/plugins/captcha/constants.d.mts +10 -0
- package/dist/plugins/captcha/constants.mjs +22 -0
- package/dist/plugins/captcha/constants.mjs.map +1 -0
- package/dist/plugins/captcha/error-codes.mjs +16 -0
- package/dist/plugins/captcha/error-codes.mjs.map +1 -0
- package/dist/plugins/captcha/index.d.mts +14 -0
- package/dist/plugins/captcha/index.mjs +60 -0
- package/dist/plugins/captcha/index.mjs.map +1 -0
- package/dist/plugins/captcha/types.d.mts +28 -0
- package/dist/plugins/captcha/utils.mjs +11 -0
- package/dist/plugins/captcha/utils.mjs.map +1 -0
- package/dist/plugins/captcha/verify-handlers/captchafox.mjs +27 -0
- package/dist/plugins/captcha/verify-handlers/captchafox.mjs.map +1 -0
- package/dist/plugins/captcha/verify-handlers/cloudflare-turnstile.mjs +25 -0
- package/dist/plugins/captcha/verify-handlers/cloudflare-turnstile.mjs.map +1 -0
- package/dist/plugins/captcha/verify-handlers/google-recaptcha.mjs +29 -0
- package/dist/plugins/captcha/verify-handlers/google-recaptcha.mjs.map +1 -0
- package/dist/plugins/captcha/verify-handlers/h-captcha.mjs +27 -0
- package/dist/plugins/captcha/verify-handlers/h-captcha.mjs.map +1 -0
- package/dist/plugins/captcha/verify-handlers/index.mjs +6 -0
- package/dist/plugins/custom-session/client.d.mts +10 -0
- package/dist/plugins/custom-session/client.mjs +11 -0
- package/dist/plugins/custom-session/client.mjs.map +1 -0
- package/dist/plugins/custom-session/index.d.mts +26 -0
- package/dist/plugins/custom-session/index.mjs +70 -0
- package/dist/plugins/custom-session/index.mjs.map +1 -0
- package/dist/plugins/device-authorization/client.d.mts +5 -0
- package/dist/plugins/device-authorization/client.mjs +18 -0
- package/dist/plugins/device-authorization/client.mjs.map +1 -0
- package/dist/plugins/device-authorization/error-codes.mjs +21 -0
- package/dist/plugins/device-authorization/error-codes.mjs.map +1 -0
- package/dist/plugins/device-authorization/index.d.mts +28 -0
- package/dist/plugins/device-authorization/index.mjs +50 -0
- package/dist/plugins/device-authorization/index.mjs.map +1 -0
- package/dist/plugins/device-authorization/routes.mjs +510 -0
- package/dist/plugins/device-authorization/routes.mjs.map +1 -0
- package/dist/plugins/device-authorization/schema.mjs +57 -0
- package/dist/plugins/device-authorization/schema.mjs.map +1 -0
- package/dist/plugins/email-otp/client.d.mts +7 -0
- package/dist/plugins/email-otp/client.mjs +18 -0
- package/dist/plugins/email-otp/client.mjs.map +1 -0
- package/dist/plugins/email-otp/error-codes.d.mts +5 -0
- package/dist/plugins/email-otp/error-codes.mjs +12 -0
- package/dist/plugins/email-otp/error-codes.mjs.map +1 -0
- package/dist/plugins/email-otp/index.d.mts +14 -0
- package/dist/plugins/email-otp/index.mjs +108 -0
- package/dist/plugins/email-otp/index.mjs.map +1 -0
- package/dist/plugins/email-otp/otp-token.mjs +29 -0
- package/dist/plugins/email-otp/otp-token.mjs.map +1 -0
- package/dist/plugins/email-otp/routes.mjs +564 -0
- package/dist/plugins/email-otp/routes.mjs.map +1 -0
- package/dist/plugins/email-otp/types.d.mts +74 -0
- package/dist/plugins/email-otp/utils.mjs +17 -0
- package/dist/plugins/email-otp/utils.mjs.map +1 -0
- package/dist/plugins/generic-oauth/client.d.mts +19 -0
- package/dist/plugins/generic-oauth/client.mjs +14 -0
- package/dist/plugins/generic-oauth/client.mjs.map +1 -0
- package/dist/plugins/generic-oauth/error-codes.d.mts +5 -0
- package/dist/plugins/generic-oauth/error-codes.mjs +15 -0
- package/dist/plugins/generic-oauth/error-codes.mjs.map +1 -0
- package/dist/plugins/generic-oauth/index.d.mts +34 -0
- package/dist/plugins/generic-oauth/index.mjs +137 -0
- package/dist/plugins/generic-oauth/index.mjs.map +1 -0
- package/dist/plugins/generic-oauth/providers/auth0.d.mts +37 -0
- package/dist/plugins/generic-oauth/providers/auth0.mjs +62 -0
- package/dist/plugins/generic-oauth/providers/auth0.mjs.map +1 -0
- package/dist/plugins/generic-oauth/providers/gumroad.d.mts +32 -0
- package/dist/plugins/generic-oauth/providers/gumroad.mjs +60 -0
- package/dist/plugins/generic-oauth/providers/gumroad.mjs.map +1 -0
- package/dist/plugins/generic-oauth/providers/hubspot.d.mts +37 -0
- package/dist/plugins/generic-oauth/providers/hubspot.mjs +60 -0
- package/dist/plugins/generic-oauth/providers/hubspot.mjs.map +1 -0
- package/dist/plugins/generic-oauth/providers/index.d.mts +9 -0
- package/dist/plugins/generic-oauth/providers/index.mjs +11 -0
- package/dist/plugins/generic-oauth/providers/keycloak.d.mts +37 -0
- package/dist/plugins/generic-oauth/providers/keycloak.mjs +62 -0
- package/dist/plugins/generic-oauth/providers/keycloak.mjs.map +1 -0
- package/dist/plugins/generic-oauth/providers/line.d.mts +55 -0
- package/dist/plugins/generic-oauth/providers/line.mjs +91 -0
- package/dist/plugins/generic-oauth/providers/line.mjs.map +1 -0
- package/dist/plugins/generic-oauth/providers/microsoft-entra-id.d.mts +37 -0
- package/dist/plugins/generic-oauth/providers/microsoft-entra-id.mjs +66 -0
- package/dist/plugins/generic-oauth/providers/microsoft-entra-id.mjs.map +1 -0
- package/dist/plugins/generic-oauth/providers/okta.d.mts +37 -0
- package/dist/plugins/generic-oauth/providers/okta.mjs +62 -0
- package/dist/plugins/generic-oauth/providers/okta.mjs.map +1 -0
- package/dist/plugins/generic-oauth/providers/patreon.d.mts +30 -0
- package/dist/plugins/generic-oauth/providers/patreon.mjs +59 -0
- package/dist/plugins/generic-oauth/providers/patreon.mjs.map +1 -0
- package/dist/plugins/generic-oauth/providers/slack.d.mts +30 -0
- package/dist/plugins/generic-oauth/providers/slack.mjs +61 -0
- package/dist/plugins/generic-oauth/providers/slack.mjs.map +1 -0
- package/dist/plugins/generic-oauth/routes.mjs +394 -0
- package/dist/plugins/generic-oauth/routes.mjs.map +1 -0
- package/dist/plugins/generic-oauth/types.d.mts +145 -0
- package/dist/plugins/haveibeenpwned/index.d.mts +21 -0
- package/dist/plugins/haveibeenpwned/index.mjs +56 -0
- package/dist/plugins/haveibeenpwned/index.mjs.map +1 -0
- package/dist/plugins/index.d.mts +68 -0
- package/dist/plugins/index.mjs +51 -0
- package/dist/plugins/jwt/adapter.mjs +27 -0
- package/dist/plugins/jwt/adapter.mjs.map +1 -0
- package/dist/plugins/jwt/client.d.mts +18 -0
- package/dist/plugins/jwt/client.mjs +19 -0
- package/dist/plugins/jwt/client.mjs.map +1 -0
- package/dist/plugins/jwt/index.d.mts +17 -0
- package/dist/plugins/jwt/index.mjs +202 -0
- package/dist/plugins/jwt/index.mjs.map +1 -0
- package/dist/plugins/jwt/schema.d.mts +5 -0
- package/dist/plugins/jwt/schema.mjs +23 -0
- package/dist/plugins/jwt/schema.mjs.map +1 -0
- package/dist/plugins/jwt/sign.d.mts +57 -0
- package/dist/plugins/jwt/sign.mjs +66 -0
- package/dist/plugins/jwt/sign.mjs.map +1 -0
- package/dist/plugins/jwt/types.d.mts +194 -0
- package/dist/plugins/jwt/utils.d.mts +42 -0
- package/dist/plugins/jwt/utils.mjs +64 -0
- package/dist/plugins/jwt/utils.mjs.map +1 -0
- package/dist/plugins/jwt/verify.d.mts +12 -0
- package/dist/plugins/jwt/verify.mjs +46 -0
- package/dist/plugins/jwt/verify.mjs.map +1 -0
- package/dist/plugins/last-login-method/client.d.mts +18 -0
- package/dist/plugins/last-login-method/client.mjs +32 -0
- package/dist/plugins/last-login-method/client.mjs.map +1 -0
- package/dist/plugins/last-login-method/index.d.mts +52 -0
- package/dist/plugins/last-login-method/index.mjs +77 -0
- package/dist/plugins/last-login-method/index.mjs.map +1 -0
- package/dist/plugins/magic-link/client.d.mts +5 -0
- package/dist/plugins/magic-link/client.mjs +11 -0
- package/dist/plugins/magic-link/client.mjs.map +1 -0
- package/dist/plugins/magic-link/index.d.mts +61 -0
- package/dist/plugins/magic-link/index.mjs +167 -0
- package/dist/plugins/magic-link/index.mjs.map +1 -0
- package/dist/plugins/magic-link/utils.mjs +12 -0
- package/dist/plugins/magic-link/utils.mjs.map +1 -0
- package/dist/plugins/mcp/authorize.mjs +133 -0
- package/dist/plugins/mcp/authorize.mjs.map +1 -0
- package/dist/plugins/mcp/index.d.mts +46 -0
- package/dist/plugins/mcp/index.mjs +717 -0
- package/dist/plugins/mcp/index.mjs.map +1 -0
- package/dist/plugins/multi-session/client.d.mts +8 -0
- package/dist/plugins/multi-session/client.mjs +20 -0
- package/dist/plugins/multi-session/client.mjs.map +1 -0
- package/dist/plugins/multi-session/error-codes.d.mts +5 -0
- package/dist/plugins/multi-session/error-codes.mjs +8 -0
- package/dist/plugins/multi-session/error-codes.mjs.map +1 -0
- package/dist/plugins/multi-session/index.d.mts +22 -0
- package/dist/plugins/multi-session/index.mjs +172 -0
- package/dist/plugins/multi-session/index.mjs.map +1 -0
- package/dist/plugins/oauth-proxy/index.d.mts +39 -0
- package/dist/plugins/oauth-proxy/index.mjs +305 -0
- package/dist/plugins/oauth-proxy/index.mjs.map +1 -0
- package/dist/plugins/oauth-proxy/utils.mjs +44 -0
- package/dist/plugins/oauth-proxy/utils.mjs.map +1 -0
- package/dist/plugins/oidc-provider/authorize.mjs +194 -0
- package/dist/plugins/oidc-provider/authorize.mjs.map +1 -0
- package/dist/plugins/oidc-provider/client.d.mts +8 -0
- package/dist/plugins/oidc-provider/client.mjs +11 -0
- package/dist/plugins/oidc-provider/client.mjs.map +1 -0
- package/dist/plugins/oidc-provider/error.mjs +17 -0
- package/dist/plugins/oidc-provider/error.mjs.map +1 -0
- package/dist/plugins/oidc-provider/index.d.mts +32 -0
- package/dist/plugins/oidc-provider/index.mjs +1093 -0
- package/dist/plugins/oidc-provider/index.mjs.map +1 -0
- package/dist/plugins/oidc-provider/schema.d.mts +26 -0
- package/dist/plugins/oidc-provider/schema.mjs +132 -0
- package/dist/plugins/oidc-provider/schema.mjs.map +1 -0
- package/dist/plugins/oidc-provider/types.d.mts +517 -0
- package/dist/plugins/oidc-provider/utils/prompt.mjs +19 -0
- package/dist/plugins/oidc-provider/utils/prompt.mjs.map +1 -0
- package/dist/plugins/oidc-provider/utils.mjs +15 -0
- package/dist/plugins/oidc-provider/utils.mjs.map +1 -0
- package/dist/plugins/one-tap/client.d.mts +159 -0
- package/dist/plugins/one-tap/client.mjs +214 -0
- package/dist/plugins/one-tap/client.mjs.map +1 -0
- package/dist/plugins/one-tap/index.d.mts +27 -0
- package/dist/plugins/one-tap/index.mjs +96 -0
- package/dist/plugins/one-tap/index.mjs.map +1 -0
- package/dist/plugins/one-time-token/client.d.mts +7 -0
- package/dist/plugins/one-time-token/client.mjs +11 -0
- package/dist/plugins/one-time-token/client.mjs.map +1 -0
- package/dist/plugins/one-time-token/index.d.mts +53 -0
- package/dist/plugins/one-time-token/index.mjs +82 -0
- package/dist/plugins/one-time-token/index.mjs.map +1 -0
- package/dist/plugins/one-time-token/utils.mjs +12 -0
- package/dist/plugins/one-time-token/utils.mjs.map +1 -0
- package/dist/plugins/open-api/generator.d.mts +115 -0
- package/dist/plugins/open-api/generator.mjs +315 -0
- package/dist/plugins/open-api/generator.mjs.map +1 -0
- package/dist/plugins/open-api/index.d.mts +45 -0
- package/dist/plugins/open-api/index.mjs +67 -0
- package/dist/plugins/open-api/index.mjs.map +1 -0
- package/dist/plugins/open-api/logo.mjs +15 -0
- package/dist/plugins/open-api/logo.mjs.map +1 -0
- package/dist/plugins/organization/access/index.d.mts +2 -0
- package/dist/plugins/organization/access/index.mjs +3 -0
- package/dist/plugins/organization/access/statement.d.mts +249 -0
- package/dist/plugins/organization/access/statement.mjs +81 -0
- package/dist/plugins/organization/access/statement.mjs.map +1 -0
- package/dist/plugins/organization/adapter.d.mts +205 -0
- package/dist/plugins/organization/adapter.mjs +624 -0
- package/dist/plugins/organization/adapter.mjs.map +1 -0
- package/dist/plugins/organization/call.mjs +19 -0
- package/dist/plugins/organization/call.mjs.map +1 -0
- package/dist/plugins/organization/client.d.mts +151 -0
- package/dist/plugins/organization/client.mjs +107 -0
- package/dist/plugins/organization/client.mjs.map +1 -0
- package/dist/plugins/organization/error-codes.d.mts +5 -0
- package/dist/plugins/organization/error-codes.mjs +65 -0
- package/dist/plugins/organization/error-codes.mjs.map +1 -0
- package/dist/plugins/organization/has-permission.mjs +35 -0
- package/dist/plugins/organization/has-permission.mjs.map +1 -0
- package/dist/plugins/organization/index.d.mts +5 -0
- package/dist/plugins/organization/index.mjs +4 -0
- package/dist/plugins/organization/organization.d.mts +252 -0
- package/dist/plugins/organization/organization.mjs +428 -0
- package/dist/plugins/organization/organization.mjs.map +1 -0
- package/dist/plugins/organization/permission.d.mts +26 -0
- package/dist/plugins/organization/permission.mjs +16 -0
- package/dist/plugins/organization/permission.mjs.map +1 -0
- package/dist/plugins/organization/routes/crud-access-control.d.mts +11 -0
- package/dist/plugins/organization/routes/crud-access-control.mjs +656 -0
- package/dist/plugins/organization/routes/crud-access-control.mjs.map +1 -0
- package/dist/plugins/organization/routes/crud-invites.d.mts +16 -0
- package/dist/plugins/organization/routes/crud-invites.mjs +555 -0
- package/dist/plugins/organization/routes/crud-invites.mjs.map +1 -0
- package/dist/plugins/organization/routes/crud-members.d.mts +13 -0
- package/dist/plugins/organization/routes/crud-members.mjs +473 -0
- package/dist/plugins/organization/routes/crud-members.mjs.map +1 -0
- package/dist/plugins/organization/routes/crud-org.d.mts +13 -0
- package/dist/plugins/organization/routes/crud-org.mjs +447 -0
- package/dist/plugins/organization/routes/crud-org.mjs.map +1 -0
- package/dist/plugins/organization/routes/crud-team.d.mts +15 -0
- package/dist/plugins/organization/routes/crud-team.mjs +676 -0
- package/dist/plugins/organization/routes/crud-team.mjs.map +1 -0
- package/dist/plugins/organization/schema.d.mts +376 -0
- package/dist/plugins/organization/schema.mjs +68 -0
- package/dist/plugins/organization/schema.mjs.map +1 -0
- package/dist/plugins/organization/types.d.mts +733 -0
- package/dist/plugins/phone-number/client.d.mts +8 -0
- package/dist/plugins/phone-number/client.mjs +20 -0
- package/dist/plugins/phone-number/client.mjs.map +1 -0
- package/dist/plugins/phone-number/error-codes.d.mts +5 -0
- package/dist/plugins/phone-number/error-codes.mjs +21 -0
- package/dist/plugins/phone-number/error-codes.mjs.map +1 -0
- package/dist/plugins/phone-number/index.d.mts +14 -0
- package/dist/plugins/phone-number/index.mjs +49 -0
- package/dist/plugins/phone-number/index.mjs.map +1 -0
- package/dist/plugins/phone-number/routes.mjs +459 -0
- package/dist/plugins/phone-number/routes.mjs.map +1 -0
- package/dist/plugins/phone-number/schema.d.mts +5 -0
- package/dist/plugins/phone-number/schema.mjs +20 -0
- package/dist/plugins/phone-number/schema.mjs.map +1 -0
- package/dist/plugins/phone-number/types.d.mts +118 -0
- package/dist/plugins/siwe/client.d.mts +5 -0
- package/dist/plugins/siwe/client.mjs +11 -0
- package/dist/plugins/siwe/client.mjs.map +1 -0
- package/dist/plugins/siwe/error-codes.mjs +13 -0
- package/dist/plugins/siwe/error-codes.mjs.map +1 -0
- package/dist/plugins/siwe/index.d.mts +26 -0
- package/dist/plugins/siwe/index.mjs +261 -0
- package/dist/plugins/siwe/index.mjs.map +1 -0
- package/dist/plugins/siwe/schema.d.mts +5 -0
- package/dist/plugins/siwe/schema.mjs +32 -0
- package/dist/plugins/siwe/schema.mjs.map +1 -0
- package/dist/plugins/siwe/types.d.mts +44 -0
- package/dist/plugins/two-factor/backup-codes/index.d.mts +91 -0
- package/dist/plugins/two-factor/backup-codes/index.mjs +277 -0
- package/dist/plugins/two-factor/backup-codes/index.mjs.map +1 -0
- package/dist/plugins/two-factor/client.d.mts +17 -0
- package/dist/plugins/two-factor/client.mjs +37 -0
- package/dist/plugins/two-factor/client.mjs.map +1 -0
- package/dist/plugins/two-factor/constant.mjs +8 -0
- package/dist/plugins/two-factor/constant.mjs.map +1 -0
- package/dist/plugins/two-factor/error-code.d.mts +5 -0
- package/dist/plugins/two-factor/error-code.mjs +18 -0
- package/dist/plugins/two-factor/error-code.mjs.map +1 -0
- package/dist/plugins/two-factor/index.d.mts +19 -0
- package/dist/plugins/two-factor/index.mjs +207 -0
- package/dist/plugins/two-factor/index.mjs.map +1 -0
- package/dist/plugins/two-factor/otp/index.d.mts +96 -0
- package/dist/plugins/two-factor/otp/index.mjs +199 -0
- package/dist/plugins/two-factor/otp/index.mjs.map +1 -0
- package/dist/plugins/two-factor/schema.d.mts +5 -0
- package/dist/plugins/two-factor/schema.mjs +36 -0
- package/dist/plugins/two-factor/schema.mjs.map +1 -0
- package/dist/plugins/two-factor/totp/index.d.mts +81 -0
- package/dist/plugins/two-factor/totp/index.mjs +157 -0
- package/dist/plugins/two-factor/totp/index.mjs.map +1 -0
- package/dist/plugins/two-factor/types.d.mts +65 -0
- package/dist/plugins/two-factor/utils.mjs +12 -0
- package/dist/plugins/two-factor/utils.mjs.map +1 -0
- package/dist/plugins/two-factor/verify-two-factor.mjs +76 -0
- package/dist/plugins/two-factor/verify-two-factor.mjs.map +1 -0
- package/dist/plugins/username/client.d.mts +7 -0
- package/dist/plugins/username/client.mjs +18 -0
- package/dist/plugins/username/client.mjs.map +1 -0
- package/dist/plugins/username/error-codes.d.mts +5 -0
- package/dist/plugins/username/error-codes.mjs +17 -0
- package/dist/plugins/username/error-codes.mjs.map +1 -0
- package/dist/plugins/username/index.d.mts +74 -0
- package/dist/plugins/username/index.mjs +237 -0
- package/dist/plugins/username/index.mjs.map +1 -0
- package/dist/plugins/username/schema.d.mts +9 -0
- package/dist/plugins/username/schema.mjs +26 -0
- package/dist/plugins/username/schema.mjs.map +1 -0
- package/dist/social-providers/index.d.mts +1 -0
- package/dist/social-providers/index.mjs +3 -0
- package/dist/state.d.mts +42 -0
- package/dist/state.mjs +107 -0
- package/dist/state.mjs.map +1 -0
- package/dist/test-utils/headers.d.mts +9 -0
- package/dist/test-utils/headers.mjs +24 -0
- package/dist/test-utils/headers.mjs.map +1 -0
- package/dist/test-utils/index.d.mts +3 -0
- package/dist/test-utils/index.mjs +4 -0
- package/dist/test-utils/test-instance.d.mts +181 -0
- package/dist/test-utils/test-instance.mjs +210 -0
- package/dist/test-utils/test-instance.mjs.map +1 -0
- package/dist/types/adapter.d.mts +24 -0
- package/dist/types/api.d.mts +29 -0
- package/dist/types/auth.d.mts +30 -0
- package/dist/types/helper.d.mts +21 -0
- package/dist/types/index.d.mts +11 -0
- package/dist/types/index.mjs +1 -0
- package/dist/types/models.d.mts +17 -0
- package/dist/types/plugins.d.mts +16 -0
- package/dist/utils/boolean.mjs +8 -0
- package/dist/utils/boolean.mjs.map +1 -0
- package/dist/utils/constants.mjs +6 -0
- package/dist/utils/constants.mjs.map +1 -0
- package/dist/utils/date.mjs +8 -0
- package/dist/utils/date.mjs.map +1 -0
- package/dist/utils/get-request-ip.d.mts +7 -0
- package/dist/utils/get-request-ip.mjs +23 -0
- package/dist/utils/get-request-ip.mjs.map +1 -0
- package/dist/utils/hashing.mjs +21 -0
- package/dist/utils/hashing.mjs.map +1 -0
- package/dist/utils/hide-metadata.d.mts +7 -0
- package/dist/utils/hide-metadata.mjs +6 -0
- package/dist/utils/hide-metadata.mjs.map +1 -0
- package/dist/utils/index.d.mts +3 -0
- package/dist/utils/index.mjs +5 -0
- package/dist/utils/is-api-error.d.mts +7 -0
- package/dist/utils/is-api-error.mjs +11 -0
- package/dist/utils/is-api-error.mjs.map +1 -0
- package/dist/utils/is-atom.mjs +8 -0
- package/dist/utils/is-atom.mjs.map +1 -0
- package/dist/utils/is-promise.mjs +8 -0
- package/dist/utils/is-promise.mjs.map +1 -0
- package/dist/utils/middleware-response.mjs +6 -0
- package/dist/utils/middleware-response.mjs.map +1 -0
- package/dist/utils/password.mjs +26 -0
- package/dist/utils/password.mjs.map +1 -0
- package/dist/utils/plugin-helper.mjs +17 -0
- package/dist/utils/plugin-helper.mjs.map +1 -0
- package/dist/utils/shim.mjs +24 -0
- package/dist/utils/shim.mjs.map +1 -0
- package/dist/utils/time.d.mts +49 -0
- package/dist/utils/time.mjs +100 -0
- package/dist/utils/time.mjs.map +1 -0
- package/dist/utils/url.mjs +92 -0
- package/dist/utils/url.mjs.map +1 -0
- package/dist/utils/wildcard.mjs +108 -0
- package/dist/utils/wildcard.mjs.map +1 -0
- package/package.json +601 -0
|
@@ -0,0 +1,717 @@
|
|
|
1
|
+
import { getBaseURL } from "../../utils/url.mjs";
|
|
2
|
+
import { generateRandomString } from "../../crypto/random.mjs";
|
|
3
|
+
import "../../crypto/index.mjs";
|
|
4
|
+
import { parseSetCookieHeader } from "../../cookies/cookie-utils.mjs";
|
|
5
|
+
import { expireCookie } from "../../cookies/index.mjs";
|
|
6
|
+
import { getSessionFromCtx } from "../../api/routes/session.mjs";
|
|
7
|
+
import { HIDE_METADATA } from "../../utils/hide-metadata.mjs";
|
|
8
|
+
import "../../utils/index.mjs";
|
|
9
|
+
import { APIError } from "../../api/index.mjs";
|
|
10
|
+
import { parsePrompt } from "../oidc-provider/utils/prompt.mjs";
|
|
11
|
+
import { schema } from "../oidc-provider/schema.mjs";
|
|
12
|
+
import { oidcProvider } from "../oidc-provider/index.mjs";
|
|
13
|
+
import { authorizeMCPOAuth } from "./authorize.mjs";
|
|
14
|
+
import { isProduction, logger } from "@better-auth/core/env";
|
|
15
|
+
import { safeJSONParse } from "@better-auth/core/utils/json";
|
|
16
|
+
import { createAuthEndpoint, createAuthMiddleware } from "@better-auth/core/api";
|
|
17
|
+
import * as z from "zod";
|
|
18
|
+
import { getWebcryptoSubtle } from "@better-auth/utils";
|
|
19
|
+
import { createHash } from "@better-auth/utils/hash";
|
|
20
|
+
import { SignJWT } from "jose";
|
|
21
|
+
import { base64 } from "@better-auth/utils/base64";
|
|
22
|
+
|
|
23
|
+
//#region src/plugins/mcp/index.ts
|
|
24
|
+
const getMCPProviderMetadata = (ctx, options) => {
|
|
25
|
+
const issuer = ctx.context.options.baseURL;
|
|
26
|
+
const baseURL = ctx.context.baseURL;
|
|
27
|
+
if (!issuer || !baseURL) throw new APIError("INTERNAL_SERVER_ERROR", {
|
|
28
|
+
error: "invalid_issuer",
|
|
29
|
+
error_description: "issuer or baseURL is not set. If you're the app developer, please make sure to set the `baseURL` in your auth config."
|
|
30
|
+
});
|
|
31
|
+
return {
|
|
32
|
+
issuer,
|
|
33
|
+
authorization_endpoint: `${baseURL}/mcp/authorize`,
|
|
34
|
+
token_endpoint: `${baseURL}/mcp/token`,
|
|
35
|
+
userinfo_endpoint: `${baseURL}/mcp/userinfo`,
|
|
36
|
+
jwks_uri: `${baseURL}/mcp/jwks`,
|
|
37
|
+
registration_endpoint: `${baseURL}/mcp/register`,
|
|
38
|
+
scopes_supported: [
|
|
39
|
+
"openid",
|
|
40
|
+
"profile",
|
|
41
|
+
"email",
|
|
42
|
+
"offline_access"
|
|
43
|
+
],
|
|
44
|
+
response_types_supported: ["code"],
|
|
45
|
+
response_modes_supported: ["query"],
|
|
46
|
+
grant_types_supported: ["authorization_code", "refresh_token"],
|
|
47
|
+
acr_values_supported: ["urn:mace:incommon:iap:silver", "urn:mace:incommon:iap:bronze"],
|
|
48
|
+
subject_types_supported: ["public"],
|
|
49
|
+
id_token_signing_alg_values_supported: ["RS256", "none"],
|
|
50
|
+
token_endpoint_auth_methods_supported: [
|
|
51
|
+
"client_secret_basic",
|
|
52
|
+
"client_secret_post",
|
|
53
|
+
"none"
|
|
54
|
+
],
|
|
55
|
+
code_challenge_methods_supported: ["S256"],
|
|
56
|
+
claims_supported: [
|
|
57
|
+
"sub",
|
|
58
|
+
"iss",
|
|
59
|
+
"aud",
|
|
60
|
+
"exp",
|
|
61
|
+
"nbf",
|
|
62
|
+
"iat",
|
|
63
|
+
"jti",
|
|
64
|
+
"email",
|
|
65
|
+
"email_verified",
|
|
66
|
+
"name"
|
|
67
|
+
],
|
|
68
|
+
...options?.metadata
|
|
69
|
+
};
|
|
70
|
+
};
|
|
71
|
+
const getMCPProtectedResourceMetadata = (ctx, options) => {
|
|
72
|
+
const baseURL = ctx.context.baseURL;
|
|
73
|
+
const origin = new URL(baseURL).origin;
|
|
74
|
+
return {
|
|
75
|
+
resource: options?.resource ?? origin,
|
|
76
|
+
authorization_servers: [origin],
|
|
77
|
+
jwks_uri: options?.oidcConfig?.metadata?.jwks_uri ?? `${baseURL}/mcp/jwks`,
|
|
78
|
+
scopes_supported: options?.oidcConfig?.metadata?.scopes_supported ?? [
|
|
79
|
+
"openid",
|
|
80
|
+
"profile",
|
|
81
|
+
"email",
|
|
82
|
+
"offline_access"
|
|
83
|
+
],
|
|
84
|
+
bearer_methods_supported: ["header"],
|
|
85
|
+
resource_signing_alg_values_supported: ["RS256", "none"]
|
|
86
|
+
};
|
|
87
|
+
};
|
|
88
|
+
const registerMcpClientBodySchema = z.object({
|
|
89
|
+
redirect_uris: z.array(z.string()),
|
|
90
|
+
token_endpoint_auth_method: z.enum([
|
|
91
|
+
"none",
|
|
92
|
+
"client_secret_basic",
|
|
93
|
+
"client_secret_post"
|
|
94
|
+
]).default("client_secret_basic").optional(),
|
|
95
|
+
grant_types: z.array(z.enum([
|
|
96
|
+
"authorization_code",
|
|
97
|
+
"implicit",
|
|
98
|
+
"password",
|
|
99
|
+
"client_credentials",
|
|
100
|
+
"refresh_token",
|
|
101
|
+
"urn:ietf:params:oauth:grant-type:jwt-bearer",
|
|
102
|
+
"urn:ietf:params:oauth:grant-type:saml2-bearer"
|
|
103
|
+
])).default(["authorization_code"]).optional(),
|
|
104
|
+
response_types: z.array(z.enum(["code", "token"])).default(["code"]).optional(),
|
|
105
|
+
client_name: z.string().optional(),
|
|
106
|
+
client_uri: z.string().optional(),
|
|
107
|
+
logo_uri: z.string().optional(),
|
|
108
|
+
scope: z.string().optional(),
|
|
109
|
+
contacts: z.array(z.string()).optional(),
|
|
110
|
+
tos_uri: z.string().optional(),
|
|
111
|
+
policy_uri: z.string().optional(),
|
|
112
|
+
jwks_uri: z.string().optional(),
|
|
113
|
+
jwks: z.record(z.string(), z.any()).optional(),
|
|
114
|
+
metadata: z.record(z.any(), z.any()).optional(),
|
|
115
|
+
software_id: z.string().optional(),
|
|
116
|
+
software_version: z.string().optional(),
|
|
117
|
+
software_statement: z.string().optional()
|
|
118
|
+
});
|
|
119
|
+
const mcpOAuthTokenBodySchema = z.record(z.any(), z.any());
|
|
120
|
+
const mcp = (options) => {
|
|
121
|
+
const opts = {
|
|
122
|
+
codeExpiresIn: 600,
|
|
123
|
+
defaultScope: "openid",
|
|
124
|
+
accessTokenExpiresIn: 3600,
|
|
125
|
+
refreshTokenExpiresIn: 604800,
|
|
126
|
+
allowPlainCodeChallengeMethod: true,
|
|
127
|
+
...options.oidcConfig,
|
|
128
|
+
loginPage: options.loginPage,
|
|
129
|
+
scopes: [
|
|
130
|
+
"openid",
|
|
131
|
+
"profile",
|
|
132
|
+
"email",
|
|
133
|
+
"offline_access",
|
|
134
|
+
...options.oidcConfig?.scopes || []
|
|
135
|
+
]
|
|
136
|
+
};
|
|
137
|
+
const modelName = {
|
|
138
|
+
oauthClient: "oauthApplication",
|
|
139
|
+
oauthAccessToken: "oauthAccessToken",
|
|
140
|
+
oauthConsent: "oauthConsent"
|
|
141
|
+
};
|
|
142
|
+
const provider = oidcProvider(opts);
|
|
143
|
+
return {
|
|
144
|
+
id: "mcp",
|
|
145
|
+
hooks: { after: [{
|
|
146
|
+
matcher() {
|
|
147
|
+
return true;
|
|
148
|
+
},
|
|
149
|
+
handler: createAuthMiddleware(async (ctx) => {
|
|
150
|
+
const cookie = await ctx.getSignedCookie("oidc_login_prompt", ctx.context.secret);
|
|
151
|
+
const cookieName = ctx.context.authCookies.sessionToken.name;
|
|
152
|
+
const parsedSetCookieHeader = parseSetCookieHeader(ctx.context.responseHeaders?.get("set-cookie") || "");
|
|
153
|
+
const hasSessionToken = parsedSetCookieHeader.has(cookieName);
|
|
154
|
+
if (!cookie || !hasSessionToken) return;
|
|
155
|
+
expireCookie(ctx, {
|
|
156
|
+
name: "oidc_login_prompt",
|
|
157
|
+
attributes: { path: "/" }
|
|
158
|
+
});
|
|
159
|
+
const sessionToken = (parsedSetCookieHeader.get(cookieName)?.value)?.split(".")[0];
|
|
160
|
+
if (!sessionToken) return;
|
|
161
|
+
const session = await ctx.context.internalAdapter.findSession(sessionToken) || ctx.context.newSession;
|
|
162
|
+
if (!session) return;
|
|
163
|
+
const parsedCookie = safeJSONParse(cookie);
|
|
164
|
+
if (!parsedCookie) return;
|
|
165
|
+
ctx.query = parsedCookie;
|
|
166
|
+
const promptSet = parsePrompt(String(ctx.query?.prompt));
|
|
167
|
+
if (promptSet.has("login")) {
|
|
168
|
+
const newPromptSet = new Set(promptSet);
|
|
169
|
+
newPromptSet.delete("login");
|
|
170
|
+
ctx.query = {
|
|
171
|
+
...ctx.query,
|
|
172
|
+
prompt: Array.from(newPromptSet).join(" ")
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
ctx.context.session = session;
|
|
176
|
+
return await authorizeMCPOAuth(ctx, opts);
|
|
177
|
+
})
|
|
178
|
+
}] },
|
|
179
|
+
endpoints: {
|
|
180
|
+
oAuthConsent: provider.endpoints.oAuthConsent,
|
|
181
|
+
getMcpOAuthConfig: createAuthEndpoint("/.well-known/oauth-authorization-server", {
|
|
182
|
+
method: "GET",
|
|
183
|
+
metadata: HIDE_METADATA
|
|
184
|
+
}, async (c) => {
|
|
185
|
+
try {
|
|
186
|
+
const metadata = getMCPProviderMetadata(c, options);
|
|
187
|
+
return c.json(metadata);
|
|
188
|
+
} catch (e) {
|
|
189
|
+
console.log(e);
|
|
190
|
+
return c.json(null);
|
|
191
|
+
}
|
|
192
|
+
}),
|
|
193
|
+
getMCPProtectedResource: createAuthEndpoint("/.well-known/oauth-protected-resource", {
|
|
194
|
+
method: "GET",
|
|
195
|
+
metadata: HIDE_METADATA
|
|
196
|
+
}, async (c) => {
|
|
197
|
+
const metadata = getMCPProtectedResourceMetadata(c, options);
|
|
198
|
+
return c.json(metadata);
|
|
199
|
+
}),
|
|
200
|
+
mcpOAuthAuthorize: createAuthEndpoint("/mcp/authorize", {
|
|
201
|
+
method: "GET",
|
|
202
|
+
query: z.record(z.string(), z.any()),
|
|
203
|
+
metadata: { openapi: {
|
|
204
|
+
description: "Authorize an OAuth2 request using MCP",
|
|
205
|
+
responses: { "200": {
|
|
206
|
+
description: "Authorization response generated successfully",
|
|
207
|
+
content: { "application/json": { schema: {
|
|
208
|
+
type: "object",
|
|
209
|
+
additionalProperties: true,
|
|
210
|
+
description: "Authorization response, contents depend on the authorize function implementation"
|
|
211
|
+
} } }
|
|
212
|
+
} }
|
|
213
|
+
} }
|
|
214
|
+
}, async (ctx) => {
|
|
215
|
+
return authorizeMCPOAuth(ctx, opts);
|
|
216
|
+
}),
|
|
217
|
+
mcpOAuthToken: createAuthEndpoint("/mcp/token", {
|
|
218
|
+
method: "POST",
|
|
219
|
+
body: mcpOAuthTokenBodySchema,
|
|
220
|
+
metadata: {
|
|
221
|
+
...HIDE_METADATA,
|
|
222
|
+
allowedMediaTypes: ["application/x-www-form-urlencoded", "application/json"]
|
|
223
|
+
}
|
|
224
|
+
}, async (ctx) => {
|
|
225
|
+
ctx.setHeader("Access-Control-Allow-Origin", "*");
|
|
226
|
+
ctx.setHeader("Access-Control-Allow-Methods", "POST, OPTIONS");
|
|
227
|
+
ctx.setHeader("Access-Control-Allow-Headers", "Content-Type, Authorization");
|
|
228
|
+
ctx.setHeader("Access-Control-Max-Age", "86400");
|
|
229
|
+
let { body } = ctx;
|
|
230
|
+
if (!body) throw ctx.error("BAD_REQUEST", {
|
|
231
|
+
error_description: "request body not found",
|
|
232
|
+
error: "invalid_request"
|
|
233
|
+
});
|
|
234
|
+
if (body instanceof FormData) body = Object.fromEntries(body.entries());
|
|
235
|
+
if (!(body instanceof Object)) throw new APIError("BAD_REQUEST", {
|
|
236
|
+
error_description: "request body is not an object",
|
|
237
|
+
error: "invalid_request"
|
|
238
|
+
});
|
|
239
|
+
let { client_id, client_secret } = body;
|
|
240
|
+
const authorization = ctx.request?.headers.get("authorization") || null;
|
|
241
|
+
if (authorization && !client_id && !client_secret && authorization.startsWith("Basic ")) try {
|
|
242
|
+
const encoded = authorization.replace("Basic ", "");
|
|
243
|
+
const decoded = new TextDecoder().decode(base64.decode(encoded));
|
|
244
|
+
if (!decoded.includes(":")) throw new APIError("UNAUTHORIZED", {
|
|
245
|
+
error_description: "invalid authorization header format",
|
|
246
|
+
error: "invalid_client"
|
|
247
|
+
});
|
|
248
|
+
const [id, secret] = decoded.split(":");
|
|
249
|
+
if (!id || !secret) throw new APIError("UNAUTHORIZED", {
|
|
250
|
+
error_description: "invalid authorization header format",
|
|
251
|
+
error: "invalid_client"
|
|
252
|
+
});
|
|
253
|
+
client_id = id;
|
|
254
|
+
client_secret = secret;
|
|
255
|
+
} catch {
|
|
256
|
+
throw new APIError("UNAUTHORIZED", {
|
|
257
|
+
error_description: "invalid authorization header format",
|
|
258
|
+
error: "invalid_client"
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
const { grant_type, code, redirect_uri, refresh_token, code_verifier } = body;
|
|
262
|
+
if (grant_type === "refresh_token") {
|
|
263
|
+
if (!refresh_token) throw new APIError("BAD_REQUEST", {
|
|
264
|
+
error_description: "refresh_token is required",
|
|
265
|
+
error: "invalid_request"
|
|
266
|
+
});
|
|
267
|
+
const token = await ctx.context.adapter.findOne({
|
|
268
|
+
model: "oauthAccessToken",
|
|
269
|
+
where: [{
|
|
270
|
+
field: "refreshToken",
|
|
271
|
+
value: refresh_token.toString()
|
|
272
|
+
}]
|
|
273
|
+
});
|
|
274
|
+
if (!token) throw new APIError("UNAUTHORIZED", {
|
|
275
|
+
error_description: "invalid refresh token",
|
|
276
|
+
error: "invalid_grant"
|
|
277
|
+
});
|
|
278
|
+
if (token.clientId !== client_id?.toString()) throw new APIError("UNAUTHORIZED", {
|
|
279
|
+
error_description: "invalid client_id",
|
|
280
|
+
error: "invalid_client"
|
|
281
|
+
});
|
|
282
|
+
if (token.refreshTokenExpiresAt < /* @__PURE__ */ new Date()) throw new APIError("UNAUTHORIZED", {
|
|
283
|
+
error_description: "refresh token expired",
|
|
284
|
+
error: "invalid_grant"
|
|
285
|
+
});
|
|
286
|
+
const accessToken = generateRandomString(32, "a-z", "A-Z");
|
|
287
|
+
const newRefreshToken = generateRandomString(32, "a-z", "A-Z");
|
|
288
|
+
const accessTokenExpiresAt = new Date(Date.now() + opts.accessTokenExpiresIn * 1e3);
|
|
289
|
+
const refreshTokenExpiresAt = new Date(Date.now() + opts.refreshTokenExpiresIn * 1e3);
|
|
290
|
+
await ctx.context.adapter.create({
|
|
291
|
+
model: modelName.oauthAccessToken,
|
|
292
|
+
data: {
|
|
293
|
+
accessToken,
|
|
294
|
+
refreshToken: newRefreshToken,
|
|
295
|
+
accessTokenExpiresAt,
|
|
296
|
+
refreshTokenExpiresAt,
|
|
297
|
+
clientId: client_id.toString(),
|
|
298
|
+
userId: token.userId,
|
|
299
|
+
scopes: token.scopes,
|
|
300
|
+
createdAt: /* @__PURE__ */ new Date(),
|
|
301
|
+
updatedAt: /* @__PURE__ */ new Date()
|
|
302
|
+
}
|
|
303
|
+
});
|
|
304
|
+
return ctx.json({
|
|
305
|
+
access_token: accessToken,
|
|
306
|
+
token_type: "bearer",
|
|
307
|
+
expires_in: opts.accessTokenExpiresIn,
|
|
308
|
+
refresh_token: newRefreshToken,
|
|
309
|
+
scope: token.scopes
|
|
310
|
+
});
|
|
311
|
+
}
|
|
312
|
+
if (!code) throw new APIError("BAD_REQUEST", {
|
|
313
|
+
error_description: "code is required",
|
|
314
|
+
error: "invalid_request"
|
|
315
|
+
});
|
|
316
|
+
if (opts.requirePKCE && !code_verifier) throw new APIError("BAD_REQUEST", {
|
|
317
|
+
error_description: "code verifier is missing",
|
|
318
|
+
error: "invalid_request"
|
|
319
|
+
});
|
|
320
|
+
/**
|
|
321
|
+
* We need to check if the code is valid before we can proceed
|
|
322
|
+
* with the rest of the request.
|
|
323
|
+
*/
|
|
324
|
+
const verificationValue = await ctx.context.internalAdapter.findVerificationValue(code.toString());
|
|
325
|
+
if (!verificationValue) throw new APIError("UNAUTHORIZED", {
|
|
326
|
+
error_description: "invalid code",
|
|
327
|
+
error: "invalid_grant"
|
|
328
|
+
});
|
|
329
|
+
if (verificationValue.expiresAt < /* @__PURE__ */ new Date()) throw new APIError("UNAUTHORIZED", {
|
|
330
|
+
error_description: "code expired",
|
|
331
|
+
error: "invalid_grant"
|
|
332
|
+
});
|
|
333
|
+
await ctx.context.internalAdapter.deleteVerificationValue(verificationValue.id);
|
|
334
|
+
if (!client_id) throw new APIError("UNAUTHORIZED", {
|
|
335
|
+
error_description: "client_id is required",
|
|
336
|
+
error: "invalid_client"
|
|
337
|
+
});
|
|
338
|
+
if (!grant_type) throw new APIError("BAD_REQUEST", {
|
|
339
|
+
error_description: "grant_type is required",
|
|
340
|
+
error: "invalid_request"
|
|
341
|
+
});
|
|
342
|
+
if (grant_type !== "authorization_code") throw new APIError("BAD_REQUEST", {
|
|
343
|
+
error_description: "grant_type must be 'authorization_code'",
|
|
344
|
+
error: "unsupported_grant_type"
|
|
345
|
+
});
|
|
346
|
+
if (!redirect_uri) throw new APIError("BAD_REQUEST", {
|
|
347
|
+
error_description: "redirect_uri is required",
|
|
348
|
+
error: "invalid_request"
|
|
349
|
+
});
|
|
350
|
+
const client = await ctx.context.adapter.findOne({
|
|
351
|
+
model: modelName.oauthClient,
|
|
352
|
+
where: [{
|
|
353
|
+
field: "clientId",
|
|
354
|
+
value: client_id.toString()
|
|
355
|
+
}]
|
|
356
|
+
}).then((res) => {
|
|
357
|
+
if (!res) return null;
|
|
358
|
+
return {
|
|
359
|
+
...res,
|
|
360
|
+
redirectUrls: res.redirectUrls.split(","),
|
|
361
|
+
metadata: res.metadata ? JSON.parse(res.metadata) : {}
|
|
362
|
+
};
|
|
363
|
+
});
|
|
364
|
+
if (!client) throw new APIError("UNAUTHORIZED", {
|
|
365
|
+
error_description: "invalid client_id",
|
|
366
|
+
error: "invalid_client"
|
|
367
|
+
});
|
|
368
|
+
if (client.disabled) throw new APIError("UNAUTHORIZED", {
|
|
369
|
+
error_description: "client is disabled",
|
|
370
|
+
error: "invalid_client"
|
|
371
|
+
});
|
|
372
|
+
if (client.type === "public") {
|
|
373
|
+
if (!code_verifier) throw new APIError("BAD_REQUEST", {
|
|
374
|
+
error_description: "code verifier is required for public clients",
|
|
375
|
+
error: "invalid_request"
|
|
376
|
+
});
|
|
377
|
+
} else {
|
|
378
|
+
if (!client_secret) throw new APIError("UNAUTHORIZED", {
|
|
379
|
+
error_description: "client_secret is required for confidential clients",
|
|
380
|
+
error: "invalid_client"
|
|
381
|
+
});
|
|
382
|
+
if (!(client.clientSecret === client_secret.toString())) throw new APIError("UNAUTHORIZED", {
|
|
383
|
+
error_description: "invalid client_secret",
|
|
384
|
+
error: "invalid_client"
|
|
385
|
+
});
|
|
386
|
+
}
|
|
387
|
+
const value = JSON.parse(verificationValue.value);
|
|
388
|
+
if (value.clientId !== client_id.toString()) throw new APIError("UNAUTHORIZED", {
|
|
389
|
+
error_description: "invalid client_id",
|
|
390
|
+
error: "invalid_client"
|
|
391
|
+
});
|
|
392
|
+
if (value.redirectURI !== redirect_uri.toString()) throw new APIError("UNAUTHORIZED", {
|
|
393
|
+
error_description: "invalid redirect_uri",
|
|
394
|
+
error: "invalid_client"
|
|
395
|
+
});
|
|
396
|
+
if (value.codeChallenge && !code_verifier) throw new APIError("BAD_REQUEST", {
|
|
397
|
+
error_description: "code verifier is missing",
|
|
398
|
+
error: "invalid_request"
|
|
399
|
+
});
|
|
400
|
+
if ((value.codeChallengeMethod === "plain" ? code_verifier : await createHash("SHA-256", "base64urlnopad").digest(code_verifier)) !== value.codeChallenge) throw new APIError("UNAUTHORIZED", {
|
|
401
|
+
error_description: "code verification failed",
|
|
402
|
+
error: "invalid_request"
|
|
403
|
+
});
|
|
404
|
+
const requestedScopes = value.scope;
|
|
405
|
+
await ctx.context.internalAdapter.deleteVerificationValue(verificationValue.id);
|
|
406
|
+
const accessToken = generateRandomString(32, "a-z", "A-Z");
|
|
407
|
+
const refreshToken = generateRandomString(32, "A-Z", "a-z");
|
|
408
|
+
const accessTokenExpiresAt = new Date(Date.now() + opts.accessTokenExpiresIn * 1e3);
|
|
409
|
+
const refreshTokenExpiresAt = new Date(Date.now() + opts.refreshTokenExpiresIn * 1e3);
|
|
410
|
+
await ctx.context.adapter.create({
|
|
411
|
+
model: modelName.oauthAccessToken,
|
|
412
|
+
data: {
|
|
413
|
+
accessToken,
|
|
414
|
+
refreshToken,
|
|
415
|
+
accessTokenExpiresAt,
|
|
416
|
+
refreshTokenExpiresAt,
|
|
417
|
+
clientId: client_id.toString(),
|
|
418
|
+
userId: value.userId,
|
|
419
|
+
scopes: requestedScopes.join(" "),
|
|
420
|
+
createdAt: /* @__PURE__ */ new Date(),
|
|
421
|
+
updatedAt: /* @__PURE__ */ new Date()
|
|
422
|
+
}
|
|
423
|
+
});
|
|
424
|
+
const user = await ctx.context.internalAdapter.findUserById(value.userId);
|
|
425
|
+
if (!user) throw new APIError("UNAUTHORIZED", {
|
|
426
|
+
error_description: "user not found",
|
|
427
|
+
error: "invalid_grant"
|
|
428
|
+
});
|
|
429
|
+
const secretKey = {
|
|
430
|
+
alg: "HS256",
|
|
431
|
+
key: await getWebcryptoSubtle().generateKey({
|
|
432
|
+
name: "HMAC",
|
|
433
|
+
hash: "SHA-256"
|
|
434
|
+
}, true, ["sign", "verify"])
|
|
435
|
+
};
|
|
436
|
+
const profile = {
|
|
437
|
+
given_name: user.name.split(" ")[0],
|
|
438
|
+
family_name: user.name.split(" ")[1],
|
|
439
|
+
name: user.name,
|
|
440
|
+
profile: user.image,
|
|
441
|
+
updated_at: Math.floor(new Date(user.updatedAt).getTime() / 1e3)
|
|
442
|
+
};
|
|
443
|
+
const email = {
|
|
444
|
+
email: user.email,
|
|
445
|
+
email_verified: user.emailVerified
|
|
446
|
+
};
|
|
447
|
+
const userClaims = {
|
|
448
|
+
...requestedScopes.includes("profile") ? profile : {},
|
|
449
|
+
...requestedScopes.includes("email") ? email : {}
|
|
450
|
+
};
|
|
451
|
+
const additionalUserClaims = opts.getAdditionalUserInfoClaim ? await opts.getAdditionalUserInfoClaim(user, requestedScopes, client) : {};
|
|
452
|
+
const idToken = await new SignJWT({
|
|
453
|
+
sub: user.id,
|
|
454
|
+
aud: client_id.toString(),
|
|
455
|
+
iat: Date.now(),
|
|
456
|
+
auth_time: ctx.context.session ? new Date(ctx.context.session.session.createdAt).getTime() : void 0,
|
|
457
|
+
nonce: value.nonce,
|
|
458
|
+
acr: "urn:mace:incommon:iap:silver",
|
|
459
|
+
...userClaims,
|
|
460
|
+
...additionalUserClaims
|
|
461
|
+
}).setProtectedHeader({ alg: secretKey.alg }).setIssuedAt().setExpirationTime(Math.floor(Date.now() / 1e3) + opts.accessTokenExpiresIn).sign(secretKey.key);
|
|
462
|
+
return ctx.json({
|
|
463
|
+
access_token: accessToken,
|
|
464
|
+
token_type: "Bearer",
|
|
465
|
+
expires_in: opts.accessTokenExpiresIn,
|
|
466
|
+
refresh_token: requestedScopes.includes("offline_access") ? refreshToken : void 0,
|
|
467
|
+
scope: requestedScopes.join(" "),
|
|
468
|
+
id_token: requestedScopes.includes("openid") ? idToken : void 0
|
|
469
|
+
}, { headers: {
|
|
470
|
+
"Cache-Control": "no-store",
|
|
471
|
+
Pragma: "no-cache"
|
|
472
|
+
} });
|
|
473
|
+
}),
|
|
474
|
+
registerMcpClient: createAuthEndpoint("/mcp/register", {
|
|
475
|
+
method: "POST",
|
|
476
|
+
body: registerMcpClientBodySchema,
|
|
477
|
+
metadata: { openapi: {
|
|
478
|
+
description: "Register an OAuth2 application",
|
|
479
|
+
responses: { "200": {
|
|
480
|
+
description: "OAuth2 application registered successfully",
|
|
481
|
+
content: { "application/json": { schema: {
|
|
482
|
+
type: "object",
|
|
483
|
+
properties: {
|
|
484
|
+
name: {
|
|
485
|
+
type: "string",
|
|
486
|
+
description: "Name of the OAuth2 application"
|
|
487
|
+
},
|
|
488
|
+
icon: {
|
|
489
|
+
type: "string",
|
|
490
|
+
nullable: true,
|
|
491
|
+
description: "Icon URL for the application"
|
|
492
|
+
},
|
|
493
|
+
metadata: {
|
|
494
|
+
type: "object",
|
|
495
|
+
additionalProperties: true,
|
|
496
|
+
nullable: true,
|
|
497
|
+
description: "Additional metadata for the application"
|
|
498
|
+
},
|
|
499
|
+
clientId: {
|
|
500
|
+
type: "string",
|
|
501
|
+
description: "Unique identifier for the client"
|
|
502
|
+
},
|
|
503
|
+
clientSecret: {
|
|
504
|
+
type: "string",
|
|
505
|
+
description: "Secret key for the client. Not included for public clients."
|
|
506
|
+
},
|
|
507
|
+
redirectUrls: {
|
|
508
|
+
type: "array",
|
|
509
|
+
items: {
|
|
510
|
+
type: "string",
|
|
511
|
+
format: "uri"
|
|
512
|
+
},
|
|
513
|
+
description: "List of allowed redirect URLs"
|
|
514
|
+
},
|
|
515
|
+
type: {
|
|
516
|
+
type: "string",
|
|
517
|
+
description: "Type of the client",
|
|
518
|
+
enum: ["web", "public"]
|
|
519
|
+
},
|
|
520
|
+
authenticationScheme: {
|
|
521
|
+
type: "string",
|
|
522
|
+
description: "Authentication scheme used by the client",
|
|
523
|
+
enum: ["client_secret", "none"]
|
|
524
|
+
},
|
|
525
|
+
disabled: {
|
|
526
|
+
type: "boolean",
|
|
527
|
+
description: "Whether the client is disabled",
|
|
528
|
+
enum: [false]
|
|
529
|
+
},
|
|
530
|
+
userId: {
|
|
531
|
+
type: "string",
|
|
532
|
+
nullable: true,
|
|
533
|
+
description: "ID of the user who registered the client, null if registered anonymously"
|
|
534
|
+
},
|
|
535
|
+
createdAt: {
|
|
536
|
+
type: "string",
|
|
537
|
+
format: "date-time",
|
|
538
|
+
description: "Creation timestamp"
|
|
539
|
+
},
|
|
540
|
+
updatedAt: {
|
|
541
|
+
type: "string",
|
|
542
|
+
format: "date-time",
|
|
543
|
+
description: "Last update timestamp"
|
|
544
|
+
}
|
|
545
|
+
},
|
|
546
|
+
required: [
|
|
547
|
+
"name",
|
|
548
|
+
"clientId",
|
|
549
|
+
"redirectUrls",
|
|
550
|
+
"type",
|
|
551
|
+
"authenticationScheme",
|
|
552
|
+
"disabled",
|
|
553
|
+
"createdAt",
|
|
554
|
+
"updatedAt"
|
|
555
|
+
]
|
|
556
|
+
} } }
|
|
557
|
+
} }
|
|
558
|
+
} }
|
|
559
|
+
}, async (ctx) => {
|
|
560
|
+
const body = ctx.body;
|
|
561
|
+
const session = await getSessionFromCtx(ctx);
|
|
562
|
+
ctx.setHeader("Access-Control-Allow-Origin", "*");
|
|
563
|
+
ctx.setHeader("Access-Control-Allow-Methods", "POST, OPTIONS");
|
|
564
|
+
ctx.setHeader("Access-Control-Allow-Headers", "Content-Type, Authorization");
|
|
565
|
+
ctx.setHeader("Access-Control-Max-Age", "86400");
|
|
566
|
+
ctx.headers?.set("Access-Control-Max-Age", "86400");
|
|
567
|
+
if ((!body.grant_types || body.grant_types.includes("authorization_code") || body.grant_types.includes("implicit")) && (!body.redirect_uris || body.redirect_uris.length === 0)) throw new APIError("BAD_REQUEST", {
|
|
568
|
+
error: "invalid_redirect_uri",
|
|
569
|
+
error_description: "Redirect URIs are required for authorization_code and implicit grant types"
|
|
570
|
+
});
|
|
571
|
+
if (body.grant_types && body.response_types) {
|
|
572
|
+
if (body.grant_types.includes("authorization_code") && !body.response_types.includes("code")) throw new APIError("BAD_REQUEST", {
|
|
573
|
+
error: "invalid_client_metadata",
|
|
574
|
+
error_description: "When 'authorization_code' grant type is used, 'code' response type must be included"
|
|
575
|
+
});
|
|
576
|
+
if (body.grant_types.includes("implicit") && !body.response_types.includes("token")) throw new APIError("BAD_REQUEST", {
|
|
577
|
+
error: "invalid_client_metadata",
|
|
578
|
+
error_description: "When 'implicit' grant type is used, 'token' response type must be included"
|
|
579
|
+
});
|
|
580
|
+
}
|
|
581
|
+
const clientId = opts.generateClientId?.() || generateRandomString(32, "a-z", "A-Z");
|
|
582
|
+
const clientSecret = opts.generateClientSecret?.() || generateRandomString(32, "a-z", "A-Z");
|
|
583
|
+
const clientType = body.token_endpoint_auth_method === "none" ? "public" : "web";
|
|
584
|
+
const finalClientSecret = clientType === "public" ? "" : clientSecret;
|
|
585
|
+
await ctx.context.adapter.create({
|
|
586
|
+
model: modelName.oauthClient,
|
|
587
|
+
data: {
|
|
588
|
+
name: body.client_name,
|
|
589
|
+
icon: body.logo_uri,
|
|
590
|
+
metadata: body.metadata ? JSON.stringify(body.metadata) : null,
|
|
591
|
+
clientId,
|
|
592
|
+
clientSecret: finalClientSecret,
|
|
593
|
+
redirectUrls: body.redirect_uris.join(","),
|
|
594
|
+
type: clientType,
|
|
595
|
+
authenticationScheme: body.token_endpoint_auth_method || "client_secret_basic",
|
|
596
|
+
disabled: false,
|
|
597
|
+
userId: session?.session.userId,
|
|
598
|
+
createdAt: /* @__PURE__ */ new Date(),
|
|
599
|
+
updatedAt: /* @__PURE__ */ new Date()
|
|
600
|
+
}
|
|
601
|
+
});
|
|
602
|
+
const responseData = {
|
|
603
|
+
client_id: clientId,
|
|
604
|
+
client_id_issued_at: Math.floor(Date.now() / 1e3),
|
|
605
|
+
redirect_uris: body.redirect_uris,
|
|
606
|
+
token_endpoint_auth_method: body.token_endpoint_auth_method || "client_secret_basic",
|
|
607
|
+
grant_types: body.grant_types || ["authorization_code"],
|
|
608
|
+
response_types: body.response_types || ["code"],
|
|
609
|
+
client_name: body.client_name,
|
|
610
|
+
client_uri: body.client_uri,
|
|
611
|
+
logo_uri: body.logo_uri,
|
|
612
|
+
scope: body.scope,
|
|
613
|
+
contacts: body.contacts,
|
|
614
|
+
tos_uri: body.tos_uri,
|
|
615
|
+
policy_uri: body.policy_uri,
|
|
616
|
+
jwks_uri: body.jwks_uri,
|
|
617
|
+
jwks: body.jwks,
|
|
618
|
+
software_id: body.software_id,
|
|
619
|
+
software_version: body.software_version,
|
|
620
|
+
software_statement: body.software_statement,
|
|
621
|
+
metadata: body.metadata,
|
|
622
|
+
...clientType !== "public" ? {
|
|
623
|
+
client_secret: finalClientSecret,
|
|
624
|
+
client_secret_expires_at: 0
|
|
625
|
+
} : {}
|
|
626
|
+
};
|
|
627
|
+
return new Response(JSON.stringify(responseData), {
|
|
628
|
+
status: 201,
|
|
629
|
+
headers: {
|
|
630
|
+
"Content-Type": "application/json",
|
|
631
|
+
"Cache-Control": "no-store",
|
|
632
|
+
Pragma: "no-cache"
|
|
633
|
+
}
|
|
634
|
+
});
|
|
635
|
+
}),
|
|
636
|
+
getMcpSession: createAuthEndpoint("/mcp/get-session", {
|
|
637
|
+
method: "GET",
|
|
638
|
+
requireHeaders: true
|
|
639
|
+
}, async (c) => {
|
|
640
|
+
const accessToken = c.headers?.get("Authorization")?.replace("Bearer ", "");
|
|
641
|
+
if (!accessToken) {
|
|
642
|
+
c.headers?.set("WWW-Authenticate", "Bearer");
|
|
643
|
+
return c.json(null);
|
|
644
|
+
}
|
|
645
|
+
const accessTokenData = await c.context.adapter.findOne({
|
|
646
|
+
model: modelName.oauthAccessToken,
|
|
647
|
+
where: [{
|
|
648
|
+
field: "accessToken",
|
|
649
|
+
value: accessToken
|
|
650
|
+
}]
|
|
651
|
+
});
|
|
652
|
+
if (!accessTokenData) return c.json(null);
|
|
653
|
+
return c.json(accessTokenData);
|
|
654
|
+
})
|
|
655
|
+
},
|
|
656
|
+
schema,
|
|
657
|
+
options
|
|
658
|
+
};
|
|
659
|
+
};
|
|
660
|
+
const withMcpAuth = (auth, handler) => {
|
|
661
|
+
return async (req) => {
|
|
662
|
+
const baseURL = getBaseURL(auth.options.baseURL, auth.options.basePath);
|
|
663
|
+
if (!baseURL && !isProduction) logger.warn("Unable to get the baseURL, please check your config!");
|
|
664
|
+
const session = await auth.api.getMcpSession({ headers: req.headers });
|
|
665
|
+
const wwwAuthenticateValue = `Bearer resource_metadata="${baseURL}/.well-known/oauth-protected-resource"`;
|
|
666
|
+
if (!session) return Response.json({
|
|
667
|
+
jsonrpc: "2.0",
|
|
668
|
+
error: {
|
|
669
|
+
code: -32e3,
|
|
670
|
+
message: "Unauthorized: Authentication required",
|
|
671
|
+
"www-authenticate": wwwAuthenticateValue
|
|
672
|
+
},
|
|
673
|
+
id: null
|
|
674
|
+
}, {
|
|
675
|
+
status: 401,
|
|
676
|
+
headers: {
|
|
677
|
+
"WWW-Authenticate": wwwAuthenticateValue,
|
|
678
|
+
"Access-Control-Expose-Headers": "WWW-Authenticate"
|
|
679
|
+
}
|
|
680
|
+
});
|
|
681
|
+
return handler(req, session);
|
|
682
|
+
};
|
|
683
|
+
};
|
|
684
|
+
const oAuthDiscoveryMetadata = (auth) => {
|
|
685
|
+
return async (request) => {
|
|
686
|
+
const res = await auth.api.getMcpOAuthConfig();
|
|
687
|
+
return new Response(JSON.stringify(res), {
|
|
688
|
+
status: 200,
|
|
689
|
+
headers: {
|
|
690
|
+
"Content-Type": "application/json",
|
|
691
|
+
"Access-Control-Allow-Origin": "*",
|
|
692
|
+
"Access-Control-Allow-Methods": "POST, OPTIONS",
|
|
693
|
+
"Access-Control-Allow-Headers": "Content-Type, Authorization",
|
|
694
|
+
"Access-Control-Max-Age": "86400"
|
|
695
|
+
}
|
|
696
|
+
});
|
|
697
|
+
};
|
|
698
|
+
};
|
|
699
|
+
const oAuthProtectedResourceMetadata = (auth) => {
|
|
700
|
+
return async (request) => {
|
|
701
|
+
const res = await auth.api.getMCPProtectedResource();
|
|
702
|
+
return new Response(JSON.stringify(res), {
|
|
703
|
+
status: 200,
|
|
704
|
+
headers: {
|
|
705
|
+
"Content-Type": "application/json",
|
|
706
|
+
"Access-Control-Allow-Origin": "*",
|
|
707
|
+
"Access-Control-Allow-Methods": "POST, OPTIONS",
|
|
708
|
+
"Access-Control-Allow-Headers": "Content-Type, Authorization",
|
|
709
|
+
"Access-Control-Max-Age": "86400"
|
|
710
|
+
}
|
|
711
|
+
});
|
|
712
|
+
};
|
|
713
|
+
};
|
|
714
|
+
|
|
715
|
+
//#endregion
|
|
716
|
+
export { getMCPProtectedResourceMetadata, getMCPProviderMetadata, mcp, oAuthDiscoveryMetadata, oAuthProtectedResourceMetadata, withMcpAuth };
|
|
717
|
+
//# sourceMappingURL=index.mjs.map
|