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