@jskit-ai/auth-core 0.2.31 → 0.2.33

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 CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ - **Breaking:** the dev auth policy (`resolveDevAuthPolicy`, `resolveDevAuthPolicyFromEnv`) names whether the application runs in staging or production `isStagingOrProduction`, in place of `isDeployed`. A read of the old field is `undefined`.
5
6
  - Email change: `features.emailChange` and three auth.service operations it gates (`AUTH_OPERATION_FEATURES`): `requestEmailChange(request, { email, password })`, the signed-in person's own change; `requestEmailChangeForUser({ userId, email })`, an application's change of an account it chose; and `confirmEmailChange({ token })`, the link sent to the new address. Two actions run them over HTTP and from server code, never automation: `auth.emailChange.request` (signed in) and `auth.emailChange.confirm` (anyone with the link), from `createEmailChangeActions` (`./server/actions/emailChangeActions`), which `AuthFeature` contributes; their commands are `authEmailChangeRequestCommand` and `authEmailChangeConfirmCommand` (`./shared/commands/authEmailChangeCommands`), and their paths `AUTH_PATHS.EMAIL_CHANGE` (`/api/email-change`) and `AUTH_PATHS.EMAIL_CHANGE_CONFIRM` (`/api/email-change/confirm`). Upgrading: every auth provider implements the three operations; one without email change throws `AUTH_OPERATION_UNSUPPORTED`.
6
7
  - The actions that sign someone in hand `auth.service` the request they came in on: `auth.register`, `auth.register.confirm`, `auth.login.password` and `auth.password.recovery.complete` call `register`, `confirmRegistration`, `login` and `completePasswordRecovery` with `(input, request)`, the request null for an internal call, as `auth.login.oauth.complete` and `auth.dev.loginAs` already did, so a provider can keep where each session was signed in from. `AuthService` documents the optional second parameter; a provider that ignores it is unchanged.
7
8
  - **Breaking:** dev sign-in, the CSRF cookie's `Secure` and `__Host-` prefix and unknown role grants follow `APP_ENV`, not `NODE_ENV`. `resolveDevAuthPolicy({ enabled, appEnv, secret })` takes the application's `APP_ENV` in place of `nodeEnv` and answers `isDeployed` (staging or production) in place of `isProduction`; a missing or unknown `appEnv` throws. `AUTH_DEV_BYPASS_ENABLED` in staging or production refuses to start with `AUTH_DEV_BYPASS_ENABLED is for development only: remove it from staging and production.` The auth plugin takes `appEnv` in place of `nodeEnv`.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jskit-ai/auth-core",
3
- "version": "0.2.31",
3
+ "version": "0.2.33",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "test": "jskit test"
@@ -149,6 +149,6 @@
149
149
  }
150
150
  },
151
151
  "peerDependencies": {
152
- "@jskit-ai/kernel": "0.2.27"
152
+ "@jskit-ai/kernel": "0.2.29"
153
153
  }
154
154
  }
@@ -1,4 +1,4 @@
1
- import { isDeployed } from "@jskit-ai/kernel/shared/support/appEnvironment";
1
+ import { isStagingOrProduction } from "@jskit-ai/kernel/shared/support/appEnvironment";
2
2
  import { AppError } from "@jskit-ai/kernel/server/runtime/errors";
3
3
  import { timingSafeEqual } from "node:crypto";
4
4
  import { parseBooleanFlag } from "./booleanFlag.js";
@@ -55,7 +55,7 @@ function isLocalDevAuthRequest(request) {
55
55
  }
56
56
 
