@onairos/react-native 3.0.26 → 3.0.28
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 +98 -186
- 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 -99
- 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 +99 -187
- 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/services/platformAuthService.js +80 -97
- 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 +86 -179
- package/src/components/onboarding/OAuthWebView.tsx +59 -121
- package/src/constants/index.ts +3 -3
- package/src/services/platformAuthService.ts +80 -115
package/src/constants/index.ts
CHANGED
|
@@ -77,7 +77,7 @@ export const PIN_REQUIREMENTS = {
|
|
|
77
77
|
};
|
|
78
78
|
|
|
79
79
|
export const DEEP_LINK_CONFIG = {
|
|
80
|
-
scheme: '
|
|
81
|
-
host: '
|
|
82
|
-
redirectUri: '
|
|
80
|
+
scheme: 'onairosanime',
|
|
81
|
+
host: 'authenticate',
|
|
82
|
+
redirectUri: 'onairosanime://auth/',
|
|
83
83
|
};
|
|
@@ -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,79 +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
|
-
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
|
-
|
|
111
131
|
// Parse the response
|
|
112
132
|
const data = await response.json();
|
|
113
|
-
console.log(`OAuth response for ${platform}:`, data);
|
|
114
|
-
|
|
115
|
-
// Check for platform-specific response keys according to schema
|
|
116
|
-
let oauthUrl: string | null = null;
|
|
117
133
|
|
|
118
|
-
if
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
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;
|
|
135
151
|
}
|
|
136
152
|
|
|
137
|
-
|
|
138
|
-
return oauthUrl;
|
|
153
|
+
throw new Error(`No OAuth URL found in response for ${platform}`);
|
|
139
154
|
} catch (error) {
|
|
140
155
|
console.error(`Error initiating OAuth for ${platform}:`, error);
|
|
141
156
|
throw error;
|
|
@@ -149,9 +164,18 @@ export const initiateOAuth = async (platform: string, userEmail: string): Promis
|
|
|
149
164
|
*/
|
|
150
165
|
export const initiateNativeAuth = async (platform: string): Promise<boolean> => {
|
|
151
166
|
try {
|
|
152
|
-
// Currently
|
|
153
|
-
|
|
154
|
-
|
|
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}`);
|
|
155
179
|
} catch (error) {
|
|
156
180
|
console.error(`Error initiating native auth for ${platform}:`, error);
|
|
157
181
|
throw error;
|
|
@@ -165,16 +189,11 @@ export const initiateNativeAuth = async (platform: string): Promise<boolean> =>
|
|
|
165
189
|
*/
|
|
166
190
|
export const handleOAuthCallback = (url: string): string | null => {
|
|
167
191
|
try {
|
|
168
|
-
console.log('Handling OAuth callback URL:', url);
|
|
169
|
-
|
|
170
192
|
// Parse the URL
|
|
171
193
|
const parsedUrl = new URL(url);
|
|
172
194
|
|
|
173
195
|
// Extract the authorization code
|
|
174
|
-
|
|
175
|
-
console.log('Extracted authorization code:', code);
|
|
176
|
-
|
|
177
|
-
return code;
|
|
196
|
+
return parsedUrl.searchParams.get('code');
|
|
178
197
|
} catch (error) {
|
|
179
198
|
console.error('Error handling OAuth callback:', error);
|
|
180
199
|
return null;
|
|
@@ -187,60 +206,6 @@ export const handleOAuthCallback = (url: string): string | null => {
|
|
|
187
206
|
* @returns True if the URL is an OAuth callback
|
|
188
207
|
*/
|
|
189
208
|
export const isOAuthCallback = (url: string): boolean => {
|
|
190
|
-
//
|
|
191
|
-
|
|
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
|
-
}
|
|
209
|
+
// Check if the URL starts with our redirect URI
|
|
210
|
+
return url.startsWith('onairosanime://auth/');
|
|
246
211
|
};
|