@passflow/core 0.22.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 CHANGED
@@ -52,6 +52,7 @@
52
52
  - [PassflowSignUpPayload](#passflowsignuppayload)
53
53
  - [UserMembership](#usermembership)
54
54
  - [PassflowEvent](#passflowevent)
55
+ - [Admin settings secrets](#admin-settings-secrets)
55
56
  - [Detailed Examples](#detailed-examples)
56
57
  - [Complete Sign In Flow](#complete-sign-in-flow)
57
58
  - [Authentication with Passkeys](#authentication-with-passkeys)
@@ -363,6 +364,36 @@ const completePasswordless = async (challengeId, otp) => {
363
364
  };
364
365
  ```
365
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
+
366
397
  ### Federated Authentication
367
398
 
368
399
  ```javascript
@@ -381,6 +412,17 @@ passflow.federatedAuthWithRedirect(
381
412
  );
382
413
  ```
383
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
+
384
426
  ### Passkey Authentication
385
427
 
386
428
  ```javascript
@@ -699,7 +741,8 @@ const subscriber = {
699
741
  // Handle different event types
700
742
  switch (eventType) {
701
743
  case "signin":
702
- // 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.
703
746
  break;
704
747
  case "signout":
705
748
  // Handle sign out
@@ -778,6 +821,7 @@ Configuration options:
778
821
  - `scopes`: Token scopes to request (default: ['id', 'offline', 'tenant', 'email', 'oidc', 'openid', 'access:tenant:all'])
779
822
  - `createTenantForNewUser`: Whether to create a tenant for new users (default: false)
780
823
  - `parseQueryParams`: Whether to parse tokens from URL query parameters (default: false)
824
+ - `deferFederatedLanding`: Leave a federated `?code=` landing to `completeFederatedLanding()` (default: false)
781
825
  - `keyStoragePrefix`: Prefix for localStorage keys
782
826
 
783
827
  #### Methods
@@ -799,6 +843,11 @@ Configuration options:
799
843
  | `sendPasswordResetEmail(payload)` | Send password reset email |
800
844
  | `resetPassword(newPassword, scopes?, resetToken?)` | Reset password |
801
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` |
802
851
 
803
852
  **Token Methods**
804
853
 
@@ -869,6 +918,7 @@ type PassflowConfig = {
869
918
  scopes?: string[];
870
919
  createTenantForNewUser?: boolean;
871
920
  parseQueryParams?: boolean;
921
+ deferFederatedLanding?: boolean; // see docs/pkce-sign-in.md
872
922
  keyStoragePrefix?: string;
873
923
  refreshCoordination?: "web-locks" | "none" | RefreshCoordinator; // see docs/token-refresh.md
874
924
  refreshStrikes?: number;
@@ -956,6 +1006,28 @@ enum PassflowEvent {
956
1006
  }
957
1007
  ```
958
1008
 
1009
+ #### Admin settings secrets
1010
+
1011
+ App secrets are write-only and server settings secrets come back masked. The SDK has no admin
1012
+ client; these exports are for admin UIs that call the admin routes themselves.
1013
+
1014
+ ```typescript
1015
+ type AppSettings = {
1016
+ // ...
1017
+ debug_otp_code_for_registration?: string; // write-only: answers return ""
1018
+ debug_otp_code_set?: boolean; // read-only: true when a code is stored
1019
+ };
1020
+ type AppSecretName = "debug_otp_code_for_registration" | "fcm_server_key" | "webpush_vapid_private_key";
1021
+ const APP_SECRET_NAMES: readonly AppSecretName[]; // DELETE /admin/apps/{id}/secrets/{name}
1022
+
1023
+ type MaskedSecret = string; // "mask://********" or "mask://********/<16 hex>"
1024
+ const MASKED_SECRET_PREFIX = "mask://";
1025
+ const SETTINGS_MASKED_VALUE_UNKNOWN_ERROR_ID = "error.server.update.settings.masked.value.unknown";
1026
+ function isMaskedSecret(value: unknown): value is MaskedSecret;
1027
+ ```
1028
+
1029
+ Write, keep and clear rules: [docs/admin-secrets.md](docs/admin-secrets.md).
1030
+
959
1031
  ## Detailed Examples
960
1032
 
961
1033
  ### Complete Sign In Flow