@microsoft/rayfin-auth-provider-fabric 1.33.2 → 1.34.0-alpha.1160

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.
@@ -1,3 +1,4 @@
1
+ import { assertBrowser } from '@microsoft/rayfin-lib';
1
2
  /** @internal BroadcastChannel name for backward-compat cross-tab handoff messaging. */
2
3
  export const FABRIC_AUTH_CHANNEL = 'rayfin_fabric_auth';
3
4
  /**
@@ -16,6 +17,7 @@ export const FABRIC_AUTH_CHANNEL = 'rayfin_fabric_auth';
16
17
  * @returns Whether a bridge message was sent.
17
18
  */
18
19
  export function bridgeFabricCallback() {
20
+ assertBrowser('bridgeFabricCallback');
19
21
  // Query params first, then hash fragment. Only match verification_code/code
20
22
  // from query params when window.opener exists (popup context) to avoid
21
23
  // colliding with magic-link callbacks that use the same param names.
@@ -1,5 +1,6 @@
1
1
  import { generateCodeVerifier, generateCodeChallenge, generateState, } from '@microsoft/rayfin-auth';
2
- import { AuthError } from '@microsoft/rayfin-lib';
2
+ import { createSessionFromTokenResponse } from '@microsoft/rayfin-auth/_internal';
3
+ import { AuthError, assertBrowser } from '@microsoft/rayfin-lib';
3
4
  import { requestHandoff } from './PostMessageAuthTransport.js';
4
5
  import { markEmbeddedHandoffCompleted } from './fabricAuthHelpers.js';
5
6
  /**
@@ -22,6 +23,7 @@ import { markEmbeddedHandoffCompleted } from './fabricAuthHelpers.js';
22
23
  * @throws `AuthError` - On missing options, transport failure, or token exchange error.
23
24
  */
24
25
  export async function embeddedFabricLogin(auth, options) {
26
+ assertBrowser('embeddedFabricLogin');
25
27
  if (!options.returnOrigin) {
26
28
  throw new AuthError('returnOrigin is required for embedded Fabric authentication.', 'MISSING_RETURN_ORIGIN');
27
29
  }
@@ -70,7 +72,7 @@ export async function embeddedFabricLogin(auth, options) {
70
72
  codeType: 'fabric_handoff',
71
73
  redirectUri,
72
74
  });
73
- auth.createSessionFromTokenResponse(tokenResponse);
75
+ await createSessionFromTokenResponse(auth, tokenResponse);
74
76
  markEmbeddedHandoffCompleted();
75
77
  console.debug('[FabricAuth:embedded] Session established');
76
78
  }
@@ -26,9 +26,41 @@ import type { FabricAuthOptions } from './types.js';
26
26
  * Steps 1–3 do not open windows and are safe to call on page load.
27
27
  *
28
28
  * @param auth - The Auth instance.
29
- * @param options - Fabric authentication options (workspaceId, projectId, returnOrigin).
29
+ * @param options - Fabric authentication options (workspaceId, projectId, fabricPortalUrl, returnOrigin).
30
30
  * @returns A promise that resolves with the authenticated session.
31
31
  * @throws `AuthError` - If all steps fail or the broker tab is blocked.
32
+ *
33
+ * @example
34
+ * ```typescript
35
+ * import { Auth } from '@microsoft/rayfin-auth';
36
+ * import { ApiClient } from '@microsoft/rayfin-lib';
37
+ * import {
38
+ * ensureSignedInWithFabric,
39
+ * type FabricAuthOptions,
40
+ * } from '@microsoft/rayfin-auth-provider-fabric';
41
+ *
42
+ * const apiClient = new ApiClient({
43
+ * baseUrl: import.meta.env.VITE_RAYFIN_API_URL,
44
+ * publishableKey: import.meta.env.VITE_RAYFIN_PUBLISHABLE_KEY,
45
+ * });
46
+ * const auth = new Auth(apiClient);
47
+ * const fabricOptions: FabricAuthOptions = {
48
+ * workspaceId: import.meta.env.VITE_FABRIC_WORKSPACE_ID,
49
+ * projectId: import.meta.env.VITE_FABRIC_ITEM_ID,
50
+ * fabricPortalUrl: import.meta.env.VITE_FABRIC_PORTAL_URL,
51
+ * returnOrigin: window.location.origin,
52
+ * };
53
+ *
54
+ * // Wire to a button click so step 4 (window.open) is in a user-gesture context.
55
+ * signInButton.addEventListener('click', async () => {
56
+ * try {
57
+ * const session = await ensureSignedInWithFabric(auth, fabricOptions);
58
+ * console.log('Signed in as', session.user?.email);
59
+ * } catch (error) {
60
+ * console.error('Fabric sign-in failed:', error.message);
61
+ * }
62
+ * });
63
+ * ```
32
64
  */
33
65
  export declare function ensureSignedInWithFabric(auth: Auth, options: FabricAuthOptions): Promise<OpaqueSession>;
34
66
  //# sourceMappingURL=ensureSignedInWithFabric.d.ts.map
@@ -1,4 +1,4 @@
1
- import { AuthError } from '@microsoft/rayfin-lib';
1
+ import { AuthError, assertBrowser } from '@microsoft/rayfin-lib';
2
2
  import { embeddedFabricLogin } from './embeddedFabricLogin.js';
