@oxyhq/services 5.18.5 → 5.20.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 (52) hide show
  1. package/README.md +51 -42
  2. package/lib/commonjs/core/mixins/OxyServices.fedcm.js +1 -1
  3. package/lib/commonjs/core/mixins/OxyServices.fedcm.js.map +1 -1
  4. package/lib/commonjs/ui/components/OxyProvider.js +106 -40
  5. package/lib/commonjs/ui/components/OxyProvider.js.map +1 -1
  6. package/lib/commonjs/ui/components/OxySignInButton.js +24 -17
  7. package/lib/commonjs/ui/components/OxySignInButton.js.map +1 -1
  8. package/lib/commonjs/ui/components/WebOxyProvider.js +13 -5
  9. package/lib/commonjs/ui/components/WebOxyProvider.js.map +1 -1
  10. package/lib/commonjs/ui/hooks/useAuth.js +33 -8
  11. package/lib/commonjs/ui/hooks/useAuth.js.map +1 -1
  12. package/lib/commonjs/ui/hooks/useWebSSO.js +55 -16
  13. package/lib/commonjs/ui/hooks/useWebSSO.js.map +1 -1
  14. package/lib/module/core/mixins/OxyServices.fedcm.js +1 -1
  15. package/lib/module/core/mixins/OxyServices.fedcm.js.map +1 -1
  16. package/lib/module/ui/components/OxyProvider.js +106 -39
  17. package/lib/module/ui/components/OxyProvider.js.map +1 -1
  18. package/lib/module/ui/components/OxySignInButton.js +24 -17
  19. package/lib/module/ui/components/OxySignInButton.js.map +1 -1
  20. package/lib/module/ui/components/WebOxyProvider.js +13 -5
  21. package/lib/module/ui/components/WebOxyProvider.js.map +1 -1
  22. package/lib/module/ui/hooks/useAuth.js +33 -8
  23. package/lib/module/ui/hooks/useAuth.js.map +1 -1
  24. package/lib/module/ui/hooks/useWebSSO.js +55 -16
  25. package/lib/module/ui/hooks/useWebSSO.js.map +1 -1
  26. package/lib/typescript/commonjs/core/mixins/OxyServices.fedcm.d.ts.map +1 -1
  27. package/lib/typescript/commonjs/ui/components/OxyProvider.d.ts +26 -3
  28. package/lib/typescript/commonjs/ui/components/OxyProvider.d.ts.map +1 -1
  29. package/lib/typescript/commonjs/ui/components/OxySignInButton.d.ts.map +1 -1
  30. package/lib/typescript/commonjs/ui/components/WebOxyProvider.d.ts +13 -5
  31. package/lib/typescript/commonjs/ui/components/WebOxyProvider.d.ts.map +1 -1
  32. package/lib/typescript/commonjs/ui/hooks/useAuth.d.ts +8 -3
  33. package/lib/typescript/commonjs/ui/hooks/useAuth.d.ts.map +1 -1
  34. package/lib/typescript/commonjs/ui/hooks/useWebSSO.d.ts +29 -7
  35. package/lib/typescript/commonjs/ui/hooks/useWebSSO.d.ts.map +1 -1
  36. package/lib/typescript/module/core/mixins/OxyServices.fedcm.d.ts.map +1 -1
  37. package/lib/typescript/module/ui/components/OxyProvider.d.ts +26 -3
  38. package/lib/typescript/module/ui/components/OxyProvider.d.ts.map +1 -1
  39. package/lib/typescript/module/ui/components/OxySignInButton.d.ts.map +1 -1
  40. package/lib/typescript/module/ui/components/WebOxyProvider.d.ts +13 -5
  41. package/lib/typescript/module/ui/components/WebOxyProvider.d.ts.map +1 -1
  42. package/lib/typescript/module/ui/hooks/useAuth.d.ts +8 -3
  43. package/lib/typescript/module/ui/hooks/useAuth.d.ts.map +1 -1
  44. package/lib/typescript/module/ui/hooks/useWebSSO.d.ts +29 -7
  45. package/lib/typescript/module/ui/hooks/useWebSSO.d.ts.map +1 -1
  46. package/package.json +1 -1
  47. package/src/core/mixins/OxyServices.fedcm.ts +1 -1
  48. package/src/ui/components/OxyProvider.tsx +112 -47
  49. package/src/ui/components/OxySignInButton.tsx +24 -17
  50. package/src/ui/components/WebOxyProvider.tsx +13 -5
  51. package/src/ui/hooks/useAuth.ts +42 -12
  52. package/src/ui/hooks/useWebSSO.ts +59 -15
@@ -1,11 +1,18 @@
1
1
  /**
2
2
  * Web SSO Hook
3
3
  *
4
- * Automatically handles cross-domain SSO for web apps.
5
- * Uses the OxyServices.silentSignIn() method which loads a hidden iframe
6
- * to check for existing session at auth.oxy.so.
4
+ * Handles cross-domain SSO for web apps using FedCM (Federated Credential Management).
5
+ *
6
+ * FedCM is the modern, privacy-preserving standard for cross-domain identity federation.
7
+ * It works across completely different TLDs (alia.onl, mention.earth, homiio.com, etc.)
8
+ * without relying on third-party cookies.
9
+ *
10
+ * For browsers without FedCM support, users will need to click a sign-in button
11
+ * which triggers a popup-based authentication flow.
7
12
  *
8
13
  * This is called automatically by OxyContext on web platforms.
14
+ *
15
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/FedCM_API
9
16
  */
