@passflow/core 0.35.3 → 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,22 @@
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
+
5
21
  ### Version 0.35.3
6
22
 
7
23
  - Fixed: in cookie and BFF mode a call answered 401 refreshes the session once and is sent once
@@ -256,6 +272,7 @@ Matches the SDK to the server's real two-factor, step-up and sign-out answers.
256
272
  - [Sign Out](#sign-out)
257
273
  - [Passwordless Authentication](#passwordless-authentication)
258
274
  - [Federated Authentication](#federated-authentication)
275
+ - [Enterprise SSO](#enterprise-sso)
259
276
  - [Passkey Authentication](#passkey-authentication)
260
277
  - [Password Reset](#password-reset)
261
278
  - [Email verification](#email-verification)
@@ -289,7 +306,7 @@ Matches the SDK to the server's real two-factor, step-up and sign-out answers.
289
306
  ### Basic Initialization
290
307
 
291
308
  ```javascript
292
- import { Passflow } from "passflow-js";
309
+ import { Passflow } from "@passflow/core";
293
310
 
294
311
  // Minimal initialization with just the required appId
295
312
  const passflow = new Passflow({
@@ -298,8 +315,8 @@ const passflow = new Passflow({
298
315
 
299
316
  // Simple session setup
300
317
  passflow.session({
301
- createSession: () => console.log("User is authenticated"),
302
- expiredSession: () => console.log("User session expired"),
318
+ createSession: async () => console.log("User is authenticated"),
319
+ expiredSession: async () => console.log("User session expired"),
303
320
  });
304
321
  ```
305
322
 
@@ -461,9 +478,9 @@ Passflow JavaScript SDK is a client library for interacting with the Passflow au
461
478
  ## Installation
462
479
 
463
480
  ```bash
464
- npm install passflow-js
481
+ npm install @passflow/core
465
482
  # or
466
- yarn add passflow-js
483
+ yarn add @passflow/core
467
484
  ```
468
485
 
469
486
  ## Getting Started
@@ -473,7 +490,7 @@ yarn add passflow-js
473
490
  Import and initialize the Passflow client with your configuration:
474
491
 
475
492
  ```javascript
476
- import { Passflow } from "passflow-js";
493
+ import { Passflow } from "@passflow/core";
477
494
 
478
495
  const passflow = new Passflow({
479
496
  url: "https://auth.passflow.cloud", // or your custom URL
@@ -499,11 +516,11 @@ Setup session management to handle authentication state:
499
516
 
500
517
  ```javascript
501
518
  passflow.session({
502
- createSession: (tokens) => {
519
+ createSession: async (tokens) => {
503
520
  console.log("Session created", tokens);
504
521
  // Set your app's authenticated state
505
522
  },
506
- expiredSession: () => {
523
+ expiredSession: async () => {
507
524
  console.log("Session expired");
508
525
  // Clear your app's authenticated state
509
526
  },
@@ -720,6 +737,32 @@ The federated payload also takes `state` (echoed back on a Simple-mode landing)
720
737
  `parent_challenge_id` (the hosted login's OIDC parent sign-in); both are sent on the start URL. Details:
721
738
  [docs/pkce-sign-in.md](docs/pkce-sign-in.md).
722
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
+
723
766
  ### Passkey Authentication
724
767
 
725
768
  ```javascript
@@ -958,10 +1001,10 @@ import { PassflowEvent } from "@passflow/core";
958
1001
  const isAuthenticated = passflow.isAuthenticated();
959
1002
 
960
1003
  // Get current tokens
961
- const tokens = passflow.getTokensCache();
1004
+ const tokens = passflow.getCachedTokens();
962
1005
 
963
1006
  // Get parsed tokens (decoded JWT payload)
964
- const parsedTokens = passflow.getParsedTokenCache();
1007
+ const parsedTokens = passflow.getParsedTokens();
965
1008
 
966
1009
  // Manually refresh token
967
1010
  const refreshToken = async () => {
@@ -1315,6 +1358,9 @@ Configuration options:
1315
1358
  | `passwordlessSignInComplete(payload)` | Complete passwordless authentication |
1316
1359
  | `federatedAuthWithPopup(provider, redirectUrl, scopes)` | Sign in with a provider using popup |
1317
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) |
1318
1364
  | `passkeyRegister(payload)` | Register a new passkey |
1319
1365
  | `passkeyAuthenticate(payload)` | Authenticate with a passkey |
1320
1366
  | `sendPasswordResetEmail(payload)` | Send password reset email |
@@ -1331,8 +1377,8 @@ Configuration options:
1331
1377
  | Method | Description |
1332
1378
  | -------------------------- | ------------------------------ |
1333
1379
  | `isAuthenticated()` | Check if user is authenticated |
1334
- | `getTokensCache()` | Get current tokens |
1335
- | `getParsedTokenCache()` | Get parsed tokens |
1380
+ | `getCachedTokens()` | Get current tokens |
1381
+ | `getParsedTokens()` | Get parsed tokens |
1336
1382
  | `refreshToken()` | Refresh the access token |
1337
1383
  | `setTokens(tokens)` | Replace the stored tokens |
1338
1384
  | `handleTokensRedirect()` | Handle tokens from redirect |
@@ -1510,7 +1556,7 @@ Write, keep and clear rules: [docs/admin-secrets.md](docs/admin-secrets.md).
1510
1556
  ### Complete Sign In Flow
1511
1557
 
1512
1558
  ```javascript
1513
- import { Passflow, PassflowError } from "passflow-js";
1559
+ import { Passflow, PassflowError } from "@passflow/core";
1514
1560
 
1515
1561
  // Initialize Passflow
1516
1562
  const passflow = new Passflow({
@@ -1520,7 +1566,7 @@ const passflow = new Passflow({
1520
1566
 
1521
1567
  // Set up session management
1522
1568
  passflow.session({
1523
- createSession: (tokens) => {
1569
+ createSession: async (tokens) => {
1524
1570
  // Store authentication state
1525
1571
  localStorage.setItem("isAuthenticated", "true");
1526
1572
 
@@ -1528,7 +1574,7 @@ passflow.session({
1528
1574
  document.getElementById("login-form").style.display = "none";
1529
1575
  document.getElementById("user-dashboard").style.display = "block";
1530
1576
  },
1531
- expiredSession: () => {
1577
+ expiredSession: async () => {
1532
1578
  // Clear authentication state
1533
1579
  localStorage.removeItem("isAuthenticated");
1534
1580
 
@@ -1577,7 +1623,7 @@ window.addEventListener("load", () => {
1577
1623
  ### Authentication with Passkeys
1578
1624
 
1579
1625
  ```javascript
1580
- import { Passflow } from "passflow-js";
1626
+ import { Passflow } from "@passflow/core";
1581
1627
 
1582
1628
  // Initialize Passflow
1583
1629
  const passflow = new Passflow({
@@ -1586,10 +1632,10 @@ const passflow = new Passflow({
1586
1632
 
1587
1633
  // Set up session management
1588
1634
  passflow.session({
1589
- createSession: (tokens) => {
1635
+ createSession: async (tokens) => {
1590
1636
  console.log("Session created", tokens);
1591
1637
  },
1592
- expiredSession: () => {
1638
+ expiredSession: async () => {
1593
1639
  console.log("Session expired");
1594
1640
  },
1595
1641
  doRefresh: true,
@@ -1636,29 +1682,44 @@ document
1636
1682
 
1637
1683
  ### Multi-tenant Application
1638
1684
 
1685
+ `getParsedTokens()` returns every tenant the user belongs to in `access_token.membership.tenants`, and your app chooses which one to use.
1686
+
1639
1687
  ```javascript
1640
- import { Passflow, PassflowEvent } from "passflow-js";
1688
+ import { Passflow, PassflowEvent } from "@passflow/core";
1641
1689
 
1642
1690
  // Initialize Passflow
1643
1691
  const passflow = new Passflow({
1644
1692
  appId: "your-app-id",
1645
1693
  });
1646
1694
 
1647
- // Track current tenant
1648
- 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
+ }
1649
1716
 
1650
1717
  // Set up session management
1651
1718
  passflow.session({
1652
- createSession: (tokens) => {
1653
- const parsedTokens = passflow.getParsedTokenCache();
1654
- if (parsedTokens?.access_token?.membership?.tenants?.length > 0) {
1655
- currentTenant = parsedTokens.access_token.membership.tenants[0];
1656
- updateTenantUI();
1657
- } else {
1658
- showCreateTenantUI();
1659
- }
1719
+ createSession: async () => {
1720
+ showTenant();
1660
1721
  },
1661
- expiredSession: () => {
1722
+ expiredSession: async () => {
1662
1723
  currentTenant = null;
1663
1724
  showLoginUI();
1664
1725
  },
@@ -1672,13 +1733,7 @@ passflow.subscribe({
1672
1733
  eventType === PassflowEvent.SignIn ||
1673
1734
  eventType === PassflowEvent.Register
1674
1735
  ) {
1675
- const parsedTokens = passflow.getParsedTokenCache();
1676
- if (parsedTokens?.access_token?.membership?.tenants?.length > 0) {
1677
- currentTenant = parsedTokens.access_token.membership.tenants[0];
1678
- updateTenantUI();
1679
- } else {
1680
- showCreateTenantUI();
1681
- }
1736
+ showTenant();
1682
1737
  }
1683
1738
  },
1684
1739
  });
@@ -1687,10 +1742,13 @@ passflow.subscribe({
1687
1742
  async function createNewTenant() {
1688
1743
  const tenantName = document.getElementById("tenant-name").value;
1689
1744
  try {
1690
- await passflow.createTenant(tenantName, true);
1691
- const parsedTokens = passflow.getParsedTokenCache();
1692
- currentTenant = parsedTokens.access_token.membership.tenants[0];
1693
- 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
+ }
1694
1752
  } catch (error) {
1695
1753
  console.error("Failed to create tenant", error);
1696
1754
  alert(`Failed to create tenant: ${error.message}`);