@passflow/core 0.23.0 → 0.24.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 +50 -1
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +210 -2
- package/dist/index.d.ts +210 -2
- package/dist/index.mjs +831 -546
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -364,6 +364,36 @@ const completePasswordless = async (challengeId, otp) => {
|
|
|
364
364
|
};
|
|
365
365
|
```
|
|
366
366
|
|
|
367
|
+
**PKCE apps: approving a magic link from any device.** On an app with PKCE on, a magic link's answer
|
|
368
|
+
holds a `match_code`. The tab that started the sign-in shows that code and finishes the sign-in. The
|
|
369
|
+
device that opens the link only approves or denies, by typing the code, and gets no tokens. A second
|
|
370
|
+
tab in the same browser approves like any other device.
|
|
371
|
+
|
|
372
|
+
```typescript
|
|
373
|
+
// Tab A: the tab that called passwordlessSignIn
|
|
374
|
+
const { challenge_id } = await passflow.passwordlessSignIn({
|
|
375
|
+
email: "user@example.com",
|
|
376
|
+
challenge_type: "magic_link",
|
|
377
|
+
redirect_url: "https://yourapp.com/auth/callback",
|
|
378
|
+
});
|
|
379
|
+
|
|
380
|
+
const pending = passflow.getPendingPasswordlessSignIn(challenge_id);
|
|
381
|
+
if (pending) {
|
|
382
|
+
showCode(pending.matchCode);
|
|
383
|
+
const result = await passflow.waitForPasswordlessSignIn(challenge_id);
|
|
384
|
+
// result.status: "signed-in" | "second-factor-required" | "denied" | "expired" | "completed"
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
// Device B: the link carries challenge_id, otp and flow=approval
|
|
388
|
+
const info = await passflow.getPasswordlessApproval(challengeId); // app, browser, OS, location, attempts_left
|
|
389
|
+
await passflow.decidePasswordlessApproval(challengeId, otp, true, typedMatchCode); // or false to deny
|
|
390
|
+
```
|
|
391
|
+
|
|
392
|
+
If `getPendingPasswordlessSignIn` answers `undefined`, there is no approval step: show today's "check
|
|
393
|
+
your email" screen. The record that finishes the sign-in lives in this tab only. If it is lost or
|
|
394
|
+
replaced (a new start, Resend, sign-out), the wait rejects and the user starts again. Results, errors
|
|
395
|
+
and the device B screen: [docs/pkce-sign-in.md](docs/pkce-sign-in.md).
|
|
396
|
+
|
|
367
397
|
### Federated Authentication
|
|
368
398
|
|
|
369
399
|
```javascript
|
|
@@ -382,6 +412,17 @@ passflow.federatedAuthWithRedirect(
|
|
|
382
412
|
);
|
|
383
413
|
```
|
|
384
414
|
|
|
415
|
+
**PKCE apps.** `federatedAuthWithRedirect` still returns `void`, but it now navigates asynchronously:
|
|
416
|
+
a missing `appId` still throws synchronously, and a later failure emits `Error` with operation
|
|
417
|
+
`federated.redirect`. The landing (`?code=&user_state=`) is taken by the constructor under
|
|
418
|
+
`parseQueryParams`, or by `handleTokensRedirect()`, which returns `undefined` for it. The exchange runs
|
|
419
|
+
in the background, so `SignIn` with `source: "federated-landing"`, `TwoFactorRequired` or that `Error` is
|
|
420
|
+
the signal. A `?code=` this tab did not ask for leaves the URL alone and emits no `SignIn`.
|
|
421
|
+
|
|
422
|
+
A host that builds its instance during render, as React StrictMode may discard it, sets
|
|
423
|
+
`deferFederatedLanding: true` and calls `completeFederatedLanding()` once the instance is kept. Details:
|
|
424
|
+
[docs/pkce-sign-in.md](docs/pkce-sign-in.md).
|
|
425
|
+
|
|
385
426
|
### Passkey Authentication
|
|
386
427
|
|
|
387
428
|
```javascript
|
|
@@ -700,7 +741,8 @@ const subscriber = {
|
|
|
700
741
|
// Handle different event types
|
|
701
742
|
switch (eventType) {
|
|
702
743
|
case "signin":
|
|
703
|
-
// Handle sign in
|
|
744
|
+
// Handle sign in. source.source is "federated-landing" only when this tab
|
|
745
|
+
// took a federated redirect's landing and exchanged its code.
|
|
704
746
|
break;
|
|
705
747
|
case "signout":
|
|
706
748
|
// Handle sign out
|
|
@@ -779,6 +821,7 @@ Configuration options:
|
|
|
779
821
|
- `scopes`: Token scopes to request (default: ['id', 'offline', 'tenant', 'email', 'oidc', 'openid', 'access:tenant:all'])
|
|
780
822
|
- `createTenantForNewUser`: Whether to create a tenant for new users (default: false)
|
|
781
823
|
- `parseQueryParams`: Whether to parse tokens from URL query parameters (default: false)
|
|
824
|
+
- `deferFederatedLanding`: Leave a federated `?code=` landing to `completeFederatedLanding()` (default: false)
|
|
782
825
|
- `keyStoragePrefix`: Prefix for localStorage keys
|
|
783
826
|
|
|
784
827
|
#### Methods
|
|
@@ -800,6 +843,11 @@ Configuration options:
|
|
|
800
843
|
| `sendPasswordResetEmail(payload)` | Send password reset email |
|
|
801
844
|
| `resetPassword(newPassword, scopes?, resetToken?)` | Reset password |
|
|
802
845
|
| `verifyEmailCode({ challenge_id, otp })` | Finish an email verification step |
|
|
846
|
+
| `waitForPasswordlessSignIn(challengeId, { signal? })` | Wait for approval on another device, then finish here |
|
|
847
|
+
| `getPendingPasswordlessSignIn(challengeId)` | The match code to show while waiting |
|
|
848
|
+
| `getPasswordlessApproval(challengeId)` | What the approving device shows |
|
|
849
|
+
| `decidePasswordlessApproval(challengeId, otp, approve, matchCode?)` | Approve or deny a waiting sign-in |
|
|
850
|
+
| `completeFederatedLanding()` | Take a federated landing, with `deferFederatedLanding` |
|
|
803
851
|
|
|
804
852
|
**Token Methods**
|
|
805
853
|
|
|
@@ -870,6 +918,7 @@ type PassflowConfig = {
|
|
|
870
918
|
scopes?: string[];
|
|
871
919
|
createTenantForNewUser?: boolean;
|
|
872
920
|
parseQueryParams?: boolean;
|
|
921
|
+
deferFederatedLanding?: boolean; // see docs/pkce-sign-in.md
|
|
873
922
|
keyStoragePrefix?: string;
|
|
874
923
|
refreshCoordination?: "web-locks" | "none" | RefreshCoordinator; // see docs/token-refresh.md
|
|
875
924
|
refreshStrikes?: number;
|