@onairos/react-native 3.0.24 → 3.0.26
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/lib/commonjs/components/OnairosButton.js +2 -3
- package/lib/commonjs/components/OnairosButton.js.map +1 -1
- package/lib/commonjs/components/TrainingModal.js +120 -16
- package/lib/commonjs/components/TrainingModal.js.map +1 -1
- package/lib/commonjs/components/UniversalOnboarding.js +196 -94
- package/lib/commonjs/components/UniversalOnboarding.js.map +1 -1
- package/lib/commonjs/components/onboarding/OAuthWebView.js +138 -27
- package/lib/commonjs/components/onboarding/OAuthWebView.js.map +1 -1
- package/lib/commonjs/constants/index.js +3 -3
- package/lib/commonjs/constants/index.js.map +1 -1
- package/lib/commonjs/services/platformAuthService.js +95 -44
- package/lib/commonjs/services/platformAuthService.js.map +1 -1
- package/lib/module/components/OnairosButton.js +2 -3
- package/lib/module/components/OnairosButton.js.map +1 -1
- package/lib/module/components/TrainingModal.js +120 -17
- package/lib/module/components/TrainingModal.js.map +1 -1
- package/lib/module/components/UniversalOnboarding.js +197 -95
- package/lib/module/components/UniversalOnboarding.js.map +1 -1
- package/lib/module/components/onboarding/OAuthWebView.js +139 -28
- package/lib/module/components/onboarding/OAuthWebView.js.map +1 -1
- package/lib/module/constants/index.js +3 -3
- package/lib/module/constants/index.js.map +1 -1
- package/lib/module/services/platformAuthService.js +92 -42
- package/lib/module/services/platformAuthService.js.map +1 -1
- package/lib/typescript/components/OnairosButton.d.ts.map +1 -1
- package/lib/typescript/components/TrainingModal.d.ts.map +1 -1
- package/lib/typescript/components/UniversalOnboarding.d.ts.map +1 -1
- package/lib/typescript/components/onboarding/OAuthWebView.d.ts.map +1 -1
- package/lib/typescript/services/platformAuthService.d.ts +11 -4
- package/lib/typescript/services/platformAuthService.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/components/OnairosButton.tsx +1 -4
- package/src/components/TrainingModal.tsx +202 -61
- package/src/components/UniversalOnboarding.tsx +188 -83
- package/src/components/onboarding/OAuthWebView.tsx +135 -25
- package/src/constants/index.ts +3 -3
- package/src/services/platformAuthService.ts +111 -40
|
@@ -17,8 +17,7 @@ const PLATFORM_AUTH_CONFIG: Record<string, PlatformAuthConfig> = {
|
|
|
17
17
|
color: '#E1306C',
|
|
18
18
|
},
|
|
19
19
|
youtube: {
|
|
20
|
-
hasNativeSDK:
|
|
21
|
-
nativeSDKPackage: '@react-native-google-signin/google-signin',
|
|
20
|
+
hasNativeSDK: false, // Changed to false to use OAuth flow through proxy
|
|
22
21
|
authEndpoint: 'https://api2.onairos.uk/youtube/authorize',
|
|
23
22
|
color: '#FF0000',
|
|
24
23
|
},
|
|
@@ -64,57 +63,79 @@ export const getPlatformColor = (platform: string): string => {
|
|
|
64
63
|
};
|
|
65
64
|
|
|
66
65
|
/**
|
|
67
|
-
* Initiates the OAuth flow for a platform
|
|
66
|
+
* Initiates the OAuth flow for a platform using Onairos proxy
|
|
68
67
|
* @param platform The platform to authenticate with
|
|
69
|
-
* @param
|
|
70
|
-
* @returns A Promise that resolves to the OAuth URL to open in a WebView
|
|
68
|
+
* @param userEmail The authenticated user's email (not random username)
|
|
69
|
+
* @returns A Promise that resolves to the OAuth URL to open in a WebView
|
|
71
70
|
*/
|
|
72
|
-
export const initiateOAuth = async (platform: string,
|
|
71
|
+
export const initiateOAuth = async (platform: string, userEmail: string): Promise<string | null> => {
|
|
73
72
|
try {
|
|
74
73
|
// Check if the platform is supported
|
|
75
74
|
if (!PLATFORM_AUTH_CONFIG[platform]) {
|
|
76
75
|
throw new Error(`Unsupported platform: ${platform}`);
|
|
77
76
|
}
|
|
78
77
|
|
|
79
|
-
|
|
80
|
-
if (PLATFORM_AUTH_CONFIG[platform].hasNativeSDK) {
|
|
81
|
-
// Return null to indicate that we should use the native SDK
|
|
82
|
-
return null;
|
|
83
|
-
}
|
|
78
|
+
console.log(`Initiating OAuth for ${platform} with user: ${userEmail}`);
|
|
84
79
|
|
|
85
|
-
// Prepare the request body
|
|
86
|
-
const
|
|
80
|
+
// Prepare the request body according to Onairos proxy schema
|
|
81
|
+
const requestBody = {
|
|
87
82
|
session: {
|
|
88
|
-
username:
|
|
83
|
+
username: userEmail || 'anonymous@example.com',
|
|
84
|
+
platform: platform,
|
|
85
|
+
timestamp: new Date().toISOString(),
|
|
89
86
|
},
|
|
90
87
|
};
|
|
91
88
|
|
|
92
|
-
|
|
89
|
+
console.log(`Making request to: ${PLATFORM_AUTH_CONFIG[platform].authEndpoint}`);
|
|
90
|
+
console.log('Request body:', JSON.stringify(requestBody, null, 2));
|
|
91
|
+
|
|
92
|
+
// Make the request to get the OAuth URL from Onairos proxy
|
|
93
93
|
const response = await fetch(PLATFORM_AUTH_CONFIG[platform].authEndpoint, {
|
|
94
94
|
method: 'POST',
|
|
95
95
|
headers: {
|
|
96
96
|
'Content-Type': 'application/json',
|
|
97
|
+
'Accept': 'application/json',
|
|
97
98
|
},
|
|
98
|
-
body: JSON.stringify(
|
|
99
|
+
body: JSON.stringify(requestBody),
|
|
99
100
|
});
|
|
100
101
|
|
|
102
|
+
console.log(`Response status: ${response.status}`);
|
|
103
|
+
console.log(`Response headers:`, response.headers);
|
|
104
|
+
|
|
105
|
+
if (!response.ok) {
|
|
106
|
+
const errorText = await response.text();
|
|
107
|
+
console.error(`HTTP error! status: ${response.status}, body: ${errorText}`);
|
|
108
|
+
throw new Error(`HTTP error! status: ${response.status} - ${errorText}`);
|
|
109
|
+
}
|
|
110
|
+
|
|
101
111
|
// Parse the response
|
|
102
112
|
const data = await response.json();
|
|
113
|
+
console.log(`OAuth response for ${platform}:`, data);
|
|
103
114
|
|
|
104
|
-
// Check
|
|
105
|
-
|
|
106
|
-
|
|
115
|
+
// Check for platform-specific response keys according to schema
|
|
116
|
+
let oauthUrl: string | null = null;
|
|
117
|
+
|
|
118
|
+
if (platform === 'youtube' && data.youtubeURL) {
|
|
119
|
+
oauthUrl = data.youtubeURL;
|
|
120
|
+
} else if (platform === 'reddit' && data.redditURL) {
|
|
121
|
+
oauthUrl = data.redditURL;
|
|
107
122
|
} else if (platform === 'pinterest' && data.pinterestURL) {
|
|
108
|
-
|
|
109
|
-
} else if (platform === 'youtube' && data.youtubeURL) {
|
|
110
|
-
return data.youtubeURL;
|
|
123
|
+
oauthUrl = data.pinterestURL;
|
|
111
124
|
} else if (platform === 'email' && data.emailURL) {
|
|
112
|
-
|
|
125
|
+
oauthUrl = data.emailURL;
|
|
126
|
+
} else if (platform === 'instagram' && data.instagramURL) {
|
|
127
|
+
oauthUrl = data.instagramURL;
|
|
113
128
|
} else if (data.url) {
|
|
114
|
-
|
|
129
|
+
// Generic fallback
|
|
130
|
+
oauthUrl = data.url;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
if (!oauthUrl) {
|
|
134
|
+
throw new Error(`No OAuth URL found in response for ${platform}. Response: ${JSON.stringify(data)}`);
|
|
115
135
|
}
|
|
116
136
|
|
|
117
|
-
|
|
137
|
+
console.log(`Successfully received OAuth URL for ${platform}: ${oauthUrl}`);
|
|
138
|
+
return oauthUrl;
|
|
118
139
|
} catch (error) {
|
|
119
140
|
console.error(`Error initiating OAuth for ${platform}:`, error);
|
|
120
141
|
throw error;
|
|
@@ -128,18 +149,9 @@ export const initiateOAuth = async (platform: string, username: string): Promise
|
|
|
128
149
|
*/
|
|
129
150
|
export const initiateNativeAuth = async (platform: string): Promise<boolean> => {
|
|
130
151
|
try {
|
|
131
|
-
// Currently
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
// In a real implementation, you would import and use the Google Sign-In SDK
|
|
135
|
-
console.log('Initiating native Google Sign-In for YouTube');
|
|
136
|
-
|
|
137
|
-
// Simulate a successful authentication
|
|
138
|
-
// In a real implementation, this would be the result of the Google Sign-In flow
|
|
139
|
-
return true;
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
throw new Error(`Native authentication not supported for ${platform}`);
|
|
152
|
+
// Currently no platforms use native SDK - all go through Onairos proxy
|
|
153
|
+
console.log(`Native authentication not available for ${platform}, use OAuth flow instead`);
|
|
154
|
+
return false;
|
|
143
155
|
} catch (error) {
|
|
144
156
|
console.error(`Error initiating native auth for ${platform}:`, error);
|
|
145
157
|
throw error;
|
|
@@ -153,11 +165,16 @@ export const initiateNativeAuth = async (platform: string): Promise<boolean> =>
|
|
|
153
165
|
*/
|
|
154
166
|
export const handleOAuthCallback = (url: string): string | null => {
|
|
155
167
|
try {
|
|
168
|
+
console.log('Handling OAuth callback URL:', url);
|
|
169
|
+
|
|
156
170
|
// Parse the URL
|
|
157
171
|
const parsedUrl = new URL(url);
|
|
158
172
|
|
|
159
173
|
// Extract the authorization code
|
|
160
|
-
|
|
174
|
+
const code = parsedUrl.searchParams.get('code');
|
|
175
|
+
console.log('Extracted authorization code:', code);
|
|
176
|
+
|
|
177
|
+
return code;
|
|
161
178
|
} catch (error) {
|
|
162
179
|
console.error('Error handling OAuth callback:', error);
|
|
163
180
|
return null;
|
|
@@ -170,6 +187,60 @@ export const handleOAuthCallback = (url: string): string | null => {
|
|
|
170
187
|
* @returns True if the URL is an OAuth callback
|
|
171
188
|
*/
|
|
172
189
|
export const isOAuthCallback = (url: string): boolean => {
|
|
173
|
-
//
|
|
174
|
-
|
|
190
|
+
// Updated to use correct deep link scheme
|
|
191
|
+
const isCallback = url.startsWith('onairosevents://auth/callback') ||
|
|
192
|
+
url.includes('/callback') ||
|
|
193
|
+
url.includes('code=') ||
|
|
194
|
+
url.includes('onairos.uk/Home');
|
|
195
|
+
|
|
196
|
+
console.log(`Checking if URL is OAuth callback: ${url} -> ${isCallback}`);
|
|
197
|
+
return isCallback;
|
|
198
|
+
};
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* Detects if OAuth flow has completed successfully based on URL patterns
|
|
202
|
+
* @param url The current URL in the WebView
|
|
203
|
+
* @param platform The platform being authenticated
|
|
204
|
+
* @returns True if the OAuth flow has completed successfully
|
|
205
|
+
*/
|
|
206
|
+
export const isOAuthSuccess = (url: string, platform: string): boolean => {
|
|
207
|
+
console.log(`Checking OAuth success for ${platform} with URL: ${url}`);
|
|
208
|
+
|
|
209
|
+
// Check for final redirect to Onairos home page (indicates proxy has processed the callback)
|
|
210
|
+
if (url.includes('onairos.uk/Home')) {
|
|
211
|
+
console.log('Detected final redirect to onairos.uk/Home - OAuth success');
|
|
212
|
+
return true;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
// Platform-specific success patterns
|
|
216
|
+
switch (platform) {
|
|
217
|
+
case 'youtube':
|
|
218
|
+
// YouTube/Google OAuth success patterns
|
|
219
|
+
return url.includes('accounts.google.com/o/oauth2/approval') ||
|
|
220
|
+
url.includes('consent.google.com/ml/save') ||
|
|
221
|
+
url.includes('myaccount.google.com');
|
|
222
|
+
|
|
223
|
+
case 'reddit':
|
|
224
|
+
// Reddit OAuth success patterns
|
|
225
|
+
return url.includes('/api/v1/authorize?done=true') ||
|
|
226
|
+
url.includes('reddit.com/api/v1/authorize/compact');
|
|
227
|
+
|
|
228
|
+
case 'pinterest':
|
|
229
|
+
// Pinterest OAuth success patterns
|
|
230
|
+
return url.includes('/oauth/success') ||
|
|
231
|
+
url.includes('/oauth/complete');
|
|
232
|
+
|
|
233
|
+
case 'instagram':
|
|
234
|
+
// Instagram OAuth success patterns
|
|
235
|
+
return url.includes('/oauth/authorize/?response_type=code') ||
|
|
236
|
+
url.includes('instagram.com/oauth/authorize');
|
|
237
|
+
|
|
238
|
+
case 'email':
|
|
239
|
+
// Email verification success patterns
|
|
240
|
+
return url.includes('/email/verify/success') ||
|
|
241
|
+
url.includes('/email/confirmed');
|
|
242
|
+
|
|
243
|
+
default:
|
|
244
|
+
return false;
|
|
245
|
+
}
|
|
175
246
|
};
|