@passflow/core 0.24.0 → 0.25.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 +35 -0
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +116 -7
- package/dist/index.d.ts +116 -7
- package/dist/index.mjs +766 -660
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -34,6 +34,7 @@
|
|
|
34
34
|
- [Passkey Authentication](#passkey-authentication)
|
|
35
35
|
- [Password Reset](#password-reset)
|
|
36
36
|
- [Email verification](#email-verification)
|
|
37
|
+
- [Two-factor sign-in and first-time enrolment](#two-factor-sign-in-and-first-time-enrolment)
|
|
37
38
|
- [Token Management](#token-management)
|
|
38
39
|
- [Tenant Management](#tenant-management)
|
|
39
40
|
- [Invitation Management](#invitation-management)
|
|
@@ -569,6 +570,40 @@ new `challenge_id`.
|
|
|
569
570
|
an optional third argument. Without it, the SDK reads `token` from the URL query, then from the
|
|
570
571
|
query of a hash route (`#/reset?token=...`).
|
|
571
572
|
|
|
573
|
+
### Two-factor sign-in and first-time enrolment
|
|
574
|
+
|
|
575
|
+
A `required` app answers every sign-in with a `tfa_token`, also for a user who has no factor yet.
|
|
576
|
+
Ask the server what this sign-in can do next before asking for a code:
|
|
577
|
+
|
|
578
|
+
```typescript
|
|
579
|
+
switch (await passflow.getTwoFactorEnrollment()) {
|
|
580
|
+
case "verify": // the user has a factor
|
|
581
|
+
await passflow.verifyTwoFactor(code);
|
|
582
|
+
break;
|
|
583
|
+
case "email_link": // no factor, validated email: the user enrols from the email, then signs in again
|
|
584
|
+
await passflow.sendTwoFactorSetupLink();
|
|
585
|
+
break;
|
|
586
|
+
case "direct": { // no factor, no validated email: enrol on this sign-in
|
|
587
|
+
const setup = await passflow.beginTwoFactorEnrollment(); // setup.secret, setup.qr_code (base64 PNG)
|
|
588
|
+
const { recovery_codes } = await passflow.confirmTwoFactorEnrollment(code); // show these once
|
|
589
|
+
await passflow.verifyTwoFactor(code); // the same code finishes the sign-in
|
|
590
|
+
break;
|
|
591
|
+
}
|
|
592
|
+
case "unavailable": // no way to enrol here: tell the user to contact the administrator
|
|
593
|
+
break;
|
|
594
|
+
}
|
|
595
|
+
```
|
|
596
|
+
|
|
597
|
+
- **The server decides.** Setup calls in the wrong state answer 403 `error.2fa.enrollment.not_allowed`.
|
|
598
|
+
- **The sign-in is over** on a 401 `error.tfa.token.invalid` or `error.otp.already.used`: sign in again.
|
|
599
|
+
- **Rate limits are per user.** `sendTwoFactorSetupLink`, `beginTwoFactorEnrollment`,
|
|
600
|
+
`requestChallenge` and `switchToAlternative` share 3 requests in 5 minutes, then a 10-minute
|
|
601
|
+
lockout. `confirmTwoFactorEnrollment` and `verifyTwoFactor` share 5 in 15 minutes. These 429s
|
|
602
|
+
reject with the raw axios error (`error.response.status`).
|
|
603
|
+
- **The emailed link.** Call `validateTwoFactorSetupMagicLink(token)` on its page. While that session
|
|
604
|
+
is active, `getTwoFactorStatus`, `beginTwoFactorSetup` and `confirmTwoFactorSetup` run on it instead
|
|
605
|
+
of the stored session, and a correct confirm ends it. A used link reads as error code `ALREADY_USED`.
|
|
606
|
+
|
|
572
607
|
## Token Management
|
|
573
608
|
|
|
574
609
|
```javascript
|