57
57
  /**
58
- * Dev sign-in's policy, and whether the application is deployed (staging or production), which every auth provider
58
+ * Dev sign-in's policy, and whether the application runs in staging or production, which every auth provider
59
59
  * reads from here to refuse development shortcuts such as cookies without Secure.
60
60
  * @param {{ enabled?: unknown, appEnv: string, secret?: string }} settings `appEnv` is the application's APP_ENV;
61
61
  * a missing or unknown one throws.
@@ -63,7 +63,7 @@ function isLocalDevAuthRequest(request) {
63
63
  function resolveDevAuthPolicy({ enabled = false, appEnv, secret = "" }) {
64
64
  return Object.freeze({
65
65
  enabled: parseBooleanFlag(enabled, false),
66
- isDeployed: isDeployed({ APP_ENV: appEnv }),
66
+ isStagingOrProduction: isStagingOrProduction({ APP_ENV: appEnv }),
67
67
  secret: String(secret || "").trim()
68
68
  });
69
69
  }
@@ -81,14 +81,14 @@ function resolveDevAuthPolicyFromEnv(env) {
81
81
  * @param {ReturnType<typeof resolveDevAuthPolicy>} policy
82
82
  */
83
83
  function isDevAuthBootstrapEnabled(policy) {
84
- return policy.enabled && !policy.isDeployed;
84
+ return policy.enabled && !policy.isStagingOrProduction;
85
85
  }
86
86
 
87
87
  function assertDevAuthPolicy(policy = {}) {
88
88
  if (!policy.enabled) {
89
89
  return;
90
90
  }
91
- if (policy.isDeployed) {
91
+ if (policy.isStagingOrProduction) {
92
92
  throw new Error("AUTH_DEV_BYPASS_ENABLED is for development only: remove it from staging and production.");
93
93
  }
94
94
  if (!policy.secret) {
@@ -97,7 +97,7 @@ function assertDevAuthPolicy(policy = {}) {
97
97
  }
98
98
 
99
99
  function ensureDevAuthRuntimeAvailable(policy = {}, request = null) {
100
- if (!policy.enabled || policy.isDeployed) {
100
+ if (!policy.enabled || policy.isStagingOrProduction) {
101
101
  throw new AppError(404, "Not found.", { code: "auth.dev.unavailable" });
102
102
  }
103
103
  if (!policy.secret) {
@@ -1,7 +1,7 @@
1
1
  import fastifyCookie from "@fastify/cookie";
2
2
  import fastifyCsrfProtection from "@fastify/csrf-protection";
3
3
  import { safeRequestUrl } from "@jskit-ai/kernel/server/runtime/requestUrl";
4
- import { isDeployed } from "@jskit-ai/kernel/shared/support/appEnvironment";
4
+ import { isStagingOrProduction } from "@jskit-ai/kernel/shared/support/appEnvironment";
5
5
  import { SECOND_FACTOR_REQUIRED } from "../../shared/authSecondFactor.js";
6
6
  import { isSecondFactorMet, secondFactorRequiredParams } from "../secondFactor.js";
7
7
  import { hostOnlyCookieName } from "../utils.js";
@@ -83,7 +83,7 @@ function authPolicyPlugin(deps = {}, options = {}) {
83
83
  // CSRF uses tokens checked against a secret cookie, never SameSite alone. In
84
84
  // staging and production (APP_ENV) that cookie is host-only (__Host-), so a sibling host cannot plant
85
85
  // a secret it knows and forge tokens.
86
- const csrfCookieSecure = typeof csrfCookieOpts.secure === "boolean" ? csrfCookieOpts.secure : isDeployed({ APP_ENV: options.appEnv });
86
+ const csrfCookieSecure = typeof csrfCookieOpts.secure === "boolean" ? csrfCookieOpts.secure : isStagingOrProduction({ APP_ENV: options.appEnv });
87
87
  const csrfCookieOptions = {
88
88
  path: "/",
89
89
  sameSite: "lax",
@@ -70,7 +70,7 @@ test("dev sign-in follows APP_ENV: allowed in development and test, refused in s
70
70
  }
71
71
  for (const APP_ENV of ["staging", "production"]) {
72
72
  const policy = policyIn(APP_ENV, "production");
73
- assert.equal(policy.isDeployed, true, APP_ENV);
73
+ assert.equal(policy.isStagingOrProduction, true, APP_ENV);
74
74
  assert.equal(isDevAuthBootstrapEnabled(policy), false, APP_ENV);
75
75
  assert.throws(() => ensureDevAuthRuntimeAvailable(policy, createRequest()), { code: "auth.dev.unavailable" }, APP_ENV);
76
76
  }