@passflow/core 0.30.2 → 0.31.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/README.md CHANGED
@@ -2,6 +2,80 @@
2
2
 
3
3
  ## Changelog
4
4
 
5
+ ### Version 0.31.0
6
+
7
+ Matches the SDK to the server's real two-factor, step-up and sign-out answers.
8
+
9
+ **Breaking:**
10
+ - `getTwoFactorEnrollment()` returns `{ enrollment, totp_digits?, totp_period? }`, not the bare string.
11
+ - 2FA types follow the server: status has no `policy`; confirm is `{ enabled, recovery_codes? }`,
12
+ disable `{ disabled }`, regenerate `{ recovery_codes }`; `remaining_recovery_codes` is optional;
13
+ `requires_2fa` and `device_trusted` are gone (a `tfa_token` marks a pending second factor).
14
+ `getAvailableMethods()` and `getRegisteredMethods()` return the arrays, not the server's wrapper.
15
+ - `TwoFactorDeviceTrusted` is no longer emitted (`@deprecated`): device trust is a server cookie.
16
+ - A sign-up that signs the user in emits `Register` and then `SignIn`; `verifyV2` emits `SignIn`
17
+ after `TwoFactorVerified` when it completes a sign-in.
18
+ - After a hosted sign-in (`authRedirect()`), `logOut()` also ends the hosted login's session: after
19
+ the local sign-out it navigates to `/oidc/end_session` with `id_token_hint` and
20
+ `post_logout_redirect_uri` (default: where the sign-in landed; `logOut({ postLogoutRedirectUri })`
21
+ overrides it, and it must match a registered redirect URL). Code after `await logOut()` may not run.
22
+ - Stored tokens whose `aud` does not name this instance's app id no longer count as a session, and
23
+ this app's sign-out leaves another app's stored session in place.
24
+ - `session({ createSession, expiredSession })` now runs for every completed sign-in, including
25
+ `signIn`, `signUp`, `passkeyRegister` and v2 verify.
26
+ - Step-up offers exactly the factors in the server's `available_factors`, in its order
27
+ (`UpgradeChallenge.availableFactors?`); without the field it suggests TOTP before passkey.
28
+ - A 429 on a step-up round is `UpgradeTransportError` kind `rate_limited` (it was `fatal`), with the
29
+ server's message and `retryAfter` from `Retry-After`; the surfaces settle it as exhausted.
30
+ - Response types that strict TypeScript code reads now say what the server may leave out. Handle
31
+ `undefined` for these, and stop checking `success` where it is gone:
32
+ - `AppSettings`: `secret`, `active`, `redirect_urls`, `origins`, `defaults`,
33
+ `custom_sms_messages`, `invite_only_registration`, `create_tenant_on_registration` and
34
+ `debug_otp_code_allowed` are optional.
35
+ - `TwoFactorVerifyResponseV2.success` is removed (a v2 verify that returns tokens succeeded).
36
+ - `success` on `TwoFactorVerifyResponse` and `TwoFactorRecoveryResponse` is optional.
37
+ - `RegisteredTwoFactorMethod.id`, `.name` and `.created_at`, and
38
+ `TwoFactorChallengeResponse.alternative_methods`, are optional.
39
+ - The `TwoFactorRecoveryUsed` event payload's `remainingCodes` is optional.
40
+
41
+ **New:**
42
+ - `UpgradeSignInRequiredError` (`upgrade_sign_in_required`) and `isUpgradeSignInRequired(res)`: the
43
+ step-up 403's `sign_in_required: true` (`prompt=login`, `max_age=0`, an expired `max_age` with no
44
+ factor to meet it; from older servers, an empty `available_factors`) means no step-up can meet it
45
+ and the user must sign in again. No prompt opens; an open prompt is
46
+ closed through the new optional `onClosed`. An empty list with `sign_in_required: false` is
47
+ `UpgradeUnsatisfiableError`: no factor of this account reaches the level.
48
+ - `passflow.hostedUpgrade` refuses to re-prove a requirement it proved in the last 10 seconds (or
49
+ within its `max_age`, if shorter) with `UpgradeInsufficientError`, so a refused proof cannot loop.
50
+ A sign-in or sign-out clears it. Keep every elevation window at 10 seconds or more (see Known
51
+ limits).
52
+ - `PassflowPasswordChangeRequiredError` and `PASSWORD_CHANGE_REQUIRED_ERROR_ID` for a 403
53
+ `error.api.password.change.required`.
54
+ - `device_trust_available?` on the v2 challenge and the enrolment answer; `redirect_url?` and
55
+ `form_post?` on the v1 and v2 verify answers for a sign-in with an OIDC parent.
56
+
57
+ **Fixed:**
58
+ - The TOTP digit count is read from enrolment and the v2 challenge too, so an 8-digit enrolment works
59
+ on a fresh sign-in; the count resets with each new second-factor step.
60
+ - `verifyV2` completes the sign-in (it waited for a `success` field the server never sends).
61
+ - Recovery codes are checked only for their form; the server decides.
62
+ - `PassflowError.name` is `'PassflowError'`.
63
+
64
+ **Known limits:**
65
+ - The `hostedUpgrade` memory assumes the app's elevation window (`auth_assurance.elevation_max_age`)
66
+ is at least 10 seconds. Servers up to src/v0.49.1, the current release, accept any window, so the
67
+ 10 s minimum does not apply on them. src/v0.50.0, the next server release (not yet released),
68
+ refuses new windows under 10 seconds but keeps a shorter one already stored. With a window under
69
+ 10 seconds, a re-challenge for the same requirement within 10 seconds of the proof is refused with
70
+ `UpgradeInsufficientError`, costing the user one extra sign-in. Keep every window at 10 seconds or
71
+ more, and re-save any shorter one.
72
+ - A stale session (`max_age` expired) asked for a level none of the account's factors reaches gets
73
+ `sign_in_required: true` first. After the fresh sign-in, the level refusal follows as
74
+ `UpgradeUnsatisfiableError`, so that sign-in cannot help.
75
+ - A cookie or BFF session that stores no ID token makes another app's session undetectable, so this
76
+ app's `logOut()` clears the shared delivery mode and session state. It fails safe: the other app is
77
+ signed out, never wrongly signed in.
78
+
5
79
  ### Version 0.30.1
