@microsoft/rayfin-auth-provider-fabric 1.28.0 → 1.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.
Files changed (2) hide show
  1. package/assets/docs/index.md +141 -0
  2. package/package.json +11 -4
@@ -0,0 +1,141 @@
1
+ # Fabric auth provider
2
+
3
+ Fabric brokered authentication helpers for Rayfin browser applications.
4
+
5
+ Use `@microsoft/rayfin-auth-provider-fabric` when your application needs to authenticate through a Fabric-hosted broker experience instead of calling the standard Rayfin auth flows directly.
6
+
7
+ The package is designed for browser applications that already use `@microsoft/rayfin-auth` and need to reuse an existing session, refresh an expired session, or open the Fabric broker when no session can be restored silently.
8
+
9
+ ## Installation
10
+
11
+ ```bash
12
+ npm install @microsoft/rayfin-auth-provider-fabric @microsoft/rayfin-auth @microsoft/rayfin-lib
13
+ ```
14
+
15
+ ## Quick start
16
+
17
+ The recommended entry point is `ensureSignedInWithFabric()`.
18
+
19
+ It performs a three-step waterfall:
20
+
21
+ 1. Return the current session if the user is already authenticated.
22
+ 2. Attempt `auth.refreshSession()` when a refresh token exists.
23
+ 3. Open the Fabric broker in a popup and complete the handoff flow.
24
+
25
+ Call it from a synchronous user gesture, such as a button click, because the broker step uses `window.open()`.
26
+
27
+ ```typescript
28
+ import { ApiClient } from '@microsoft/rayfin-lib';
29
+ import { Auth } from '@microsoft/rayfin-auth';
30
+ import { ensureSignedInWithFabric } from '@microsoft/rayfin-auth-provider-fabric';
31
+
32
+ const apiClient = new ApiClient({
33
+ baseUrl: 'https://api.contoso.example',
34
+ publishableKey: 'pk_your_publishable_key',
35
+ });
36
+
37
+ const auth = new Auth(apiClient);
38
+
39
+ const fabricOptions = {
40
+ workspaceId: '00000000-0000-0000-0000-000000000000',
41
+ projectId: '11111111-1111-1111-1111-111111111111',
42
+ fabricPortalUrl: 'https://app.fabric.microsoft.com',
43
+ returnOrigin: window.location.origin,
44
+ };
45
+
46
+ document.querySelector('#sign-in')?.addEventListener('click', async () => {
47
+ const session = await ensureSignedInWithFabric(auth, fabricOptions);
48
+ console.log('Authenticated', session.isAuthenticated);
49
+ });
50
+ ```
51
+
52
+ ## Options
53
+
54
+ `FabricAuthOptions` controls how the broker URL is constructed and how the handoff is returned to your app.
55
+
56
+ ```typescript
57
+ interface FabricAuthOptions {
58
+ workspaceId: string;
59
+ projectId: string;
60
+ fabricPortalUrl: string;
61
+ returnOrigin: string;
62
+ callbackUrl?: string;
63
+ }
64
+ ```
65
+
66
+ `fabricPortalUrl` preserves existing paths and query parameters.
67
+
68
+ This supports production and development portal URLs such as `https://app.fabric.microsoft.com` or `https://powerbi-df.analysis-df.windows.net?debug.useLocalManifests=1&experience=power-bi`.
69
+
70
+ ## Supported flows
71
+
72
+ Use `ensureSignedInWithFabric()` when you want silent-session and refresh-token fallback behavior before opening the broker UI.
73
+
74
+ Use `initiateFabricLogin()` when you only want the broker step and do not need the session and refresh pre-checks.
75
+
76
+ ```typescript
77
+ import { initiateFabricLogin } from '@microsoft/rayfin-auth-provider-fabric';
78
+
79
+ await initiateFabricLogin(auth, {
80
+ workspaceId: '00000000-0000-0000-0000-000000000000',
81
+ projectId: '11111111-1111-1111-1111-111111111111',
82
+ fabricPortalUrl: 'https://app.fabric.microsoft.com',
83
+ returnOrigin: window.location.origin,
84
+ });
85
+ ```
86
+
87
+ On success, the package exchanges the Fabric handoff code for tokens through the Rayfin auth API and creates the session on your `Auth` instance.
88
+
89
+ ## Legacy callback bridge
90
+
91
+ Newer broker flows use `postMessage` to send the handoff code back to the opener window.
92
+
93
+ Older broker flows may redirect the popup to a callback page in your app instead.
94
+
95
+ For those older flows, call `bridgeFabricCallback()` as early as possible in the callback page.
96
+
97
+ If the URL contains Fabric handoff parameters, the function forwards them to the opener window and closes the popup.
98
+
99
+ ```typescript
100
+ import { bridgeFabricCallback } from '@microsoft/rayfin-auth-provider-fabric';
101
+
102
+ const bridged = bridgeFabricCallback();
103
+
104
+ if (!bridged) {
105
+ console.log('No Fabric handoff detected');
106
+ }
107
+ ```
108
+
109
+ The bridge returns `true` when it handled a Fabric handoff and `false` when the current URL is unrelated.
110
+
111
+ ## Behavior notes
112
+
113
+ - The broker URL is built with PKCE using the `S256` challenge method.
114
+ - Existing query parameters on `fabricPortalUrl` are preserved.
115
+ - `callbackUrl` defaults to `${returnOrigin}/auth/callback` when omitted.
116
+ - The broker handoff waits up to five minutes before timing out.
117
+ - If `window.opener` is unavailable in legacy flows, the bridge falls back to `BroadcastChannel`.
118
+
119
+ ## Error handling
120
+
121
+ The package throws `AuthError` values from `@microsoft/rayfin-lib` for validation and broker failures.
122
+
123
+ Common cases include missing required options, blocked popups, explicit broker errors, and handoff timeout.
124
+
125
+ ```typescript
126
+ import { AuthError } from '@microsoft/rayfin-lib';
127
+
128
+ try {
129
+ await ensureSignedInWithFabric(auth, fabricOptions);
130
+ } catch (error) {
131
+ if (error instanceof AuthError) {
132
+ console.error(error.code, error.message);
133
+ }
134
+ }
135
+ ```
136
+
137
+ ## Browser requirements
138
+
139
+ This package is intended for browser environments.
140
+
141
+ It depends on browser APIs such as `window.open()`, `postMessage`, `BroadcastChannel`, and `window.location`.
package/package.json CHANGED
@@ -1,20 +1,21 @@
1
1
  {
2
2
  "name": "@microsoft/rayfin-auth-provider-fabric",
3
- "version": "1.28.0",
3
+ "version": "1.30.0",
4
4
  "description": "Fabric brokered authentication provider for Rayfin SDK",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "files": [
8
8
  "dist/**/*.js",
9
9
  "dist/**/*.d.ts",
10
+ "assets/docs/**/*.md",
10
11
  "!dist/**/__tests__/**",
11
12
  "LICENSE"
12
13
  ],
13
14
  "type": "module",
14
15
  "dependencies": {
15
- "@microsoft/rayfin-auth": "1.28.0",
16
- "@microsoft/fabric-embedded-host": "1.28.0",
17
- "@microsoft/rayfin-lib": "1.28.0"
16
+ "@microsoft/rayfin-auth": "1.30.0",
17
+ "@microsoft/rayfin-lib": "1.30.0",
18
+ "@microsoft/fabric-embedded-host": "1.30.0"
18
19
  },
19
20
  "devDependencies": {
20
21
  "typescript": "^5.8.3",
@@ -26,6 +27,12 @@
26
27
  "registry": "https://npm.pkg.github.com",
27
28
  "access": "restricted"
28
29
  },
30
+ "rayfinDocs": {
31
+ "version": 1,
32
+ "dir": "assets/docs",
33
+ "module": "rayfin-auth-provider-fabric",
34
+ "kind": "api-reference"
35
+ },
29
36
  "repository": {
30
37
  "type": "git",
31
38
  "url": "https://github.com/microsoft/project-rayfin.git",