@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.
- package/README.md +51 -42
- package/lib/commonjs/core/mixins/OxyServices.fedcm.js +1 -1
- package/lib/commonjs/core/mixins/OxyServices.fedcm.js.map +1 -1
- package/lib/commonjs/ui/components/OxyProvider.js +106 -40
- package/lib/commonjs/ui/components/OxyProvider.js.map +1 -1
- package/lib/commonjs/ui/components/OxySignInButton.js +24 -17
- package/lib/commonjs/ui/components/OxySignInButton.js.map +1 -1
- package/lib/commonjs/ui/components/WebOxyProvider.js +13 -5
- package/lib/commonjs/ui/components/WebOxyProvider.js.map +1 -1
- package/lib/commonjs/ui/hooks/useAuth.js +33 -8
- package/lib/commonjs/ui/hooks/useAuth.js.map +1 -1
- package/lib/commonjs/ui/hooks/useWebSSO.js +55 -16
- package/lib/commonjs/ui/hooks/useWebSSO.js.map +1 -1
- package/lib/module/core/mixins/OxyServices.fedcm.js +1 -1
- package/lib/module/core/mixins/OxyServices.fedcm.js.map +1 -1
- package/lib/module/ui/components/OxyProvider.js +106 -39
- package/lib/module/ui/components/OxyProvider.js.map +1 -1
- package/lib/module/ui/components/OxySignInButton.js +24 -17
- package/lib/module/ui/components/OxySignInButton.js.map +1 -1
- package/lib/module/ui/components/WebOxyProvider.js +13 -5
- package/lib/module/ui/components/WebOxyProvider.js.map +1 -1
- package/lib/module/ui/hooks/useAuth.js +33 -8
- package/lib/module/ui/hooks/useAuth.js.map +1 -1
- package/lib/module/ui/hooks/useWebSSO.js +55 -16
- package/lib/module/ui/hooks/useWebSSO.js.map +1 -1
- package/lib/typescript/commonjs/core/mixins/OxyServices.fedcm.d.ts.map +1 -1
- package/lib/typescript/commonjs/ui/components/OxyProvider.d.ts +26 -3
- package/lib/typescript/commonjs/ui/components/OxyProvider.d.ts.map +1 -1
- package/lib/typescript/commonjs/ui/components/OxySignInButton.d.ts.map +1 -1
- package/lib/typescript/commonjs/ui/components/WebOxyProvider.d.ts +13 -5
- package/lib/typescript/commonjs/ui/components/WebOxyProvider.d.ts.map +1 -1
- package/lib/typescript/commonjs/ui/hooks/useAuth.d.ts +8 -3
- package/lib/typescript/commonjs/ui/hooks/useAuth.d.ts.map +1 -1
- package/lib/typescript/commonjs/ui/hooks/useWebSSO.d.ts +29 -7
- package/lib/typescript/commonjs/ui/hooks/useWebSSO.d.ts.map +1 -1
- package/lib/typescript/module/core/mixins/OxyServices.fedcm.d.ts.map +1 -1
- package/lib/typescript/module/ui/components/OxyProvider.d.ts +26 -3
- package/lib/typescript/module/ui/components/OxyProvider.d.ts.map +1 -1
- package/lib/typescript/module/ui/components/OxySignInButton.d.ts.map +1 -1
- package/lib/typescript/module/ui/components/WebOxyProvider.d.ts +13 -5
- package/lib/typescript/module/ui/components/WebOxyProvider.d.ts.map +1 -1
- package/lib/typescript/module/ui/hooks/useAuth.d.ts +8 -3
- package/lib/typescript/module/ui/hooks/useAuth.d.ts.map +1 -1
- package/lib/typescript/module/ui/hooks/useWebSSO.d.ts +29 -7
- package/lib/typescript/module/ui/hooks/useWebSSO.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/core/mixins/OxyServices.fedcm.ts +1 -1
- package/src/ui/components/OxyProvider.tsx +112 -47
- package/src/ui/components/OxySignInButton.tsx +24 -17
- package/src/ui/components/WebOxyProvider.tsx +13 -5
- package/src/ui/hooks/useAuth.ts +42 -12
- package/src/ui/hooks/useWebSSO.ts +59 -15
|
@@ -1,11 +1,18 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Web SSO Hook
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
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
|
-
*
|
|
41
|
-
*
|
|
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
|
|
61
|
-
//
|
|
62
|
-
const session = await (oxyServices as any).
|
|
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
|
-
|
|
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
|
-
|
|
85
|
-
|
|
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
|
|