3
3
  import { hasEmbeddedHandoffCompleted, isEmbeddedMode, tryResumeSession, } from './fabricAuthHelpers.js';
4
4
  import { initiateFabricLogin } from './initiateFabricLogin.js';
@@ -28,11 +28,44 @@ import { initiateFabricLogin } from './initiateFabricLogin.js';
28
28
  * Steps 1–3 do not open windows and are safe to call on page load.
29
29
  *
30
30
  * @param auth - The Auth instance.
31
- * @param options - Fabric authentication options (workspaceId, projectId, returnOrigin).
31
+ * @param options - Fabric authentication options (workspaceId, projectId, fabricPortalUrl, returnOrigin).
32
32
  * @returns A promise that resolves with the authenticated session.
33
33
  * @throws `AuthError` - If all steps fail or the broker tab is blocked.
34
+ *
35
+ * @example
36
+ * ```typescript
37
+ * import { Auth } from '@microsoft/rayfin-auth';
38
+ * import { ApiClient } from '@microsoft/rayfin-lib';
39
+ * import {
40
+ * ensureSignedInWithFabric,
41
+ * type FabricAuthOptions,
42
+ * } from '@microsoft/rayfin-auth-provider-fabric';
43
+ *
44
+ * const apiClient = new ApiClient({
45
+ * baseUrl: import.meta.env.VITE_RAYFIN_API_URL,
46
+ * publishableKey: import.meta.env.VITE_RAYFIN_PUBLISHABLE_KEY,
47
+ * });
48
+ * const auth = new Auth(apiClient);
49
+ * const fabricOptions: FabricAuthOptions = {
50
+ * workspaceId: import.meta.env.VITE_FABRIC_WORKSPACE_ID,
51
+ * projectId: import.meta.env.VITE_FABRIC_ITEM_ID,
52
+ * fabricPortalUrl: import.meta.env.VITE_FABRIC_PORTAL_URL,
53
+ * returnOrigin: window.location.origin,
54
+ * };
55
+ *
56
+ * // Wire to a button click so step 4 (window.open) is in a user-gesture context.
57
+ * signInButton.addEventListener('click', async () => {
58
+ * try {
59
+ * const session = await ensureSignedInWithFabric(auth, fabricOptions);
60
+ * console.log('Signed in as', session.user?.email);
61
+ * } catch (error) {
62
+ * console.error('Fabric sign-in failed:', error.message);
63
+ * }
64
+ * });
65
+ * ```
34
66
  */
35
67
  export async function ensureSignedInWithFabric(auth, options) {
68
+ assertBrowser('ensureSignedInWithFabric');
36
69
  // Steps 1-2: existing session or refresh.
37
70
  // In embedded mode we MUST skip this on the first call per page load —
38
71
  // the session in iframe localStorage may belong to a previously
@@ -1,5 +1,6 @@
1
1
  import { generateCodeVerifier, generateCodeChallenge, generateState, } from '@microsoft/rayfin-auth';
2
- import { AuthError } from '@microsoft/rayfin-lib';
2
+ import { createSessionFromTokenResponse } from '@microsoft/rayfin-auth/_internal';
3
+ import { AuthError, assertBrowser } from '@microsoft/rayfin-lib';
3
4
  import { FABRIC_AUTH_CHANNEL } from './bridgeFabricCallback.js';
4
5
  import { buildBrokerUrl } from './brokerUrl.js';
5
6
  /**
@@ -17,6 +18,7 @@ import { buildBrokerUrl } from './brokerUrl.js';
17
18
  * @throws `AuthError` - On missing options, blocked popup, or auth failure.
18
19
  */
19
20
  export async function initiateFabricLogin(auth, options) {
21
+ assertBrowser('initiateFabricLogin');
20
22
  // Validate required params
21
23
  if (!options.workspaceId) {
22
24
  throw new AuthError('workspaceId is required.', 'MISSING_WORKSPACE_ID');
@@ -83,9 +85,9 @@ export async function initiateFabricLogin(auth, options) {
83
85
  codeType: 'fabric_handoff',
84
86
  redirectUri,
85
87
  })
86
- .then((tokenResponse) => {
88
+ .then(async (tokenResponse) => {
87
89
  console.debug('[FabricAuth] Token exchange succeeded, creating session');
88
- auth.createSessionFromTokenResponse(tokenResponse);
90
+ await createSessionFromTokenResponse(auth, tokenResponse);
89
91
  resolve();
90
92
  })
91
93
  .catch((err) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@microsoft/rayfin-auth-provider-fabric",
3
- "version": "1.33.2",
3
+ "version": "1.34.0-alpha.1160",
4
4
  "description": "Fabric brokered authentication provider for Rayfin SDK",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -13,9 +13,9 @@
13
13
  ],
14
14
  "type": "module",
15
15
  "dependencies": {
16
- "@microsoft/rayfin-auth": "1.33.2",
17
- "@microsoft/fabric-embedded-host": "1.33.2",
18
- "@microsoft/rayfin-lib": "1.33.2"
16
+ "@microsoft/rayfin-auth": "1.34.0-alpha.1160",
17
+ "@microsoft/fabric-embedded-host": "1.34.0-alpha.1160",
18
+ "@microsoft/rayfin-lib": "1.34.0-alpha.1160"
19
19
  },
20
20
  "devDependencies": {
21
21
  "typescript": "^5.8.3",