@passflow/core 0.35.2 → 0.36.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,45 @@
2
2
 
3
3
  ## Changelog
4
4
 
5
+ ### Version 0.36.0
6
+
7
+ - Added: enterprise SSO. `enterpriseResolve(email)` answers which enterprise (OIDC or SAML)
8
+ connections the app offers for the email's domain, as `{ available, connections }`, each
9
+ connection with `connection_id`, `display_name` and `protocol`. `enterpriseStart(payload)` starts
10
+ a sign-in through a connection, given its `connection_id` or an email, with a POST that answers
11
+ `{ auth_url }` and carries the anti-bot header on a `human_only` app.
12
+ `createEnterpriseAuthUrl(payload)` builds the same start as a GET address for a plain link.
13
+ Needs Passflow server v0.79.0 or later. See [docs/enterprise-sso.md](docs/enterprise-sso.md).
14
+ - Added: `federatedAuthWithRedirect` and `federatedAuthWithPopup` take `conn_<connection_id>` as
15
+ the provider, so a "Sign in with SSO" button keeps PKCE and the landing exchange.
16
+ - Added: the refusal ids `ENTERPRISE_CONNECTION_AMBIGUOUS_ERROR_ID`,
17
+ `ENTERPRISE_NO_CONNECTION_ERROR_ID`, `ENTERPRISE_EMAIL_INVALID_ERROR_ID` and
18
+ `ENTERPRISE_START_INPUT_ERROR_ID`, matched on `PassflowError.id`. A 429 rejects with the raw HTTP
19
+ error, as for every other POST.
20
+
21
+ ### Version 0.35.3
22
+
23
+ - Fixed: in cookie and BFF mode a call answered 401 refreshes the session once and is sent once
24
+ more, so an expired access cookie with a good refresh cookie no longer fails the call or marks
25
+ the session invalid. Calls answered 401 together share one refresh. When the refresh fails, the
26
+ session has ended, or the second send is also answered 401, the call rejects with the 401 and
27
+ the session is marked invalid, as before. `/auth/refresh`, logout, the sign-in calls, the hosted
28
+ session's calls, calls made with their own bearer and step-up 401s are not sent again. This
29
+ needs a Passflow server that answers 401 for a missing or expired access token.
30
+ - Fixed: after the first cookie-mode sign-in on a page, API calls carry `withCredentials` and the
31
+ `X-CSRF-Token` header at once. Each API client kept the delivery mode it read when it was built,
32
+ so those calls went out without them until the next page load.
33
+ - Fixed: `setAppId()` reloads the in-memory token cache, so `getCachedTokens()` returns what is
34
+ stored for the new app and no longer the previous app's tokens.
35
+ - Fixed: a token refresh, step-up commit or page-load session check still unanswered when
36
+ `setAppId()` switches from one app id to another no longer applies its answer to the new app,
37
+ and `setAppId()` then checks the new app's cookie or BFF session itself. A step-up commit
38
+ answered after the switch rejects with `UpgradeCommitInterruptedError` (`superseded`).
39
+ `setAppId()` with the app id the instance already has changes nothing, and the first app id
40
+ given to an instance built without one keeps what is on its way.
41
+ - Fixed: a sign-in answer whose tokens were issued for another app than the current app id is
42
+ refused with an error and stores nothing.
43
+
5
44
  ### Version 0.35.2
6
45
 
7
46
  - Fixed: the cookie and BFF session is stored per app. The session state, delivery mode, CSRF token
