@passflow/core 0.27.0 → 0.29.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,31 @@
2
2
 
3
3
  ## Changelog
4
4
 
5
+ ### Version 0.29.0
6
+
7
+ - **Breaking:** `authRedirect()` is now `async` and returns `Promise<void>`. It reads the app
8
+ settings and follows the app's mode: Simple mode (`pkce_enabled: false`) goes to the hosted `/web`
9
+ page as before; SDK mode (`pkce_enabled: true`) starts an authorization-code request with PKCE at
10
+ `/oidc/authorize`, and hosted sign-in returns an authorization code that the SDK redeems on the
11
+ landing page. Every failure emits one `Error` with operation `auth-redirect` and rejects, so
12
+ `await` it or add `.catch()`. A `url` or `appId` option that differs from the instance's rejects
13
+ with code `OVERRIDE_NOT_SUPPORTED`. See [Hosted Sign-In](#hosted-sign-in).
14
+ - **Breaking:** core accepts URL tokens only for apps in Simple mode. Tokens in the URL of an app
15
+ in SDK mode, with no app id, or whose settings cannot be read are refused with an `Error` with
16
+ operation `tokens.from-url` and code `TOKENS_IN_URL_NOT_ALLOWED`, and nothing is saved. A federated
17
+ popup follows the same rule.
18
+ - New `SignIn` source `'oidc-landing'` and `Error` operation `oidc.redirect` for the SDK-mode landing;
19
+ `completeFederatedLanding()` also takes that landing. New `PassflowOidcError` with its `code`.
20
+ - `SignIn` with `source: 'tokens-in-url'` carries `state` when the URL had one. Removing the tokens
21
+ from the URL now keeps the other fragment params.
22
+ - `authRedirect({ state })` (Simple mode) and `PassflowFederatedAuthPayload.state` and
23
+ `parent_challenge_id` are sent to the server. A federated popup reads tokens from the fragment too.
24
+ - `AppSettings.public_client` and `PasswordlessApprovalInfo.one_click` are typed. The app settings
25
+ are read once per app id and shared by sign-in, `authRedirect()`, the URL-token reader and
26
+ `getAppSettings()`.
27
+ - `waitForPasswordlessSignIn` ends on an answer with `redirect_url` (`signed-in`) or `tfa_token`
28
+ (`second-factor-required`), as a sign-in under an OIDC parent answers.
29
+
5
30
  ### Version 0.1.45
6
31
 
7
32
  - Fixed bug related to null/undefined checks in the codebase
@@ -10,6 +35,7 @@
10
35
 
11
36
  - [Passflow JavaScript SDK Documentation](#passflow-javascript-sdk-documentation)
12
37
  - [Changelog](#changelog)
38
+ - [Unreleased](#unreleased)
13
39
  - [Version 0.1.45](#version-0145)
14
40
  - [Table of Contents](#table-of-contents)
15
41
  - [Quick Start Examples](#quick-start-examples)
@@ -25,6 +51,7 @@
25
51
  - [Getting Started](#getting-started)
26
52
  - [Initialization](#initialization)
27
53
  - [Session Management](#session-management)
54
+ - [Hosted Sign-In](#hosted-sign-in)
28
55
  - [Authentication](#authentication)
29
56
  - [Sign In](#sign-in)
30
57
  - [Sign Up](#sign-up)
@@ -275,6 +302,61 @@ passflow.session({
275
302
  });
276
303
  ```
277
304
 
305
+ ## Hosted Sign-In
306
+
307
+ `authRedirect()` sends the user to Passflow's hosted sign-in page. It is `async`: it reads the app
308
+ settings (once per app id) and follows the app's hand-off mode, `pkce_enabled` in the app settings.
309
+
310
+ ```javascript
311
+ const passflow = new Passflow({ url: "https://auth.example.com", appId: "your-app-id", parseQueryParams: true });
312
+
313
+ passflow.subscribe(
314
+ {
315
+ onAuthChange: (event, payload) => {
316
+ if (event === PassflowEvent.Error && payload.operation === "auth-redirect") showError(payload.message);
317
+ if (event === PassflowEvent.Error && payload.operation === "oidc.redirect") showError(payload.message);
318
+ },
319
+ },
320
+ [PassflowEvent.SignIn, PassflowEvent.Error],
321
+ );
322
+
323
+ // The app starts sign-in itself whenever there is no session: nothing redirects on its own.
324
+ if (!passflow.isAuthenticated()) {
325
+ passflow.authRedirect().catch(() => {}); // the Error event above reports the failure
326
+ }
327
+ ```
328
+
329
+ - **Simple mode** (`pkce_enabled: false`, and the outcome when the instance has no app id): the
330
+ browser goes to `{url}/web?appId&redirectto&scopes`, and hosted sign-in returns tokens in the URL
331
+ (`#access_token=…`). `parseQueryParams` or `handleTokensRedirect()` takes them (see
332
+ [Token Management](#token-management)). `authRedirect({ state })` sends a `state`, which comes back
333
+ on the `SignIn` event as `payload.state`. The default `redirectUrl` is the current `href`.
334
+ `authRedirectUrl()` still builds this URL synchronously for integrations that navigate themselves.
335
+ - **SDK mode** (`pkce_enabled: true`): the browser goes to `{url}/oidc/authorize` with a PKCE (S256)
336
+ challenge, a `state` and, when the scopes include `openid`, a `nonce`; the proof key stays in this
337
+ tab's sessionStorage. Hosted sign-in returns an authorization code (`?code=&state=`), which the SDK
338
+ redeems at `{url}/oidc/token` on the landing page, as a public client with no secret. The outcome
339
+ is `SignIn` with `source: 'oidc-landing'`, or one `Error` with operation `oidc.redirect` (codes
340
+ `STATE_MISMATCH`, `VERIFIER_MISSING`, `ID_TOKEN_INVALID`, `TOKEN_EXCHANGE_FAILED`, `invalid_client`,
341
+ `invalid_grant`, or the OAuth `error` the server returned). Nothing is retried: the user signs in
342
+ again.
343
+ - `options.state` is Simple-only: in SDK mode the SDK generates `state` itself and does not send yours.
344
+ - The default `redirectUrl` is the page's origin and pathname, because the redirect URI must match a
345
+ registered one exactly. A deep link passes an explicit, registered `redirectUrl`.
346
+ - `openid` is added to the scopes when they include `id` or `oidc`, so an ID token is issued. That ID
347
+ token is the slim OIDC one (`sub`, `iss`, `aud`, `exp`, `iat`, `nonce`, `at_hash`, `auth_time`, `amr`, `acr`);
348
+ profile claims come from the access token and `/userinfo`. After a refresh the token pair has the
349
+ same shape as one from `/auth/login`.
350
+ - The app must be a public client (type SPA). An app whose settings report `public_client: false`
351
+ is refused before any redirect with code `CONFIDENTIAL_CLIENT` and a message naming the fix.
352
+ - The page must be a secure context (https or localhost) and sessionStorage must be writable;
353
+ otherwise `authRedirect()` rejects with `SECURE_CONTEXT_REQUIRED` or `STORAGE_UNAVAILABLE`.
354
+
355
+ `options.url` and `options.appId` may only repeat the instance's own values (compared without case,
356
+ default port or trailing slash); a different value rejects with `OVERRIDE_NOT_SUPPORTED`. Create a
357
+ second `Passflow` instance for another server or app. Every failure, including a failed settings read,
358
+ emits one `Error` with operation `auth-redirect`, rejects with that error, and does not navigate.
359
+
278
360
  ## Authentication
279
361
 
280
362
  ### Sign In
@@ -421,7 +503,12 @@ in the background, so `SignIn` with `source: "federated-landing"`, `TwoFactorReq
421
503
  the signal. A `?code=` this tab did not ask for leaves the URL alone and emits no `SignIn`.
422
504
 
423
505
  A host that builds its instance during render, as React StrictMode may discard it, sets
424
- `deferFederatedLanding: true` and calls `completeFederatedLanding()` once the instance is kept. Details:
506
+ `deferFederatedLanding: true` and calls `completeFederatedLanding()` once the instance is kept. It takes
507
+ the SDK-mode hosted sign-in landing (`?code=&state=`) the same way: `true` means this tab started that
508
+ sign-in and the outcome follows by event; `false` means nothing was touched and no event follows.
509
+
510
+ The federated payload also takes `state` (echoed back on a Simple-mode landing) and
511
+ `parent_challenge_id` (the hosted login's OIDC parent sign-in); both are sent on the start URL. Details:
425
512
  [docs/pkce-sign-in.md](docs/pkce-sign-in.md).
426
513
 
427
514
  ### Passkey Authentication
@@ -658,13 +745,18 @@ const handleRedirect = () => {
658
745
  };
659
746
  ```
660
747
 
661
- `handleTokensRedirect()` returns nothing. It removes the tokens from the URL at once, then
662
- verifies them in the background before saving them: each signature against the keys at
748
+ `handleTokensRedirect()` returns nothing. It removes the tokens (and their `state`) from the URL at
749
+ once; the other query and fragment params stay. Core accepts URL tokens only for apps in Simple mode:
750
+ it reads the app settings first, and an app in SDK mode, an instance with no app id, or a failed read
751
+ ends in `Error` with operation `tokens.from-url` and code `TOKENS_IN_URL_NOT_ALLOWED`, with nothing
752
+ saved. For a Simple app it then verifies the tokens in the background before saving them: each signature against the keys at
663
753
  `<url>/.well-known/jwks.json`, `iss` against the issuer in `<url>/.well-known/openid-configuration`,
664
754
  `aud` against your `appId` (required), `exp`, and the token type. The outcome is `SignIn` with
665
755
  `source: "tokens-in-url"`, or `Error` with operation `tokens.from-url` and code `TOKEN_NOT_VERIFIED`
666
- with nothing saved. Verification needs the Web Crypto API (https or localhost). A federated popup
667
- that returns tokens in its callback URL is verified the same way.
756
+ with nothing saved. Verification needs the Web Crypto API (https or localhost). `SignIn` carries
757
+ `state` when the URL had one. A federated popup that returns tokens in its callback URL (query or
758
+ fragment) follows the same Simple-only rule and is verified the same way; on a PKCE app it requires a
759
+ code.
668
760
 
669
761
  ### Token refresh across tabs
670
762
 
@@ -854,6 +946,35 @@ try {
854
946
  }
855
947
  ```
856
948
 
949
+ ### Service unavailable
950
+
951
+ In a browser, when the Passflow API cannot be reached or its gateway answers 502, 503 or 504 itself,
952
+ an SDK API call rejects with one `PassflowError`:
953
+
954
+ - `id`: `error.service.unavailable`, exported as `SERVICE_UNAVAILABLE_ERROR_ID`
955
+ - `message`: `Passflow is temporarily unavailable. Please try again in a moment.`, exported as
956
+ `SERVICE_UNAVAILABLE_MESSAGE`
957
+ - `status`: the gateway status (502, 503 or 504), or `0` when no answer arrived
958
+ - `cause`: the underlying network error, without the request's config, body or headers
959
+
960
+ ```typescript
961
+ import { PassflowError, SERVICE_UNAVAILABLE_ERROR_ID } from "@passflow/core";
962
+
963
+ try {
964
+ await passflow.signIn({ email: "user@example.com", password: "secret" });
965
+ } catch (e) {
966
+ if (e instanceof PassflowError && e.id === SERVICE_UNAVAILABLE_ERROR_ID) {
967
+ showBanner(e.message);
968
+ }
969
+ }
970
+ ```
971
+
972
+ It also covers a device that is offline and a request the browser blocked (a gateway answer with no
973
+ CORS headers). The call is not retried; token refresh keeps its own retry schedule. A tab that
974
+ joins another tab's failed token refresh gets `error.refresh.unavailable` instead (see
975
+ [docs/token-refresh.md](docs/token-refresh.md)). An error the Passflow server wrote keeps its own
976
+ id, even with status 503. Calls that wrap their errors in a result object report it in that shape.
977
+
857
978
  ## API Reference
858
979
 
859
980
  ### Passflow Class
@@ -912,7 +1033,7 @@ Configuration options:
912
1033
  | `setTokens(tokens)` | Set tokens manually |
913
1034
  | `handleTokensRedirect()` | Handle tokens from redirect |
914
1035
  | `authRedirectUrl(options)` | Generate an auth redirect URL |
915
- | `authRedirect(options)` | Redirect to the auth page |
1036
+ | `authRedirect(options)` | Redirect to hosted sign-in in the app's mode (async, see [Hosted Sign-In](#hosted-sign-in)) |
916
1037
 
917
1038
  **Tenant Methods**
918
1039