@warlock.js/auth 5.11.0 → 5.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +65 -0
- package/README.md +88 -86
- package/esm/commands/auth-cleanup-command.mjs +1 -1
- package/esm/commands/auth-cleanup-command.mjs.map +1 -1
- package/esm/contracts/index.d.mts +4 -2
- package/esm/contracts/providers.d.mts +101 -0
- package/esm/contracts/providers.d.mts.map +1 -0
- package/esm/contracts/request-locals.d.mts +43 -0
- package/esm/contracts/request-locals.d.mts.map +1 -0
- package/esm/contracts/types.d.mts +159 -1
- package/esm/contracts/types.d.mts.map +1 -1
- package/esm/contracts/types.mjs.map +1 -1
- package/esm/errors/auth-provider-sdk-missing.error.d.mts +17 -0
- package/esm/errors/auth-provider-sdk-missing.error.d.mts.map +1 -0
- package/esm/errors/auth-provider-sdk-missing.error.mjs +22 -0
- package/esm/errors/auth-provider-sdk-missing.error.mjs.map +1 -0
- package/esm/errors/email-not-verified.error.d.mts +16 -0
- package/esm/errors/email-not-verified.error.d.mts.map +1 -0
- package/esm/errors/email-not-verified.error.mjs +20 -0
- package/esm/errors/email-not-verified.error.mjs.map +1 -0
- package/esm/errors/index.d.mts +7 -0
- package/esm/errors/index.mjs +9 -0
- package/esm/errors/invalid-one-time-token.error.d.mts +17 -0
- package/esm/errors/invalid-one-time-token.error.d.mts.map +1 -0
- package/esm/errors/invalid-one-time-token.error.mjs +21 -0
- package/esm/errors/invalid-one-time-token.error.mjs.map +1 -0
- package/esm/errors/invalid-passkey.error.d.mts +18 -0
- package/esm/errors/invalid-passkey.error.d.mts.map +1 -0
- package/esm/errors/invalid-passkey.error.mjs +23 -0
- package/esm/errors/invalid-passkey.error.mjs.map +1 -0
- package/esm/errors/invalid-provider-callback.error.d.mts +18 -0
- package/esm/errors/invalid-provider-callback.error.d.mts.map +1 -0
- package/esm/errors/invalid-provider-callback.error.mjs +23 -0
- package/esm/errors/invalid-provider-callback.error.mjs.map +1 -0
- package/esm/errors/notifications-unavailable.error.d.mts +15 -0
- package/esm/errors/notifications-unavailable.error.d.mts.map +1 -0
- package/esm/errors/notifications-unavailable.error.mjs +20 -0
- package/esm/errors/notifications-unavailable.error.mjs.map +1 -0
- package/esm/errors/provider-email-not-verified.error.d.mts +16 -0
- package/esm/errors/provider-email-not-verified.error.d.mts.map +1 -0
- package/esm/errors/provider-email-not-verified.error.mjs +20 -0
- package/esm/errors/provider-email-not-verified.error.mjs.map +1 -0
- package/esm/index.d.mts +31 -3
- package/esm/index.mjs +29 -1
- package/esm/middleware/auth.middleware.d.mts.map +1 -1
- package/esm/middleware/auth.middleware.mjs +13 -2
- package/esm/middleware/auth.middleware.mjs.map +1 -1
- package/esm/middleware/csrf-origin-check.d.mts +40 -0
- package/esm/middleware/csrf-origin-check.d.mts.map +1 -0
- package/esm/middleware/csrf-origin-check.mjs +105 -0
- package/esm/middleware/csrf-origin-check.mjs.map +1 -0
- package/esm/middleware/index.d.mts +5 -1
- package/esm/middleware/index.mjs +4 -0
- package/esm/middleware/one-time-token-throttle.middleware.d.mts +36 -0
- package/esm/middleware/one-time-token-throttle.middleware.d.mts.map +1 -0
- package/esm/middleware/one-time-token-throttle.middleware.mjs +53 -0
- package/esm/middleware/one-time-token-throttle.middleware.mjs.map +1 -0
- package/esm/middleware/otp-throttle.middleware.d.mts +30 -0
- package/esm/middleware/otp-throttle.middleware.d.mts.map +1 -0
- package/esm/middleware/otp-throttle.middleware.mjs +45 -0
- package/esm/middleware/otp-throttle.middleware.mjs.map +1 -0
- package/esm/middleware/require-verified-email.middleware.d.mts +18 -0
- package/esm/middleware/require-verified-email.middleware.d.mts.map +1 -0
- package/esm/middleware/require-verified-email.middleware.mjs +24 -0
- package/esm/middleware/require-verified-email.middleware.mjs.map +1 -0
- package/esm/models/access-token/access-token.model.d.mts +8 -0
- package/esm/models/access-token/access-token.model.d.mts.map +1 -1
- package/esm/models/access-token/access-token.model.mjs +3 -0
- package/esm/models/access-token/access-token.model.mjs.map +1 -1
- package/esm/models/index.d.mts +3 -1
- package/esm/models/index.d.mts.map +1 -1
- package/esm/models/index.mjs +16 -1
- package/esm/models/index.mjs.map +1 -1
- package/esm/models/one-time-token/index.d.mts +1 -0
- package/esm/models/one-time-token/index.mjs +3 -0
- package/esm/models/one-time-token/migration.mjs +31 -0
- package/esm/models/one-time-token/migration.mjs.map +1 -0
- package/esm/models/one-time-token/one-time-token.model.d.mts +173 -0
- package/esm/models/one-time-token/one-time-token.model.d.mts.map +1 -0
- package/esm/models/one-time-token/one-time-token.model.mjs +151 -0
- package/esm/models/one-time-token/one-time-token.model.mjs.map +1 -0
- package/esm/models/passkey-credential/index.d.mts +1 -0
- package/esm/models/passkey-credential/index.mjs +3 -0
- package/esm/models/passkey-credential/migration.mjs +25 -0
- package/esm/models/passkey-credential/migration.mjs.map +1 -0
- package/esm/models/passkey-credential/passkey-credential.model.d.mts +108 -0
- package/esm/models/passkey-credential/passkey-credential.model.d.mts.map +1 -0
- package/esm/models/passkey-credential/passkey-credential.model.mjs +70 -0
- package/esm/models/passkey-credential/passkey-credential.model.mjs.map +1 -0
- package/esm/models/provider-account/index.d.mts +1 -0
- package/esm/models/provider-account/index.mjs +3 -0
- package/esm/models/provider-account/migration.mjs +25 -0
- package/esm/models/provider-account/migration.mjs.map +1 -0
- package/esm/models/provider-account/provider-account.model.d.mts +75 -0
- package/esm/models/provider-account/provider-account.model.d.mts.map +1 -0
- package/esm/models/provider-account/provider-account.model.mjs +55 -0
- package/esm/models/provider-account/provider-account.model.mjs.map +1 -0
- package/esm/models/refresh-token/refresh-token.model.d.mts +7 -0
- package/esm/models/refresh-token/refresh-token.model.d.mts.map +1 -1
- package/esm/models/refresh-token/refresh-token.model.mjs +3 -0
- package/esm/models/refresh-token/refresh-token.model.mjs.map +1 -1
- package/esm/otp/index.d.mts +1 -0
- package/esm/otp/index.mjs +3 -0
- package/esm/otp/otp.d.mts +38 -0
- package/esm/otp/otp.d.mts.map +1 -0
- package/esm/otp/otp.mjs +105 -0
- package/esm/otp/otp.mjs.map +1 -0
- package/esm/passkeys/index.d.mts +3 -0
- package/esm/passkeys/index.mjs +4 -0
- package/esm/passkeys/passkey-authentication.d.mts +33 -0
- package/esm/passkeys/passkey-authentication.d.mts.map +1 -0
- package/esm/passkeys/passkey-authentication.mjs +93 -0
- package/esm/passkeys/passkey-authentication.mjs.map +1 -0
- package/esm/passkeys/passkey-challenges.mjs +53 -0
- package/esm/passkeys/passkey-challenges.mjs.map +1 -0
- package/esm/passkeys/passkey-registration.d.mts +29 -0
- package/esm/passkeys/passkey-registration.d.mts.map +1 -0
- package/esm/passkeys/passkey-registration.mjs +88 -0
- package/esm/passkeys/passkey-registration.mjs.map +1 -0
- package/esm/passkeys/simplewebauthn.d.mts +21 -0
- package/esm/passkeys/simplewebauthn.d.mts.map +1 -0
- package/esm/passkeys/simplewebauthn.mjs +13 -0
- package/esm/passkeys/simplewebauthn.mjs.map +1 -0
- package/esm/providers/google-provider.d.mts +40 -0
- package/esm/providers/google-provider.d.mts.map +1 -0
- package/esm/providers/google-provider.mjs +105 -0
- package/esm/providers/google-provider.mjs.map +1 -0
- package/esm/providers/index.d.mts +2 -0
- package/esm/providers/index.mjs +4 -0
- package/esm/providers/provider-login.d.mts +43 -0
- package/esm/providers/provider-login.d.mts.map +1 -0
- package/esm/providers/provider-login.mjs +86 -0
- package/esm/providers/provider-login.mjs.map +1 -0
- package/esm/providers/provider-state-cookie.mjs +63 -0
- package/esm/providers/provider-state-cookie.mjs.map +1 -0
- package/esm/providers/resolve-provider-user.mjs +45 -0
- package/esm/providers/resolve-provider-user.mjs.map +1 -0
- package/esm/services/auth-config.mjs +84 -0
- package/esm/services/auth-config.mjs.map +1 -1
- package/esm/services/auth.service.d.mts +59 -2
- package/esm/services/auth.service.d.mts.map +1 -1
- package/esm/services/auth.service.mjs +86 -1
- package/esm/services/auth.service.mjs.map +1 -1
- package/esm/services/current-user.d.mts +21 -0
- package/esm/services/current-user.d.mts.map +1 -0
- package/esm/services/current-user.mjs +24 -0
- package/esm/services/current-user.mjs.map +1 -0
- package/esm/services/email-verification.d.mts +35 -0
- package/esm/services/email-verification.d.mts.map +1 -0
- package/esm/services/email-verification.mjs +55 -0
- package/esm/services/email-verification.mjs.map +1 -0
- package/esm/services/index.d.mts +5 -1
- package/esm/services/index.mjs +4 -0
- package/esm/services/one-time-tokens.d.mts +32 -0
- package/esm/services/one-time-tokens.d.mts.map +1 -0
- package/esm/services/one-time-tokens.mjs +56 -0
- package/esm/services/one-time-tokens.mjs.map +1 -0
- package/esm/services/optional-peer.mjs +37 -0
- package/esm/services/optional-peer.mjs.map +1 -0
- package/esm/services/password-reset.d.mts +34 -0
- package/esm/services/password-reset.d.mts.map +1 -0
- package/esm/services/password-reset.mjs +81 -0
- package/esm/services/password-reset.mjs.map +1 -0
- package/esm/services/token-notifications.mjs +87 -0
- package/esm/services/token-notifications.mjs.map +1 -0
- package/esm/utils/auth-error-codes.d.mts +48 -1
- package/esm/utils/auth-error-codes.d.mts.map +1 -1
- package/esm/utils/auth-error-codes.mjs +41 -0
- package/esm/utils/auth-error-codes.mjs.map +1 -1
- package/esm/utils/index.mjs +1 -0
- package/esm/utils/safe-equal.d.mts +6 -0
- package/esm/utils/safe-equal.d.mts.map +1 -0
- package/esm/utils/safe-equal.mjs +13 -0
- package/esm/utils/safe-equal.mjs.map +1 -0
- package/llms-full.txt +402 -29
- package/llms.txt +2 -0
- package/package.json +21 -7
- package/skills/handle-login-and-logout/SKILL.md +1 -1
- package/skills/login-with-providers/SKILL.md +154 -0
- package/skills/manage-tokens/SKILL.md +7 -1
- package/skills/overview/SKILL.md +1 -1
- package/skills/protect-routes/SKILL.md +71 -13
- package/skills/register-user/SKILL.md +6 -8
- package/skills/run-auth-commands/SKILL.md +1 -1
- package/skills/verify-email-and-reset-password/SKILL.md +137 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.mjs","names":[],"sources":["../../../../../../../auth/src/contracts/types.ts"],"sourcesContent":["import { type ChildModel } from \"@warlock.js/cascade\";\r\nimport { type Algorithm } from \"fast-jwt\";\r\nimport type { AccessToken } from \"../models/access-token\";\r\nimport type { Auth } from \"../models/auth.model\";\r\nimport type { RefreshToken } from \"../models/refresh-token\";\r\n\r\n/**\r\n * Symbol to indicate no expiration for tokens\r\n * Use this when you explicitly want tokens to never expire\r\n *\r\n * @example\r\n * ```typescript\r\n * // src/config/auth.ts\r\n * import { NO_EXPIRATION, type AuthConfigurations } from \"@warlock.js/auth\";\r\n *\r\n * const authConfigurations: AuthConfigurations = {\r\n * accessToken: {\r\n * secret: env(\"JWT_SECRET\"),\r\n * expiresIn: NO_EXPIRATION, // Token expires within 100 years\r\n * },\r\n * };\r\n *\r\n * export default authConfigurations;\r\n * ```\r\n */\r\nexport const NO_EXPIRATION = \"100y\";\r\n\r\n/**\r\n * Behavior when logout is called without a refresh token\r\n * - \"revoke-all\": Revoke all refresh tokens for the user (secure default)\r\n * - \"error\": Return an error requiring the refresh token\r\n */\r\nexport type LogoutWithoutTokenBehavior = \"revoke-all\" | \"error\";\r\n\r\n/** The single request credential source an auth middleware instance accepts. */\r\nexport type TokenFrom = \"header\" | `cookie:${string}`;\r\n\r\n/** Application policy that decides whether a resolved user may authenticate. */\r\nexport type CanAuthenticate = (user: Auth) => boolean | Promise<boolean>;\r\n\r\n/** Password credentials plus the application-defined identity fields. */\r\nexport type AuthCredentials = Record<string, unknown> & {\r\n password: string;\r\n};\r\n\r\n/**\r\n * Access-token configuration.\r\n *\r\n * `secret` may also be supplied via the deprecated `jwt.secret` (resolved by a\r\n * backward-compatible shim); one of the two is required at runtime.\r\n */\r\nexport type AccessTokenConfig = {\r\n /**\r\n * Override the persisted access-token model — extend {@link AccessToken} to\r\n * add columns (e.g. a tenant key) or rename them, then register the subclass\r\n * here. Defaults to the package's `AccessToken`.\r\n */\r\n model?: typeof AccessToken;\r\n /**\r\n * Secret used to sign access tokens.\r\n */\r\n secret?: string;\r\n /**\r\n * JWT algorithm.\r\n * @default \"HS256\"\r\n */\r\n algorithm?: Algorithm;\r\n /**\r\n * Access-token lifetime — a duration string `ms` parses to a **positive**\r\n * number of milliseconds. A value `ms` cannot parse (`\"30dayz\"`), a\r\n * non-positive one (`\"0d\"`), or a bare number throws naming this key on the\r\n * first token issue: each of them would otherwise sign a token with no `exp`\r\n * claim at all.\r\n * @example \"1h\" or NO_EXPIRATION\r\n * @default \"1h\"\r\n */\r\n expiresIn?: string;\r\n};\r\n\r\n/**\r\n * Refresh-token configuration.\r\n */\r\nexport type RefreshTokenConfig = {\r\n /**\r\n * Override the persisted refresh-token model — extend {@link RefreshToken}.\r\n * Defaults to the package's `RefreshToken`.\r\n */\r\n model?: typeof RefreshToken;\r\n /**\r\n * Enable refresh tokens.\r\n * @default true\r\n */\r\n enabled?: boolean;\r\n /**\r\n * Separate secret for refresh tokens (recommended for security). Falls back\r\n * to the access-token secret when omitted.\r\n */\r\n secret?: string;\r\n /**\r\n * Refresh-token lifetime — a duration string `ms` parses to a **positive**\r\n * number of milliseconds; an unusable value throws naming this key on issue\r\n * (see {@link AccessTokenConfig.expiresIn}).\r\n * @example \"7d\" or \"1w\"\r\n * @default \"7d\"\r\n */\r\n expiresIn?: string;\r\n /**\r\n * Rotate the refresh token on each use (old token revoked, replay detected).\r\n * @default true\r\n */\r\n rotation?: boolean;\r\n /**\r\n * Maximum active refresh tokens per user; the oldest are revoked past it.\r\n * @default 5\r\n */\r\n maxPerUser?: number;\r\n /**\r\n * Behavior when logout is called without a refresh token.\r\n * @default \"revoke-all\"\r\n */\r\n logoutWithoutToken?: LogoutWithoutTokenBehavior;\r\n};\r\n\r\n/**\r\n * Legacy JWT configuration shape. Still honored by the resolver shim with a\r\n * deprecation warning.\r\n *\r\n * @deprecated Use the top-level `accessToken` / `refreshToken` blocks.\r\n */\r\nexport type LegacyJwtConfig = {\r\n secret?: string;\r\n algorithm?: Algorithm;\r\n expiresIn?: string;\r\n refresh?: {\r\n secret?: string;\r\n enabled?: boolean;\r\n expiresIn?: string;\r\n rotation?: boolean;\r\n maxPerUser?: number;\r\n logoutWithoutToken?: LogoutWithoutTokenBehavior;\r\n };\r\n};\r\n\r\n/**\r\n * Page-route auth-failure behavior. When a guarded PAGE route (a React-SSR page,\r\n * `route.isPage`) rejects a logged-out browser, this decides whether it redirects\r\n * to a login page instead of returning the API-style JSON 401.\r\n *\r\n * Read at runtime through `authConfig.pageAuth` (`auth.pageAuth.*`). API routes\r\n * always keep the JSON 401 contract regardless of this setting.\r\n */\r\nexport type PageAuthConfig = {\r\n /**\r\n * Login path a guarded page route redirects a logged-out browser to (e.g.\r\n * `\"/login\"`). Unset ⇒ page-route auth failures keep the JSON 401, so the\r\n * behavior is opt-in and backward-compatible.\r\n */\r\n loginPath?: string;\r\n /**\r\n * Query parameter the redirect carries the originally-requested path in, so\r\n * the login flow can send the user back where they were headed.\r\n * @default \"returnUrl\"\r\n */\r\n returnUrlParam?: string;\r\n};\r\n\r\nexport type AuthConfigurations = {\r\n /**\r\n * Define all user types — maps a user-type slug to its `Auth` model class so\r\n * tokens and the middleware can resolve the right model.\r\n */\r\n userType: {\r\n [userType: string]: ChildModel<Auth>;\r\n };\r\n /**\r\n * Decide whether a resolved user may authenticate or receive new tokens.\r\n * @default () => true\r\n */\r\n canAuthenticate?: CanAuthenticate;\r\n /**\r\n * Access-token configuration (secret, expiry, algorithm, model override).\r\n */\r\n accessToken?: AccessTokenConfig;\r\n /**\r\n * Refresh-token configuration (rotation, lifetime, cap, model override).\r\n */\r\n refreshToken?: RefreshTokenConfig;\r\n /**\r\n * Page-route auth-failure behavior — set `loginPath` to redirect a logged-out\r\n * browser on a guarded PAGE route to a login page instead of the JSON 401.\r\n * Opt-in; API routes are unaffected. Read via `authConfig.pageAuth`.\r\n */\r\n pageAuth?: PageAuthConfig;\r\n /**\r\n * @deprecated Use `accessToken` / `refreshToken`. Read via a backward-compatible shim.\r\n */\r\n jwt?: LegacyJwtConfig;\r\n};\r\n\r\nexport type AccessTokenOutput = {\r\n /**\r\n * JWT Token\r\n */\r\n token: string;\r\n /**\r\n * Exprie time in ISO format UTC time\r\n */\r\n expiresAt: string;\r\n};\r\n\r\n/**\r\n * Token pair returned after login or token refresh\r\n */\r\nexport type TokenPair = {\r\n /**\r\n * JWT access token (short-lived)\r\n */\r\n accessToken: AccessTokenOutput;\r\n /**\r\n * JWT refresh token (long-lived)\r\n */\r\n refreshToken?: AccessTokenOutput;\r\n};\r\n\r\n/**\r\n * Device information for session tracking\r\n */\r\nexport type DeviceInfo = {\r\n /**\r\n * User agent string from request\r\n */\r\n userAgent?: string;\r\n /**\r\n * Client IP address\r\n */\r\n ip?: string;\r\n /**\r\n * Optional device identifier\r\n */\r\n deviceId?: string;\r\n /**\r\n * Token family ID (for rotation tracking)\r\n * @internal\r\n */\r\n familyId?: string;\r\n /**\r\n * Access token payload\r\n */\r\n payload?: Record<string, unknown>;\r\n};\r\n\r\nexport type LoginResult<UserType extends Auth> = {\r\n user: UserType;\r\n tokens: TokenPair;\r\n};\r\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAyBA,MAAa,gBAAgB"}
|
|
1
|
+
{"version":3,"file":"types.mjs","names":[],"sources":["../../../../../../../auth/src/contracts/types.ts"],"sourcesContent":["import { type ChildModel } from \"@warlock.js/cascade\";\r\nimport { type Algorithm } from \"fast-jwt\";\r\nimport type { AccessToken } from \"../models/access-token\";\r\nimport type { Auth } from \"../models/auth.model\";\r\nimport type { OneTimeToken } from \"../models/one-time-token\";\r\nimport type { OtpConfig, PasskeysConfig, ProvidersConfig } from \"./providers\";\r\nimport type { RefreshToken } from \"../models/refresh-token\";\r\n\r\n/**\r\n * Symbol to indicate no expiration for tokens\r\n * Use this when you explicitly want tokens to never expire\r\n *\r\n * @example\r\n * ```typescript\r\n * // src/config/auth.ts\r\n * import { NO_EXPIRATION, type AuthConfigurations } from \"@warlock.js/auth\";\r\n *\r\n * const authConfigurations: AuthConfigurations = {\r\n * accessToken: {\r\n * secret: env(\"JWT_SECRET\"),\r\n * expiresIn: NO_EXPIRATION, // Token expires within 100 years\r\n * },\r\n * };\r\n *\r\n * export default authConfigurations;\r\n * ```\r\n */\r\nexport const NO_EXPIRATION = \"100y\";\r\n\r\n/**\r\n * Behavior when logout is called without a refresh token\r\n * - \"revoke-all\": Revoke all refresh tokens for the user (secure default)\r\n * - \"error\": Return an error requiring the refresh token\r\n */\r\nexport type LogoutWithoutTokenBehavior = \"revoke-all\" | \"error\";\r\n\r\n/** The single request credential source an auth middleware instance accepts. */\r\nexport type TokenFrom = \"header\" | `cookie:${string}`;\r\n\r\n/** Application policy that decides whether a resolved user may authenticate. */\r\nexport type CanAuthenticate = (user: Auth) => boolean | Promise<boolean>;\r\n\r\n/** Password credentials plus the application-defined identity fields. */\r\nexport type AuthCredentials = Record<string, unknown> & {\r\n password: string;\r\n};\r\n\r\n/**\r\n * Access-token configuration.\r\n *\r\n * `secret` may also be supplied via the deprecated `jwt.secret` (resolved by a\r\n * backward-compatible shim); one of the two is required at runtime.\r\n */\r\nexport type AccessTokenConfig = {\r\n /**\r\n * Override the persisted access-token model — extend {@link AccessToken} to\r\n * add columns (e.g. a tenant key) or rename them, then register the subclass\r\n * here. Defaults to the package's `AccessToken`.\r\n */\r\n model?: typeof AccessToken;\r\n /**\r\n * Secret used to sign access tokens.\r\n */\r\n secret?: string;\r\n /**\r\n * JWT algorithm.\r\n * @default \"HS256\"\r\n */\r\n algorithm?: Algorithm;\r\n /**\r\n * Access-token lifetime — a duration string `ms` parses to a **positive**\r\n * number of milliseconds. A value `ms` cannot parse (`\"30dayz\"`), a\r\n * non-positive one (`\"0d\"`), or a bare number throws naming this key on the\r\n * first token issue: each of them would otherwise sign a token with no `exp`\r\n * claim at all.\r\n * @example \"1h\" or NO_EXPIRATION\r\n * @default \"1h\"\r\n */\r\n expiresIn?: string;\r\n};\r\n\r\n/**\r\n * Refresh-token configuration.\r\n */\r\nexport type RefreshTokenConfig = {\r\n /**\r\n * Override the persisted refresh-token model — extend {@link RefreshToken}.\r\n * Defaults to the package's `RefreshToken`.\r\n */\r\n model?: typeof RefreshToken;\r\n /**\r\n * Enable refresh tokens.\r\n * @default true\r\n */\r\n enabled?: boolean;\r\n /**\r\n * Separate secret for refresh tokens (recommended for security). Falls back\r\n * to the access-token secret when omitted.\r\n */\r\n secret?: string;\r\n /**\r\n * Refresh-token lifetime — a duration string `ms` parses to a **positive**\r\n * number of milliseconds; an unusable value throws naming this key on issue\r\n * (see {@link AccessTokenConfig.expiresIn}).\r\n * @example \"7d\" or \"1w\"\r\n * @default \"7d\"\r\n */\r\n expiresIn?: string;\r\n /**\r\n * Rotate the refresh token on each use (old token revoked, replay detected).\r\n * @default true\r\n */\r\n rotation?: boolean;\r\n /**\r\n * Maximum active refresh tokens per user; the oldest are revoked past it.\r\n * @default 5\r\n */\r\n maxPerUser?: number;\r\n /**\r\n * Behavior when logout is called without a refresh token.\r\n * @default \"revoke-all\"\r\n */\r\n logoutWithoutToken?: LogoutWithoutTokenBehavior;\r\n};\r\n\r\n/**\r\n * Legacy JWT configuration shape. Still honored by the resolver shim with a\r\n * deprecation warning.\r\n *\r\n * @deprecated Use the top-level `accessToken` / `refreshToken` blocks.\r\n */\r\nexport type LegacyJwtConfig = {\r\n secret?: string;\r\n algorithm?: Algorithm;\r\n expiresIn?: string;\r\n refresh?: {\r\n secret?: string;\r\n enabled?: boolean;\r\n expiresIn?: string;\r\n rotation?: boolean;\r\n maxPerUser?: number;\r\n logoutWithoutToken?: LogoutWithoutTokenBehavior;\r\n };\r\n};\r\n\r\n/**\r\n * Page-route auth-failure behavior. When a guarded PAGE route (a React-SSR page,\r\n * `route.isPage`) rejects a logged-out browser, this decides whether it redirects\r\n * to a login page instead of returning the API-style JSON 401.\r\n *\r\n * Read at runtime through `authConfig.pageAuth` (`auth.pageAuth.*`). API routes\r\n * always keep the JSON 401 contract regardless of this setting.\r\n */\r\nexport type PageAuthConfig = {\r\n /**\r\n * Login path a guarded page route redirects a logged-out browser to (e.g.\r\n * `\"/login\"`). Unset ⇒ page-route auth failures keep the JSON 401, so the\r\n * behavior is opt-in and backward-compatible.\r\n */\r\n loginPath?: string;\r\n /**\r\n * Query parameter the redirect carries the originally-requested path in, so\r\n * the login flow can send the user back where they were headed.\r\n * @default \"returnUrl\"\r\n */\r\n returnUrlParam?: string;\r\n};\r\n\r\n/**\r\n * Data every email-verification / password-reset notification receives.\r\n */\r\nexport type OneTimeTokenNotificationData = {\r\n /** The raw token — the only place it exists; only its SHA-256 hash is stored. */\r\n token: string;\r\n /** When the token stops working. */\r\n expiresAt: Date;\r\n /** The link built by `auth.verification.url` / `auth.passwordReset.url`, when configured. */\r\n url?: string;\r\n};\r\n\r\n/**\r\n * Anything auth can deliver a token through — a `defineNotification(...)`\r\n * result satisfies it, as does any object with a compatible `send`.\r\n */\r\nexport type AuthNotification = {\r\n send: (to: Auth, data: OneTimeTokenNotificationData) => unknown;\r\n};\r\n\r\n/** Builds the link a token notification points at. */\r\nexport type OneTimeTokenUrlBuilder = (token: string, user: Auth) => string;\r\n\r\n/** Persists a new plaintext password for a user during a password reset. */\r\nexport type PasswordSetter = (user: Auth, plainPassword: string) => void | Promise<void>;\r\n\r\n/**\r\n * Email-verification configuration (`auth.verification`).\r\n */\r\nexport type EmailVerificationConfig = {\r\n /**\r\n * Token lifetime — a positive `ms` duration string.\r\n * @default \"24h\"\r\n */\r\n expiresIn?: string;\r\n /**\r\n * User attribute stamped with the verification `Date`. Declare it in the\r\n * user schema (e.g. `emailVerifiedAt: v.date().optional()`).\r\n * @default \"emailVerifiedAt\"\r\n */\r\n field?: string;\r\n /** Replace the default verification email. */\r\n notification?: AuthNotification;\r\n /** Build the verification link passed to the notification as `url`. */\r\n url?: OneTimeTokenUrlBuilder;\r\n};\r\n\r\n/**\r\n * Password-reset configuration (`auth.passwordReset`).\r\n */\r\nexport type PasswordResetConfig = {\r\n /**\r\n * Token lifetime — a positive `ms` duration string.\r\n * @default \"60m\"\r\n */\r\n expiresIn?: string;\r\n /**\r\n * User attribute `requestPasswordReset` looks the account up by.\r\n * @default \"email\"\r\n */\r\n identifierField?: string;\r\n /** Replace the default reset email. */\r\n notification?: AuthNotification;\r\n /** Build the reset link passed to the notification as `url`. */\r\n url?: OneTimeTokenUrlBuilder;\r\n /**\r\n * Persist the new password yourself. By default auth saves a hash made by\r\n * the same `hashPassword` login verifies against, and falls back to the\r\n * plaintext when the model hashes on save (`useHashedPassword()`), checking\r\n * the stored value with `verifyPassword` either way.\r\n */\r\n setPassword?: PasswordSetter;\r\n};\r\n\r\n/**\r\n * One-time token storage configuration (`auth.oneTimeToken`).\r\n */\r\nexport type OneTimeTokenConfig = {\r\n /** Override the persisted model — extend {@link OneTimeToken}. */\r\n model?: typeof OneTimeToken;\r\n};\r\n\r\nexport type AuthConfigurations = {\r\n /**\r\n * Define all user types — maps a user-type slug to its `Auth` model class so\r\n * tokens and the middleware can resolve the right model.\r\n */\r\n userType: {\r\n [userType: string]: ChildModel<Auth>;\r\n };\r\n /**\r\n * Decide whether a resolved user may authenticate or receive new tokens.\r\n * @default () => true\r\n */\r\n canAuthenticate?: CanAuthenticate;\r\n /**\r\n * Access-token configuration (secret, expiry, algorithm, model override).\r\n */\r\n accessToken?: AccessTokenConfig;\r\n /**\r\n * Refresh-token configuration (rotation, lifetime, cap, model override).\r\n */\r\n refreshToken?: RefreshTokenConfig;\r\n /**\r\n * Page-route auth-failure behavior — set `loginPath` to redirect a logged-out\r\n * browser on a guarded PAGE route to a login page instead of the JSON 401.\r\n * Opt-in; API routes are unaffected. Read via `authConfig.pageAuth`.\r\n */\r\n pageAuth?: PageAuthConfig;\r\n /**\r\n * Cookie auth session config — read by `authService.setAuthCookie` /\r\n * `clearAuthCookie`. Opt-in: unset ⇒ the helpers fall back to their own\r\n * defaults (`name: \"access_token\"`, `path: \"/\"`).\r\n */\r\n cookie?: CookieAuthConfig;\r\n /**\r\n * CSRF Origin-check config for cookie-authenticated unsafe-method requests.\r\n */\r\n csrf?: CsrfConfig;\r\n /**\r\n * Email verification — token lifetime, verified field, notification override.\r\n */\r\n verification?: EmailVerificationConfig;\r\n /**\r\n * Password reset — token lifetime, lookup field, notification and password-writer overrides.\r\n */\r\n passwordReset?: PasswordResetConfig;\r\n /**\r\n * One-time token (verification / reset) storage — model override.\r\n */\r\n oneTimeToken?: OneTimeTokenConfig;\r\n /**\r\n * Redirect login providers (`google`, `custom`) and account-linking policy.\r\n */\r\n providers?: ProvidersConfig;\r\n /**\r\n * Passkey (WebAuthn) relying-party settings. Requires `@simplewebauthn/server`.\r\n */\r\n passkeys?: PasskeysConfig;\r\n /**\r\n * Phone one-time-code login — channel, lifetime, attempts, delivery.\r\n */\r\n otp?: OtpConfig;\r\n /**\r\n * @deprecated Use `accessToken` / `refreshToken`. Read via a backward-compatible shim.\r\n */\r\n jwt?: LegacyJwtConfig;\r\n};\r\n\r\nexport type AccessTokenOutput = {\r\n /**\r\n * JWT Token\r\n */\r\n token: string;\r\n /**\r\n * Exprie time in ISO format UTC time\r\n */\r\n expiresAt: string;\r\n};\r\n\r\n/**\r\n * Token pair returned after login or token refresh\r\n */\r\nexport type TokenPair = {\r\n /**\r\n * JWT access token (short-lived)\r\n */\r\n accessToken: AccessTokenOutput;\r\n /**\r\n * JWT refresh token (long-lived)\r\n */\r\n refreshToken?: AccessTokenOutput;\r\n};\r\n\r\n/**\r\n * Device information for session tracking\r\n */\r\nexport type DeviceInfo = {\r\n /**\r\n * User agent string from request\r\n */\r\n userAgent?: string;\r\n /**\r\n * Client IP address\r\n */\r\n ip?: string;\r\n /**\r\n * Optional device identifier\r\n */\r\n deviceId?: string;\r\n /**\r\n * Token family ID (for rotation tracking)\r\n * @internal\r\n */\r\n familyId?: string;\r\n /**\r\n * Access token payload\r\n */\r\n payload?: Record<string, unknown>;\r\n};\r\n\r\nexport type LoginResult<UserType extends Auth> = {\r\n user: UserType;\r\n tokens: TokenPair;\r\n};\r\n\r\n/**\r\n * Configuration for the cookie an app opts into via `authService.setAuthCookie`\r\n * / `clearAuthCookie` and reads back with `authMiddleware([], \"cookie:<name>\")`.\r\n * Attribute flags (`httpOnly` / `sameSite` / `secure`) are deliberately NOT\r\n * configurable here — they come from core's `secureCookieDefaults()`, the\r\n * same floor every `response.cookie()` call gets, so a cookie auth session can\r\n * never be weakened to a laxer policy than the framework default.\r\n */\r\nexport type CookieAuthConfig = {\r\n /**\r\n * Cookie name `setAuthCookie`/`clearAuthCookie` write and clear, and that a\r\n * `cookie:<name>` token source must match to read it back.\r\n * @default \"access_token\"\r\n */\r\n name?: string;\r\n /**\r\n * Cookie `Path` attribute.\r\n * @default \"/\"\r\n */\r\n path?: string;\r\n};\r\n\r\n/**\r\n * CSRF Origin-check configuration. Read via\r\n * `authConfig.csrf.allowedOrigins()`.\r\n */\r\nexport type CsrfConfig = {\r\n /**\r\n * Extra origins allowed on a cookie-authenticated unsafe-method request,\r\n * in addition to the request's own origin.\r\n * @default []\r\n */\r\n allowedOrigins?: string[];\r\n};\r\n\r\n/**\r\n * Per-call overrides for {@link AuthService.setAuthCookie}. Anything omitted\r\n * falls back to `auth.cookie.*` config, then the package default. Cookie\r\n * *attribute* flags (`httpOnly`/`sameSite`/`secure`) are never settable here —\r\n * see {@link CookieAuthConfig}.\r\n */\r\nexport type SetAuthCookieOptions = {\r\n /** Cookie name; defaults to `auth.cookie.name` (package default `\"access_token\"`). */\r\n name?: string;\r\n /** Cookie `Path`; defaults to `auth.cookie.path` (package default `\"/\"`). */\r\n path?: string;\r\n /**\r\n * `Max-Age`, in seconds. Overrides the expiry `setAuthCookie` would\r\n * otherwise derive from an `AccessTokenOutput`'s `expiresAt`. Passing a\r\n * bare token string with no `maxAge` produces a session cookie (cleared\r\n * when the browser closes).\r\n */\r\n maxAge?: number;\r\n};\r\n\r\n/** Per-call overrides for {@link AuthService.clearAuthCookie}. */\r\nexport type ClearAuthCookieOptions = {\r\n /** Cookie name; defaults to `auth.cookie.name` (package default `\"access_token\"`). */\r\n name?: string;\r\n /** Cookie `Path`; defaults to `auth.cookie.path` (package default `\"/\"`). Must match the `Path` the cookie was set with. */\r\n path?: string;\r\n};\r\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AA2BA,MAAa,gBAAgB"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ServerError } from "@warlock.js/core";
|
|
2
|
+
|
|
3
|
+
//#region ../auth/src/errors/auth-provider-sdk-missing.error.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* A login method needs a vendor SDK that is an optional peer of
|
|
6
|
+
* `@warlock.js/auth` and is not installed. The message names the package and
|
|
7
|
+
* the `warlock add` command that installs it; the resolver failure is kept on
|
|
8
|
+
* `cause`.
|
|
9
|
+
*/
|
|
10
|
+
declare class AuthProviderSdkMissingError extends ServerError {
|
|
11
|
+
readonly packageName: string;
|
|
12
|
+
readonly feature: string;
|
|
13
|
+
constructor(packageName: string, feature: string, cause?: unknown);
|
|
14
|
+
}
|
|
15
|
+
//#endregion
|
|
16
|
+
export { AuthProviderSdkMissingError };
|
|
17
|
+
//# sourceMappingURL=auth-provider-sdk-missing.error.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth-provider-sdk-missing.error.d.mts","names":[],"sources":["../../../../../../../auth/src/errors/auth-provider-sdk-missing.error.ts"],"mappings":";;;;;AAQA;;;;cAAa,2BAAA,SAAoC,WAAW;EAAA,SAExC,WAAA;EAAA,SACA,OAAA;cADA,WAAA,UACA,OAAA,UAChB,KAAA;AAAA"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { ServerError } from "@warlock.js/core";
|
|
2
|
+
|
|
3
|
+
//#region ../auth/src/errors/auth-provider-sdk-missing.error.ts
|
|
4
|
+
/**
|
|
5
|
+
* A login method needs a vendor SDK that is an optional peer of
|
|
6
|
+
* `@warlock.js/auth` and is not installed. The message names the package and
|
|
7
|
+
* the `warlock add` command that installs it; the resolver failure is kept on
|
|
8
|
+
* `cause`.
|
|
9
|
+
*/
|
|
10
|
+
var AuthProviderSdkMissingError = class extends ServerError {
|
|
11
|
+
constructor(packageName, feature, cause) {
|
|
12
|
+
super(`@warlock.js/auth: this login method needs "${packageName}", which is not installed — run \`warlock add ${feature}\`.`);
|
|
13
|
+
this.packageName = packageName;
|
|
14
|
+
this.feature = feature;
|
|
15
|
+
this.name = "AuthProviderSdkMissingError";
|
|
16
|
+
this.cause = cause;
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
//#endregion
|
|
21
|
+
export { AuthProviderSdkMissingError };
|
|
22
|
+
//# sourceMappingURL=auth-provider-sdk-missing.error.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth-provider-sdk-missing.error.mjs","names":[],"sources":["../../../../../../../auth/src/errors/auth-provider-sdk-missing.error.ts"],"sourcesContent":["import { ServerError } from \"@warlock.js/core\";\n\n/**\n * A login method needs a vendor SDK that is an optional peer of\n * `@warlock.js/auth` and is not installed. The message names the package and\n * the `warlock add` command that installs it; the resolver failure is kept on\n * `cause`.\n */\nexport class AuthProviderSdkMissingError extends ServerError {\n public constructor(\n public readonly packageName: string,\n public readonly feature: string,\n cause?: unknown,\n ) {\n super(\n `@warlock.js/auth: this login method needs \"${packageName}\", which is not installed — ` +\n `run \\`warlock add ${feature}\\`.`,\n );\n this.name = \"AuthProviderSdkMissingError\";\n this.cause = cause;\n }\n}\n"],"mappings":";;;;;;;;;AAQA,IAAa,8BAAb,cAAiD,YAAY;CAC3D,AAAO,YACL,AAAgB,aAChB,AAAgB,SAChB,OACA;EACA,MACE,8CAA8C,YAAY,gDACnC,QAAQ,IACjC;EAPgB;EACA;EAOhB,KAAK,OAAO;EACZ,KAAK,QAAQ;CACf;AACF"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { AuthErrorCodes } from "../utils/auth-error-codes.mjs";
|
|
2
|
+
import { ForbiddenError } from "@warlock.js/core";
|
|
3
|
+
|
|
4
|
+
//#region ../auth/src/errors/email-not-verified.error.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* The authenticated user has not verified their email address. Thrown by
|
|
7
|
+
* `requireVerifiedEmail()`; core's error handler answers it with `403` and a
|
|
8
|
+
* `payload.errorCode` of `EC007`.
|
|
9
|
+
*/
|
|
10
|
+
declare class EmailNotVerifiedError extends ForbiddenError {
|
|
11
|
+
readonly code = AuthErrorCodes.EmailNotVerified;
|
|
12
|
+
constructor(message?: string);
|
|
13
|
+
}
|
|
14
|
+
//#endregion
|
|
15
|
+
export { EmailNotVerifiedError };
|
|
16
|
+
//# sourceMappingURL=email-not-verified.error.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"email-not-verified.error.d.mts","names":[],"sources":["../../../../../../../auth/src/errors/email-not-verified.error.ts"],"mappings":";;;;;;AAQA;;;cAAa,qBAAA,SAA8B,cAAc;EAAA,SACvC,IAAA,GAAI,cAAA,CAAA,gBAAA;cAED,OAAA;AAAA"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { AuthErrorCodes } from "../utils/auth-error-codes.mjs";
|
|
2
|
+
import { ForbiddenError } from "@warlock.js/core";
|
|
3
|
+
|
|
4
|
+
//#region ../auth/src/errors/email-not-verified.error.ts
|
|
5
|
+
/**
|
|
6
|
+
* The authenticated user has not verified their email address. Thrown by
|
|
7
|
+
* `requireVerifiedEmail()`; core's error handler answers it with `403` and a
|
|
8
|
+
* `payload.errorCode` of `EC007`.
|
|
9
|
+
*/
|
|
10
|
+
var EmailNotVerifiedError = class extends ForbiddenError {
|
|
11
|
+
constructor(message = "Email address is not verified.") {
|
|
12
|
+
super(message, { errorCode: "EC007" });
|
|
13
|
+
this.code = "EC007";
|
|
14
|
+
this.name = "EmailNotVerifiedError";
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
//#endregion
|
|
19
|
+
export { EmailNotVerifiedError };
|
|
20
|
+
//# sourceMappingURL=email-not-verified.error.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"email-not-verified.error.mjs","names":[],"sources":["../../../../../../../auth/src/errors/email-not-verified.error.ts"],"sourcesContent":["import { ForbiddenError } from \"@warlock.js/core\";\nimport { AuthErrorCodes } from \"../utils/auth-error-codes\";\n\n/**\n * The authenticated user has not verified their email address. Thrown by\n * `requireVerifiedEmail()`; core's error handler answers it with `403` and a\n * `payload.errorCode` of `EC007`.\n */\nexport class EmailNotVerifiedError extends ForbiddenError {\n public readonly code = AuthErrorCodes.EmailNotVerified;\n\n public constructor(message = \"Email address is not verified.\") {\n super(message, { errorCode: AuthErrorCodes.EmailNotVerified });\n this.name = \"EmailNotVerifiedError\";\n }\n}\n"],"mappings":";;;;;;;;;AAQA,IAAa,wBAAb,cAA2C,eAAe;CAGxD,AAAO,YAAY,UAAU,kCAAkC;EAC7D,MAAM,SAAS,EAAE,mBAA2C,CAAC;;EAC7D,KAAK,OAAO;CACd;AACF"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { AuthProviderSdkMissingError } from "./auth-provider-sdk-missing.error.mjs";
|
|
2
|
+
import { EmailNotVerifiedError } from "./email-not-verified.error.mjs";
|
|
3
|
+
import { InvalidOneTimeTokenError } from "./invalid-one-time-token.error.mjs";
|
|
4
|
+
import { InvalidPasskeyError } from "./invalid-passkey.error.mjs";
|
|
5
|
+
import { InvalidProviderCallbackError } from "./invalid-provider-callback.error.mjs";
|
|
6
|
+
import { NotificationsUnavailableError } from "./notifications-unavailable.error.mjs";
|
|
7
|
+
import { ProviderEmailNotVerifiedError } from "./provider-email-not-verified.error.mjs";
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { AuthProviderSdkMissingError } from "./auth-provider-sdk-missing.error.mjs";
|
|
2
|
+
import { EmailNotVerifiedError } from "./email-not-verified.error.mjs";
|
|
3
|
+
import { InvalidOneTimeTokenError } from "./invalid-one-time-token.error.mjs";
|
|
4
|
+
import { InvalidPasskeyError } from "./invalid-passkey.error.mjs";
|
|
5
|
+
import { InvalidProviderCallbackError } from "./invalid-provider-callback.error.mjs";
|
|
6
|
+
import { NotificationsUnavailableError } from "./notifications-unavailable.error.mjs";
|
|
7
|
+
import { ProviderEmailNotVerifiedError } from "./provider-email-not-verified.error.mjs";
|
|
8
|
+
|
|
9
|
+
export { };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { AuthErrorCodes } from "../utils/auth-error-codes.mjs";
|
|
2
|
+
import { BadRequestError } from "@warlock.js/core";
|
|
3
|
+
|
|
4
|
+
//#region ../auth/src/errors/invalid-one-time-token.error.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* An email-verification or password-reset token was rejected: unknown, issued
|
|
7
|
+
* for the other purpose, expired, or already consumed (including losing a
|
|
8
|
+
* concurrent consumption race). Deliberately ONE error for all of them, so a
|
|
9
|
+
* caller cannot probe which case applies. Answers `400` with `EC008`.
|
|
10
|
+
*/
|
|
11
|
+
declare class InvalidOneTimeTokenError extends BadRequestError {
|
|
12
|
+
readonly code = AuthErrorCodes.InvalidOneTimeToken;
|
|
13
|
+
constructor(message?: string);
|
|
14
|
+
}
|
|
15
|
+
//#endregion
|
|
16
|
+
export { InvalidOneTimeTokenError };
|
|
17
|
+
//# sourceMappingURL=invalid-one-time-token.error.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"invalid-one-time-token.error.d.mts","names":[],"sources":["../../../../../../../auth/src/errors/invalid-one-time-token.error.ts"],"mappings":";;;;;;AASA;;;;cAAa,wBAAA,SAAiC,eAAe;EAAA,SAC3C,IAAA,GAAI,cAAA,CAAA,mBAAA;cAED,OAAA;AAAA"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { AuthErrorCodes } from "../utils/auth-error-codes.mjs";
|
|
2
|
+
import { BadRequestError } from "@warlock.js/core";
|
|
3
|
+
|
|
4
|
+
//#region ../auth/src/errors/invalid-one-time-token.error.ts
|
|
5
|
+
/**
|
|
6
|
+
* An email-verification or password-reset token was rejected: unknown, issued
|
|
7
|
+
* for the other purpose, expired, or already consumed (including losing a
|
|
8
|
+
* concurrent consumption race). Deliberately ONE error for all of them, so a
|
|
9
|
+
* caller cannot probe which case applies. Answers `400` with `EC008`.
|
|
10
|
+
*/
|
|
11
|
+
var InvalidOneTimeTokenError = class extends BadRequestError {
|
|
12
|
+
constructor(message = "Invalid or expired token.") {
|
|
13
|
+
super(message, { errorCode: "EC008" });
|
|
14
|
+
this.code = "EC008";
|
|
15
|
+
this.name = "InvalidOneTimeTokenError";
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
//#endregion
|
|
20
|
+
export { InvalidOneTimeTokenError };
|
|
21
|
+
//# sourceMappingURL=invalid-one-time-token.error.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"invalid-one-time-token.error.mjs","names":[],"sources":["../../../../../../../auth/src/errors/invalid-one-time-token.error.ts"],"sourcesContent":["import { BadRequestError } from \"@warlock.js/core\";\nimport { AuthErrorCodes } from \"../utils/auth-error-codes\";\n\n/**\n * An email-verification or password-reset token was rejected: unknown, issued\n * for the other purpose, expired, or already consumed (including losing a\n * concurrent consumption race). Deliberately ONE error for all of them, so a\n * caller cannot probe which case applies. Answers `400` with `EC008`.\n */\nexport class InvalidOneTimeTokenError extends BadRequestError {\n public readonly code = AuthErrorCodes.InvalidOneTimeToken;\n\n public constructor(message = \"Invalid or expired token.\") {\n super(message, { errorCode: AuthErrorCodes.InvalidOneTimeToken });\n this.name = \"InvalidOneTimeTokenError\";\n }\n}\n"],"mappings":";;;;;;;;;;AASA,IAAa,2BAAb,cAA8C,gBAAgB;CAG5D,AAAO,YAAY,UAAU,6BAA6B;EACxD,MAAM,SAAS,EAAE,mBAA8C,CAAC;;EAChE,KAAK,OAAO;CACd;AACF"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { AuthErrorCodes } from "../utils/auth-error-codes.mjs";
|
|
2
|
+
import { BadRequestError } from "@warlock.js/core";
|
|
3
|
+
|
|
4
|
+
//#region ../auth/src/errors/invalid-passkey.error.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* A passkey registration or authentication was rejected — unknown, expired
|
|
7
|
+
* or used challenge, unknown credential, failed verification, or a signature
|
|
8
|
+
* counter that did not advance. `reason` is for logs; the message stays
|
|
9
|
+
* generic. Answers `400` with `EC011`.
|
|
10
|
+
*/
|
|
11
|
+
declare class InvalidPasskeyError extends BadRequestError {
|
|
12
|
+
readonly reason: string;
|
|
13
|
+
readonly code = AuthErrorCodes.InvalidPasskey;
|
|
14
|
+
constructor(reason: string, cause?: unknown);
|
|
15
|
+
}
|
|
16
|
+
//#endregion
|
|
17
|
+
export { InvalidPasskeyError };
|
|
18
|
+
//# sourceMappingURL=invalid-passkey.error.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"invalid-passkey.error.d.mts","names":[],"sources":["../../../../../../../auth/src/errors/invalid-passkey.error.ts"],"mappings":";;;;;;AASA;;;;cAAa,mBAAA,SAA4B,eAAe;EAAA,SAIpC,MAAA;EAAA,SAHF,IAAA,GAAI,cAAA,CAAA,cAAA;cAGF,MAAA,UAChB,KAAA;AAAA"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { AuthErrorCodes } from "../utils/auth-error-codes.mjs";
|
|
2
|
+
import { BadRequestError } from "@warlock.js/core";
|
|
3
|
+
|
|
4
|
+
//#region ../auth/src/errors/invalid-passkey.error.ts
|
|
5
|
+
/**
|
|
6
|
+
* A passkey registration or authentication was rejected — unknown, expired
|
|
7
|
+
* or used challenge, unknown credential, failed verification, or a signature
|
|
8
|
+
* counter that did not advance. `reason` is for logs; the message stays
|
|
9
|
+
* generic. Answers `400` with `EC011`.
|
|
10
|
+
*/
|
|
11
|
+
var InvalidPasskeyError = class extends BadRequestError {
|
|
12
|
+
constructor(reason, cause) {
|
|
13
|
+
super("Passkey verification failed.", { errorCode: "EC011" });
|
|
14
|
+
this.reason = reason;
|
|
15
|
+
this.code = "EC011";
|
|
16
|
+
this.name = "InvalidPasskeyError";
|
|
17
|
+
this.cause = cause;
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
//#endregion
|
|
22
|
+
export { InvalidPasskeyError };
|
|
23
|
+
//# sourceMappingURL=invalid-passkey.error.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"invalid-passkey.error.mjs","names":[],"sources":["../../../../../../../auth/src/errors/invalid-passkey.error.ts"],"sourcesContent":["import { BadRequestError } from \"@warlock.js/core\";\nimport { AuthErrorCodes } from \"../utils/auth-error-codes\";\n\n/**\n * A passkey registration or authentication was rejected — unknown, expired\n * or used challenge, unknown credential, failed verification, or a signature\n * counter that did not advance. `reason` is for logs; the message stays\n * generic. Answers `400` with `EC011`.\n */\nexport class InvalidPasskeyError extends BadRequestError {\n public readonly code = AuthErrorCodes.InvalidPasskey;\n\n public constructor(\n public readonly reason: string,\n cause?: unknown,\n ) {\n super(\"Passkey verification failed.\", { errorCode: AuthErrorCodes.InvalidPasskey });\n this.name = \"InvalidPasskeyError\";\n this.cause = cause;\n }\n}\n"],"mappings":";;;;;;;;;;AASA,IAAa,sBAAb,cAAyC,gBAAgB;CAGvD,AAAO,YACL,AAAgB,QAChB,OACA;EACA,MAAM,gCAAgC,EAAE,mBAAyC,CAAC;EAHlE;;EAIhB,KAAK,OAAO;EACZ,KAAK,QAAQ;CACf;AACF"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { AuthErrorCodes } from "../utils/auth-error-codes.mjs";
|
|
2
|
+
import { BadRequestError } from "@warlock.js/core";
|
|
3
|
+
|
|
4
|
+
//#region ../auth/src/errors/invalid-provider-callback.error.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* A redirect-provider callback was rejected — missing, forged or expired
|
|
7
|
+
* state cookie, `state` mismatch, failed code exchange, or an id_token with a
|
|
8
|
+
* bad signature, issuer, audience, expiry or nonce. `reason` is for logs;
|
|
9
|
+
* the response message stays generic. Answers `400` with `EC009`.
|
|
10
|
+
*/
|
|
11
|
+
declare class InvalidProviderCallbackError extends BadRequestError {
|
|
12
|
+
readonly reason: string;
|
|
13
|
+
readonly code = AuthErrorCodes.InvalidProviderCallback;
|
|
14
|
+
constructor(reason: string, cause?: unknown);
|
|
15
|
+
}
|
|
16
|
+
//#endregion
|
|
17
|
+
export { InvalidProviderCallbackError };
|
|
18
|
+
//# sourceMappingURL=invalid-provider-callback.error.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"invalid-provider-callback.error.d.mts","names":[],"sources":["../../../../../../../auth/src/errors/invalid-provider-callback.error.ts"],"mappings":";;;;;;AASA;;;;cAAa,4BAAA,SAAqC,eAAe;EAAA,SAI7C,MAAA;EAAA,SAHF,IAAA,GAAI,cAAA,CAAA,uBAAA;cAGF,MAAA,UAChB,KAAA;AAAA"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { AuthErrorCodes } from "../utils/auth-error-codes.mjs";
|
|
2
|
+
import { BadRequestError } from "@warlock.js/core";
|
|
3
|
+
|
|
4
|
+
//#region ../auth/src/errors/invalid-provider-callback.error.ts
|
|
5
|
+
/**
|
|
6
|
+
* A redirect-provider callback was rejected — missing, forged or expired
|
|
7
|
+
* state cookie, `state` mismatch, failed code exchange, or an id_token with a
|
|
8
|
+
* bad signature, issuer, audience, expiry or nonce. `reason` is for logs;
|
|
9
|
+
* the response message stays generic. Answers `400` with `EC009`.
|
|
10
|
+
*/
|
|
11
|
+
var InvalidProviderCallbackError = class extends BadRequestError {
|
|
12
|
+
constructor(reason, cause) {
|
|
13
|
+
super("Login with the provider failed.", { errorCode: "EC009" });
|
|
14
|
+
this.reason = reason;
|
|
15
|
+
this.code = "EC009";
|
|
16
|
+
this.name = "InvalidProviderCallbackError";
|
|
17
|
+
this.cause = cause;
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
//#endregion
|
|
22
|
+
export { InvalidProviderCallbackError };
|
|
23
|
+
//# sourceMappingURL=invalid-provider-callback.error.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"invalid-provider-callback.error.mjs","names":[],"sources":["../../../../../../../auth/src/errors/invalid-provider-callback.error.ts"],"sourcesContent":["import { BadRequestError } from \"@warlock.js/core\";\nimport { AuthErrorCodes } from \"../utils/auth-error-codes\";\n\n/**\n * A redirect-provider callback was rejected — missing, forged or expired\n * state cookie, `state` mismatch, failed code exchange, or an id_token with a\n * bad signature, issuer, audience, expiry or nonce. `reason` is for logs;\n * the response message stays generic. Answers `400` with `EC009`.\n */\nexport class InvalidProviderCallbackError extends BadRequestError {\n public readonly code = AuthErrorCodes.InvalidProviderCallback;\n\n public constructor(\n public readonly reason: string,\n cause?: unknown,\n ) {\n super(\"Login with the provider failed.\", {\n errorCode: AuthErrorCodes.InvalidProviderCallback,\n });\n this.name = \"InvalidProviderCallbackError\";\n this.cause = cause;\n }\n}\n"],"mappings":";;;;;;;;;;AASA,IAAa,+BAAb,cAAkD,gBAAgB;CAGhE,AAAO,YACL,AAAgB,QAChB,OACA;EACA,MAAM,mCAAmC,EACvC,mBACF,CAAC;EALe;;EAMhB,KAAK,OAAO;EACZ,KAAK,QAAQ;CACf;AACF"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ServerError } from "@warlock.js/core";
|
|
2
|
+
|
|
3
|
+
//#region ../auth/src/errors/notifications-unavailable.error.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Email verification / password reset could not send its notification because
|
|
6
|
+
* `@warlock.js/notifications` is not installed or not configured. Thrown BEFORE
|
|
7
|
+
* any token is issued — auth never issues a token it cannot deliver, and never
|
|
8
|
+
* skips the send silently. The original failure is kept on `cause`.
|
|
9
|
+
*/
|
|
10
|
+
declare class NotificationsUnavailableError extends ServerError {
|
|
11
|
+
constructor(reason: "not-installed" | "not-configured", cause?: unknown);
|
|
12
|
+
}
|
|
13
|
+
//#endregion
|
|
14
|
+
export { NotificationsUnavailableError };
|
|
15
|
+
//# sourceMappingURL=notifications-unavailable.error.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"notifications-unavailable.error.d.mts","names":[],"sources":["../../../../../../../auth/src/errors/notifications-unavailable.error.ts"],"mappings":";;;;;AAQA;;;;cAAa,6BAAA,SAAsC,WAAW;cACzC,MAAA,sCAA4C,KAAA;AAAA"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { ServerError } from "@warlock.js/core";
|
|
2
|
+
|
|
3
|
+
//#region ../auth/src/errors/notifications-unavailable.error.ts
|
|
4
|
+
/**
|
|
5
|
+
* Email verification / password reset could not send its notification because
|
|
6
|
+
* `@warlock.js/notifications` is not installed or not configured. Thrown BEFORE
|
|
7
|
+
* any token is issued — auth never issues a token it cannot deliver, and never
|
|
8
|
+
* skips the send silently. The original failure is kept on `cause`.
|
|
9
|
+
*/
|
|
10
|
+
var NotificationsUnavailableError = class extends ServerError {
|
|
11
|
+
constructor(reason, cause) {
|
|
12
|
+
super(reason === "not-installed" ? "@warlock.js/auth: email verification and password reset send through @warlock.js/notifications, which is not installed — add it to the app's dependencies." : "@warlock.js/auth: email verification and password reset send through @warlock.js/notifications, which is not configured — add `src/config/notifications.ts` with a `mail` channel.");
|
|
13
|
+
this.name = "NotificationsUnavailableError";
|
|
14
|
+
this.cause = cause;
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
//#endregion
|
|
19
|
+
export { NotificationsUnavailableError };
|
|
20
|
+
//# sourceMappingURL=notifications-unavailable.error.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"notifications-unavailable.error.mjs","names":[],"sources":["../../../../../../../auth/src/errors/notifications-unavailable.error.ts"],"sourcesContent":["import { ServerError } from \"@warlock.js/core\";\n\n/**\n * Email verification / password reset could not send its notification because\n * `@warlock.js/notifications` is not installed or not configured. Thrown BEFORE\n * any token is issued — auth never issues a token it cannot deliver, and never\n * skips the send silently. The original failure is kept on `cause`.\n */\nexport class NotificationsUnavailableError extends ServerError {\n public constructor(reason: \"not-installed\" | \"not-configured\", cause?: unknown) {\n super(\n reason === \"not-installed\"\n ? \"@warlock.js/auth: email verification and password reset send through \" +\n \"@warlock.js/notifications, which is not installed — add it to the app's dependencies.\"\n : \"@warlock.js/auth: email verification and password reset send through \" +\n \"@warlock.js/notifications, which is not configured — add `src/config/notifications.ts` \" +\n \"with a `mail` channel.\",\n );\n this.name = \"NotificationsUnavailableError\";\n this.cause = cause;\n }\n}\n"],"mappings":";;;;;;;;;AAQA,IAAa,gCAAb,cAAmD,YAAY;CAC7D,AAAO,YAAY,QAA4C,OAAiB;EAC9E,MACE,WAAW,kBACP,+JAEA,oLAGN;EACA,KAAK,OAAO;EACZ,KAAK,QAAQ;CACf;AACF"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { AuthErrorCodes } from "../utils/auth-error-codes.mjs";
|
|
2
|
+
import { ForbiddenError } from "@warlock.js/core";
|
|
3
|
+
|
|
4
|
+
//#region ../auth/src/errors/provider-email-not-verified.error.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* The provider did not verify the email on a profile with no existing link,
|
|
7
|
+
* so auth refused to link it to (or create) an account. Answers `403` with
|
|
8
|
+
* `EC010`.
|
|
9
|
+
*/
|
|
10
|
+
declare class ProviderEmailNotVerifiedError extends ForbiddenError {
|
|
11
|
+
readonly code = AuthErrorCodes.ProviderEmailNotVerified;
|
|
12
|
+
constructor(message?: string);
|
|
13
|
+
}
|
|
14
|
+
//#endregion
|
|
15
|
+
export { ProviderEmailNotVerifiedError };
|
|
16
|
+
//# sourceMappingURL=provider-email-not-verified.error.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider-email-not-verified.error.d.mts","names":[],"sources":["../../../../../../../auth/src/errors/provider-email-not-verified.error.ts"],"mappings":";;;;;;AAQA;;;cAAa,6BAAA,SAAsC,cAAc;EAAA,SAC/C,IAAA,GAAI,cAAA,CAAA,wBAAA;cAED,OAAA;AAAA"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { AuthErrorCodes } from "../utils/auth-error-codes.mjs";
|
|
2
|
+
import { ForbiddenError } from "@warlock.js/core";
|
|
3
|
+
|
|
4
|
+
//#region ../auth/src/errors/provider-email-not-verified.error.ts
|
|
5
|
+
/**
|
|
6
|
+
* The provider did not verify the email on a profile with no existing link,
|
|
7
|
+
* so auth refused to link it to (or create) an account. Answers `403` with
|
|
8
|
+
* `EC010`.
|
|
9
|
+
*/
|
|
10
|
+
var ProviderEmailNotVerifiedError = class extends ForbiddenError {
|
|
11
|
+
constructor(message = "The provider has not verified this email address.") {
|
|
12
|
+
super(message, { errorCode: "EC010" });
|
|
13
|
+
this.code = "EC010";
|
|
14
|
+
this.name = "ProviderEmailNotVerifiedError";
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
//#endregion
|
|
19
|
+
export { ProviderEmailNotVerifiedError };
|
|
20
|
+
//# sourceMappingURL=provider-email-not-verified.error.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider-email-not-verified.error.mjs","names":[],"sources":["../../../../../../../auth/src/errors/provider-email-not-verified.error.ts"],"sourcesContent":["import { ForbiddenError } from \"@warlock.js/core\";\nimport { AuthErrorCodes } from \"../utils/auth-error-codes\";\n\n/**\n * The provider did not verify the email on a profile with no existing link,\n * so auth refused to link it to (or create) an account. Answers `403` with\n * `EC010`.\n */\nexport class ProviderEmailNotVerifiedError extends ForbiddenError {\n public readonly code = AuthErrorCodes.ProviderEmailNotVerified;\n\n public constructor(message = \"The provider has not verified this email address.\") {\n super(message, { errorCode: AuthErrorCodes.ProviderEmailNotVerified });\n this.name = \"ProviderEmailNotVerifiedError\";\n }\n}\n"],"mappings":";;;;;;;;;AAQA,IAAa,gCAAb,cAAmD,eAAe;CAGhE,AAAO,YAAY,UAAU,qDAAqD;EAChF,MAAM,SAAS,EAAE,mBAAmD,CAAC;;EACrE,KAAK,OAAO;CACd;AACF"}
|
package/esm/index.d.mts
CHANGED
|
@@ -3,16 +3,44 @@ import { registerAuthPurgeNeverExpiringCommand } from "./commands/auth-purge-nev
|
|
|
3
3
|
import { registerJWTSecretGeneratorCommand } from "./commands/jwt-secret-generator-command.mjs";
|
|
4
4
|
import { Auth } from "./models/auth.model.mjs";
|
|
5
5
|
import { AccessToken, accessTokenSchema } from "./models/access-token/access-token.model.mjs";
|
|
6
|
-
import {
|
|
6
|
+
import { OneTimeToken, OneTimeTokenPurpose, oneTimeTokenSchema } from "./models/one-time-token/one-time-token.model.mjs";
|
|
7
|
+
import { AuthProvider, GoogleProviderConfig, OtpConfig, OtpMessage, OtpSender, PasskeysConfig, ProviderAuthorizationState, ProviderCallbackParams, ProviderProfile, ProviderUserCreator, ProvidersConfig } from "./contracts/providers.mjs";
|
|
8
|
+
import { AccessTokenConfig, AccessTokenOutput, AuthConfigurations, AuthCredentials, AuthNotification, CanAuthenticate, ClearAuthCookieOptions, CookieAuthConfig, CsrfConfig, DeviceInfo, EmailVerificationConfig, LegacyJwtConfig, LoginResult, LogoutWithoutTokenBehavior, NO_EXPIRATION, OneTimeTokenConfig, OneTimeTokenNotificationData, OneTimeTokenUrlBuilder, PageAuthConfig, PasswordResetConfig, PasswordSetter, RefreshTokenConfig, SetAuthCookieOptions, TokenFrom, TokenPair } from "./contracts/types.mjs";
|
|
7
9
|
import { RefreshToken, RefreshTokenIssueOptions, refreshTokenSchema } from "./models/refresh-token/refresh-token.model.mjs";
|
|
8
10
|
import { Authenticable } from "./contracts/auth-contract.mjs";
|
|
11
|
+
import { RequestUser } from "./contracts/request-locals.mjs";
|
|
12
|
+
import { AuthProviderSdkMissingError } from "./errors/auth-provider-sdk-missing.error.mjs";
|
|
13
|
+
import { AuthErrorCodes } from "./utils/auth-error-codes.mjs";
|
|
14
|
+
import { EmailNotVerifiedError } from "./errors/email-not-verified.error.mjs";
|
|
15
|
+
import { InvalidOneTimeTokenError } from "./errors/invalid-one-time-token.error.mjs";
|
|
16
|
+
import { InvalidPasskeyError } from "./errors/invalid-passkey.error.mjs";
|
|
17
|
+
import { InvalidProviderCallbackError } from "./errors/invalid-provider-callback.error.mjs";
|
|
18
|
+
import { NotificationsUnavailableError } from "./errors/notifications-unavailable.error.mjs";
|
|
19
|
+
import { ProviderEmailNotVerifiedError } from "./errors/provider-email-not-verified.error.mjs";
|
|
9
20
|
import { authMiddleware } from "./middleware/auth.middleware.mjs";
|
|
21
|
+
import { CsrfOriginMismatchError, CsrfOriginMismatchReason, assertCsrfOriginAllowed, requiresCsrfOriginCheck } from "./middleware/csrf-origin-check.mjs";
|
|
10
22
|
import { LoginThrottleIdentifier, LoginThrottleOptions, loginThrottleMiddleware } from "./middleware/login-throttle.middleware.mjs";
|
|
23
|
+
import { tokenConsumeThrottleMiddleware, tokenIssueThrottleMiddleware } from "./middleware/one-time-token-throttle.middleware.mjs";
|
|
24
|
+
import { otpRequestThrottleMiddleware, otpVerifyThrottleMiddleware } from "./middleware/otp-throttle.middleware.mjs";
|
|
25
|
+
import { requireVerifiedEmail } from "./middleware/require-verified-email.middleware.mjs";
|
|
26
|
+
import { PasskeyCredential, passkeyCredentialSchema } from "./models/passkey-credential/passkey-credential.model.mjs";
|
|
27
|
+
import { ProviderAccount, providerAccountSchema } from "./models/provider-account/provider-account.model.mjs";
|
|
11
28
|
import { authMigrations } from "./models/index.mjs";
|
|
29
|
+
import { requestOtp, verifyOtp } from "./otp/otp.mjs";
|
|
30
|
+
import { PasskeyOptionsJSON, PasskeyResponseJSON } from "./passkeys/simplewebauthn.mjs";
|
|
31
|
+
import { generatePasskeyAuthenticationOptions, verifyPasskeyAuthentication } from "./passkeys/passkey-authentication.mjs";
|
|
32
|
+
import { generatePasskeyRegistrationOptions, verifyPasskeyRegistration } from "./passkeys/passkey-registration.mjs";
|
|
33
|
+
import { GOOGLE_AUTH_FEATURE, GoogleProvider, JoseModule, pkceChallenge } from "./providers/google-provider.mjs";
|
|
34
|
+
import { completeProviderLogin, resolveAuthProvider, startProviderLogin } from "./providers/provider-login.mjs";
|
|
12
35
|
import { AuthEventCallback, AuthEventName, AuthEventPayloads, authEvents } from "./services/auth-events.mjs";
|
|
13
36
|
import { authService } from "./services/auth.service.mjs";
|
|
37
|
+
import { currentUser } from "./services/current-user.mjs";
|
|
14
38
|
import { generateJWTSecret } from "./services/generate-jwt-secret.mjs";
|
|
15
|
-
import { AuthErrorCodes } from "./utils/auth-error-codes.mjs";
|
|
16
39
|
import { TokenType, TokenTypeError, isInvalidCredentialError, jwt } from "./services/jwt.mjs";
|
|
40
|
+
import { isEmailVerified, sendEmailVerification, verifyEmail } from "./services/email-verification.mjs";
|
|
41
|
+
import { IssuedOneTimeToken, consumeOneTimeToken, hashOneTimeToken, issueOneTimeToken, oneTimeTokenModel } from "./services/one-time-tokens.mjs";
|
|
42
|
+
import { requestPasswordReset, resetPassword } from "./services/password-reset.mjs";
|
|
43
|
+
import { safeEqual } from "./utils/safe-equal.mjs";
|
|
17
44
|
import { isNeverExpiring, isUsableExpiry, tokenHasExpClaim } from "./utils/token-expiry.mjs";
|
|
18
|
-
export { AccessToken, AccessTokenConfig, AccessTokenOutput, Auth, AuthConfigurations, AuthCredentials, AuthErrorCodes, AuthEventCallback, AuthEventName, AuthEventPayloads, Authenticable, CanAuthenticate, DeviceInfo, LegacyJwtConfig, LoginResult, LoginThrottleIdentifier, LoginThrottleOptions, LogoutWithoutTokenBehavior, NO_EXPIRATION, PageAuthConfig, RefreshToken, RefreshTokenConfig, RefreshTokenIssueOptions, TokenFrom, TokenPair, TokenType, TokenTypeError, accessTokenSchema, authEvents, authMiddleware, authMigrations, authService, generateJWTSecret, isInvalidCredentialError, isNeverExpiring, isUsableExpiry, jwt, loginThrottleMiddleware, refreshTokenSchema, registerAuthCleanupCommand, registerAuthPurgeNeverExpiringCommand, registerJWTSecretGeneratorCommand, tokenHasExpClaim };
|
|
45
|
+
export { AccessToken, AccessTokenConfig, AccessTokenOutput, Auth, AuthConfigurations, AuthCredentials, AuthErrorCodes, AuthEventCallback, AuthEventName, AuthEventPayloads, AuthNotification, AuthProvider, AuthProviderSdkMissingError, Authenticable, CanAuthenticate, ClearAuthCookieOptions, CookieAuthConfig, CsrfConfig, CsrfOriginMismatchError, CsrfOriginMismatchReason, DeviceInfo, EmailNotVerifiedError, EmailVerificationConfig, GOOGLE_AUTH_FEATURE, GoogleProvider, GoogleProviderConfig, InvalidOneTimeTokenError, InvalidPasskeyError, InvalidProviderCallbackError, IssuedOneTimeToken, JoseModule, LegacyJwtConfig, LoginResult, LoginThrottleIdentifier, LoginThrottleOptions, LogoutWithoutTokenBehavior, NO_EXPIRATION, NotificationsUnavailableError, OneTimeToken, OneTimeTokenConfig, OneTimeTokenNotificationData, OneTimeTokenPurpose, OneTimeTokenUrlBuilder, OtpConfig, OtpMessage, OtpSender, PageAuthConfig, PasskeyCredential, type PasskeyOptionsJSON, type PasskeyResponseJSON, PasskeysConfig, PasswordResetConfig, PasswordSetter, ProviderAccount, ProviderAuthorizationState, ProviderCallbackParams, ProviderEmailNotVerifiedError, ProviderProfile, ProviderUserCreator, ProvidersConfig, RefreshToken, RefreshTokenConfig, RefreshTokenIssueOptions, RequestUser, SetAuthCookieOptions, TokenFrom, TokenPair, TokenType, TokenTypeError, accessTokenSchema, assertCsrfOriginAllowed, authEvents, authMiddleware, authMigrations, authService, completeProviderLogin, consumeOneTimeToken, currentUser, generateJWTSecret, generatePasskeyAuthenticationOptions, generatePasskeyRegistrationOptions, hashOneTimeToken, isEmailVerified, isInvalidCredentialError, isNeverExpiring, isUsableExpiry, issueOneTimeToken, jwt, loginThrottleMiddleware, oneTimeTokenModel, oneTimeTokenSchema, otpRequestThrottleMiddleware, otpVerifyThrottleMiddleware, passkeyCredentialSchema, pkceChallenge, providerAccountSchema, refreshTokenSchema, registerAuthCleanupCommand, registerAuthPurgeNeverExpiringCommand, registerJWTSecretGeneratorCommand, requestOtp, requestPasswordReset, requireVerifiedEmail, requiresCsrfOriginCheck, resetPassword, resolveAuthProvider, safeEqual, sendEmailVerification, startProviderLogin, tokenConsumeThrottleMiddleware, tokenHasExpClaim, tokenIssueThrottleMiddleware, verifyEmail, verifyOtp, verifyPasskeyAuthentication, verifyPasskeyRegistration };
|
|
46
|
+
import "./contracts/request-locals.mjs";
|
package/esm/index.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { isNeverExpiring, isUsableExpiry, tokenHasExpClaim } from "./utils/token-expiry.mjs";
|
|
2
2
|
import { AccessToken, accessTokenSchema } from "./models/access-token/access-token.model.mjs";
|
|
3
|
+
import { OneTimeToken, oneTimeTokenSchema } from "./models/one-time-token/one-time-token.model.mjs";
|
|
3
4
|
import { RefreshToken, refreshTokenSchema } from "./models/refresh-token/refresh-token.model.mjs";
|
|
4
5
|
import { authEvents } from "./services/auth-events.mjs";
|
|
5
6
|
import { AuthErrorCodes } from "./utils/auth-error-codes.mjs";
|
|
@@ -10,12 +11,39 @@ import { registerAuthPurgeNeverExpiringCommand } from "./commands/auth-purge-nev
|
|
|
10
11
|
import { generateJWTSecret } from "./services/generate-jwt-secret.mjs";
|
|
11
12
|
import { registerJWTSecretGeneratorCommand } from "./commands/jwt-secret-generator-command.mjs";
|
|
12
13
|
import { NO_EXPIRATION } from "./contracts/types.mjs";
|
|
14
|
+
import { AuthProviderSdkMissingError } from "./errors/auth-provider-sdk-missing.error.mjs";
|
|
15
|
+
import { EmailNotVerifiedError } from "./errors/email-not-verified.error.mjs";
|
|
16
|
+
import { InvalidOneTimeTokenError } from "./errors/invalid-one-time-token.error.mjs";
|
|
17
|
+
import { InvalidPasskeyError } from "./errors/invalid-passkey.error.mjs";
|
|
18
|
+
import { InvalidProviderCallbackError } from "./errors/invalid-provider-callback.error.mjs";
|
|
19
|
+
import { NotificationsUnavailableError } from "./errors/notifications-unavailable.error.mjs";
|
|
20
|
+
import { ProviderEmailNotVerifiedError } from "./errors/provider-email-not-verified.error.mjs";
|
|
21
|
+
import "./errors/index.mjs";
|
|
22
|
+
import { CsrfOriginMismatchError, assertCsrfOriginAllowed, requiresCsrfOriginCheck } from "./middleware/csrf-origin-check.mjs";
|
|
13
23
|
import { authMiddleware } from "./middleware/auth.middleware.mjs";
|
|
14
24
|
import { loginThrottleMiddleware } from "./middleware/login-throttle.middleware.mjs";
|
|
25
|
+
import { tokenConsumeThrottleMiddleware, tokenIssueThrottleMiddleware } from "./middleware/one-time-token-throttle.middleware.mjs";
|
|
26
|
+
import { otpRequestThrottleMiddleware, otpVerifyThrottleMiddleware } from "./middleware/otp-throttle.middleware.mjs";
|
|
27
|
+
import { requireVerifiedEmail } from "./middleware/require-verified-email.middleware.mjs";
|
|
15
28
|
import "./middleware/index.mjs";
|
|
29
|
+
import { PasskeyCredential, passkeyCredentialSchema } from "./models/passkey-credential/passkey-credential.model.mjs";
|
|
30
|
+
import { ProviderAccount, providerAccountSchema } from "./models/provider-account/provider-account.model.mjs";
|
|
31
|
+
import { currentUser } from "./services/current-user.mjs";
|
|
32
|
+
import { consumeOneTimeToken, hashOneTimeToken, issueOneTimeToken, oneTimeTokenModel } from "./services/one-time-tokens.mjs";
|
|
33
|
+
import { isEmailVerified, sendEmailVerification, verifyEmail } from "./services/email-verification.mjs";
|
|
34
|
+
import { requestPasswordReset, resetPassword } from "./services/password-reset.mjs";
|
|
16
35
|
import "./services/index.mjs";
|
|
17
36
|
import { Auth } from "./models/auth.model.mjs";
|
|
18
37
|
import { authMigrations } from "./models/index.mjs";
|
|
38
|
+
import { safeEqual } from "./utils/safe-equal.mjs";
|
|
39
|
+
import { requestOtp, verifyOtp } from "./otp/otp.mjs";
|
|
40
|
+
import "./otp/index.mjs";
|
|
41
|
+
import { generatePasskeyAuthenticationOptions, verifyPasskeyAuthentication } from "./passkeys/passkey-authentication.mjs";
|
|
42
|
+
import { generatePasskeyRegistrationOptions, verifyPasskeyRegistration } from "./passkeys/passkey-registration.mjs";
|
|
43
|
+
import "./passkeys/index.mjs";
|
|
44
|
+
import { GOOGLE_AUTH_FEATURE, GoogleProvider, pkceChallenge } from "./providers/google-provider.mjs";
|
|
45
|
+
import { completeProviderLogin, resolveAuthProvider, startProviderLogin } from "./providers/provider-login.mjs";
|
|
46
|
+
import "./providers/index.mjs";
|
|
19
47
|
import "./utils/index.mjs";
|
|
20
48
|
|
|
21
|
-
export { AccessToken, Auth, AuthErrorCodes, NO_EXPIRATION, RefreshToken, TokenTypeError, accessTokenSchema, authEvents, authMiddleware, authMigrations, authService, generateJWTSecret, isInvalidCredentialError, isNeverExpiring, isUsableExpiry, jwt, loginThrottleMiddleware, refreshTokenSchema, registerAuthCleanupCommand, registerAuthPurgeNeverExpiringCommand, registerJWTSecretGeneratorCommand, tokenHasExpClaim };
|
|
49
|
+
export { AccessToken, Auth, AuthErrorCodes, AuthProviderSdkMissingError, CsrfOriginMismatchError, EmailNotVerifiedError, GOOGLE_AUTH_FEATURE, GoogleProvider, InvalidOneTimeTokenError, InvalidPasskeyError, InvalidProviderCallbackError, NO_EXPIRATION, NotificationsUnavailableError, OneTimeToken, PasskeyCredential, ProviderAccount, ProviderEmailNotVerifiedError, RefreshToken, TokenTypeError, accessTokenSchema, assertCsrfOriginAllowed, authEvents, authMiddleware, authMigrations, authService, completeProviderLogin, consumeOneTimeToken, currentUser, generateJWTSecret, generatePasskeyAuthenticationOptions, generatePasskeyRegistrationOptions, hashOneTimeToken, isEmailVerified, isInvalidCredentialError, isNeverExpiring, isUsableExpiry, issueOneTimeToken, jwt, loginThrottleMiddleware, oneTimeTokenModel, oneTimeTokenSchema, otpRequestThrottleMiddleware, otpVerifyThrottleMiddleware, passkeyCredentialSchema, pkceChallenge, providerAccountSchema, refreshTokenSchema, registerAuthCleanupCommand, registerAuthPurgeNeverExpiringCommand, registerJWTSecretGeneratorCommand, requestOtp, requestPasswordReset, requireVerifiedEmail, requiresCsrfOriginCheck, resetPassword, resolveAuthProvider, safeEqual, sendEmailVerification, startProviderLogin, tokenConsumeThrottleMiddleware, tokenHasExpClaim, tokenIssueThrottleMiddleware, verifyEmail, verifyOtp, verifyPasskeyAuthentication, verifyPasskeyRegistration };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.middleware.d.mts","names":[],"sources":["../../../../../../../auth/src/middleware/auth.middleware.ts"],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"auth.middleware.d.mts","names":[],"sources":["../../../../../../../auth/src/middleware/auth.middleware.ts"],"mappings":";;;;;;AA6GA;;;;;;;;;AAGa;;;;;;;;;;iBAHG,cAAA,CACd,eAAA,qBACA,SAAA,GAAW,SAAA,GACV,UAAU"}
|
|
@@ -4,6 +4,7 @@ import { authConfig } from "../services/auth-config.mjs";
|
|
|
4
4
|
import { AuthErrorCodes } from "../utils/auth-error-codes.mjs";
|
|
5
5
|
import { isInvalidCredentialError, jwt } from "../services/jwt.mjs";
|
|
6
6
|
import { authService } from "../services/auth.service.mjs";
|
|
7
|
+
import { CsrfOriginMismatchError, assertCsrfOriginAllowed, requiresCsrfOriginCheck } from "./csrf-origin-check.mjs";
|
|
7
8
|
import { config, t } from "@warlock.js/core";
|
|
8
9
|
import { log } from "@warlock.js/logger";
|
|
9
10
|
|
|
@@ -90,13 +91,23 @@ function authMiddleware(allowedUserType, tokenFrom = "header") {
|
|
|
90
91
|
error: t("auth.errors.missingAccessToken"),
|
|
91
92
|
errorCode: "EC001"
|
|
92
93
|
});
|
|
94
|
+
if (requiresCsrfOriginCheck(tokenFrom, request.method)) try {
|
|
95
|
+
assertCsrfOriginAllowed(request);
|
|
96
|
+
} catch (error) {
|
|
97
|
+
if (!(error instanceof CsrfOriginMismatchError)) throw error;
|
|
98
|
+
log.error("http", "auth", error);
|
|
99
|
+
return response.forbidden({
|
|
100
|
+
error: t("auth.errors.csrfOriginMismatch"),
|
|
101
|
+
errorCode: "EC006"
|
|
102
|
+
});
|
|
103
|
+
}
|
|
93
104
|
let decoded;
|
|
94
105
|
try {
|
|
95
106
|
decoded = await jwt.verify(authorizationValue);
|
|
96
107
|
} catch (error) {
|
|
97
108
|
if (!isInvalidCredentialError(error)) throw error;
|
|
98
109
|
log.error("http", "auth", error);
|
|
99
|
-
request.
|
|
110
|
+
request.locals.user = void 0;
|
|
100
111
|
return rejectUnauthorized({
|
|
101
112
|
request,
|
|
102
113
|
response
|
|
@@ -152,7 +163,7 @@ function authMiddleware(allowedUserType, tokenFrom = "header") {
|
|
|
152
163
|
error: t("auth.errors.unauthorized"),
|
|
153
164
|
errorCode: "EC003"
|
|
154
165
|
});
|
|
155
|
-
request.user = currentUser;
|
|
166
|
+
request.locals.user = currentUser;
|
|
156
167
|
};
|
|
157
168
|
return auth;
|
|
158
169
|
}
|