@gatwech/auth 1.0.0-beta.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +31 -0
- package/dist/access-BO2g7QVe.mjs +45 -0
- package/dist/access-C6O_osEz.mjs +79 -0
- package/dist/access-DT1f6l5k.mjs +51 -0
- package/dist/adapter-factory-BZ2Qiqpn.mjs +640 -0
- package/dist/adapters/drizzle-adapter/index.d.mts +47 -0
- package/dist/adapters/drizzle-adapter/index.mjs +208 -0
- package/dist/adapters/index.d.mts +132 -0
- package/dist/adapters/index.mjs +18 -0
- package/dist/adapters/kysely-adapter/index.d.mts +47 -0
- package/dist/adapters/kysely-adapter/index.mjs +11 -0
- package/dist/adapters/memory-adapter/index.d.mts +14 -0
- package/dist/adapters/memory-adapter/index.mjs +154 -0
- package/dist/adapters/mongodb-adapter/index.d.mts +35 -0
- package/dist/adapters/mongodb-adapter/index.mjs +315 -0
- package/dist/adapters/prisma-adapter/index.d.mts +34 -0
- package/dist/adapters/prisma-adapter/index.mjs +159 -0
- package/dist/adapters/test.d.mts +81 -0
- package/dist/adapters/test.mjs +793 -0
- package/dist/admin-Bcq53Nwj.mjs +743 -0
- package/dist/admin-DtfO1PLg.d.mts +1689 -0
- package/dist/anonymous-CRt1imBW.mjs +107 -0
- package/dist/api/index.d.mts +6 -0
- package/dist/api/index.mjs +17 -0
- package/dist/api-0pR_I-Nx.mjs +3139 -0
- package/dist/auth-CBUoBX6o.mjs +233 -0
- package/dist/bearer-Djf_awfo.mjs +63 -0
- package/dist/bun-sqlite-dialect-CeNvMaZz.mjs +155 -0
- package/dist/captcha-BqaMxlKC.mjs +178 -0
- package/dist/chunk-BK_LfMhE.mjs +40 -0
- package/dist/client/index.d.mts +186 -0
- package/dist/client/index.mjs +7 -0
- package/dist/client/plugins/index.d.mts +949 -0
- package/dist/client/plugins/index.mjs +539 -0
- package/dist/client/react/index.d.mts +179 -0
- package/dist/client/react/index.mjs +69 -0
- package/dist/client-BOX93C3d.d.mts +1250 -0
- package/dist/client-CNY0tn9g.d.mts +628 -0
- package/dist/client-CygJhqeB.mjs +29 -0
- package/dist/client-WiN43tAS.mjs +17 -0
- package/dist/client-aExCkfwm.mjs +30 -0
- package/dist/cookies/index.d.mts +7 -0
- package/dist/cookies/index.mjs +7 -0
- package/dist/cookies-cJObLwn1.mjs +597 -0
- package/dist/crypto/index.d.mts +44 -0
- package/dist/crypto/index.mjs +4 -0
- package/dist/crypto-Bb42eMrH.mjs +70 -0
- package/dist/custom-session-L3t7ecsd.mjs +67 -0
- package/dist/date-Cx2yCiC4.mjs +115 -0
- package/dist/db/index.d.mts +7 -0
- package/dist/db/index.mjs +15 -0
- package/dist/db-BrstmDhc.mjs +1124 -0
- package/dist/device-authorization-V4s3h4Mj.mjs +557 -0
- package/dist/dialect-CeddeGHf.mjs +72 -0
- package/dist/email-otp-BtDHSw14.mjs +592 -0
- package/dist/esm-C-QicDNz.mjs +4090 -0
- package/dist/generic-oauth-CL5X27ZI.mjs +445 -0
- package/dist/get-request-ip-DSjrEpGo.mjs +27 -0
- package/dist/get-tables-BQP7YW9c.mjs +249 -0
- package/dist/has-permission-BpAr7uCn.mjs +14 -0
- package/dist/haveibeenpwned-cMpJvmzI.mjs +43 -0
- package/dist/helper-tmxW3BHj.d.mts +21 -0
- package/dist/index-34ONrP8l.d.mts +503 -0
- package/dist/index-65G5U5DB-DSdjzreF.d.mts +2543 -0
- package/dist/index-B-XKqFvY.d.mts +30 -0
- package/dist/index-B3n8e37d.d.mts +165 -0
- package/dist/index-BBm8nQ9Q.d.mts +42 -0
- package/dist/index-BHoQlf7a.d.mts +7699 -0
- package/dist/index-BYMI9r_d.d.mts +257 -0
- package/dist/index-BqhKCbPH.d.mts +36 -0
- package/dist/index-Buhn3hkR.d.mts +433 -0
- package/dist/index-C-u1h_WX.d.mts +174 -0
- package/dist/index-C7fQuk-V.d.mts +41 -0
- package/dist/index-CM-CFWwr.d.mts +1919 -0
- package/dist/index-CuFzhoS6.d.mts +359 -0
- package/dist/index-Cxi7TbLE.d.mts +11347 -0
- package/dist/index-DB7t8whN.d.mts +1 -0
- package/dist/index-DKNNV1kb.d.mts +626 -0
- package/dist/index-DR0xXno9.d.mts +113 -0
- package/dist/index-D_k662QG.d.mts +833 -0
- package/dist/index-DaBcikv9.d.mts +118 -0
- package/dist/index-DlaMq1nb.d.mts +955 -0
- package/dist/index-DoXZYQpq.d.mts +290 -0
- package/dist/index-G6V0Z_Mn.d.mts +125 -0
- package/dist/index-z0KSvE5i.d.mts +246 -0
- package/dist/index-zjjNBRY2.d.mts +95 -0
- package/dist/index.d.mts +12 -0
- package/dist/index.mjs +33 -0
- package/dist/integrations/next-js.d.mts +21 -0
- package/dist/integrations/next-js.mjs +62 -0
- package/dist/integrations/node.d.mts +15 -0
- package/dist/integrations/node.mjs +15 -0
- package/dist/integrations/react-start.d.mts +15 -0
- package/dist/integrations/react-start.mjs +46 -0
- package/dist/json-D0TBLy4q.mjs +24 -0
- package/dist/jwt-CmxZAGe2.mjs +94 -0
- package/dist/jwt-lHV4QHpD.mjs +387 -0
- package/dist/kysely-adapter-DpzYO8Yf.mjs +181 -0
- package/dist/magic-link-Bk-ueorR.mjs +176 -0
- package/dist/misc-beA1w3XV.mjs +7 -0
- package/dist/multi-session-DRrLKrg9.mjs +144 -0
- package/dist/node-sqlite-dialect-BcKxBQnm.mjs +155 -0
- package/dist/oauth-proxy-D1sWh9B_.mjs +133 -0
- package/dist/oauth2/index.d.mts +60 -0
- package/dist/oauth2/index.mjs +19 -0
- package/dist/one-tap-DMswkTEc.mjs +113 -0
- package/dist/organization-BArHO_5v.mjs +3857 -0
- package/dist/parser-DcrIEuXE.mjs +73 -0
- package/dist/passkey-CcD4CnhM.mjs +558 -0
- package/dist/password-sVC4nePO.mjs +25 -0
- package/dist/permission-DLYUF3cW.mjs +15 -0
- package/dist/phone-number-rHDIlh-2.mjs +485 -0
- package/dist/plugin-helper-4L-lzsjZ.mjs +16 -0
- package/dist/plugins/access/index.d.mts +3 -0
- package/dist/plugins/access/index.mjs +3 -0
- package/dist/plugins/admin/access/index.d.mts +116 -0
- package/dist/plugins/admin/access/index.mjs +4 -0
- package/dist/plugins/admin/index.d.mts +9 -0
- package/dist/plugins/admin/index.mjs +22 -0
- package/dist/plugins/anonymous/index.d.mts +7 -0
- package/dist/plugins/anonymous/index.mjs +18 -0
- package/dist/plugins/bearer/index.d.mts +2 -0
- package/dist/plugins/bearer/index.mjs +8 -0
- package/dist/plugins/captcha/index.d.mts +2 -0
- package/dist/plugins/captcha/index.mjs +4 -0
- package/dist/plugins/custom-session/index.d.mts +7 -0
- package/dist/plugins/custom-session/index.mjs +19 -0
- package/dist/plugins/device-authorization/index.d.mts +4 -0
- package/dist/plugins/device-authorization/index.mjs +18 -0
- package/dist/plugins/email-otp/index.d.mts +3 -0
- package/dist/plugins/email-otp/index.mjs +19 -0
- package/dist/plugins/generic-oauth/index.d.mts +7 -0
- package/dist/plugins/generic-oauth/index.mjs +18 -0
- package/dist/plugins/haveibeenpwned/index.d.mts +2 -0
- package/dist/plugins/haveibeenpwned/index.mjs +18 -0
- package/dist/plugins/index.d.mts +139 -0
- package/dist/plugins/index.mjs +47 -0
- package/dist/plugins/jwt/index.d.mts +7 -0
- package/dist/plugins/jwt/index.mjs +18 -0
- package/dist/plugins/magic-link/index.d.mts +2 -0
- package/dist/plugins/magic-link/index.mjs +18 -0
- package/dist/plugins/multi-session/index.d.mts +3 -0
- package/dist/plugins/multi-session/index.mjs +18 -0
- package/dist/plugins/oauth-proxy/index.d.mts +2 -0
- package/dist/plugins/oauth-proxy/index.mjs +18 -0
- package/dist/plugins/one-tap/index.d.mts +2 -0
- package/dist/plugins/one-tap/index.mjs +18 -0
- package/dist/plugins/one-time-token/index.d.mts +7 -0
- package/dist/plugins/one-time-token/index.mjs +47 -0
- package/dist/plugins/organization/access/index.d.mts +4 -0
- package/dist/plugins/organization/access/index.mjs +4 -0
- package/dist/plugins/organization/index.d.mts +9 -0
- package/dist/plugins/organization/index.mjs +22 -0
- package/dist/plugins/passkey/index.d.mts +7 -0
- package/dist/plugins/passkey/index.mjs +18 -0
- package/dist/plugins/phone-number/index.d.mts +7 -0
- package/dist/plugins/phone-number/index.mjs +18 -0
- package/dist/plugins/two-factor/index.d.mts +7 -0
- package/dist/plugins/two-factor/index.mjs +20 -0
- package/dist/plugins/username/index.d.mts +4 -0
- package/dist/plugins/username/index.mjs +18 -0
- package/dist/plugins-3jfNste3.mjs +1544 -0
- package/dist/plugins-hFZT3hmK.d.mts +14 -0
- package/dist/promise-8rrEHRXd.mjs +23154 -0
- package/dist/proxy-CL9PZXJA.mjs +441 -0
- package/dist/session-Dgp133Yt.mjs +413 -0
- package/dist/social-providers/index.d.mts +1 -0
- package/dist/social-providers/index.mjs +3 -0
- package/dist/src/adapters/adapter-factory/index.d.ts +10 -0
- package/dist/src/adapters/adapter-factory/types.d.ts +124 -0
- package/dist/src/adapters/create-test-suite.d.ts +97 -0
- package/dist/src/adapters/drizzle-adapter/drizzle-adapter.d.ts +43 -0
- package/dist/src/adapters/drizzle-adapter/index.d.ts +1 -0
- package/dist/src/adapters/drizzle-adapter/test/generate-schema.d.ts +12 -0
- package/dist/src/adapters/index.d.ts +21 -0
- package/dist/src/adapters/kysely-adapter/bun-sqlite-dialect.d.ts +58 -0
- package/dist/src/adapters/kysely-adapter/dialect.d.ts +13 -0
- package/dist/src/adapters/kysely-adapter/index.d.ts +3 -0
- package/dist/src/adapters/kysely-adapter/kysely-adapter.d.ts +32 -0
- package/dist/src/adapters/kysely-adapter/node-sqlite-dialect.d.ts +58 -0
- package/dist/src/adapters/kysely-adapter/types.d.ts +1 -0
- package/dist/src/adapters/memory-adapter/index.d.ts +1 -0
- package/dist/src/adapters/memory-adapter/memory-adapter.d.ts +9 -0
- package/dist/src/adapters/mongodb-adapter/index.d.ts +1 -0
- package/dist/src/adapters/mongodb-adapter/mongodb-adapter.d.ts +31 -0
- package/dist/src/adapters/prisma-adapter/index.d.ts +1 -0
- package/dist/src/adapters/prisma-adapter/prisma-adapter.d.ts +32 -0
- package/dist/src/adapters/prisma-adapter/test/auth.d.ts +3 -0
- package/dist/src/adapters/prisma-adapter/test/generate-auth-config.d.ts +2 -0
- package/dist/src/adapters/prisma-adapter/test/generate-prisma-schema.d.ts +3 -0
- package/dist/src/adapters/prisma-adapter/test/get-prisma-client.d.ts +7 -0
- package/dist/src/adapters/prisma-adapter/test/push-prisma-schema.d.ts +1 -0
- package/dist/src/adapters/test-adapter.d.ts +61 -0
- package/dist/src/adapters/test.d.ts +78 -0
- package/dist/src/adapters/tests/auth-flow.d.ts +22 -0
- package/dist/src/adapters/tests/index.d.ts +5 -0
- package/dist/src/adapters/tests/normal.d.ts +87 -0
- package/dist/src/adapters/tests/number-id.d.ts +17 -0
- package/dist/src/adapters/tests/performance.d.ts +24 -0
- package/dist/src/adapters/tests/transactions.d.ts +20 -0
- package/dist/src/adapters/utils.d.ts +3 -0
- package/dist/src/api/index.d.ts +7150 -0
- package/dist/src/api/middlewares/index.d.ts +2 -0
- package/dist/src/api/middlewares/oauth.d.ts +15 -0
- package/dist/src/api/middlewares/origin-check.d.ts +8 -0
- package/dist/src/api/rate-limiter/index.d.ts +13 -0
- package/dist/src/api/routes/account.d.ts +623 -0
- package/dist/src/api/routes/callback.d.ts +68 -0
- package/dist/src/api/routes/email-verification.d.ts +266 -0
- package/dist/src/api/routes/error.d.ts +51 -0
- package/dist/src/api/routes/index.d.ts +11 -0
- package/dist/src/api/routes/ok.d.ts +61 -0
- package/dist/src/api/routes/reset-password.d.ts +203 -0
- package/dist/src/api/routes/session.d.ts +586 -0
- package/dist/src/api/routes/sign-in.d.ts +298 -0
- package/dist/src/api/routes/sign-out.d.ts +59 -0
- package/dist/src/api/routes/sign-up.d.ts +625 -0
- package/dist/src/api/routes/update-user.d.ts +862 -0
- package/dist/src/api/to-auth-endpoints.d.ts +3 -0
- package/dist/src/auth.d.ts +25 -0
- package/dist/src/client/broadcast-channel.d.ts +12 -0
- package/dist/src/client/config.d.ts +85 -0
- package/dist/src/client/fetch-plugins.d.ts +14 -0
- package/dist/src/client/index.d.ts +15 -0
- package/dist/src/client/parser.d.ts +12 -0
- package/dist/src/client/path-to-object.d.ts +63 -0
- package/dist/src/client/plugins/index.d.ts +21 -0
- package/dist/src/client/plugins/infer-plugin.d.ts +11 -0
- package/dist/src/client/proxy.d.ts +8 -0
- package/dist/src/client/query.d.ts +16 -0
- package/dist/src/client/react/index.d.ts +130 -0
- package/dist/src/client/react/react-store.d.ts +43 -0
- package/dist/src/client/session-atom.d.ts +18 -0
- package/dist/src/client/session-refresh.d.ts +17 -0
- package/dist/src/client/test-plugin.d.ts +147 -0
- package/dist/src/client/types.d.ts +49 -0
- package/dist/src/client/vanilla.d.ts +124 -0
- package/dist/src/cookies/check-cookies.d.ts +4 -0
- package/dist/src/cookies/cookie-utils.d.ts +16 -0
- package/dist/src/cookies/index.d.ts +56 -0
- package/dist/src/cookies/session-store.d.ts +43 -0
- package/dist/src/crypto/buffer.d.ts +4 -0
- package/dist/src/crypto/index.d.ts +14 -0
- package/dist/src/crypto/jwt.d.ts +4 -0
- package/dist/src/crypto/password.d.ts +5 -0
- package/dist/src/crypto/random.d.ts +1 -0
- package/dist/src/db/field.d.ts +97 -0
- package/dist/src/db/get-migration.d.ts +18 -0
- package/dist/src/db/get-schema.d.ts +6 -0
- package/dist/src/db/get-tables.d.ts +3 -0
- package/dist/src/db/index.d.ts +10 -0
- package/dist/src/db/internal-adapter.d.ts +9 -0
- package/dist/src/db/schema.d.ts +76 -0
- package/dist/src/db/to-zod.d.ts +31 -0
- package/dist/src/db/utils.d.ts +6 -0
- package/dist/src/db/with-hooks.d.ts +27 -0
- package/dist/src/index.d.ts +14 -0
- package/dist/src/init.d.ts +2 -0
- package/dist/src/integrations/next-js.d.ts +15 -0
- package/dist/src/integrations/node.d.ts +6 -0
- package/dist/src/integrations/react-start.d.ts +9 -0
- package/dist/src/oauth2/index.d.ts +4 -0
- package/dist/src/oauth2/link-account.d.ts +41 -0
- package/dist/src/oauth2/state.d.ts +21 -0
- package/dist/src/oauth2/utils.d.ts +3 -0
- package/dist/src/plugins/access/access.d.ts +25 -0
- package/dist/src/plugins/access/index.d.ts +2 -0
- package/dist/src/plugins/access/types.d.ts +14 -0
- package/dist/src/plugins/additional-fields/client.d.ts +91 -0
- package/dist/src/plugins/admin/access/index.d.ts +1 -0
- package/dist/src/plugins/admin/access/statement.d.ts +110 -0
- package/dist/src/plugins/admin/admin.d.ts +1570 -0
- package/dist/src/plugins/admin/client.d.ts +62 -0
- package/dist/src/plugins/admin/error-codes.d.ts +21 -0
- package/dist/src/plugins/admin/has-permission.d.ts +21 -0
- package/dist/src/plugins/admin/index.d.ts +2 -0
- package/dist/src/plugins/admin/schema.d.ts +36 -0
- package/dist/src/plugins/admin/types.d.ts +77 -0
- package/dist/src/plugins/anonymous/client.d.ts +8 -0
- package/dist/src/plugins/anonymous/index.d.ts +159 -0
- package/dist/src/plugins/api-key/client.d.ts +11 -0
- package/dist/src/plugins/api-key/index.d.ts +1431 -0
- package/dist/src/plugins/api-key/rate-limit.d.ts +20 -0
- package/dist/src/plugins/api-key/routes/create-api-key.d.ts +244 -0
- package/dist/src/plugins/api-key/routes/delete-all-expired-api-keys.d.ts +45 -0
- package/dist/src/plugins/api-key/routes/delete-api-key.d.ts +112 -0
- package/dist/src/plugins/api-key/routes/get-api-key.d.ts +234 -0
- package/dist/src/plugins/api-key/routes/index.d.ts +1136 -0
- package/dist/src/plugins/api-key/routes/list-api-keys.d.ts +231 -0
- package/dist/src/plugins/api-key/routes/update-api-key.d.ts +235 -0
- package/dist/src/plugins/api-key/routes/verify-api-key.d.ts +80 -0
- package/dist/src/plugins/api-key/schema.d.ts +188 -0
- package/dist/src/plugins/api-key/types.d.ts +285 -0
- package/dist/src/plugins/bearer/index.d.ts +31 -0
- package/dist/src/plugins/captcha/constants.d.ts +9 -0
- package/dist/src/plugins/captcha/error-codes.d.ts +9 -0
- package/dist/src/plugins/captcha/index.d.ts +7 -0
- package/dist/src/plugins/captcha/types.d.ts +23 -0
- package/dist/src/plugins/captcha/utils.d.ts +1 -0
- package/dist/src/plugins/captcha/verify-handlers/captchafox.d.ts +11 -0
- package/dist/src/plugins/captcha/verify-handlers/cloudflare-turnstile.d.ts +10 -0
- package/dist/src/plugins/captcha/verify-handlers/google-recaptcha.d.ts +11 -0
- package/dist/src/plugins/captcha/verify-handlers/h-captcha.d.ts +11 -0
- package/dist/src/plugins/captcha/verify-handlers/index.d.ts +4 -0
- package/dist/src/plugins/custom-session/client.d.ts +12 -0
- package/dist/src/plugins/custom-session/index.d.ts +89 -0
- package/dist/src/plugins/device-authorization/client.d.ts +12 -0
- package/dist/src/plugins/device-authorization/index.d.ts +568 -0
- package/dist/src/plugins/device-authorization/schema.d.ts +56 -0
- package/dist/src/plugins/email-otp/client.d.ts +9 -0
- package/dist/src/plugins/email-otp/index.d.ts +826 -0
- package/dist/src/plugins/email-otp/utils.d.ts +2 -0
- package/dist/src/plugins/generic-oauth/client.d.ts +5 -0
- package/dist/src/plugins/generic-oauth/index.d.ts +428 -0
- package/dist/src/plugins/haveibeenpwned/index.d.ts +25 -0
- package/dist/src/plugins/index.d.ts +28 -0
- package/dist/src/plugins/jwt/adapter.d.ts +8 -0
- package/dist/src/plugins/jwt/client.d.ts +5 -0
- package/dist/src/plugins/jwt/index.d.ts +276 -0
- package/dist/src/plugins/jwt/schema.d.ts +18 -0
- package/dist/src/plugins/jwt/sign.d.ts +8 -0
- package/dist/src/plugins/jwt/types.d.ts +175 -0
- package/dist/src/plugins/jwt/utils.d.ts +46 -0
- package/dist/src/plugins/last-login-method/client.d.ts +34 -0
- package/dist/src/plugins/last-login-method/index.d.ts +103 -0
- package/dist/src/plugins/magic-link/client.d.ts +5 -0
- package/dist/src/plugins/magic-link/index.d.ts +253 -0
- package/dist/src/plugins/magic-link/utils.d.ts +1 -0
- package/dist/src/plugins/multi-session/client.d.ts +9 -0
- package/dist/src/plugins/multi-session/index.d.ts +284 -0
- package/dist/src/plugins/oauth-proxy/index.d.ts +119 -0
- package/dist/src/plugins/one-tap/client.d.ts +81 -0
- package/dist/src/plugins/one-tap/index.d.ts +114 -0
- package/dist/src/plugins/one-time-token/client.d.ts +5 -0
- package/dist/src/plugins/one-time-token/index.d.ts +170 -0
- package/dist/src/plugins/one-time-token/utils.d.ts +1 -0
- package/dist/src/plugins/organization/access/index.d.ts +1 -0
- package/dist/src/plugins/organization/access/statement.d.ts +241 -0
- package/dist/src/plugins/organization/adapter.d.ts +685 -0
- package/dist/src/plugins/organization/call.d.ts +55 -0
- package/dist/src/plugins/organization/client.d.ts +344 -0
- package/dist/src/plugins/organization/error-codes.d.ts +58 -0
- package/dist/src/plugins/organization/has-permission.d.ts +13 -0
- package/dist/src/plugins/organization/index.d.ts +4 -0
- package/dist/src/plugins/organization/organization.d.ts +412 -0
- package/dist/src/plugins/organization/permission.d.ts +27 -0
- package/dist/src/plugins/organization/routes/crud-access-control.d.ts +701 -0
- package/dist/src/plugins/organization/routes/crud-invites.d.ts +1522 -0
- package/dist/src/plugins/organization/routes/crud-members.d.ts +1220 -0
- package/dist/src/plugins/organization/routes/crud-org.d.ts +1399 -0
- package/dist/src/plugins/organization/routes/crud-team.d.ts +1323 -0
- package/dist/src/plugins/organization/schema.d.ts +366 -0
- package/dist/src/plugins/organization/types.d.ts +737 -0
- package/dist/src/plugins/passkey/client.d.ts +190 -0
- package/dist/src/plugins/passkey/error-codes.d.ts +9 -0
- package/dist/src/plugins/passkey/index.d.ts +838 -0
- package/dist/src/plugins/passkey/schema.d.ts +50 -0
- package/dist/src/plugins/passkey/types.d.ts +69 -0
- package/dist/src/plugins/passkey/utils.d.ts +2 -0
- package/dist/src/plugins/phone-number/client.d.ts +9 -0
- package/dist/src/plugins/phone-number/index.d.ts +622 -0
- package/dist/src/plugins/phone-number/phone-number-error.d.ts +10 -0
- package/dist/src/plugins/two-factor/backup-codes/index.d.ts +387 -0
- package/dist/src/plugins/two-factor/client.d.ts +28 -0
- package/dist/src/plugins/two-factor/constant.d.ts +2 -0
- package/dist/src/plugins/two-factor/error-code.d.ts +11 -0
- package/dist/src/plugins/two-factor/index.d.ts +1014 -0
- package/dist/src/plugins/two-factor/otp/index.d.ts +282 -0
- package/dist/src/plugins/two-factor/schema.d.ts +35 -0
- package/dist/src/plugins/two-factor/totp/index.d.ts +298 -0
- package/dist/src/plugins/two-factor/types.d.ts +50 -0
- package/dist/src/plugins/two-factor/utils.d.ts +1 -0
- package/dist/src/plugins/two-factor/verify-two-factor.d.ts +59 -0
- package/dist/src/plugins/username/client.d.ts +5 -0
- package/dist/src/plugins/username/error-codes.d.ts +10 -0
- package/dist/src/plugins/username/index.d.ts +313 -0
- package/dist/src/plugins/username/schema.d.ts +27 -0
- package/dist/src/social-providers/index.d.ts +1 -0
- package/dist/src/test-utils/headers.d.ts +5 -0
- package/dist/src/test-utils/index.d.ts +2 -0
- package/dist/src/test-utils/test-instance.d.ts +17849 -0
- package/dist/src/types/adapter.d.ts +21 -0
- package/dist/src/types/api.d.ts +29 -0
- package/dist/src/types/helper.d.ts +32 -0
- package/dist/src/types/index.d.ts +7 -0
- package/dist/src/types/models.d.ts +13 -0
- package/dist/src/types/plugins.d.ts +14 -0
- package/dist/src/utils/await-object.d.ts +3 -0
- package/dist/src/utils/boolean.d.ts +1 -0
- package/dist/src/utils/clone.d.ts +1 -0
- package/dist/src/utils/constants.d.ts +1 -0
- package/dist/src/utils/date.d.ts +1 -0
- package/dist/src/utils/ensure-utc.d.ts +1 -0
- package/dist/src/utils/get-request-ip.d.ts +2 -0
- package/dist/src/utils/hashing.d.ts +6 -0
- package/dist/src/utils/hide-metadata.d.ts +3 -0
- package/dist/src/utils/id.d.ts +1 -0
- package/dist/src/utils/import-util.d.ts +1 -0
- package/dist/src/utils/index.d.ts +5 -0
- package/dist/src/utils/is-atom.d.ts +2 -0
- package/dist/src/utils/is-promise.d.ts +1 -0
- package/dist/src/utils/json.d.ts +1 -0
- package/dist/src/utils/merger.d.ts +1 -0
- package/dist/src/utils/middleware-response.d.ts +8 -0
- package/dist/src/utils/misc.d.ts +1 -0
- package/dist/src/utils/password.d.ts +6 -0
- package/dist/src/utils/plugin-helper.d.ts +5 -0
- package/dist/src/utils/shim.d.ts +3 -0
- package/dist/src/utils/time.d.ts +4 -0
- package/dist/src/utils/url.d.ts +4 -0
- package/dist/src/utils/wildcard.d.ts +45 -0
- package/dist/test-utils/index.d.mts +17870 -0
- package/dist/test-utils/index.mjs +272 -0
- package/dist/two-factor-ClUXxom2.mjs +914 -0
- package/dist/types/index.d.mts +6 -0
- package/dist/types/index.mjs +3 -0
- package/dist/types-B1OL7hyf.d.mts +4 -0
- package/dist/types-Bjn15Uy6.mjs +1 -0
- package/dist/url-VB2gAbTI.mjs +59 -0
- package/dist/username-DiGklOGl.mjs +278 -0
- package/dist/utils-SOMB4Px5.mjs +132 -0
- package/package.json +447 -0
|
@@ -0,0 +1,445 @@
|
|
|
1
|
+
import { i as parseState, r as generateState } from "./utils-SOMB4Px5.mjs";
|
|
2
|
+
import { O as handleOAuthUserInfo } from "./api-0pR_I-Nx.mjs";
|
|
3
|
+
import { c as setSessionCookie } from "./cookies-cJObLwn1.mjs";
|
|
4
|
+
import { u as sessionMiddleware } from "./session-Dgp133Yt.mjs";
|
|
5
|
+
import { BASE_ERROR_CODES } from "@gatwech/core/error";
|
|
6
|
+
import { createAuthorizationURL, refreshAccessToken, validateAuthorizationCode } from "@gatwech/core/oauth2";
|
|
7
|
+
import { defineErrorCodes } from "@gatwech/core/utils";
|
|
8
|
+
import { APIError } from "better-call";
|
|
9
|
+
import { createAuthEndpoint } from "@gatwech/core/api";
|
|
10
|
+
import * as z$1 from "zod";
|
|
11
|
+
import { decodeJwt } from "jose";
|
|
12
|
+
import { betterFetch } from "@better-fetch/fetch";
|
|
13
|
+
|
|
14
|
+
//#region src/plugins/generic-oauth/index.ts
|
|
15
|
+
async function getUserInfo(tokens, finalUserInfoUrl) {
|
|
16
|
+
if (tokens.idToken) {
|
|
17
|
+
const decoded = decodeJwt(tokens.idToken);
|
|
18
|
+
if (decoded) {
|
|
19
|
+
if (decoded.sub && decoded.email) return {
|
|
20
|
+
id: decoded.sub,
|
|
21
|
+
emailVerified: decoded.email_verified,
|
|
22
|
+
image: decoded.picture,
|
|
23
|
+
...decoded
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
if (!finalUserInfoUrl) return null;
|
|
28
|
+
const userInfo = await betterFetch(finalUserInfoUrl, {
|
|
29
|
+
method: "GET",
|
|
30
|
+
headers: { Authorization: `Bearer ${tokens.accessToken}` }
|
|
31
|
+
});
|
|
32
|
+
return {
|
|
33
|
+
id: userInfo.data?.sub,
|
|
34
|
+
emailVerified: userInfo.data?.email_verified ?? false,
|
|
35
|
+
email: userInfo.data?.email,
|
|
36
|
+
image: userInfo.data?.picture,
|
|
37
|
+
name: userInfo.data?.name,
|
|
38
|
+
...userInfo.data
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
const ERROR_CODES = defineErrorCodes({ INVALID_OAUTH_CONFIGURATION: "Invalid OAuth configuration" });
|
|
42
|
+
/**
|
|
43
|
+
* A generic OAuth plugin that can be used to add OAuth support to any provider
|
|
44
|
+
*/
|
|
45
|
+
const genericOAuth = (options) => {
|
|
46
|
+
return {
|
|
47
|
+
id: "generic-oauth",
|
|
48
|
+
init: (ctx) => {
|
|
49
|
+
return { context: { socialProviders: options.config.map((c) => {
|
|
50
|
+
let finalUserInfoUrl = c.userInfoUrl;
|
|
51
|
+
return {
|
|
52
|
+
id: c.providerId,
|
|
53
|
+
name: c.providerId,
|
|
54
|
+
createAuthorizationURL(data) {
|
|
55
|
+
return createAuthorizationURL({
|
|
56
|
+
id: c.providerId,
|
|
57
|
+
options: {
|
|
58
|
+
clientId: c.clientId,
|
|
59
|
+
clientSecret: c.clientSecret,
|
|
60
|
+
redirectURI: c.redirectURI
|
|
61
|
+
},
|
|
62
|
+
authorizationEndpoint: c.authorizationUrl,
|
|
63
|
+
state: data.state,
|
|
64
|
+
codeVerifier: c.pkce ? data.codeVerifier : void 0,
|
|
65
|
+
scopes: c.scopes || [],
|
|
66
|
+
redirectURI: `${ctx.baseURL}/oauth2/callback/${c.providerId}`
|
|
67
|
+
});
|
|
68
|
+
},
|
|
69
|
+
async validateAuthorizationCode(data) {
|
|
70
|
+
let finalTokenUrl = c.tokenUrl;
|
|
71
|
+
if (c.discoveryUrl) {
|
|
72
|
+
const discovery = await betterFetch(c.discoveryUrl, {
|
|
73
|
+
method: "GET",
|
|
74
|
+
headers: c.discoveryHeaders
|
|
75
|
+
});
|
|
76
|
+
if (discovery.data) {
|
|
77
|
+
finalTokenUrl = discovery.data.token_endpoint;
|
|
78
|
+
finalUserInfoUrl = discovery.data.userinfo_endpoint;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
if (!finalTokenUrl) throw new APIError("BAD_REQUEST", { message: "Invalid OAuth configuration. Token URL not found." });
|
|
82
|
+
return validateAuthorizationCode({
|
|
83
|
+
headers: c.authorizationHeaders,
|
|
84
|
+
code: data.code,
|
|
85
|
+
codeVerifier: data.codeVerifier,
|
|
86
|
+
redirectURI: data.redirectURI,
|
|
87
|
+
options: {
|
|
88
|
+
clientId: c.clientId,
|
|
89
|
+
clientSecret: c.clientSecret,
|
|
90
|
+
redirectURI: c.redirectURI
|
|
91
|
+
},
|
|
92
|
+
tokenEndpoint: finalTokenUrl,
|
|
93
|
+
authentication: c.authentication
|
|
94
|
+
});
|
|
95
|
+
},
|
|
96
|
+
async refreshAccessToken(refreshToken) {
|
|
97
|
+
let finalTokenUrl = c.tokenUrl;
|
|
98
|
+
if (c.discoveryUrl) {
|
|
99
|
+
const discovery = await betterFetch(c.discoveryUrl, {
|
|
100
|
+
method: "GET",
|
|
101
|
+
headers: c.discoveryHeaders
|
|
102
|
+
});
|
|
103
|
+
if (discovery.data) finalTokenUrl = discovery.data.token_endpoint;
|
|
104
|
+
}
|
|
105
|
+
if (!finalTokenUrl) throw new APIError("BAD_REQUEST", { message: "Invalid OAuth configuration. Token URL not found." });
|
|
106
|
+
return refreshAccessToken({
|
|
107
|
+
refreshToken,
|
|
108
|
+
options: {
|
|
109
|
+
clientId: c.clientId,
|
|
110
|
+
clientSecret: c.clientSecret
|
|
111
|
+
},
|
|
112
|
+
authentication: c.authentication,
|
|
113
|
+
tokenEndpoint: finalTokenUrl
|
|
114
|
+
});
|
|
115
|
+
},
|
|
116
|
+
async getUserInfo(tokens) {
|
|
117
|
+
const userInfo = c.getUserInfo ? await c.getUserInfo(tokens) : await getUserInfo(tokens, finalUserInfoUrl);
|
|
118
|
+
if (!userInfo) return null;
|
|
119
|
+
return {
|
|
120
|
+
user: {
|
|
121
|
+
id: userInfo?.id,
|
|
122
|
+
email: userInfo?.email,
|
|
123
|
+
emailVerified: userInfo?.emailVerified,
|
|
124
|
+
image: userInfo?.image,
|
|
125
|
+
name: userInfo?.name,
|
|
126
|
+
...c.mapProfileToUser?.(userInfo)
|
|
127
|
+
},
|
|
128
|
+
data: userInfo
|
|
129
|
+
};
|
|
130
|
+
},
|
|
131
|
+
options: { overrideUserInfoOnSignIn: c.overrideUserInfo }
|
|
132
|
+
};
|
|
133
|
+
}).concat(ctx.socialProviders) } };
|
|
134
|
+
},
|
|
135
|
+
endpoints: {
|
|
136
|
+
signInWithOAuth2: createAuthEndpoint("/sign-in/oauth2", {
|
|
137
|
+
method: "POST",
|
|
138
|
+
body: z$1.object({
|
|
139
|
+
providerId: z$1.string().meta({ description: "The provider ID for the OAuth provider" }),
|
|
140
|
+
callbackURL: z$1.string().meta({ description: "The URL to redirect to after sign in" }).optional(),
|
|
141
|
+
errorCallbackURL: z$1.string().meta({ description: "The URL to redirect to if an error occurs" }).optional(),
|
|
142
|
+
newUserCallbackURL: z$1.string().meta({ description: "The URL to redirect to after login if the user is new. Eg: \"/welcome\"" }).optional(),
|
|
143
|
+
disableRedirect: z$1.boolean().meta({ description: "Disable redirect" }).optional(),
|
|
144
|
+
scopes: z$1.array(z$1.string()).meta({ description: "Scopes to be passed to the provider authorization request." }).optional(),
|
|
145
|
+
requestSignUp: z$1.boolean().meta({ description: "Explicitly request sign-up. Useful when disableImplicitSignUp is true for this provider. Eg: false" }).optional(),
|
|
146
|
+
additionalData: z$1.record(z$1.string(), z$1.any()).optional()
|
|
147
|
+
}),
|
|
148
|
+
metadata: { openapi: {
|
|
149
|
+
description: "Sign in with OAuth2",
|
|
150
|
+
responses: { 200: {
|
|
151
|
+
description: "Sign in with OAuth2",
|
|
152
|
+
content: { "application/json": { schema: {
|
|
153
|
+
type: "object",
|
|
154
|
+
properties: {
|
|
155
|
+
url: { type: "string" },
|
|
156
|
+
redirect: { type: "boolean" }
|
|
157
|
+
}
|
|
158
|
+
} } }
|
|
159
|
+
} }
|
|
160
|
+
} }
|
|
161
|
+
}, async (ctx) => {
|
|
162
|
+
const { providerId } = ctx.body;
|
|
163
|
+
const config = options.config.find((c) => c.providerId === providerId);
|
|
164
|
+
if (!config) throw new APIError("BAD_REQUEST", { message: `No config found for provider ${providerId}` });
|
|
165
|
+
const { discoveryUrl, authorizationUrl, tokenUrl, clientId, clientSecret, scopes, redirectURI, responseType, pkce, prompt, accessType, authorizationUrlParams, responseMode, authentication } = config;
|
|
166
|
+
let finalAuthUrl = authorizationUrl;
|
|
167
|
+
let finalTokenUrl = tokenUrl;
|
|
168
|
+
if (discoveryUrl) {
|
|
169
|
+
const discovery = await betterFetch(discoveryUrl, {
|
|
170
|
+
method: "GET",
|
|
171
|
+
headers: config.discoveryHeaders,
|
|
172
|
+
onError(context) {
|
|
173
|
+
ctx.context.logger.error(context.error.message, context.error, { discoveryUrl });
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
if (discovery.data) {
|
|
177
|
+
finalAuthUrl = discovery.data.authorization_endpoint;
|
|
178
|
+
finalTokenUrl = discovery.data.token_endpoint;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
if (!finalAuthUrl || !finalTokenUrl) throw new APIError("BAD_REQUEST", { message: ERROR_CODES.INVALID_OAUTH_CONFIGURATION });
|
|
182
|
+
if (authorizationUrlParams) {
|
|
183
|
+
const withAdditionalParams = new URL(finalAuthUrl);
|
|
184
|
+
for (const [paramName, paramValue] of Object.entries(authorizationUrlParams)) withAdditionalParams.searchParams.set(paramName, paramValue);
|
|
185
|
+
finalAuthUrl = withAdditionalParams.toString();
|
|
186
|
+
}
|
|
187
|
+
const additionalParams = typeof authorizationUrlParams === "function" ? authorizationUrlParams(ctx) : authorizationUrlParams;
|
|
188
|
+
const { state, codeVerifier } = await generateState(ctx, void 0, ctx.body.additionalData);
|
|
189
|
+
const authUrl = await createAuthorizationURL({
|
|
190
|
+
id: providerId,
|
|
191
|
+
options: {
|
|
192
|
+
clientId,
|
|
193
|
+
clientSecret,
|
|
194
|
+
redirectURI
|
|
195
|
+
},
|
|
196
|
+
authorizationEndpoint: finalAuthUrl,
|
|
197
|
+
state,
|
|
198
|
+
codeVerifier: pkce ? codeVerifier : void 0,
|
|
199
|
+
scopes: ctx.body.scopes ? [...ctx.body.scopes, ...scopes || []] : scopes || [],
|
|
200
|
+
redirectURI: `${ctx.context.baseURL}/oauth2/callback/${providerId}`,
|
|
201
|
+
prompt,
|
|
202
|
+
accessType,
|
|
203
|
+
responseType,
|
|
204
|
+
responseMode,
|
|
205
|
+
additionalParams
|
|
206
|
+
});
|
|
207
|
+
return ctx.json({
|
|
208
|
+
url: authUrl.toString(),
|
|
209
|
+
redirect: !ctx.body.disableRedirect
|
|
210
|
+
});
|
|
211
|
+
}),
|
|
212
|
+
oAuth2Callback: createAuthEndpoint("/oauth2/callback/:providerId", {
|
|
213
|
+
method: "GET",
|
|
214
|
+
query: z$1.object({
|
|
215
|
+
code: z$1.string().meta({ description: "The OAuth2 code" }).optional(),
|
|
216
|
+
error: z$1.string().meta({ description: "The error message, if any" }).optional(),
|
|
217
|
+
error_description: z$1.string().meta({ description: "The error description, if any" }).optional(),
|
|
218
|
+
state: z$1.string().meta({ description: "The state parameter from the OAuth2 request" }).optional()
|
|
219
|
+
}),
|
|
220
|
+
metadata: {
|
|
221
|
+
client: false,
|
|
222
|
+
openapi: {
|
|
223
|
+
description: "OAuth2 callback",
|
|
224
|
+
responses: { 200: {
|
|
225
|
+
description: "OAuth2 callback",
|
|
226
|
+
content: { "application/json": { schema: {
|
|
227
|
+
type: "object",
|
|
228
|
+
properties: { url: { type: "string" } }
|
|
229
|
+
} } }
|
|
230
|
+
} }
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
}, async (ctx) => {
|
|
234
|
+
const defaultErrorURL = ctx.context.options.onAPIError?.errorURL || `${ctx.context.baseURL}/error`;
|
|
235
|
+
if (ctx.query.error || !ctx.query.code) throw ctx.redirect(`${defaultErrorURL}?error=${ctx.query.error || "oAuth_code_missing"}&error_description=${ctx.query.error_description}`);
|
|
236
|
+
const provider = options.config.find((p) => p.providerId === ctx.params.providerId);
|
|
237
|
+
if (!provider) throw new APIError("BAD_REQUEST", { message: `No config found for provider ${ctx.params.providerId}` });
|
|
238
|
+
let tokens = void 0;
|
|
239
|
+
const { callbackURL, codeVerifier, errorURL, requestSignUp, newUserURL, link } = await parseState(ctx);
|
|
240
|
+
const code = ctx.query.code;
|
|
241
|
+
function redirectOnError(error) {
|
|
242
|
+
const defaultErrorURL$1 = ctx.context.options.onAPIError?.errorURL || `${ctx.context.baseURL}/error`;
|
|
243
|
+
let url = errorURL || defaultErrorURL$1;
|
|
244
|
+
if (url.includes("?")) url = `${url}&error=${error}`;
|
|
245
|
+
else url = `${url}?error=${error}`;
|
|
246
|
+
throw ctx.redirect(url);
|
|
247
|
+
}
|
|
248
|
+
let finalTokenUrl = provider.tokenUrl;
|
|
249
|
+
let finalUserInfoUrl = provider.userInfoUrl;
|
|
250
|
+
if (provider.discoveryUrl) {
|
|
251
|
+
const discovery = await betterFetch(provider.discoveryUrl, {
|
|
252
|
+
method: "GET",
|
|
253
|
+
headers: provider.discoveryHeaders
|
|
254
|
+
});
|
|
255
|
+
if (discovery.data) {
|
|
256
|
+
finalTokenUrl = discovery.data.token_endpoint;
|
|
257
|
+
finalUserInfoUrl = discovery.data.userinfo_endpoint;
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
try {
|
|
261
|
+
if (!finalTokenUrl) throw new APIError("BAD_REQUEST", { message: "Invalid OAuth configuration." });
|
|
262
|
+
const additionalParams = typeof provider.tokenUrlParams === "function" ? provider.tokenUrlParams(ctx) : provider.tokenUrlParams;
|
|
263
|
+
tokens = await validateAuthorizationCode({
|
|
264
|
+
headers: provider.authorizationHeaders,
|
|
265
|
+
code,
|
|
266
|
+
codeVerifier: provider.pkce ? codeVerifier : void 0,
|
|
267
|
+
redirectURI: `${ctx.context.baseURL}/oauth2/callback/${provider.providerId}`,
|
|
268
|
+
options: {
|
|
269
|
+
clientId: provider.clientId,
|
|
270
|
+
clientSecret: provider.clientSecret,
|
|
271
|
+
redirectURI: provider.redirectURI
|
|
272
|
+
},
|
|
273
|
+
tokenEndpoint: finalTokenUrl,
|
|
274
|
+
authentication: provider.authentication,
|
|
275
|
+
additionalParams
|
|
276
|
+
});
|
|
277
|
+
} catch (e) {
|
|
278
|
+
ctx.context.logger.error(e && typeof e === "object" && "name" in e ? e.name : "", e);
|
|
279
|
+
throw redirectOnError("oauth_code_verification_failed");
|
|
280
|
+
}
|
|
281
|
+
if (!tokens) throw new APIError("BAD_REQUEST", { message: "Invalid OAuth configuration." });
|
|
282
|
+
const userInfo = await (async function handleUserInfo() {
|
|
283
|
+
const userInfo$1 = provider.getUserInfo ? await provider.getUserInfo(tokens) : await getUserInfo(tokens, finalUserInfoUrl);
|
|
284
|
+
if (!userInfo$1) throw redirectOnError("user_info_is_missing");
|
|
285
|
+
const mapUser = provider.mapProfileToUser ? await provider.mapProfileToUser(userInfo$1) : userInfo$1;
|
|
286
|
+
const email = mapUser.email ? mapUser.email.toLowerCase() : userInfo$1.email?.toLowerCase();
|
|
287
|
+
if (!email) {
|
|
288
|
+
ctx.context.logger.error("Unable to get user info", userInfo$1);
|
|
289
|
+
throw redirectOnError("email_is_missing");
|
|
290
|
+
}
|
|
291
|
+
const id = mapUser.id ? String(mapUser.id) : String(userInfo$1.id);
|
|
292
|
+
const name = mapUser.name ? mapUser.name : userInfo$1.name;
|
|
293
|
+
if (!name) {
|
|
294
|
+
ctx.context.logger.error("Unable to get user info", userInfo$1);
|
|
295
|
+
throw redirectOnError("name_is_missing");
|
|
296
|
+
}
|
|
297
|
+
return {
|
|
298
|
+
...userInfo$1,
|
|
299
|
+
...mapUser,
|
|
300
|
+
email,
|
|
301
|
+
id,
|
|
302
|
+
name
|
|
303
|
+
};
|
|
304
|
+
})();
|
|
305
|
+
if (link) {
|
|
306
|
+
if (ctx.context.options.account?.accountLinking?.allowDifferentEmails !== true && link.email !== userInfo.email) return redirectOnError("email_doesn't_match");
|
|
307
|
+
const existingAccount = await ctx.context.internalAdapter.findAccountByProviderId(String(userInfo.id), provider.providerId);
|
|
308
|
+
if (existingAccount) {
|
|
309
|
+
if (existingAccount.userId !== link.userId) return redirectOnError("account_already_linked_to_different_user");
|
|
310
|
+
const updateData = Object.fromEntries(Object.entries({
|
|
311
|
+
accessToken: tokens.accessToken,
|
|
312
|
+
idToken: tokens.idToken,
|
|
313
|
+
refreshToken: tokens.refreshToken,
|
|
314
|
+
accessTokenExpiresAt: tokens.accessTokenExpiresAt,
|
|
315
|
+
refreshTokenExpiresAt: tokens.refreshTokenExpiresAt,
|
|
316
|
+
scope: tokens.scopes?.join(",")
|
|
317
|
+
}).filter(([_, value]) => value !== void 0));
|
|
318
|
+
await ctx.context.internalAdapter.updateAccount(existingAccount.id, updateData);
|
|
319
|
+
} else if (!await ctx.context.internalAdapter.createAccount({
|
|
320
|
+
userId: link.userId,
|
|
321
|
+
providerId: provider.providerId,
|
|
322
|
+
accountId: userInfo.id,
|
|
323
|
+
accessToken: tokens.accessToken,
|
|
324
|
+
accessTokenExpiresAt: tokens.accessTokenExpiresAt,
|
|
325
|
+
refreshTokenExpiresAt: tokens.refreshTokenExpiresAt,
|
|
326
|
+
scope: tokens.scopes?.join(","),
|
|
327
|
+
refreshToken: tokens.refreshToken,
|
|
328
|
+
idToken: tokens.idToken
|
|
329
|
+
})) return redirectOnError("unable_to_link_account");
|
|
330
|
+
let toRedirectTo$1;
|
|
331
|
+
try {
|
|
332
|
+
toRedirectTo$1 = callbackURL.toString();
|
|
333
|
+
} catch {
|
|
334
|
+
toRedirectTo$1 = callbackURL;
|
|
335
|
+
}
|
|
336
|
+
throw ctx.redirect(toRedirectTo$1);
|
|
337
|
+
}
|
|
338
|
+
const result = await handleOAuthUserInfo(ctx, {
|
|
339
|
+
userInfo,
|
|
340
|
+
account: {
|
|
341
|
+
providerId: provider.providerId,
|
|
342
|
+
accountId: userInfo.id,
|
|
343
|
+
...tokens,
|
|
344
|
+
scope: tokens.scopes?.join(",")
|
|
345
|
+
},
|
|
346
|
+
callbackURL,
|
|
347
|
+
disableSignUp: provider.disableImplicitSignUp && !requestSignUp || provider.disableSignUp,
|
|
348
|
+
overrideUserInfo: provider.overrideUserInfo
|
|
349
|
+
});
|
|
350
|
+
if (result.error) return redirectOnError(result.error.split(" ").join("_"));
|
|
351
|
+
const { session, user } = result.data;
|
|
352
|
+
await setSessionCookie(ctx, {
|
|
353
|
+
session,
|
|
354
|
+
user
|
|
355
|
+
});
|
|
356
|
+
let toRedirectTo;
|
|
357
|
+
try {
|
|
358
|
+
toRedirectTo = (result.isRegister ? newUserURL || callbackURL : callbackURL).toString();
|
|
359
|
+
} catch {
|
|
360
|
+
toRedirectTo = result.isRegister ? newUserURL || callbackURL : callbackURL;
|
|
361
|
+
}
|
|
362
|
+
throw ctx.redirect(toRedirectTo);
|
|
363
|
+
}),
|
|
364
|
+
oAuth2LinkAccount: createAuthEndpoint("/oauth2/link", {
|
|
365
|
+
method: "POST",
|
|
366
|
+
body: z$1.object({
|
|
367
|
+
providerId: z$1.string(),
|
|
368
|
+
callbackURL: z$1.string(),
|
|
369
|
+
scopes: z$1.array(z$1.string()).meta({ description: "Additional scopes to request when linking the account" }).optional(),
|
|
370
|
+
errorCallbackURL: z$1.string().meta({ description: "The URL to redirect to if there is an error during the link process" }).optional()
|
|
371
|
+
}),
|
|
372
|
+
use: [sessionMiddleware],
|
|
373
|
+
metadata: { openapi: {
|
|
374
|
+
description: "Link an OAuth2 account to the current user session",
|
|
375
|
+
responses: { "200": {
|
|
376
|
+
description: "Authorization URL generated successfully for linking an OAuth2 account",
|
|
377
|
+
content: { "application/json": { schema: {
|
|
378
|
+
type: "object",
|
|
379
|
+
properties: {
|
|
380
|
+
url: {
|
|
381
|
+
type: "string",
|
|
382
|
+
format: "uri",
|
|
383
|
+
description: "The authorization URL to redirect the user to for linking the OAuth2 account"
|
|
384
|
+
},
|
|
385
|
+
redirect: {
|
|
386
|
+
type: "boolean",
|
|
387
|
+
description: "Indicates that the client should redirect to the provided URL",
|
|
388
|
+
enum: [true]
|
|
389
|
+
}
|
|
390
|
+
},
|
|
391
|
+
required: ["url", "redirect"]
|
|
392
|
+
} } }
|
|
393
|
+
} }
|
|
394
|
+
} }
|
|
395
|
+
}, async (c) => {
|
|
396
|
+
const session = c.context.session;
|
|
397
|
+
const provider = options.config.find((p) => p.providerId === c.body.providerId);
|
|
398
|
+
if (!provider) throw new APIError("NOT_FOUND", { message: BASE_ERROR_CODES.PROVIDER_NOT_FOUND });
|
|
399
|
+
const { providerId, clientId, clientSecret, redirectURI, authorizationUrl, discoveryUrl, pkce, scopes, prompt, accessType, authorizationUrlParams } = provider;
|
|
400
|
+
let finalAuthUrl = authorizationUrl;
|
|
401
|
+
if (!finalAuthUrl) {
|
|
402
|
+
if (!discoveryUrl) throw new APIError("BAD_REQUEST", { message: ERROR_CODES.INVALID_OAUTH_CONFIGURATION });
|
|
403
|
+
const discovery = await betterFetch(discoveryUrl, {
|
|
404
|
+
method: "GET",
|
|
405
|
+
headers: provider.discoveryHeaders,
|
|
406
|
+
onError(context) {
|
|
407
|
+
c.context.logger.error(context.error.message, context.error, { discoveryUrl });
|
|
408
|
+
}
|
|
409
|
+
});
|
|
410
|
+
if (discovery.data) finalAuthUrl = discovery.data.authorization_endpoint;
|
|
411
|
+
}
|
|
412
|
+
if (!finalAuthUrl) throw new APIError("BAD_REQUEST", { message: ERROR_CODES.INVALID_OAUTH_CONFIGURATION });
|
|
413
|
+
const state = await generateState(c, {
|
|
414
|
+
userId: session.user.id,
|
|
415
|
+
email: session.user.email
|
|
416
|
+
}, void 0);
|
|
417
|
+
const additionalParams = typeof authorizationUrlParams === "function" ? authorizationUrlParams(c) : authorizationUrlParams;
|
|
418
|
+
const url = await createAuthorizationURL({
|
|
419
|
+
id: providerId,
|
|
420
|
+
options: {
|
|
421
|
+
clientId,
|
|
422
|
+
clientSecret,
|
|
423
|
+
redirectURI: redirectURI || `${c.context.baseURL}/oauth2/callback/${providerId}`
|
|
424
|
+
},
|
|
425
|
+
authorizationEndpoint: finalAuthUrl,
|
|
426
|
+
state: state.state,
|
|
427
|
+
codeVerifier: pkce ? state.codeVerifier : void 0,
|
|
428
|
+
scopes: c.body.scopes || scopes || [],
|
|
429
|
+
redirectURI: redirectURI || `${c.context.baseURL}/oauth2/callback/${providerId}`,
|
|
430
|
+
prompt,
|
|
431
|
+
accessType,
|
|
432
|
+
additionalParams
|
|
433
|
+
});
|
|
434
|
+
return c.json({
|
|
435
|
+
url: url.toString(),
|
|
436
|
+
redirect: true
|
|
437
|
+
});
|
|
438
|
+
})
|
|
439
|
+
},
|
|
440
|
+
$ERROR_CODES: ERROR_CODES
|
|
441
|
+
};
|
|
442
|
+
};
|
|
443
|
+
|
|
444
|
+
//#endregion
|
|
445
|
+
export { genericOAuth as t };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { isDevelopment, isTest } from "@gatwech/core/env";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
|
|
4
|
+
//#region src/utils/get-request-ip.ts
|
|
5
|
+
const LOCALHOST_IP = "127.0.0.1";
|
|
6
|
+
function getIp(req, options) {
|
|
7
|
+
if (options.advanced?.ipAddress?.disableIpTracking) return null;
|
|
8
|
+
if (isTest() || isDevelopment()) return LOCALHOST_IP;
|
|
9
|
+
const headers = "headers" in req ? req.headers : req;
|
|
10
|
+
const ipHeaders = options.advanced?.ipAddress?.ipAddressHeaders || ["x-forwarded-for"];
|
|
11
|
+
for (const key of ipHeaders) {
|
|
12
|
+
const value = "get" in headers ? headers.get(key) : headers[key];
|
|
13
|
+
if (typeof value === "string") {
|
|
14
|
+
const ip = value.split(",")[0].trim();
|
|
15
|
+
if (isValidIP(ip)) return ip;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
function isValidIP(ip) {
|
|
21
|
+
if (z.ipv4().safeParse(ip).success) return true;
|
|
22
|
+
if (z.ipv6().safeParse(ip).success) return true;
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
//#endregion
|
|
27
|
+
export { getIp as t };
|