@passflow/core 0.28.0 → 0.30.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,44 @@
2
2
 
3
3
  ## Changelog
4
4
 
5
+ ### Version 0.30.0
6
+
7
+ - `passflow.hostedUpgrade`: step-up for the hosted login page's cookie session. It has the same
8
+ surface as `passflow.upgrade`, but sends `POST /auth/session/upgrade/start` and
9
+ `POST /auth/session/upgrade` with the session cookie, and the server issues nothing, so no tokens
10
+ are stored. Call `enable({ prompt })` once, then `elevate(challenge, { kind: 'imperative' })`.
11
+ Never wire interception (`interceptFetch`, `withAuth`, `attachAuth`) to it.
12
+ - `UpgradeAPI.startHostedUpgrade()` and `UpgradeAPI.commitHostedUpgrade()`, and the endpoint
13
+ paths `PassflowEndpointPaths.hostedUpgradeStart` and `.hostedUpgrade`.
14
+ - Requests to `/auth/session/*` never carry the stored `Authorization` header and never trigger
15
+ a token refresh. A 401 from them never ends the stored token session, and the
16
+ `passflow.upgrade` step-up never acts on them.
17
+
18
+ ### Version 0.29.0
19
+
20
+ - **Breaking:** `authRedirect()` is now `async` and returns `Promise<void>`. It reads the app
21
+ settings and follows the app's mode: Simple mode (`pkce_enabled: false`) goes to the hosted `/web`
22
+ page as before; SDK mode (`pkce_enabled: true`) starts an authorization-code request with PKCE at
23
+ `/oidc/authorize`, and hosted sign-in returns an authorization code that the SDK redeems on the
24
+ landing page. Every failure emits one `Error` with operation `auth-redirect` and rejects, so
25
+ `await` it or add `.catch()`. A `url` or `appId` option that differs from the instance's rejects
26
+ with code `OVERRIDE_NOT_SUPPORTED`. See [Hosted Sign-In](#hosted-sign-in).
27
+ - **Breaking:** core accepts URL tokens only for apps in Simple mode. Tokens in the URL of an app
28
+ in SDK mode, with no app id, or whose settings cannot be read are refused with an `Error` with
29
+ operation `tokens.from-url` and code `TOKENS_IN_URL_NOT_ALLOWED`, and nothing is saved. A federated
30
+ popup follows the same rule.
31
+ - New `SignIn` source `'oidc-landing'` and `Error` operation `oidc.redirect` for the SDK-mode landing;
32
+ `completeFederatedLanding()` also takes that landing. New `PassflowOidcError` with its `code`.
33
+ - `SignIn` with `source: 'tokens-in-url'` carries `state` when the URL had one. Removing the tokens
34
+ from the URL now keeps the other fragment params.
35
+ - `authRedirect({ state })` (Simple mode) and `PassflowFederatedAuthPayload.state` and
36
+ `parent_challenge_id` are sent to the server. A federated popup reads tokens from the fragment too.
37
+ - `AppSettings.public_client` and `PasswordlessApprovalInfo.one_click` are typed. The app settings
38
+ are read once per app id and shared by sign-in, `authRedirect()`, the URL-token reader and
39
+ `getAppSettings()`.
40
+ - `waitForPasswordlessSignIn` ends on an answer with `redirect_url` (`signed-in`) or `tfa_token`
41
+ (`second-factor-required`), as a sign-in under an OIDC parent answers.
42
+
5
43
  ### Version 0.1.45
6
44
 
7
45
  - Fixed bug related to null/undefined checks in the codebase
@@ -10,6 +48,7 @@
10
48
 
11
49
  - [Passflow JavaScript SDK Documentation](#passflow-javascript-sdk-documentation)
12
50
  - [Changelog](#changelog)
51
+ - [Unreleased](#unreleased)
13
52
  - [Version 0.1.45](#version-0145)
14
53
  - [Table of Contents](#table-of-contents)
15
54
  - [Quick Start Examples](#quick-start-examples)
@@ -25,6 +64,7 @@
25
64
  - [Getting Started](#getting-started)
26
65
  - [Initialization](#initialization)
27
66
  - [Session Management](#session-management)
67
+ - [Hosted Sign-In](#hosted-sign-in)
28
68
  - [Authentication](#authentication)
29
69
  - [Sign In](#sign-in)
30
70
  - [Sign Up](#sign-up)
@@ -275,6 +315,61 @@ passflow.session({
275
315
  });
276
316
  ```
277
317
 
318
+ ## Hosted Sign-In
319
+
320
+ `authRedirect()` sends the user to Passflow's hosted sign-in page. It is `async`: it reads the app
321
+ settings (once per app id) and follows the app's hand-off mode, `pkce_enabled` in the app settings.
322
+
323
+ ```javascript
324
+ const passflow = new Passflow({ url: "https://auth.example.com", appId: "your-app-id", parseQueryParams: true });
325
+
326
+ passflow.subscribe(
327
+ {
328
+ onAuthChange: (event, payload) => {
329
+ if (event === PassflowEvent.Error && payload.operation === "auth-redirect") showError(payload.message);
330
+ if (event === PassflowEvent.Error && payload.operation === "oidc.redirect") showError(payload.message);
331
+ },
332
+ },
333
+ [PassflowEvent.SignIn, PassflowEvent.Error],
334
+ );
335
+
336
+ // The app starts sign-in itself whenever there is no session: nothing redirects on its own.
337
+ if (!passflow.isAuthenticated()) {
338
+ passflow.authRedirect().catch(() => {}); // the Error event above reports the failure
339
+ }
340
+ ```
341
+
342
+ - **Simple mode** (`pkce_enabled: false`, and the outcome when the instance has no app id): the
343
+ browser goes to `{url}/web?appId&redirectto&scopes`, and hosted sign-in returns tokens in the URL
344
+ (`#access_token=…`). `parseQueryParams` or `handleTokensRedirect()` takes them (see
345
+ [Token Management](#token-management)). `authRedirect({ state })` sends a `state`, which comes back
346
+ on the `SignIn` event as `payload.state`. The default `redirectUrl` is the current `href`.
347
+ `authRedirectUrl()` still builds this URL synchronously for integrations that navigate themselves.
348
+ - **SDK mode** (`pkce_enabled: true`): the browser goes to `{url}/oidc/authorize` with a PKCE (S256)
349
+ challenge, a `state` and, when the scopes include `openid`, a `nonce`; the proof key stays in this
350
+ tab's sessionStorage. Hosted sign-in returns an authorization code (`?code=&state=`), which the SDK
351
+ redeems at `{url}/oidc/token` on the landing page, as a public client with no secret. The outcome
352
+ is `SignIn` with `source: 'oidc-landing'`, or one `Error` with operation `oidc.redirect` (codes
353
+ `STATE_MISMATCH`, `VERIFIER_MISSING`, `ID_TOKEN_INVALID`, `TOKEN_EXCHANGE_FAILED`, `invalid_client`,
354
+ `invalid_grant`, or the OAuth `error` the server returned). Nothing is retried: the user signs in
355
+ again.
356
+ - `options.state` is Simple-only: in SDK mode the SDK generates `state` itself and does not send yours.
357
+ - The default `redirectUrl` is the page's origin and pathname, because the redirect URI must match a
358
+ registered one exactly. A deep link passes an explicit, registered `redirectUrl`.
359
+ - `openid` is added to the scopes when they include `id` or `oidc`, so an ID token is issued. That ID
360
+ token is the slim OIDC one (`sub`, `iss`, `aud`, `exp`, `iat`, `nonce`, `at_hash`, `auth_time`, `amr`, `acr`);
361
+ profile claims come from the access token and `/userinfo`. After a refresh the token pair has the
362
+ same shape as one from `/auth/login`.
363
+ - The app must be a public client (type SPA). An app whose settings report `public_client: false`
364
+ is refused before any redirect with code `CONFIDENTIAL_CLIENT` and a message naming the fix.
365
+ - The page must be a secure context (https or localhost) and sessionStorage must be writable;
366
+ otherwise `authRedirect()` rejects with `SECURE_CONTEXT_REQUIRED` or `STORAGE_UNAVAILABLE`.
367
+
368
+ `options.url` and `options.appId` may only repeat the instance's own values (compared without case,
369
+ default port or trailing slash); a different value rejects with `OVERRIDE_NOT_SUPPORTED`. Create a
370
+ second `Passflow` instance for another server or app. Every failure, including a failed settings read,
371
+ emits one `Error` with operation `auth-redirect`, rejects with that error, and does not navigate.
372
+
278
373
  ## Authentication
279
374
 
280
375
  ### Sign In
@@ -421,7 +516,12 @@ in the background, so `SignIn` with `source: "federated-landing"`, `TwoFactorReq
421
516
  the signal. A `?code=` this tab did not ask for leaves the URL alone and emits no `SignIn`.
422
517
 
423
518
  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:
519
+ `deferFederatedLanding: true` and calls `completeFederatedLanding()` once the instance is kept. It takes
520
+ the SDK-mode hosted sign-in landing (`?code=&state=`) the same way: `true` means this tab started that
521
+ sign-in and the outcome follows by event; `false` means nothing was touched and no event follows.
522
+
523
+ The federated payload also takes `state` (echoed back on a Simple-mode landing) and
524
+ `parent_challenge_id` (the hosted login's OIDC parent sign-in); both are sent on the start URL. Details:
425
525
  [docs/pkce-sign-in.md](docs/pkce-sign-in.md).
426
526
 
427
527
  ### Passkey Authentication
@@ -658,13 +758,18 @@ const handleRedirect = () => {
658
758
  };
659
759
  ```
660
760
 
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
761
+ `handleTokensRedirect()` returns nothing. It removes the tokens (and their `state`) from the URL at
762
+ once; the other query and fragment params stay. Core accepts URL tokens only for apps in Simple mode:
763
+ it reads the app settings first, and an app in SDK mode, an instance with no app id, or a failed read
764
+ ends in `Error` with operation `tokens.from-url` and code `TOKENS_IN_URL_NOT_ALLOWED`, with nothing
765
+ saved. For a Simple app it then verifies the tokens in the background before saving them: each signature against the keys at
663
766
  `<url>/.well-known/jwks.json`, `iss` against the issuer in `<url>/.well-known/openid-configuration`,
664
767
  `aud` against your `appId` (required), `exp`, and the token type. The outcome is `SignIn` with
665
768
  `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.
769
+ with nothing saved. Verification needs the Web Crypto API (https or localhost). `SignIn` carries
770
+ `state` when the URL had one. A federated popup that returns tokens in its callback URL (query or
771
+ fragment) follows the same Simple-only rule and is verified the same way; on a PKCE app it requires a
772
+ code.
668
773
 
669
774
  ### Token refresh across tabs
670
775
 
@@ -941,7 +1046,7 @@ Configuration options:
941
1046
  | `setTokens(tokens)` | Set tokens manually |
942
1047
  | `handleTokensRedirect()` | Handle tokens from redirect |
943
1048
  | `authRedirectUrl(options)` | Generate an auth redirect URL |
944
- | `authRedirect(options)` | Redirect to the auth page |
1049
+ | `authRedirect(options)` | Redirect to hosted sign-in in the app's mode (async, see [Hosted Sign-In](#hosted-sign-in)) |
945
1050
 
946
1051
  **Tenant Methods**
947
1052