@@ -233,6 +272,7 @@ Matches the SDK to the server's real two-factor, step-up and sign-out answers.
233
272
  - [Sign Out](#sign-out)
234
273
  - [Passwordless Authentication](#passwordless-authentication)
235
274
  - [Federated Authentication](#federated-authentication)
275
+ - [Enterprise SSO](#enterprise-sso)
236
276
  - [Passkey Authentication](#passkey-authentication)
237
277
  - [Password Reset](#password-reset)
238
278
  - [Email verification](#email-verification)
@@ -266,7 +306,7 @@ Matches the SDK to the server's real two-factor, step-up and sign-out answers.
266
306
  ### Basic Initialization
267
307
 
268
308
  ```javascript
269
- import { Passflow } from "passflow-js";
309
+ import { Passflow } from "@passflow/core";
270
310
 
271
311
  // Minimal initialization with just the required appId
272
312
  const passflow = new Passflow({
@@ -275,8 +315,8 @@ const passflow = new Passflow({
275
315
 
276
316
  // Simple session setup
277
317
  passflow.session({
278
- createSession: () => console.log("User is authenticated"),
279
- expiredSession: () => console.log("User session expired"),
318
+ createSession: async () => console.log("User is authenticated"),
319
+ expiredSession: async () => console.log("User session expired"),
280
320
  });
281
321
  ```
282
322
 
@@ -438,9 +478,9 @@ Passflow JavaScript SDK is a client library for interacting with the Passflow au
438
478
  ## Installation
439
479
 
440
480
  ```bash
441
- npm install passflow-js
481
+ npm install @passflow/core
442
482
  # or
443
- yarn add passflow-js
483
+ yarn add @passflow/core
444
484
  ```
445
485
 
446
486
  ## Getting Started
@@ -450,7 +490,7 @@ yarn add passflow-js
450
490
  Import and initialize the Passflow client with your configuration:
451
491
 
452
492
  ```javascript
453
- import { Passflow } from "passflow-js";
493
+ import { Passflow } from "@passflow/core";
454
494
 
455
495
  const passflow = new Passflow({
456
496
  url: "https://auth.passflow.cloud", // or your custom URL
@@ -476,11 +516,11 @@ Setup session management to handle authentication state:
476
516
 
477
517
  ```javascript
478
518
  passflow.session({
479
- createSession: (tokens) => {
519
+ createSession: async (tokens) => {
480
520
  console.log("Session created", tokens);
481
521
  // Set your app's authenticated state
482
522
  },
483
- expiredSession: () => {
523
+ expiredSession: async () => {
484
524
  console.log("Session expired");
485
525
  // Clear your app's authenticated state
486
526
  },
@@ -697,6 +737,32 @@ The federated payload also takes `state` (echoed back on a Simple-mode landing)
697
737
  `parent_challenge_id` (the hosted login's OIDC parent sign-in); both are sent on the start URL. Details:
698
738
  [docs/pkce-sign-in.md](docs/pkce-sign-in.md).
699
739
 
740
+ ### Enterprise SSO
741
+
742
+ An app can offer enterprise connections (OIDC or SAML) by email domain. `enterpriseResolve` answers
743
+ which connections serve the email; the `connection_id` it returns starts one.
744
+
745
+ ```typescript
746
+ const { connections } = await passflow.enterpriseResolve("jane@corp.example");
747
+ if (connections.length === 1) {
748
+ passflow.federatedAuthWithRedirect({
749
+ provider: `conn_${connections[0].connection_id}`,
750
+ redirect_url: window.location.origin,
751
+ });
752
+ } else if (connections.length > 1) {
753
+ // Show a picker (display_name, protocol), then start the chosen connection the same way.
754
+ } else {
755
+ // No connection serves this domain: SSO is not set up for it.
756
+ }
757
+ ```
758
+
759
+ A "Sign in with SSO" button and its picker use `enterpriseResolve` plus the federated flows with
760
+ `conn_<connection_id>` (which keep PKCE and the landing exchange), or `enterpriseStart`, the POST form
761
+ that answers `{ auth_url }` and rejects with `ENTERPRISE_CONNECTION_AMBIGUOUS_ERROR_ID` when the picker is
762
+ needed. They never use `createEnterpriseAuthUrl`, the GET form: a refused GET lands on the server's error
763
+ page, not on the app, and a `human_only` app refuses it with 403. Contract and error ids:
764
+ [docs/enterprise-sso.md](docs/enterprise-sso.md).
765
+
700
766
  ### Passkey Authentication
701
767
 
702
768
  ```javascript
@@ -935,10 +1001,10 @@ import { PassflowEvent } from "@passflow/core";
935
1001
  const isAuthenticated = passflow.isAuthenticated();
936
1002
 
937
1003
  // Get current tokens
938
- const tokens = passflow.getTokensCache();
1004
+ const tokens = passflow.getCachedTokens();
939
1005
 
940
1006
  // Get parsed tokens (decoded JWT payload)
941
- const parsedTokens = passflow.getParsedTokenCache();
1007
+ const parsedTokens = passflow.getParsedTokens();
942
1008
 
943
1009
  // Manually refresh token
944
1010
  const refreshToken = async () => {
@@ -1292,6 +1358,9 @@ Configuration options:
1292
1358
  | `passwordlessSignInComplete(payload)` | Complete passwordless authentication |
1293
1359
  | `federatedAuthWithPopup(provider, redirectUrl, scopes)` | Sign in with a provider using popup |
1294
1360
  | `federatedAuthWithRedirect(provider, redirectUrl, scopes)` | Sign in with a provider using redirect |
1361
+ | `enterpriseResolve(email)` | Enterprise connections for the email's domain |
1362
+ | `enterpriseStart(payload, options?)` | Start an enterprise sign-in; answers `{ auth_url }` |
1363
+ | `createEnterpriseAuthUrl(payload)` | The GET enterprise start address (not for `human_only` apps) |
1295
1364
  | `passkeyRegister(payload)` | Register a new passkey |
1296
1365
  | `passkeyAuthenticate(payload)` | Authenticate with a passkey |
1297
1366
  | `sendPasswordResetEmail(payload)` | Send password reset email |
@@ -1308,8 +1377,8 @@ Configuration options:
1308
1377
  | Method | Description |
1309
1378
  | -------------------------- | ------------------------------ |
1310
1379
  | `isAuthenticated()` | Check if user is authenticated |
1311
- | `getTokensCache()` | Get current tokens |
1312
- | `getParsedTokenCache()` | Get parsed tokens |
1380
+ | `getCachedTokens()` | Get current tokens |
1381
+ | `getParsedTokens()` | Get parsed tokens |
1313
1382
  | `refreshToken()` | Refresh the access token |
1314
1383
  | `setTokens(tokens)` | Replace the stored tokens |
1315
1384
  | `handleTokensRedirect()` | Handle tokens from redirect |
@@ -1487,7 +1556,7 @@ Write, keep and clear rules: [docs/admin-secrets.md](docs/admin-secrets.md).
1487
1556
  ### Complete Sign In Flow
1488
1557
 
1489
1558
  ```javascript
1490
- import { Passflow, PassflowError } from "passflow-js";
1559
+ import { Passflow, PassflowError } from "@passflow/core";
1491
1560
 
1492
1561
  // Initialize Passflow
1493
1562
  const passflow = new Passflow({
@@ -1497,7 +1566,7 @@ const passflow = new Passflow({
1497
1566
 
1498
1567
  // Set up session management
1499
1568
  passflow.session({
1500
- createSession: (tokens) => {
1569
+ createSession: async (tokens) => {
1501
1570
  // Store authentication state
1502
1571
  localStorage.setItem("isAuthenticated", "true");
1503
1572
 
@@ -1505,7 +1574,7 @@ passflow.session({
1505
1574
  document.getElementById("login-form").style.display = "none";
1506
1575
  document.getElementById("user-dashboard").style.display = "block";
1507
1576
  },
1508
- expiredSession: () => {
1577
+ expiredSession: async () => {
1509
1578
  // Clear authentication state
1510
1579
  localStorage.removeItem("isAuthenticated");
1511
1580
 
@@ -1554,7 +1623,7 @@ window.addEventListener("load", () => {
1554
1623
  ### Authentication with Passkeys
1555
1624
 
1556
1625
  ```javascript
1557
- import { Passflow } from "passflow-js";
1626
+ import { Passflow } from "@passflow/core";
1558
1627
 
1559
1628
  // Initialize Passflow
1560
1629
  const passflow = new Passflow({
@@ -1563,10 +1632,10 @@ const passflow = new Passflow({
1563
1632
 
1564
1633
  // Set up session management
1565
1634
  passflow.session({
1566
- createSession: (tokens) => {
1635
+ createSession: async (tokens) => {
1567
1636
  console.log("Session created", tokens);
1568
1637
  },
1569
- expiredSession: () => {
1638
+ expiredSession: async () => {
1570
1639
  console.log("Session expired");
1571
1640
  },
1572
1641
  doRefresh: true,
@@ -1613,29 +1682,44 @@ document
1613
1682
 
1614
1683
  ### Multi-tenant Application
1615
1684
 
1685
+ `getParsedTokens()` returns every tenant the user belongs to in `access_token.membership.tenants`, and your app chooses which one to use.
1686
+
1616
1687
  ```javascript
1617
- import { Passflow, PassflowEvent } from "passflow-js";
1688
+ import { Passflow, PassflowEvent } from "@passflow/core";
1618
1689
 
1619
1690
  // Initialize Passflow
1620
1691
  const passflow = new Passflow({
1621
1692
  appId: "your-app-id",
1622
1693
  });
1623
1694
 
1624
- // Track current tenant
1625
- let currentTenant = null;
1695
+ // The tenant this app works in
1696
+ let currentTenant;
1697
+
1698
+ // Every tenant the user belongs to, from the parsed access token
1699
+ function getTenants() {
1700
+ return passflow.getParsedTokens()?.access_token?.membership?.tenants ?? [];
1701
+ }
1702
+
1703
+ // Your app chooses the tenant. This example takes the first one.
1704
+ function chooseTenant(tenants) {
1705
+ return tenants[0] ?? null;
1706
+ }
1707
+
1708
+ function showTenant() {
1709
+ currentTenant = chooseTenant(getTenants());
1710
+ if (currentTenant) {
1711
+ updateTenantUI();
1712
+ } else {
1713
+ showCreateTenantUI();
1714
+ }
1715
+ }
1626
1716
 
1627
1717
  // Set up session management
1628
1718
  passflow.session({
1629
- createSession: (tokens) => {
1630
- const parsedTokens = passflow.getParsedTokenCache();
1631
- if (parsedTokens?.access_token?.membership?.tenants?.length > 0) {
1632
- currentTenant = parsedTokens.access_token.membership.tenants[0];
1633
- updateTenantUI();
1634
- } else {
1635
- showCreateTenantUI();
1636
- }
1719
+ createSession: async () => {
1720
+ showTenant();
1637
1721
  },
1638
- expiredSession: () => {
1722
+ expiredSession: async () => {
1639
1723
  currentTenant = null;
1640
1724
  showLoginUI();
1641
1725
  },
@@ -1649,13 +1733,7 @@ passflow.subscribe({
1649
1733
  eventType === PassflowEvent.SignIn ||
1650
1734
  eventType === PassflowEvent.Register
1651
1735
  ) {
1652
- const parsedTokens = passflow.getParsedTokenCache();
1653
- if (parsedTokens?.access_token?.membership?.tenants?.length > 0) {
1654
- currentTenant = parsedTokens.access_token.membership.tenants[0];
1655
- updateTenantUI();
1656
- } else {
1657
- showCreateTenantUI();
1658
- }
1736
+ showTenant();
1659
1737
  }
1660
1738
  },
1661
1739
  });
@@ -1664,10 +1742,13 @@ passflow.subscribe({
1664
1742
  async function createNewTenant() {
1665
1743
  const tenantName = document.getElementById("tenant-name").value;
1666
1744
  try {
1667
- await passflow.createTenant(tenantName, true);
1668
- const parsedTokens = passflow.getParsedTokenCache();
1669
- currentTenant = parsedTokens.access_token.membership.tenants[0];
1670
- updateTenantUI();
1745
+ // true refreshes the tokens, so the new tenant is in the membership
1746
+ const created = await passflow.createTenant(tenantName, true);
1747
+ currentTenant =
1748
+ getTenants().find((m) => m.tenant.id === created.tenant_id) ?? null;
1749
+ if (currentTenant) {
1750
+ updateTenantUI();
1751
+ }
1671
1752
  } catch (error) {
1672
1753
  console.error("Failed to create tenant", error);
1673
1754
  alert(`Failed to create tenant: ${error.message}`);