6
80
 
7
81
  - Fixed: `setAppId()` on an instance built with an `appId` now changes the `X-Passflow-ClientID`
@@ -160,6 +234,17 @@ const simpleSignOut = async () => {
160
234
  };
161
235
  ```
162
236
 
237
+ After a hosted sign-in (`authRedirect()`), `logOut()` also ends the hosted login's own session.
238
+ Otherwise the next hosted sign-in would go through with no password. Once the local sign-out and
239
+ its `SignOut` event have run, the page leaves for the server's `/oidc/end_session`, which returns
240
+ the browser to `postLogoutRedirectUri`. By default that is the address the hosted sign-in landed
241
+ on, and it must match one of the app's registered redirect URLs. Code after `await logOut()` may
242
+ not run then. A sign-in made in the app itself never navigates.
243
+
244
+ ```javascript
245
+ await passflow.logOut({ postLogoutRedirectUri: "https://app.example.com/signed-out" });
246
+ ```
247
+
163
248
  ### Quick Passwordless Authentication
164
249
 
165
250
  ```javascript
@@ -665,10 +750,12 @@ expired or spent code throws a `PassflowError` with an `error.otp.*` id, and an
665
750
  throws `error.not.found`. To send a fresh code, call the original method again; the new step has a
666
751
  new `challenge_id`.
667
752
 
668
- - **Register or SignIn.** `verifyEmailCode` emits `Register` for a challenge this `Passflow`
669
- instance got from `signUp`, and `SignIn` for one from `signIn` or `resetPassword`. Challenges are
670
- remembered in memory only, so a code entered in another tab, after a reload, or on a recreated
671
- instance emits `SignIn`, even for a sign-up. It emits no `SignInStart` or `RegisterStart`.
753
+ - **Register or SignIn.** `verifyEmailCode` emits `Register` then `SignIn` for a challenge this
754
+ `Passflow` instance got from `signUp`, and `SignIn` alone for one from `signIn` or
755
+ `resetPassword`. Challenges are remembered in memory only, so a code entered in another tab, after
756
+ a reload, or on a recreated instance emits `SignIn` alone, even for a sign-up. `verifyEmailCode`
757
+ emits no `SignInStart` or `RegisterStart`. `signUp` and `passkeyRegister` that sign the user in at
758
+ once also emit `Register` then `SignIn`.
672
759
  - **No `challenge_id`.** The code budget is spent and the server emailed a link instead. There is
673
760
  nothing to call: show `message` and let the user follow the link.
674
761
  - **Password reset.** `resetPassword(newPassword, scopes?, resetToken?)` takes the reset token as
@@ -681,7 +768,8 @@ A `required` app answers every sign-in with a `tfa_token`, also for a user who h
681
768
  Ask the server what this sign-in can do next before asking for a code:
682
769
 
683
770
  ```typescript
684
- switch (await passflow.getTwoFactorEnrollment()) {
771
+ const { enrollment } = await passflow.getTwoFactorEnrollment();
772
+ switch (enrollment) {
685
773
  case "verify": // the user has a factor
686
774
  await passflow.verifyTwoFactor(code);
687
775
  break;
@@ -699,6 +787,52 @@ switch (await passflow.getTwoFactorEnrollment()) {
699
787
  }
700
788
  ```
701
789
 
