@oxyhq/services 5.19.0 → 5.20.1
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 +46 -24
- 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/WebOxyProvider.js +9 -10
- package/lib/commonjs/ui/components/WebOxyProvider.js.map +1 -1
- package/lib/commonjs/ui/hooks/useAuth.js +21 -8
- package/lib/commonjs/ui/hooks/useAuth.js.map +1 -1
- package/lib/commonjs/ui/hooks/useWebSSO.js +21 -2
- package/lib/commonjs/ui/hooks/useWebSSO.js.map +1 -1
- package/lib/module/core/mixins/OxyServices.fedcm.js +46 -24
- 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/WebOxyProvider.js +9 -10
- package/lib/module/ui/components/WebOxyProvider.js.map +1 -1
- package/lib/module/ui/hooks/useAuth.js +21 -8
- package/lib/module/ui/hooks/useAuth.js.map +1 -1
- package/lib/module/ui/hooks/useWebSSO.js +21 -2
- package/lib/module/ui/hooks/useWebSSO.js.map +1 -1
- package/lib/typescript/commonjs/core/mixins/OxyServices.fedcm.d.ts +10 -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/WebOxyProvider.d.ts +9 -10
- package/lib/typescript/commonjs/ui/components/WebOxyProvider.d.ts.map +1 -1
- package/lib/typescript/commonjs/ui/hooks/useAuth.d.ts.map +1 -1
- package/lib/typescript/commonjs/ui/hooks/useWebSSO.d.ts.map +1 -1
- package/lib/typescript/module/core/mixins/OxyServices.fedcm.d.ts +10 -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/WebOxyProvider.d.ts +9 -10
- package/lib/typescript/module/ui/components/WebOxyProvider.d.ts.map +1 -1
- package/lib/typescript/module/ui/hooks/useAuth.d.ts.map +1 -1
- package/lib/typescript/module/ui/hooks/useWebSSO.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/core/mixins/OxyServices.fedcm.ts +47 -23
- package/src/ui/components/OxyProvider.tsx +112 -47
- package/src/ui/components/WebOxyProvider.tsx +9 -10
- package/src/ui/hooks/useAuth.ts +25 -8
- package/src/ui/hooks/useWebSSO.ts +21 -2
package/src/ui/hooks/useAuth.ts
CHANGED
|
@@ -101,8 +101,13 @@ export function useAuth(): UseAuthReturn {
|
|
|
101
101
|
} = useOxy();
|
|
102
102
|
|
|
103
103
|
const signIn = useCallback(async (publicKey?: string): Promise<User> => {
|
|
104
|
-
//
|
|
105
|
-
|
|
104
|
+
// Check if we're on the identity provider itself (auth.oxy.so)
|
|
105
|
+
// Only auth.oxy.so has local login forms - accounts.oxy.so is a client app
|
|
106
|
+
const isIdentityProvider = isWebBrowser() &&
|
|
107
|
+
window.location.hostname === 'auth.oxy.so';
|
|
108
|
+
|
|
109
|
+
// Web (not on IdP): Use FedCM or popup-based authentication
|
|
110
|
+
if (isWebBrowser() && !publicKey && !isIdentityProvider) {
|
|
106
111
|
try {
|
|
107
112
|
// Try FedCM first (instant if user already signed in)
|
|
108
113
|
if ((oxyServices as any).isFedCMSupported?.()) {
|
|
@@ -145,13 +150,25 @@ export function useAuth(): UseAuthReturn {
|
|
|
145
150
|
}
|
|
146
151
|
}
|
|
147
152
|
|
|
148
|
-
// No identity - show auth UI
|
|
149
|
-
showBottomSheet
|
|
153
|
+
// No identity - show auth UI
|
|
154
|
+
if (showBottomSheet) {
|
|
155
|
+
showBottomSheet('OxyAuth');
|
|
156
|
+
// Return a promise that resolves when auth completes
|
|
157
|
+
return new Promise((_, reject) => {
|
|
158
|
+
reject(new Error('Please complete sign-in in the auth sheet'));
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// Web fallback: navigate to login page on auth domain
|
|
163
|
+
if (isWebBrowser()) {
|
|
164
|
+
const loginUrl = window.location.hostname.includes('oxy.so')
|
|
165
|
+
? '/login'
|
|
166
|
+
: 'https://accounts.oxy.so/login';
|
|
167
|
+
window.location.href = loginUrl;
|
|
168
|
+
return new Promise(() => {}); // Never resolves, page will redirect
|
|
169
|
+
}
|
|
150
170
|
|
|
151
|
-
|
|
152
|
-
return new Promise((_, reject) => {
|
|
153
|
-
reject(new Error('Please complete sign-in in the auth sheet'));
|
|
154
|
-
});
|
|
171
|
+
throw new Error('No authentication method available');
|
|
155
172
|
}, [oxySignIn, hasIdentity, getPublicKey, showBottomSheet, oxyServices]);
|
|
156
173
|
|
|
157
174
|
const signOut = useCallback(async (): Promise<void> => {
|
|
@@ -45,6 +45,16 @@ function isWebBrowser(): boolean {
|
|
|
45
45
|
typeof document.documentElement !== 'undefined';
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
+
/**
|
|
49
|
+
* Check if we're on the identity provider domain (where FedCM would authenticate against itself)
|
|
50
|
+
* Only auth.oxy.so is the IdP - accounts.oxy.so is a client app like any other
|
|
51
|
+
*/
|
|
52
|
+
function isIdentityProvider(): boolean {
|
|
53
|
+
if (!isWebBrowser()) return false;
|
|
54
|
+
const hostname = window.location.hostname;
|
|
55
|
+
return hostname === 'auth.oxy.so';
|
|
56
|
+
}
|
|
57
|
+
|
|
48
58
|
/**
|
|
49
59
|
* Hook for automatic cross-domain web SSO
|
|
50
60
|
*
|
|
@@ -79,6 +89,12 @@ export function useWebSSO({
|
|
|
79
89
|
return null;
|
|
80
90
|
}
|
|
81
91
|
|
|
92
|
+
// Don't use FedCM on the auth domain itself - it would authenticate against itself
|
|
93
|
+
if (isIdentityProvider()) {
|
|
94
|
+
onSSOUnavailable?.();
|
|
95
|
+
return null;
|
|
96
|
+
}
|
|
97
|
+
|
|
82
98
|
// FedCM is the only reliable cross-domain SSO mechanism
|
|
83
99
|
// Third-party cookies are deprecated and unreliable
|
|
84
100
|
if (!fedCMSupported) {
|
|
@@ -111,9 +127,12 @@ export function useWebSSO({
|
|
|
111
127
|
}
|
|
112
128
|
}, [oxyServices, onSessionFound, onSSOUnavailable, onError, fedCMSupported]);
|
|
113
129
|
|
|
114
|
-
// Auto-check SSO on mount (web only, FedCM only)
|
|
130
|
+
// Auto-check SSO on mount (web only, FedCM only, not on auth domain)
|
|
115
131
|
useEffect(() => {
|
|
116
|
-
if (!enabled || !isWebBrowser() || hasCheckedRef.current) {
|
|
132
|
+
if (!enabled || !isWebBrowser() || hasCheckedRef.current || isIdentityProvider()) {
|
|
133
|
+
if (isIdentityProvider()) {
|
|
134
|
+
onSSOUnavailable?.();
|
|
135
|
+
}
|
|
117
136
|
return;
|
|
118
137
|
}
|
|
119
138
|
|