@sirketio/auth 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/_virtual/_rolldown/runtime.mjs +36 -0
- package/dist/adapter/index.d.mts +4 -0
- package/dist/adapter/index.mjs +7 -0
- package/dist/api/index.d.mts +3872 -0
- package/dist/api/index.mjs +206 -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 +18 -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 +204 -0
- package/dist/api/rate-limiter/index.mjs.map +1 -0
- package/dist/api/routes/account.d.mts +410 -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 +31 -0
- package/dist/api/routes/callback.mjs +179 -0
- package/dist/api/routes/callback.mjs.map +1 -0
- package/dist/api/routes/email-verification.d.mts +161 -0
- package/dist/api/routes/email-verification.mjs +299 -0
- package/dist/api/routes/email-verification.mjs.map +1 -0
- package/dist/api/routes/error.d.mts +28 -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 +36 -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 +182 -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 +415 -0
- package/dist/api/routes/session.mjs +483 -0
- package/dist/api/routes/session.mjs.map +1 -0
- package/dist/api/routes/sign-in.d.mts +171 -0
- package/dist/api/routes/sign-in.mjs +263 -0
- package/dist/api/routes/sign-in.mjs.map +1 -0
- package/dist/api/routes/sign-out.d.mts +36 -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 +160 -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 +445 -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 +18 -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 +45 -0
- package/dist/auth/base.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 +33 -0
- package/dist/client/index.mjs +21 -0
- package/dist/client/index.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 +65 -0
- package/dist/client/plugins/index.d.mts +53 -0
- package/dist/client/plugins/index.mjs +30 -0
- package/dist/client/plugins/infer-plugin.d.mts +16 -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 +128 -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/types.d.mts +41 -0
- package/dist/client/vanilla.d.mts +127 -0
- package/dist/client/vanilla.mjs +20 -0
- package/dist/client/vanilla.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 +83 -0
- package/dist/context/helpers.mjs.map +1 -0
- package/dist/context/init.mjs +20 -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 +121 -0
- package/dist/cookies/index.mjs +261 -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 +19 -0
- package/dist/db/adapter-base.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 +42 -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 +18 -0
- package/dist/db/index.mjs +34 -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 +49 -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 +53 -0
- package/dist/index.mjs +27 -0
- package/dist/integrations/next-js.d.mts +29 -0
- package/dist/integrations/next-js.mjs +85 -0
- package/dist/integrations/next-js.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 +48 -0
- package/dist/oauth2/link-account.mjs +143 -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 +96 -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 +911 -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 +76 -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 +29 -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 +841 -0
- package/dist/plugins/admin/routes.mjs.map +1 -0
- package/dist/plugins/admin/schema.d.mts +40 -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/api-key/adapter.mjs +468 -0
- package/dist/plugins/api-key/adapter.mjs.map +1 -0
- package/dist/plugins/api-key/client.d.mts +46 -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 +33 -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 +1251 -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 +224 -0
- package/dist/plugins/api-key/routes/verify-api-key.mjs.map +1 -0
- package/dist/plugins/api-key/schema.d.mts +199 -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 +45 -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 +21 -0
- package/dist/plugins/captcha/index.mjs +62 -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 +28 -0
- package/dist/plugins/captcha/verify-handlers/captchafox.mjs.map +1 -0
- package/dist/plugins/captcha/verify-handlers/cloudflare-turnstile.mjs +26 -0
- package/dist/plugins/captcha/verify-handlers/cloudflare-turnstile.mjs.map +1 -0
- package/dist/plugins/captcha/verify-handlers/google-recaptcha.mjs +30 -0
- package/dist/plugins/captcha/verify-handlers/google-recaptcha.mjs.map +1 -0
- package/dist/plugins/captcha/verify-handlers/h-captcha.mjs +28 -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 +17 -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 +72 -0
- package/dist/plugins/custom-session/index.mjs +78 -0
- package/dist/plugins/custom-session/index.mjs.map +1 -0
- package/dist/plugins/device-authorization/client.d.mts +17 -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 +424 -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 +21 -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 +11 -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 +428 -0
- package/dist/plugins/email-otp/index.mjs +130 -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 +631 -0
- package/dist/plugins/email-otp/routes.mjs.map +1 -0
- package/dist/plugins/email-otp/types.d.mts +86 -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 +33 -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 +16 -0
- package/dist/plugins/generic-oauth/error-codes.mjs +17 -0
- package/dist/plugins/generic-oauth/error-codes.mjs.map +1 -0
- package/dist/plugins/generic-oauth/index.d.mts +201 -0
- package/dist/plugins/generic-oauth/index.mjs +145 -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 +411 -0
- package/dist/plugins/generic-oauth/routes.mjs.map +1 -0
- package/dist/plugins/generic-oauth/types.d.mts +159 -0
- package/dist/plugins/haveibeenpwned/index.d.mts +46 -0
- package/dist/plugins/haveibeenpwned/index.mjs +57 -0
- package/dist/plugins/haveibeenpwned/index.mjs.map +1 -0
- package/dist/plugins/index.d.mts +65 -0
- package/dist/plugins/index.mjs +48 -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 +40 -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 +224 -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 +26 -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 +38 -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 +118 -0
- package/dist/plugins/last-login-method/index.mjs +76 -0
- package/dist/plugins/last-login-method/index.mjs.map +1 -0
- package/dist/plugins/magic-link/client.d.mts +10 -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 +193 -0
- package/dist/plugins/magic-link/index.mjs +177 -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 +458 -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 +19 -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 +9 -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 +235 -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 +97 -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 +51 -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 +12 -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 +702 -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 +160 -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 +174 -0
- package/dist/plugins/one-tap/client.mjs +188 -0
- package/dist/plugins/one-tap/client.mjs.map +1 -0
- package/dist/plugins/one-tap/index.d.mts +83 -0
- package/dist/plugins/one-tap/index.mjs +95 -0
- package/dist/plugins/one-tap/index.mjs.map +1 -0
- package/dist/plugins/one-time-token/client.d.mts +10 -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 +133 -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 +97 -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 +792 -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 +372 -0
- package/dist/plugins/organization/client.mjs +95 -0
- package/dist/plugins/organization/client.mjs.map +1 -0
- package/dist/plugins/organization/error-codes.d.mts +65 -0
- package/dist/plugins/organization/error-codes.mjs +66 -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 +394 -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 +17 -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 +394 -0
- package/dist/plugins/organization/routes/crud-access-control.mjs +678 -0
- package/dist/plugins/organization/routes/crud-access-control.mjs.map +1 -0
- package/dist/plugins/organization/routes/crud-invites.d.mts +1031 -0
- package/dist/plugins/organization/routes/crud-invites.mjs +551 -0
- package/dist/plugins/organization/routes/crud-invites.mjs.map +1 -0
- package/dist/plugins/organization/routes/crud-members.d.mts +940 -0
- package/dist/plugins/organization/routes/crud-members.mjs +466 -0
- package/dist/plugins/organization/routes/crud-members.mjs.map +1 -0
- package/dist/plugins/organization/routes/crud-org.d.mts +708 -0
- package/dist/plugins/organization/routes/crud-org.mjs +423 -0
- package/dist/plugins/organization/routes/crud-org.mjs.map +1 -0
- package/dist/plugins/organization/routes/crud-team.d.mts +1071 -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 +677 -0
- package/dist/plugins/phone-number/client.d.mts +31 -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 +20 -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 +318 -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 +472 -0
- package/dist/plugins/phone-number/routes.mjs.map +1 -0
- package/dist/plugins/phone-number/schema.d.mts +23 -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/two-factor/backup-codes/index.d.mts +279 -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 +55 -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 +17 -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 +670 -0
- package/dist/plugins/two-factor/index.mjs +228 -0
- package/dist/plugins/two-factor/index.mjs.map +1 -0
- package/dist/plugins/two-factor/otp/index.d.mts +216 -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 +41 -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 +210 -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 +73 -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 +85 -0
- package/dist/plugins/two-factor/verify-two-factor.mjs.map +1 -0
- package/dist/plugins/username/client.d.mts +26 -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 +16 -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 +251 -0
- package/dist/plugins/username/index.mjs +234 -0
- package/dist/plugins/username/index.mjs.map +1 -0
- package/dist/plugins/username/schema.d.mts +33 -0
- package/dist/plugins/username/schema.mjs +26 -0
- package/dist/plugins/username/schema.mjs.map +1 -0
- package/dist/providers/index.d.mts +1 -0
- package/dist/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/types/adapter.d.mts +2 -0
- package/dist/types/api.d.mts +29 -0
- package/dist/types/auth.d.mts +29 -0
- package/dist/types/helper.d.mts +10 -0
- package/dist/types/index.d.mts +11 -0
- package/dist/types/index.mjs +1 -0
- package/dist/types/models.d.mts +11 -0
- package/dist/types/plugins.d.mts +20 -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/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 +4 -0
- package/dist/utils/index.mjs +6 -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 +9 -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.d.mts +8 -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 +428 -0
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { parseSetCookieHeader } from "../../cookies/cookie-utils.mjs";
|
|
2
|
+
import { getSession } from "../../api/routes/session.mjs";
|
|
3
|
+
import "../../api/index.mjs";
|
|
4
|
+
import { getEndpointResponse } from "../../utils/plugin-helper.mjs";
|
|
5
|
+
import { createAuthEndpoint, createAuthMiddleware } from "@better-auth/core/api";
|
|
6
|
+
import * as z from "zod";
|
|
7
|
+
|
|
8
|
+
//#region src/plugins/custom-session/index.ts
|
|
9
|
+
const getSessionQuerySchema = z.optional(z.object({
|
|
10
|
+
disableCookieCache: z.boolean().meta({ description: "Disable cookie cache and fetch session from database" }).or(z.string().transform((v) => v === "true")).optional(),
|
|
11
|
+
disableRefresh: z.boolean().meta({ description: "Disable session refresh. Useful for checking session status, without updating the session" }).optional()
|
|
12
|
+
}));
|
|
13
|
+
const customSession = (fn, options, pluginOptions) => {
|
|
14
|
+
return {
|
|
15
|
+
id: "custom-session",
|
|
16
|
+
hooks: { after: [{
|
|
17
|
+
matcher: (ctx) => ctx.path === "/multi-session/list-device-sessions" && (pluginOptions?.shouldMutateListDeviceSessionsEndpoint ?? false),
|
|
18
|
+
handler: createAuthMiddleware(async (ctx) => {
|
|
19
|
+
const response = await getEndpointResponse(ctx);
|
|
20
|
+
if (!response) return;
|
|
21
|
+
const newResponse = await Promise.all(response.map(async (v) => await fn(v, ctx)));
|
|
22
|
+
return ctx.json(newResponse);
|
|
23
|
+
})
|
|
24
|
+
}] },
|
|
25
|
+
endpoints: { getSession: createAuthEndpoint("/get-session", {
|
|
26
|
+
method: "GET",
|
|
27
|
+
query: getSessionQuerySchema,
|
|
28
|
+
metadata: {
|
|
29
|
+
CUSTOM_SESSION: true,
|
|
30
|
+
openapi: {
|
|
31
|
+
description: "Get custom session data",
|
|
32
|
+
responses: { "200": {
|
|
33
|
+
description: "Success",
|
|
34
|
+
content: { "application/json": { schema: {
|
|
35
|
+
type: "array",
|
|
36
|
+
nullable: true,
|
|
37
|
+
items: { $ref: "#/components/schemas/Session" }
|
|
38
|
+
} } }
|
|
39
|
+
} }
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
requireHeaders: true
|
|
43
|
+
}, async (ctx) => {
|
|
44
|
+
const session = await getSession()({
|
|
45
|
+
...ctx,
|
|
46
|
+
asResponse: false,
|
|
47
|
+
headers: ctx.headers,
|
|
48
|
+
returnHeaders: true
|
|
49
|
+
}).catch((e) => {
|
|
50
|
+
return null;
|
|
51
|
+
});
|
|
52
|
+
if (!session?.response) return ctx.json(null);
|
|
53
|
+
const fnResult = await fn(session.response, ctx);
|
|
54
|
+
for (const cookieStr of session.headers.getSetCookie()) parseSetCookieHeader(cookieStr).forEach((attrs, name) => {
|
|
55
|
+
ctx.setCookie(name, attrs.value, {
|
|
56
|
+
maxAge: attrs["max-age"],
|
|
57
|
+
expires: attrs.expires,
|
|
58
|
+
domain: attrs.domain,
|
|
59
|
+
path: attrs.path,
|
|
60
|
+
secure: attrs.secure,
|
|
61
|
+
httpOnly: attrs.httponly,
|
|
62
|
+
sameSite: attrs.samesite
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
session.headers.delete("set-cookie");
|
|
66
|
+
session.headers.forEach((value, key) => {
|
|
67
|
+
ctx.setHeader(key, value);
|
|
68
|
+
});
|
|
69
|
+
return ctx.json(fnResult);
|
|
70
|
+
}) },
|
|
71
|
+
$Infer: { Session: {} },
|
|
72
|
+
options: pluginOptions
|
|
73
|
+
};
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
//#endregion
|
|
77
|
+
export { customSession };
|
|
78
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../../src/plugins/custom-session/index.ts"],"sourcesContent":["import type {\n\tBetterAuthOptions,\n\tBetterAuthPlugin,\n\tGenericEndpointContext,\n} from \"@better-auth/core\";\nimport {\n\tcreateAuthEndpoint,\n\tcreateAuthMiddleware,\n} from \"@better-auth/core/api\";\nimport type { Session, User } from \"@better-auth/core/db\";\nimport * as z from \"zod\";\nimport { getSession } from \"../../api\";\nimport { parseSetCookieHeader } from \"../../cookies/cookie-utils\";\nimport { getEndpointResponse } from \"../../utils/plugin-helper\";\n\ndeclare module \"@better-auth/core\" {\n\tinterface BetterAuthPluginRegistry<AuthOptions, Options> {\n\t\t\"custom-session\": {\n\t\t\tcreator: typeof customSession;\n\t\t};\n\t}\n}\n\nconst getSessionQuerySchema = z.optional(\n\tz.object({\n\t\t/**\n\t\t * If cookie cache is enabled, it will disable the cache\n\t\t * and fetch the session from the database\n\t\t */\n\t\tdisableCookieCache: z\n\t\t\t.boolean()\n\t\t\t.meta({\n\t\t\t\tdescription: \"Disable cookie cache and fetch session from database\",\n\t\t\t})\n\t\t\t.or(z.string().transform((v) => v === \"true\"))\n\t\t\t.optional(),\n\t\tdisableRefresh: z\n\t\t\t.boolean()\n\t\t\t.meta({\n\t\t\t\tdescription:\n\t\t\t\t\t\"Disable session refresh. Useful for checking session status, without updating the session\",\n\t\t\t})\n\t\t\t.optional(),\n\t}),\n);\n\nexport type CustomSessionPluginOptions = {\n\t/**\n\t * This option is used to determine if the list-device-sessions endpoint should be mutated to the custom session data.\n\t * @default false\n\t */\n\tshouldMutateListDeviceSessionsEndpoint?: boolean | undefined;\n};\n\nexport const customSession = <\n\tReturns extends Record<string, any>,\n\tO extends BetterAuthOptions = BetterAuthOptions,\n>(\n\tfn: (\n\t\tsession: {\n\t\t\tuser: User<O[\"user\"], O[\"plugins\"]>;\n\t\t\tsession: Session<O[\"session\"], O[\"plugins\"]>;\n\t\t},\n\t\tctx: GenericEndpointContext,\n\t) => Promise<Returns>,\n\toptions?: O | undefined,\n\tpluginOptions?: CustomSessionPluginOptions | undefined,\n) => {\n\treturn {\n\t\tid: \"custom-session\",\n\t\thooks: {\n\t\t\tafter: [\n\t\t\t\t{\n\t\t\t\t\tmatcher: (ctx) =>\n\t\t\t\t\t\tctx.path === \"/multi-session/list-device-sessions\" &&\n\t\t\t\t\t\t(pluginOptions?.shouldMutateListDeviceSessionsEndpoint ?? false),\n\t\t\t\t\thandler: createAuthMiddleware(async (ctx) => {\n\t\t\t\t\t\tconst response = await getEndpointResponse<[]>(ctx);\n\t\t\t\t\t\tif (!response) return;\n\t\t\t\t\t\tconst newResponse = await Promise.all(\n\t\t\t\t\t\t\tresponse.map(async (v) => await fn(v, ctx)),\n\t\t\t\t\t\t);\n\t\t\t\t\t\treturn ctx.json(newResponse);\n\t\t\t\t\t}),\n\t\t\t\t},\n\t\t\t],\n\t\t},\n\t\tendpoints: {\n\t\t\tgetSession: createAuthEndpoint(\n\t\t\t\t\"/get-session\",\n\t\t\t\t{\n\t\t\t\t\tmethod: \"GET\",\n\t\t\t\t\tquery: getSessionQuerySchema,\n\t\t\t\t\tmetadata: {\n\t\t\t\t\t\tCUSTOM_SESSION: true,\n\t\t\t\t\t\topenapi: {\n\t\t\t\t\t\t\tdescription: \"Get custom session data\",\n\t\t\t\t\t\t\tresponses: {\n\t\t\t\t\t\t\t\t\"200\": {\n\t\t\t\t\t\t\t\t\tdescription: \"Success\",\n\t\t\t\t\t\t\t\t\tcontent: {\n\t\t\t\t\t\t\t\t\t\t\"application/json\": {\n\t\t\t\t\t\t\t\t\t\t\tschema: {\n\t\t\t\t\t\t\t\t\t\t\t\ttype: \"array\",\n\t\t\t\t\t\t\t\t\t\t\t\tnullable: true,\n\t\t\t\t\t\t\t\t\t\t\t\titems: {\n\t\t\t\t\t\t\t\t\t\t\t\t\t$ref: \"#/components/schemas/Session\",\n\t\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\trequireHeaders: true,\n\t\t\t\t},\n\t\t\t\tasync (ctx): Promise<Returns | null> => {\n\t\t\t\t\tconst session = await getSession()({\n\t\t\t\t\t\t...ctx,\n\t\t\t\t\t\tasResponse: false,\n\t\t\t\t\t\theaders: ctx.headers,\n\t\t\t\t\t\treturnHeaders: true,\n\t\t\t\t\t}).catch((e) => {\n\t\t\t\t\t\treturn null;\n\t\t\t\t\t});\n\t\t\t\t\tif (!session?.response) {\n\t\t\t\t\t\treturn ctx.json(null);\n\t\t\t\t\t}\n\t\t\t\t\tconst fnResult = await fn(session.response as any, ctx);\n\n\t\t\t\t\tfor (const cookieStr of session.headers.getSetCookie()) {\n\t\t\t\t\t\tconst parsed = parseSetCookieHeader(cookieStr);\n\t\t\t\t\t\tparsed.forEach((attrs, name) => {\n\t\t\t\t\t\t\tctx.setCookie(name, attrs.value, {\n\t\t\t\t\t\t\t\tmaxAge: attrs[\"max-age\"],\n\t\t\t\t\t\t\t\texpires: attrs.expires,\n\t\t\t\t\t\t\t\tdomain: attrs.domain,\n\t\t\t\t\t\t\t\tpath: attrs.path,\n\t\t\t\t\t\t\t\tsecure: attrs.secure,\n\t\t\t\t\t\t\t\thttpOnly: attrs.httponly,\n\t\t\t\t\t\t\t\tsameSite: attrs.samesite,\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t\tsession.headers.delete(\"set-cookie\");\n\n\t\t\t\t\tsession.headers.forEach((value, key) => {\n\t\t\t\t\t\tctx.setHeader(key, value);\n\t\t\t\t\t});\n\t\t\t\t\treturn ctx.json(fnResult);\n\t\t\t\t},\n\t\t\t),\n\t\t},\n\t\t$Infer: {\n\t\t\tSession: {} as Awaited<ReturnType<typeof fn>>,\n\t\t},\n\t\toptions: pluginOptions,\n\t} satisfies BetterAuthPlugin;\n};\n"],"mappings":";;;;;;;;AAuBA,MAAM,wBAAwB,EAAE,SAC/B,EAAE,OAAO;CAKR,oBAAoB,EAClB,SAAS,CACT,KAAK,EACL,aAAa,wDACb,CAAC,CACD,GAAG,EAAE,QAAQ,CAAC,WAAW,MAAM,MAAM,OAAO,CAAC,CAC7C,UAAU;CACZ,gBAAgB,EACd,SAAS,CACT,KAAK,EACL,aACC,6FACD,CAAC,CACD,UAAU;CACZ,CAAC,CACF;AAUD,MAAa,iBAIZ,IAOA,SACA,kBACI;AACJ,QAAO;EACN,IAAI;EACJ,OAAO,EACN,OAAO,CACN;GACC,UAAU,QACT,IAAI,SAAS,0CACZ,eAAe,0CAA0C;GAC3D,SAAS,qBAAqB,OAAO,QAAQ;IAC5C,MAAM,WAAW,MAAM,oBAAwB,IAAI;AACnD,QAAI,CAAC,SAAU;IACf,MAAM,cAAc,MAAM,QAAQ,IACjC,SAAS,IAAI,OAAO,MAAM,MAAM,GAAG,GAAG,IAAI,CAAC,CAC3C;AACD,WAAO,IAAI,KAAK,YAAY;KAC3B;GACF,CACD,EACD;EACD,WAAW,EACV,YAAY,mBACX,gBACA;GACC,QAAQ;GACR,OAAO;GACP,UAAU;IACT,gBAAgB;IAChB,SAAS;KACR,aAAa;KACb,WAAW,EACV,OAAO;MACN,aAAa;MACb,SAAS,EACR,oBAAoB,EACnB,QAAQ;OACP,MAAM;OACN,UAAU;OACV,OAAO,EACN,MAAM,gCACN;OACD,EACD,EACD;MACD,EACD;KACD;IACD;GACD,gBAAgB;GAChB,EACD,OAAO,QAAiC;GACvC,MAAM,UAAU,MAAM,YAAY,CAAC;IAClC,GAAG;IACH,YAAY;IACZ,SAAS,IAAI;IACb,eAAe;IACf,CAAC,CAAC,OAAO,MAAM;AACf,WAAO;KACN;AACF,OAAI,CAAC,SAAS,SACb,QAAO,IAAI,KAAK,KAAK;GAEtB,MAAM,WAAW,MAAM,GAAG,QAAQ,UAAiB,IAAI;AAEvD,QAAK,MAAM,aAAa,QAAQ,QAAQ,cAAc,CAErD,CADe,qBAAqB,UAAU,CACvC,SAAS,OAAO,SAAS;AAC/B,QAAI,UAAU,MAAM,MAAM,OAAO;KAChC,QAAQ,MAAM;KACd,SAAS,MAAM;KACf,QAAQ,MAAM;KACd,MAAM,MAAM;KACZ,QAAQ,MAAM;KACd,UAAU,MAAM;KAChB,UAAU,MAAM;KAChB,CAAC;KACD;AAEH,WAAQ,QAAQ,OAAO,aAAa;AAEpC,WAAQ,QAAQ,SAAS,OAAO,QAAQ;AACvC,QAAI,UAAU,KAAK,MAAM;KACxB;AACF,UAAO,IAAI,KAAK,SAAS;IAE1B,EACD;EACD,QAAQ,EACP,SAAS,EAAE,EACX;EACD,SAAS;EACT"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { deviceAuthorization } from "./index.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/plugins/device-authorization/client.d.ts
|
|
4
|
+
declare const deviceAuthorizationClient: () => {
|
|
5
|
+
id: "device-authorization";
|
|
6
|
+
$InferServerPlugin: ReturnType<typeof deviceAuthorization>;
|
|
7
|
+
pathMethods: {
|
|
8
|
+
"/device/code": "POST";
|
|
9
|
+
"/device/token": "POST";
|
|
10
|
+
"/device": "GET";
|
|
11
|
+
"/device/approve": "POST";
|
|
12
|
+
"/device/deny": "POST";
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
//#endregion
|
|
16
|
+
export { deviceAuthorizationClient };
|
|
17
|
+
//# sourceMappingURL=client.d.mts.map
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
//#region src/plugins/device-authorization/client.ts
|
|
2
|
+
const deviceAuthorizationClient = () => {
|
|
3
|
+
return {
|
|
4
|
+
id: "device-authorization",
|
|
5
|
+
$InferServerPlugin: {},
|
|
6
|
+
pathMethods: {
|
|
7
|
+
"/device/code": "POST",
|
|
8
|
+
"/device/token": "POST",
|
|
9
|
+
"/device": "GET",
|
|
10
|
+
"/device/approve": "POST",
|
|
11
|
+
"/device/deny": "POST"
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
//#endregion
|
|
17
|
+
export { deviceAuthorizationClient };
|
|
18
|
+
//# sourceMappingURL=client.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.mjs","names":[],"sources":["../../../src/plugins/device-authorization/client.ts"],"sourcesContent":["import type { BetterAuthClientPlugin } from \"@better-auth/core\";\nimport type { deviceAuthorization } from \".\";\n\nexport const deviceAuthorizationClient = () => {\n\treturn {\n\t\tid: \"device-authorization\",\n\t\t$InferServerPlugin: {} as ReturnType<typeof deviceAuthorization>,\n\t\tpathMethods: {\n\t\t\t\"/device/code\": \"POST\",\n\t\t\t\"/device/token\": \"POST\",\n\t\t\t\"/device\": \"GET\",\n\t\t\t\"/device/approve\": \"POST\",\n\t\t\t\"/device/deny\": \"POST\",\n\t\t},\n\t} satisfies BetterAuthClientPlugin;\n};\n"],"mappings":";AAGA,MAAa,kCAAkC;AAC9C,QAAO;EACN,IAAI;EACJ,oBAAoB,EAAE;EACtB,aAAa;GACZ,gBAAgB;GAChB,iBAAiB;GACjB,WAAW;GACX,mBAAmB;GACnB,gBAAgB;GAChB;EACD"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { defineErrorCodes } from "@better-auth/core/utils/error-codes";
|
|
2
|
+
|
|
3
|
+
//#region src/plugins/device-authorization/error-codes.ts
|
|
4
|
+
const DEVICE_AUTHORIZATION_ERROR_CODES = defineErrorCodes({
|
|
5
|
+
INVALID_DEVICE_CODE: "Invalid device code",
|
|
6
|
+
EXPIRED_DEVICE_CODE: "Device code has expired",
|
|
7
|
+
EXPIRED_USER_CODE: "User code has expired",
|
|
8
|
+
AUTHORIZATION_PENDING: "Authorization pending",
|
|
9
|
+
ACCESS_DENIED: "Access denied",
|
|
10
|
+
INVALID_USER_CODE: "Invalid user code",
|
|
11
|
+
DEVICE_CODE_ALREADY_PROCESSED: "Device code already processed",
|
|
12
|
+
POLLING_TOO_FREQUENTLY: "Polling too frequently",
|
|
13
|
+
USER_NOT_FOUND: "User not found",
|
|
14
|
+
FAILED_TO_CREATE_SESSION: "Failed to create session",
|
|
15
|
+
INVALID_DEVICE_CODE_STATUS: "Invalid device code status",
|
|
16
|
+
AUTHENTICATION_REQUIRED: "Authentication required"
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
//#endregion
|
|
20
|
+
export { DEVICE_AUTHORIZATION_ERROR_CODES };
|
|
21
|
+
//# sourceMappingURL=error-codes.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error-codes.mjs","names":[],"sources":["../../../src/plugins/device-authorization/error-codes.ts"],"sourcesContent":["import { defineErrorCodes } from \"@better-auth/core/utils/error-codes\";\n\nexport const DEVICE_AUTHORIZATION_ERROR_CODES = defineErrorCodes({\n\tINVALID_DEVICE_CODE: \"Invalid device code\",\n\tEXPIRED_DEVICE_CODE: \"Device code has expired\",\n\tEXPIRED_USER_CODE: \"User code has expired\",\n\tAUTHORIZATION_PENDING: \"Authorization pending\",\n\tACCESS_DENIED: \"Access denied\",\n\tINVALID_USER_CODE: \"Invalid user code\",\n\tDEVICE_CODE_ALREADY_PROCESSED: \"Device code already processed\",\n\tPOLLING_TOO_FREQUENTLY: \"Polling too frequently\",\n\tUSER_NOT_FOUND: \"User not found\",\n\tFAILED_TO_CREATE_SESSION: \"Failed to create session\",\n\tINVALID_DEVICE_CODE_STATUS: \"Invalid device code status\",\n\tAUTHENTICATION_REQUIRED: \"Authentication required\",\n});\n"],"mappings":";;;AAEA,MAAa,mCAAmC,iBAAiB;CAChE,qBAAqB;CACrB,qBAAqB;CACrB,mBAAmB;CACnB,uBAAuB;CACvB,eAAe;CACf,mBAAmB;CACnB,+BAA+B;CAC/B,wBAAwB;CACxB,gBAAgB;CAChB,0BAA0B;CAC1B,4BAA4B;CAC5B,yBAAyB;CACzB,CAAC"}
|
|
@@ -0,0 +1,424 @@
|
|
|
1
|
+
import { TimeString, ms, sec } from "../../utils/time.mjs";
|
|
2
|
+
import * as _better_auth_core_utils_error_codes0 from "@better-auth/core/utils/error-codes";
|
|
3
|
+
import * as better_call0 from "better-call";
|
|
4
|
+
import * as z from "zod";
|
|
5
|
+
|
|
6
|
+
//#region src/plugins/device-authorization/index.d.ts
|
|
7
|
+
declare module "@better-auth/core" {
|
|
8
|
+
interface BetterAuthPluginRegistry<AuthOptions, Options> {
|
|
9
|
+
"device-authorization": {
|
|
10
|
+
creator: typeof deviceAuthorization;
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
declare const deviceAuthorizationOptionsSchema: z.ZodObject<{
|
|
15
|
+
expiresIn: z.ZodDefault<z.ZodCustom<TimeString, TimeString>>;
|
|
16
|
+
interval: z.ZodDefault<z.ZodCustom<TimeString, TimeString>>;
|
|
17
|
+
deviceCodeLength: z.ZodDefault<z.ZodNumber>;
|
|
18
|
+
userCodeLength: z.ZodDefault<z.ZodNumber>;
|
|
19
|
+
generateDeviceCode: z.ZodOptional<z.ZodCustom<() => string | Promise<string>, () => string | Promise<string>>>;
|
|
20
|
+
generateUserCode: z.ZodOptional<z.ZodCustom<() => string | Promise<string>, () => string | Promise<string>>>;
|
|
21
|
+
validateClient: z.ZodOptional<z.ZodCustom<(clientId: string) => boolean | Promise<boolean>, (clientId: string) => boolean | Promise<boolean>>>;
|
|
22
|
+
onDeviceAuthRequest: z.ZodOptional<z.ZodCustom<(clientId: string, scope: string | undefined) => void | Promise<void>, (clientId: string, scope: string | undefined) => void | Promise<void>>>;
|
|
23
|
+
verificationUri: z.ZodOptional<z.ZodString>;
|
|
24
|
+
schema: z.ZodCustom<{
|
|
25
|
+
deviceCode?: {
|
|
26
|
+
modelName?: string | undefined;
|
|
27
|
+
fields?: {
|
|
28
|
+
deviceCode?: string | undefined;
|
|
29
|
+
userCode?: string | undefined;
|
|
30
|
+
userId?: string | undefined;
|
|
31
|
+
expiresAt?: string | undefined;
|
|
32
|
+
status?: string | undefined;
|
|
33
|
+
lastPolledAt?: string | undefined;
|
|
34
|
+
pollingInterval?: string | undefined;
|
|
35
|
+
clientId?: string | undefined;
|
|
36
|
+
scope?: string | undefined;
|
|
37
|
+
} | undefined;
|
|
38
|
+
} | undefined;
|
|
39
|
+
}, {
|
|
40
|
+
deviceCode?: {
|
|
41
|
+
modelName?: string | undefined;
|
|
42
|
+
fields?: {
|
|
43
|
+
deviceCode?: string | undefined;
|
|
44
|
+
userCode?: string | undefined;
|
|
45
|
+
userId?: string | undefined;
|
|
46
|
+
expiresAt?: string | undefined;
|
|
47
|
+
status?: string | undefined;
|
|
48
|
+
lastPolledAt?: string | undefined;
|
|
49
|
+
pollingInterval?: string | undefined;
|
|
50
|
+
clientId?: string | undefined;
|
|
51
|
+
scope?: string | undefined;
|
|
52
|
+
} | undefined;
|
|
53
|
+
} | undefined;
|
|
54
|
+
}>;
|
|
55
|
+
}, z.core.$strip>;
|
|
56
|
+
type DeviceAuthorizationOptions = z.infer<typeof deviceAuthorizationOptionsSchema>;
|
|
57
|
+
declare const deviceAuthorization: (options?: Partial<DeviceAuthorizationOptions>) => {
|
|
58
|
+
id: "device-authorization";
|
|
59
|
+
schema: {
|
|
60
|
+
deviceCode: {
|
|
61
|
+
fields: {
|
|
62
|
+
deviceCode: {
|
|
63
|
+
type: "string";
|
|
64
|
+
required: true;
|
|
65
|
+
};
|
|
66
|
+
userCode: {
|
|
67
|
+
type: "string";
|
|
68
|
+
required: true;
|
|
69
|
+
};
|
|
70
|
+
userId: {
|
|
71
|
+
type: "string";
|
|
72
|
+
required: false;
|
|
73
|
+
};
|
|
74
|
+
expiresAt: {
|
|
75
|
+
type: "date";
|
|
76
|
+
required: true;
|
|
77
|
+
};
|
|
78
|
+
status: {
|
|
79
|
+
type: "string";
|
|
80
|
+
required: true;
|
|
81
|
+
};
|
|
82
|
+
lastPolledAt: {
|
|
83
|
+
type: "date";
|
|
84
|
+
required: false;
|
|
85
|
+
};
|
|
86
|
+
pollingInterval: {
|
|
87
|
+
type: "number";
|
|
88
|
+
required: false;
|
|
89
|
+
};
|
|
90
|
+
clientId: {
|
|
91
|
+
type: "string";
|
|
92
|
+
required: false;
|
|
93
|
+
};
|
|
94
|
+
scope: {
|
|
95
|
+
type: "string";
|
|
96
|
+
required: false;
|
|
97
|
+
};
|
|
98
|
+
};
|
|
99
|
+
};
|
|
100
|
+
};
|
|
101
|
+
endpoints: {
|
|
102
|
+
deviceCode: better_call0.StrictEndpoint<"/device/code", {
|
|
103
|
+
method: "POST";
|
|
104
|
+
body: z.ZodObject<{
|
|
105
|
+
client_id: z.ZodString;
|
|
106
|
+
scope: z.ZodOptional<z.ZodString>;
|
|
107
|
+
}, z.core.$strip>;
|
|
108
|
+
error: z.ZodObject<{
|
|
109
|
+
error: z.ZodEnum<{
|
|
110
|
+
invalid_request: "invalid_request";
|
|
111
|
+
invalid_client: "invalid_client";
|
|
112
|
+
}>;
|
|
113
|
+
error_description: z.ZodString;
|
|
114
|
+
}, z.core.$strip>;
|
|
115
|
+
metadata: {
|
|
116
|
+
openapi: {
|
|
117
|
+
description: string;
|
|
118
|
+
responses: {
|
|
119
|
+
200: {
|
|
120
|
+
description: string;
|
|
121
|
+
content: {
|
|
122
|
+
"application/json": {
|
|
123
|
+
schema: {
|
|
124
|
+
type: "object";
|
|
125
|
+
properties: {
|
|
126
|
+
device_code: {
|
|
127
|
+
type: string;
|
|
128
|
+
description: string;
|
|
129
|
+
};
|
|
130
|
+
user_code: {
|
|
131
|
+
type: string;
|
|
132
|
+
description: string;
|
|
133
|
+
};
|
|
134
|
+
verification_uri: {
|
|
135
|
+
type: string;
|
|
136
|
+
format: string;
|
|
137
|
+
description: string;
|
|
138
|
+
};
|
|
139
|
+
verification_uri_complete: {
|
|
140
|
+
type: string;
|
|
141
|
+
format: string;
|
|
142
|
+
description: string;
|
|
143
|
+
};
|
|
144
|
+
expires_in: {
|
|
145
|
+
type: string;
|
|
146
|
+
description: string;
|
|
147
|
+
};
|
|
148
|
+
interval: {
|
|
149
|
+
type: string;
|
|
150
|
+
description: string;
|
|
151
|
+
};
|
|
152
|
+
};
|
|
153
|
+
};
|
|
154
|
+
};
|
|
155
|
+
};
|
|
156
|
+
};
|
|
157
|
+
400: {
|
|
158
|
+
description: string;
|
|
159
|
+
content: {
|
|
160
|
+
"application/json": {
|
|
161
|
+
schema: {
|
|
162
|
+
type: "object";
|
|
163
|
+
properties: {
|
|
164
|
+
error: {
|
|
165
|
+
type: string;
|
|
166
|
+
enum: string[];
|
|
167
|
+
};
|
|
168
|
+
error_description: {
|
|
169
|
+
type: string;
|
|
170
|
+
};
|
|
171
|
+
};
|
|
172
|
+
};
|
|
173
|
+
};
|
|
174
|
+
};
|
|
175
|
+
};
|
|
176
|
+
};
|
|
177
|
+
};
|
|
178
|
+
};
|
|
179
|
+
}, {
|
|
180
|
+
device_code: string;
|
|
181
|
+
user_code: string;
|
|
182
|
+
verification_uri: string;
|
|
183
|
+
verification_uri_complete: string;
|
|
184
|
+
expires_in: number;
|
|
185
|
+
interval: number;
|
|
186
|
+
}>;
|
|
187
|
+
deviceToken: better_call0.StrictEndpoint<"/device/token", {
|
|
188
|
+
method: "POST";
|
|
189
|
+
body: z.ZodObject<{
|
|
190
|
+
grant_type: z.ZodLiteral<"urn:ietf:params:oauth:grant-type:device_code">;
|
|
191
|
+
device_code: z.ZodString;
|
|
192
|
+
client_id: z.ZodString;
|
|
193
|
+
}, z.core.$strip>;
|
|
194
|
+
error: z.ZodObject<{
|
|
195
|
+
error: z.ZodEnum<{
|
|
196
|
+
invalid_request: "invalid_request";
|
|
197
|
+
invalid_grant: "invalid_grant";
|
|
198
|
+
authorization_pending: "authorization_pending";
|
|
199
|
+
slow_down: "slow_down";
|
|
200
|
+
expired_token: "expired_token";
|
|
201
|
+
access_denied: "access_denied";
|
|
202
|
+
}>;
|
|
203
|
+
error_description: z.ZodString;
|
|
204
|
+
}, z.core.$strip>;
|
|
205
|
+
metadata: {
|
|
206
|
+
openapi: {
|
|
207
|
+
description: string;
|
|
208
|
+
responses: {
|
|
209
|
+
200: {
|
|
210
|
+
description: string;
|
|
211
|
+
content: {
|
|
212
|
+
"application/json": {
|
|
213
|
+
schema: {
|
|
214
|
+
type: "object";
|
|
215
|
+
properties: {
|
|
216
|
+
session: {
|
|
217
|
+
$ref: string;
|
|
218
|
+
};
|
|
219
|
+
user: {
|
|
220
|
+
$ref: string;
|
|
221
|
+
};
|
|
222
|
+
};
|
|
223
|
+
};
|
|
224
|
+
};
|
|
225
|
+
};
|
|
226
|
+
};
|
|
227
|
+
400: {
|
|
228
|
+
description: string;
|
|
229
|
+
content: {
|
|
230
|
+
"application/json": {
|
|
231
|
+
schema: {
|
|
232
|
+
type: "object";
|
|
233
|
+
properties: {
|
|
234
|
+
error: {
|
|
235
|
+
type: string;
|
|
236
|
+
enum: string[];
|
|
237
|
+
};
|
|
238
|
+
error_description: {
|
|
239
|
+
type: string;
|
|
240
|
+
};
|
|
241
|
+
};
|
|
242
|
+
};
|
|
243
|
+
};
|
|
244
|
+
};
|
|
245
|
+
};
|
|
246
|
+
};
|
|
247
|
+
};
|
|
248
|
+
};
|
|
249
|
+
}, {
|
|
250
|
+
access_token: string;
|
|
251
|
+
token_type: string;
|
|
252
|
+
expires_in: number;
|
|
253
|
+
scope: string;
|
|
254
|
+
}>;
|
|
255
|
+
deviceVerify: better_call0.StrictEndpoint<"/device", {
|
|
256
|
+
method: "GET";
|
|
257
|
+
query: z.ZodObject<{
|
|
258
|
+
user_code: z.ZodString;
|
|
259
|
+
}, z.core.$strip>;
|
|
260
|
+
error: z.ZodObject<{
|
|
261
|
+
error: z.ZodEnum<{
|
|
262
|
+
invalid_request: "invalid_request";
|
|
263
|
+
}>;
|
|
264
|
+
error_description: z.ZodString;
|
|
265
|
+
}, z.core.$strip>;
|
|
266
|
+
metadata: {
|
|
267
|
+
openapi: {
|
|
268
|
+
description: string;
|
|
269
|
+
responses: {
|
|
270
|
+
200: {
|
|
271
|
+
description: string;
|
|
272
|
+
content: {
|
|
273
|
+
"application/json": {
|
|
274
|
+
schema: {
|
|
275
|
+
type: "object";
|
|
276
|
+
properties: {
|
|
277
|
+
user_code: {
|
|
278
|
+
type: string;
|
|
279
|
+
description: string;
|
|
280
|
+
};
|
|
281
|
+
status: {
|
|
282
|
+
type: string;
|
|
283
|
+
enum: string[];
|
|
284
|
+
description: string;
|
|
285
|
+
};
|
|
286
|
+
};
|
|
287
|
+
};
|
|
288
|
+
};
|
|
289
|
+
};
|
|
290
|
+
};
|
|
291
|
+
};
|
|
292
|
+
};
|
|
293
|
+
};
|
|
294
|
+
}, {
|
|
295
|
+
user_code: string;
|
|
296
|
+
status: string;
|
|
297
|
+
}>;
|
|
298
|
+
deviceApprove: better_call0.StrictEndpoint<"/device/approve", {
|
|
299
|
+
method: "POST";
|
|
300
|
+
body: z.ZodObject<{
|
|
301
|
+
userCode: z.ZodString;
|
|
302
|
+
}, z.core.$strip>;
|
|
303
|
+
error: z.ZodObject<{
|
|
304
|
+
error: z.ZodEnum<{
|
|
305
|
+
invalid_request: "invalid_request";
|
|
306
|
+
expired_token: "expired_token";
|
|
307
|
+
access_denied: "access_denied";
|
|
308
|
+
device_code_already_processed: "device_code_already_processed";
|
|
309
|
+
unauthorized: "unauthorized";
|
|
310
|
+
}>;
|
|
311
|
+
error_description: z.ZodString;
|
|
312
|
+
}, z.core.$strip>;
|
|
313
|
+
requireHeaders: true;
|
|
314
|
+
metadata: {
|
|
315
|
+
openapi: {
|
|
316
|
+
description: string;
|
|
317
|
+
responses: {
|
|
318
|
+
200: {
|
|
319
|
+
description: string;
|
|
320
|
+
content: {
|
|
321
|
+
"application/json": {
|
|
322
|
+
schema: {
|
|
323
|
+
type: "object";
|
|
324
|
+
properties: {
|
|
325
|
+
success: {
|
|
326
|
+
type: string;
|
|
327
|
+
};
|
|
328
|
+
};
|
|
329
|
+
};
|
|
330
|
+
};
|
|
331
|
+
};
|
|
332
|
+
};
|
|
333
|
+
};
|
|
334
|
+
};
|
|
335
|
+
};
|
|
336
|
+
}, {
|
|
337
|
+
success: boolean;
|
|
338
|
+
}>;
|
|
339
|
+
deviceDeny: better_call0.StrictEndpoint<"/device/deny", {
|
|
340
|
+
method: "POST";
|
|
341
|
+
body: z.ZodObject<{
|
|
342
|
+
userCode: z.ZodString;
|
|
343
|
+
}, z.core.$strip>;
|
|
344
|
+
error: z.ZodObject<{
|
|
345
|
+
error: z.ZodEnum<{
|
|
346
|
+
invalid_request: "invalid_request";
|
|
347
|
+
expired_token: "expired_token";
|
|
348
|
+
access_denied: "access_denied";
|
|
349
|
+
unauthorized: "unauthorized";
|
|
350
|
+
}>;
|
|
351
|
+
error_description: z.ZodString;
|
|
352
|
+
}, z.core.$strip>;
|
|
353
|
+
requireHeaders: true;
|
|
354
|
+
metadata: {
|
|
355
|
+
openapi: {
|
|
356
|
+
description: string;
|
|
357
|
+
responses: {
|
|
358
|
+
200: {
|
|
359
|
+
description: string;
|
|
360
|
+
content: {
|
|
361
|
+
"application/json": {
|
|
362
|
+
schema: {
|
|
363
|
+
type: "object";
|
|
364
|
+
properties: {
|
|
365
|
+
success: {
|
|
366
|
+
type: string;
|
|
367
|
+
};
|
|
368
|
+
};
|
|
369
|
+
};
|
|
370
|
+
};
|
|
371
|
+
};
|
|
372
|
+
};
|
|
373
|
+
};
|
|
374
|
+
};
|
|
375
|
+
};
|
|
376
|
+
}, {
|
|
377
|
+
success: boolean;
|
|
378
|
+
}>;
|
|
379
|
+
};
|
|
380
|
+
$ERROR_CODES: {
|
|
381
|
+
USER_NOT_FOUND: _better_auth_core_utils_error_codes0.RawError<"USER_NOT_FOUND">;
|
|
382
|
+
FAILED_TO_CREATE_SESSION: _better_auth_core_utils_error_codes0.RawError<"FAILED_TO_CREATE_SESSION">;
|
|
383
|
+
INVALID_DEVICE_CODE: _better_auth_core_utils_error_codes0.RawError<"INVALID_DEVICE_CODE">;
|
|
384
|
+
EXPIRED_DEVICE_CODE: _better_auth_core_utils_error_codes0.RawError<"EXPIRED_DEVICE_CODE">;
|
|
385
|
+
EXPIRED_USER_CODE: _better_auth_core_utils_error_codes0.RawError<"EXPIRED_USER_CODE">;
|
|
386
|
+
AUTHORIZATION_PENDING: _better_auth_core_utils_error_codes0.RawError<"AUTHORIZATION_PENDING">;
|
|
387
|
+
ACCESS_DENIED: _better_auth_core_utils_error_codes0.RawError<"ACCESS_DENIED">;
|
|
388
|
+
INVALID_USER_CODE: _better_auth_core_utils_error_codes0.RawError<"INVALID_USER_CODE">;
|
|
389
|
+
DEVICE_CODE_ALREADY_PROCESSED: _better_auth_core_utils_error_codes0.RawError<"DEVICE_CODE_ALREADY_PROCESSED">;
|
|
390
|
+
POLLING_TOO_FREQUENTLY: _better_auth_core_utils_error_codes0.RawError<"POLLING_TOO_FREQUENTLY">;
|
|
391
|
+
INVALID_DEVICE_CODE_STATUS: _better_auth_core_utils_error_codes0.RawError<"INVALID_DEVICE_CODE_STATUS">;
|
|
392
|
+
AUTHENTICATION_REQUIRED: _better_auth_core_utils_error_codes0.RawError<"AUTHENTICATION_REQUIRED">;
|
|
393
|
+
};
|
|
394
|
+
options: Partial<{
|
|
395
|
+
expiresIn: TimeString;
|
|
396
|
+
interval: TimeString;
|
|
397
|
+
deviceCodeLength: number;
|
|
398
|
+
userCodeLength: number;
|
|
399
|
+
schema: {
|
|
400
|
+
deviceCode?: {
|
|
401
|
+
modelName?: string | undefined;
|
|
402
|
+
fields?: {
|
|
403
|
+
deviceCode?: string | undefined;
|
|
404
|
+
userCode?: string | undefined;
|
|
405
|
+
userId?: string | undefined;
|
|
406
|
+
expiresAt?: string | undefined;
|
|
407
|
+
status?: string | undefined;
|
|
408
|
+
lastPolledAt?: string | undefined;
|
|
409
|
+
pollingInterval?: string | undefined;
|
|
410
|
+
clientId?: string | undefined;
|
|
411
|
+
scope?: string | undefined;
|
|
412
|
+
} | undefined;
|
|
413
|
+
} | undefined;
|
|
414
|
+
};
|
|
415
|
+
generateDeviceCode?: (() => string | Promise<string>) | undefined;
|
|
416
|
+
generateUserCode?: (() => string | Promise<string>) | undefined;
|
|
417
|
+
validateClient?: ((clientId: string) => boolean | Promise<boolean>) | undefined;
|
|
418
|
+
onDeviceAuthRequest?: ((clientId: string, scope: string | undefined) => void | Promise<void>) | undefined;
|
|
419
|
+
verificationUri?: string | undefined;
|
|
420
|
+
}>;
|
|
421
|
+
};
|
|
422
|
+
//#endregion
|
|
423
|
+
export { DeviceAuthorizationOptions, TimeString, deviceAuthorization, deviceAuthorizationOptionsSchema, ms, sec };
|
|
424
|
+
//# sourceMappingURL=index.d.mts.map
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { mergeSchema } from "../../db/schema.mjs";
|
|
2
|
+
import "../../db/index.mjs";
|
|
3
|
+
import { ms } from "../../utils/time.mjs";
|
|
4
|
+
import { DEVICE_AUTHORIZATION_ERROR_CODES } from "./error-codes.mjs";
|
|
5
|
+
import { deviceApprove, deviceCode, deviceDeny, deviceToken, deviceVerify } from "./routes.mjs";
|
|
6
|
+
import { schema } from "./schema.mjs";
|
|
7
|
+
import * as z from "zod";
|
|
8
|
+
|
|
9
|
+
//#region src/plugins/device-authorization/index.ts
|
|
10
|
+
const timeStringSchema = z.custom((val) => {
|
|
11
|
+
if (typeof val !== "string") return false;
|
|
12
|
+
try {
|
|
13
|
+
ms(val);
|
|
14
|
+
return true;
|
|
15
|
+
} catch {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
}, { message: "Invalid time string format. Use formats like '30m', '5s', '1h', etc." });
|
|
19
|
+
const deviceAuthorizationOptionsSchema = z.object({
|
|
20
|
+
expiresIn: timeStringSchema.default("30m").describe("Time in seconds until the device code expires. Use formats like '30m', '5s', '1h', etc."),
|
|
21
|
+
interval: timeStringSchema.default("5s").describe("Time in seconds between polling attempts. Use formats like '30m', '5s', '1h', etc."),
|
|
22
|
+
deviceCodeLength: z.number().int().positive().default(40).describe("Length of the device code to be generated. Default is 40 characters."),
|
|
23
|
+
userCodeLength: z.number().int().positive().default(8).describe("Length of the user code to be generated. Default is 8 characters."),
|
|
24
|
+
generateDeviceCode: z.custom((val) => typeof val === "function", { message: "generateDeviceCode must be a function that returns a string or a promise that resolves to a string." }).optional().describe("Function to generate a device code. If not provided, a default random string generator will be used."),
|
|
25
|
+
generateUserCode: z.custom((val) => typeof val === "function", { message: "generateUserCode must be a function that returns a string or a promise that resolves to a string." }).optional().describe("Function to generate a user code. If not provided, a default random string generator will be used."),
|
|
26
|
+
validateClient: z.custom((val) => typeof val === "function", { message: "validateClient must be a function that returns a boolean or a promise that resolves to a boolean." }).optional().describe("Function to validate the client ID. If not provided, no validation will be performed."),
|
|
27
|
+
onDeviceAuthRequest: z.custom((val) => typeof val === "function", { message: "onDeviceAuthRequest must be a function that returns void or a promise that resolves to void." }).optional().describe("Function to handle device authorization requests. If not provided, no additional actions will be taken."),
|
|
28
|
+
verificationUri: z.string().optional().describe("The URI where users verify their device code. Can be an absolute URL (https://example.com/device) or relative path (/custom-path). This will be returned as verification_uri in the device code response. If not provided, defaults to /device."),
|
|
29
|
+
schema: z.custom(() => true)
|
|
30
|
+
});
|
|
31
|
+
const deviceAuthorization = (options = {}) => {
|
|
32
|
+
const opts = deviceAuthorizationOptionsSchema.parse(options);
|
|
33
|
+
return {
|
|
34
|
+
id: "device-authorization",
|
|
35
|
+
schema: mergeSchema(schema, options?.schema),
|
|
36
|
+
endpoints: {
|
|
37
|
+
deviceCode: deviceCode(opts),
|
|
38
|
+
deviceToken: deviceToken(opts),
|
|
39
|
+
deviceVerify,
|
|
40
|
+
deviceApprove,
|
|
41
|
+
deviceDeny
|
|
42
|
+
},
|
|
43
|
+
$ERROR_CODES: DEVICE_AUTHORIZATION_ERROR_CODES,
|
|
44
|
+
options
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
//#endregion
|
|
49
|
+
export { deviceAuthorization, deviceAuthorizationOptionsSchema };
|
|
50
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../../src/plugins/device-authorization/index.ts"],"sourcesContent":["import type { BetterAuthPlugin } from \"@better-auth/core\";\nimport * as z from \"zod\";\nimport { mergeSchema } from \"../../db\";\nimport type { InferOptionSchema } from \"../../types/plugins\";\nimport type { TimeString } from \"../../utils/time\";\nimport { ms } from \"../../utils/time\";\nimport { DEVICE_AUTHORIZATION_ERROR_CODES } from \"./error-codes\";\nimport {\n\tdeviceApprove,\n\tdeviceCode,\n\tdeviceDeny,\n\tdeviceToken,\n\tdeviceVerify,\n} from \"./routes\";\nimport { schema } from \"./schema\";\n\ndeclare module \"@better-auth/core\" {\n\tinterface BetterAuthPluginRegistry<AuthOptions, Options> {\n\t\t\"device-authorization\": {\n\t\t\tcreator: typeof deviceAuthorization;\n\t\t};\n\t}\n}\n\nconst timeStringSchema = z.custom<TimeString>(\n\t(val) => {\n\t\tif (typeof val !== \"string\") return false;\n\t\ttry {\n\t\t\tms(val as TimeString);\n\t\t\treturn true;\n\t\t} catch {\n\t\t\treturn false;\n\t\t}\n\t},\n\t{\n\t\tmessage:\n\t\t\t\"Invalid time string format. Use formats like '30m', '5s', '1h', etc.\",\n\t},\n);\n\nexport const deviceAuthorizationOptionsSchema = z.object({\n\texpiresIn: timeStringSchema\n\t\t.default(\"30m\")\n\t\t.describe(\n\t\t\t\"Time in seconds until the device code expires. Use formats like '30m', '5s', '1h', etc.\",\n\t\t),\n\tinterval: timeStringSchema\n\t\t.default(\"5s\")\n\t\t.describe(\n\t\t\t\"Time in seconds between polling attempts. Use formats like '30m', '5s', '1h', etc.\",\n\t\t),\n\tdeviceCodeLength: z\n\t\t.number()\n\t\t.int()\n\t\t.positive()\n\t\t.default(40)\n\t\t.describe(\n\t\t\t\"Length of the device code to be generated. Default is 40 characters.\",\n\t\t),\n\tuserCodeLength: z\n\t\t.number()\n\t\t.int()\n\t\t.positive()\n\t\t.default(8)\n\t\t.describe(\n\t\t\t\"Length of the user code to be generated. Default is 8 characters.\",\n\t\t),\n\tgenerateDeviceCode: z\n\t\t.custom<() => string | Promise<string>>(\n\t\t\t(val) => typeof val === \"function\",\n\t\t\t{\n\t\t\t\tmessage:\n\t\t\t\t\t\"generateDeviceCode must be a function that returns a string or a promise that resolves to a string.\",\n\t\t\t},\n\t\t)\n\t\t.optional()\n\t\t.describe(\n\t\t\t\"Function to generate a device code. If not provided, a default random string generator will be used.\",\n\t\t),\n\tgenerateUserCode: z\n\t\t.custom<() => string | Promise<string>>(\n\t\t\t(val) => typeof val === \"function\",\n\t\t\t{\n\t\t\t\tmessage:\n\t\t\t\t\t\"generateUserCode must be a function that returns a string or a promise that resolves to a string.\",\n\t\t\t},\n\t\t)\n\t\t.optional()\n\t\t.describe(\n\t\t\t\"Function to generate a user code. If not provided, a default random string generator will be used.\",\n\t\t),\n\tvalidateClient: z\n\t\t.custom<(clientId: string) => boolean | Promise<boolean>>(\n\t\t\t(val) => typeof val === \"function\",\n\t\t\t{\n\t\t\t\tmessage:\n\t\t\t\t\t\"validateClient must be a function that returns a boolean or a promise that resolves to a boolean.\",\n\t\t\t},\n\t\t)\n\t\t.optional()\n\t\t.describe(\n\t\t\t\"Function to validate the client ID. If not provided, no validation will be performed.\",\n\t\t),\n\tonDeviceAuthRequest: z\n\t\t.custom<\n\t\t\t(clientId: string, scope: string | undefined) => void | Promise<void>\n\t\t>((val) => typeof val === \"function\", {\n\t\t\tmessage:\n\t\t\t\t\"onDeviceAuthRequest must be a function that returns void or a promise that resolves to void.\",\n\t\t})\n\t\t.optional()\n\t\t.describe(\n\t\t\t\"Function to handle device authorization requests. If not provided, no additional actions will be taken.\",\n\t\t),\n\tverificationUri: z\n\t\t.string()\n\t\t.optional()\n\t\t.describe(\n\t\t\t\"The URI where users verify their device code. Can be an absolute URL (https://example.com/device) or relative path (/custom-path). This will be returned as verification_uri in the device code response. If not provided, defaults to /device.\",\n\t\t),\n\tschema: z.custom<InferOptionSchema<typeof schema>>(() => true),\n});\n\nexport type DeviceAuthorizationOptions = z.infer<\n\ttypeof deviceAuthorizationOptionsSchema\n>;\n\nexport const deviceAuthorization = (\n\toptions: Partial<DeviceAuthorizationOptions> = {},\n) => {\n\tconst opts = deviceAuthorizationOptionsSchema.parse(options);\n\n\treturn {\n\t\tid: \"device-authorization\",\n\t\tschema: mergeSchema(schema, options?.schema),\n\t\tendpoints: {\n\t\t\tdeviceCode: deviceCode(opts),\n\t\t\tdeviceToken: deviceToken(opts),\n\t\t\tdeviceVerify,\n\t\t\tdeviceApprove,\n\t\t\tdeviceDeny,\n\t\t},\n\t\t$ERROR_CODES: DEVICE_AUTHORIZATION_ERROR_CODES,\n\t\toptions,\n\t} satisfies BetterAuthPlugin;\n};\n\nexport type * from \"../../utils/time\";\n"],"mappings":";;;;;;;;;AAwBA,MAAM,mBAAmB,EAAE,QACzB,QAAQ;AACR,KAAI,OAAO,QAAQ,SAAU,QAAO;AACpC,KAAI;AACH,KAAG,IAAkB;AACrB,SAAO;SACA;AACP,SAAO;;GAGT,EACC,SACC,wEACD,CACD;AAED,MAAa,mCAAmC,EAAE,OAAO;CACxD,WAAW,iBACT,QAAQ,MAAM,CACd,SACA,0FACA;CACF,UAAU,iBACR,QAAQ,KAAK,CACb,SACA,qFACA;CACF,kBAAkB,EAChB,QAAQ,CACR,KAAK,CACL,UAAU,CACV,QAAQ,GAAG,CACX,SACA,uEACA;CACF,gBAAgB,EACd,QAAQ,CACR,KAAK,CACL,UAAU,CACV,QAAQ,EAAE,CACV,SACA,oEACA;CACF,oBAAoB,EAClB,QACC,QAAQ,OAAO,QAAQ,YACxB,EACC,SACC,uGACD,CACD,CACA,UAAU,CACV,SACA,uGACA;CACF,kBAAkB,EAChB,QACC,QAAQ,OAAO,QAAQ,YACxB,EACC,SACC,qGACD,CACD,CACA,UAAU,CACV,SACA,qGACA;CACF,gBAAgB,EACd,QACC,QAAQ,OAAO,QAAQ,YACxB,EACC,SACC,qGACD,CACD,CACA,UAAU,CACV,SACA,wFACA;CACF,qBAAqB,EACnB,QAEE,QAAQ,OAAO,QAAQ,YAAY,EACrC,SACC,gGACD,CAAC,CACD,UAAU,CACV,SACA,0GACA;CACF,iBAAiB,EACf,QAAQ,CACR,UAAU,CACV,SACA,kPACA;CACF,QAAQ,EAAE,aAA+C,KAAK;CAC9D,CAAC;AAMF,MAAa,uBACZ,UAA+C,EAAE,KAC7C;CACJ,MAAM,OAAO,iCAAiC,MAAM,QAAQ;AAE5D,QAAO;EACN,IAAI;EACJ,QAAQ,YAAY,QAAQ,SAAS,OAAO;EAC5C,WAAW;GACV,YAAY,WAAW,KAAK;GAC5B,aAAa,YAAY,KAAK;GAC9B;GACA;GACA;GACA;EACD,cAAc;EACd;EACA"}
|