10
17
 
11
18
  import { useEffect, useRef, useCallback } from 'react';
@@ -15,78 +22,115 @@ import type { SessionLoginResponse } from '../../models/session';
15
22
  interface UseWebSSOOptions {
16
23
  oxyServices: OxyServices;
17
24
  onSessionFound: (session: SessionLoginResponse) => Promise<void>;
25
+ onSSOUnavailable?: () => void;
18
26
  onError?: (error: Error) => void;
19
27
  enabled?: boolean;
20
28
  }
21
29
 
22
30
  interface UseWebSSOResult {
31
+ /** Manually trigger SSO check */
23
32
  checkSSO: () => Promise<SessionLoginResponse | null>;
33
+ /** Whether SSO check is in progress */
24
34
  isChecking: boolean;
35
+ /** Whether FedCM is supported in this browser */
36
+ isFedCMSupported: boolean;
25
37
  }
26
38
 
27
39
  /**
28
40
  * Check if we're running in a web browser environment (not React Native)
29
41
  */
30
42
  function isWebBrowser(): boolean {
31
- // Check for browser globals and that we have a real DOM (React Native has window but not documentElement)
32
43
  return typeof window !== 'undefined' &&
33
44
  typeof document !== 'undefined' &&
34
45
  typeof document.documentElement !== 'undefined';
35
46
  }
36
47
 
37
48
  /**
38
- * Hook for automatic web SSO
49
+ * Hook for automatic cross-domain web SSO
39
50
  *
40
- * Automatically checks for existing cross-domain session on mount.
41
- * Only runs on web platforms. Uses OxyServices.silentSignIn() internally.
51
+ * Uses FedCM (Federated Credential Management) - the modern browser-native
52
+ * identity federation API. This is the same technology that powers
53
+ * Google's cross-domain SSO (YouTube, Gmail, Maps, etc.).
54
+ *
55
+ * Key benefits:
56
+ * - Works across different TLDs (alia.onl ↔ mention.earth ↔ homiio.com)
57
+ * - No third-party cookies required
58
+ * - Privacy-preserving (browser mediates identity, IdP can't track)
59
+ * - Automatic silent sign-in after initial authentication
60
+ *
61
+ * For browsers without FedCM (Firefox, older browsers), automatic SSO
62
+ * is not possible. Users will see a sign-in button instead.
42
63
  */
43
64
  export function useWebSSO({
44
65
  oxyServices,
45
66
  onSessionFound,
67
+ onSSOUnavailable,
46
68
  onError,
47
69
  enabled = true,
48
70
  }: UseWebSSOOptions): UseWebSSOResult {
49
71
  const isCheckingRef = useRef(false);
50
72
  const hasCheckedRef = useRef(false);
51
73
 
74
+ // Check FedCM support once
75
+ const fedCMSupported = isWebBrowser() && (oxyServices as any).isFedCMSupported?.();
76
+
52
77
  const checkSSO = useCallback(async (): Promise<SessionLoginResponse | null> => {
53
78
  if (!isWebBrowser() || isCheckingRef.current) {
54
79
  return null;
55
80
  }
56
81
 
82
+ // FedCM is the only reliable cross-domain SSO mechanism
83
+ // Third-party cookies are deprecated and unreliable
84
+ if (!fedCMSupported) {
85
+ onSSOUnavailable?.();
86
+ return null;
87
+ }
88
+
57
89
  isCheckingRef.current = true;
58
90
 
59
91
  try {
60
- // Use the existing silentSignIn method from OxyServices
61
- // which handles iframe creation, postMessage, and token storage
62
- const session = await (oxyServices as any).silentSignIn?.();
92
+ // Use FedCM for cross-domain SSO
93
+ // This works because browser treats IdP requests as first-party
94
+ const session = await (oxyServices as any).silentSignInWithFedCM?.();
63
95
 
64
96
  if (session) {
65
97
  await onSessionFound(session);
98
+ return session;
66
99
  }
67
100
 
68
- return session;
101
+ // No session found - user needs to sign in
102
+ onSSOUnavailable?.();
103
+ return null;
69
104
  } catch (error) {
105
+ // FedCM failed - could be network error, user not signed in, etc.
106
+ onSSOUnavailable?.();
70
107
  onError?.(error instanceof Error ? error : new Error(String(error)));
71
108
  return null;
72
109
  } finally {
73
110
  isCheckingRef.current = false;
74
111
  }
75
- }, [oxyServices, onSessionFound, onError]);
112
+ }, [oxyServices, onSessionFound, onSSOUnavailable, onError, fedCMSupported]);
76
113
 
77
- // Auto-check SSO on mount (web only)
114
+ // Auto-check SSO on mount (web only, FedCM only)
78
115
  useEffect(() => {
79
116
  if (!enabled || !isWebBrowser() || hasCheckedRef.current) {
80
117
  return;
81
118
  }
82
119
 
83
120
  hasCheckedRef.current = true;
84
- checkSSO();
85
- }, [enabled, checkSSO]);
121
+
122
+ if (fedCMSupported) {
123
+ checkSSO();
124
+ } else {
125
+ // Browser doesn't support FedCM - notify caller
126
+ onSSOUnavailable?.();
127
+ }
128
+ }, [enabled, checkSSO, fedCMSupported, onSSOUnavailable]);
86
129
 
87
130
  return {
88
131
  checkSSO,
89
132
  isChecking: isCheckingRef.current,
133
+ isFedCMSupported: fedCMSupported,
90
134
  };
91
135
  }
92
136