790
+ - **Trusted devices.** `device_trust_available` on the enrolment and on a v2 challenge says whether
791
+ to offer "trust this device" (`trust_device`) on this sign-in. Older servers leave it out: absent
792
+ means unknown, so hide the option only when it is `false`.
793
+ - **TOTP digits.** Read `getTwoFactorEnrollment()` before asking for the code. With a TOTP
794
+ enrolment it answers `totp_digits` (6 or 8) and `totp_period`, as does `requestChallenge`: size the
795
+ code input from `totp_digits`, and `verifyTwoFactor` then expects exactly that many digits. Until
796
+ an answer gives the count, `verifyTwoFactor` accepts 6 or 8 digits and the server decides. The
797
+ count lasts one sign-in.
798
+ - **Recovery codes** are 12 characters by default, issued as `XXXX-XXXX-XXXX`; apps choose 10–16
799
+ (only 12 is grouped with dashes). The server issues recovery codes
800
+ on every enrolment; `recovery_codes` on confirm is optional only so an older or different server
801
+ that omits it doesn't break the type. Older 8-character `XXXX-XXXX`
802
+ codes still work until they are regenerated. The SDK checks only the form (letters, digits and
803
+ optional dashes) and upper-cases the code; the server decides whether it is valid. `remaining_recovery_codes` may be
804
+ absent from the answer.
805
+ - **Step-up offers what the server lists.** The step-up 403 from `/auth/session/exchange` carries
806
+ `available_factors`, the factors this user can step up with, and the SDK offers exactly those in
807
+ that order. Without it (older servers), TOTP is suggested before passkey. When the list is empty,
808
+ no prompt opens and an open prompt is closed (its `onClosed` is called). The body's
809
+ `sign_in_required` says why:
810
+ - `true`: no step-up can meet the requirement, and the user must sign in again (`prompt=login`,
811
+ `max_age=0`, or an expired `max_age` with no factor to meet it). If the requested level is also
812
+ out of the account's reach, the next answer after that sign-in is the `false` case. The step-up
813
+ rejects with `UpgradeSignInRequiredError` (on a response, `isUpgradeSignInRequired(res)` is
814
+ true). Sign the user in again: an embedded app can call `authRedirect()`; the hosted login page
815
+ shows its own sign-in form instead.
816
+ - `false`: a step-up could meet it, but this account has no factor that reaches the level (for
817
+ example AAL3 needs a device-bound passkey). The step-up rejects with `UpgradeUnsatisfiableError`;
818
+ signing in again will not help.
819
+ - absent (older servers): an empty list counts as `true`.
820
+
821
+ A requirement like this that joins an open step-up ends it for every waiter, including one whose
822
+ own requirement the open prompt could have met: they all settle with the same error.
823
+
824
+ `UpgradeUnsatisfiableError` also means the server listed only factors this SDK cannot complete.
825
+ - **A hosted step-up is proved once per requirement.** `passflow.hostedUpgrade` remembers the
826
+ challenge it last proved on this page. An `elevate()` with a challenge that is not strictly
827
+ stronger (a higher level or a shorter `max_age`) rejects with `UpgradeInsufficientError`, with no
828
+ prompt and no request: the server refused a proof that met it, so prompting again would loop. Sign
829
+ the user in again instead. The proof counts for 10 seconds from its commit request (or the
830
+ requirement's `max_age`, if shorter): after that the same requirement prompts again. A sign-in or
831
+ sign-out clears it. Keep the app's elevation window (`auth_assurance.elevation_max_age`) at 10
832
+ seconds or more: a shorter window can lapse inside those 10 seconds, and the re-challenge is then
833
+ refused, costing one extra sign-in. Servers up to src/v0.49.1 accept any window. src/v0.50.0, the
834
+ next server release (not yet released), refuses new windows under 10 seconds; after upgrading,
835
+ re-save any shorter one already stored.
702
836
  - **The server decides.** Setup calls in the wrong state answer 403 `error.2fa.enrollment.not_allowed`.
703
837
  - **The sign-in is over** on a 401 `error.tfa.token.invalid` or `error.otp.already.used`: sign in again.
704
838
  - **Rate limits are per user.** `sendTwoFactorSetupLink`, `beginTwoFactorEnrollment`,
@@ -964,6 +1098,13 @@ try {
964
1098
  }
965
1099
  ```
966
1100
 
1101
+ ### Password change required
1102
+
1103
+ A password sign-in for a user who must change the password first rejects with
1104
+ `PassflowPasswordChangeRequiredError` (a `PassflowError`, status 403, id
1105
+ `error.api.password.change.required`, exported as `PASSWORD_CHANGE_REQUIRED_ERROR_ID`). No token
1106
+ comes with it.
1107
+
967
1108
  ### Service unavailable
968
1109
 
969
1110
  In a browser, when the Passflow API cannot be reached or its gateway answers 502, 503 or 504 itself,
@@ -1024,7 +1165,7 @@ Configuration options:
1024
1165
  | `session({ createSession, expiredSession, doRefresh })` | Set up session management |
1025
1166
  | `signIn(payload)` | Sign in with email/password |
1026
1167
  | `signUp(payload)` | Register a new user |
1027
- | `logOut()` | Sign out the current user |
1168
+ | `logOut(options?)` | Sign out the current user |
1028
1169
  | `passwordlessSignIn(payload)` | Start passwordless authentication |
1029
1170
  | `passwordlessSignInComplete(payload)` | Complete passwordless authentication |
1030
1171
  | `federatedAuthWithPopup(provider, redirectUrl, scopes)` | Sign in with a provider using popup |