@onairos/react-native 3.0.22 → 3.0.25
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 +242 -39
- 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 -2
- package/lib/commonjs/constants/index.js.map +1 -1
- package/lib/commonjs/services/platformAuthService.js +227 -0
- package/lib/commonjs/services/platformAuthService.js.map +1 -0
- 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 +243 -40
- 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 -2
- package/lib/module/constants/index.js.map +1 -1
- package/lib/module/services/platformAuthService.js +213 -0
- package/lib/module/services/platformAuthService.js.map +1 -0
- 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/constants/index.d.ts +1 -0
- package/lib/typescript/constants/index.d.ts.map +1 -1
- package/lib/typescript/services/platformAuthService.d.ts +45 -0
- package/lib/typescript/services/platformAuthService.d.ts.map +1 -0
- package/package.json +2 -1
- package/src/components/OnairosButton.tsx +1 -4
- package/src/components/TrainingModal.tsx +202 -61
- package/src/components/UniversalOnboarding.tsx +232 -35
- package/src/components/onboarding/OAuthWebView.tsx +135 -25
- package/src/constants/index.ts +3 -2
- package/src/services/platformAuthService.ts +241 -0
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
import { Platform, Linking } from 'react-native';
|
|
2
|
+
import { DEEP_LINK_CONFIG } from '../constants';
|
|
3
|
+
|
|
4
|
+
// Define types for platform auth configuration
|
|
5
|
+
interface PlatformAuthConfig {
|
|
6
|
+
hasNativeSDK: boolean;
|
|
7
|
+
nativeSDKPackage?: string;
|
|
8
|
+
authEndpoint: string;
|
|
9
|
+
color: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
// Configuration for each platform's authentication
|
|
13
|
+
const PLATFORM_AUTH_CONFIG: Record<string, PlatformAuthConfig> = {
|
|
14
|
+
instagram: {
|
|
15
|
+
hasNativeSDK: false, // Instagram doesn't have a public OAuth SDK for React Native
|
|
16
|
+
authEndpoint: 'https://api2.onairos.uk/instagram/authorize',
|
|
17
|
+
color: '#E1306C',
|
|
18
|
+
},
|
|
19
|
+
youtube: {
|
|
20
|
+
hasNativeSDK: false, // Changed to false to use OAuth flow through proxy
|
|
21
|
+
authEndpoint: 'https://api2.onairos.uk/youtube/authorize',
|
|
22
|
+
color: '#FF0000',
|
|
23
|
+
},
|
|
24
|
+
reddit: {
|
|
25
|
+
hasNativeSDK: false,
|
|
26
|
+
authEndpoint: 'https://api2.onairos.uk/reddit/authorize',
|
|
27
|
+
color: '#FF4500',
|
|
28
|
+
},
|
|
29
|
+
pinterest: {
|
|
30
|
+
hasNativeSDK: false,
|
|
31
|
+
authEndpoint: 'https://api2.onairos.uk/pinterest/authorize',
|
|
32
|
+
color: '#E60023',
|
|
33
|
+
},
|
|
34
|
+
email: {
|
|
35
|
+
hasNativeSDK: false,
|
|
36
|
+
authEndpoint: 'https://api2.onairos.uk/email/authorize',
|
|
37
|
+
color: '#4285F4',
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Checks if a native SDK is available for the given platform
|
|
43
|
+
*/
|
|
44
|
+
export const hasNativeSDK = (platform: string): boolean => {
|
|
45
|
+
const config = PLATFORM_AUTH_CONFIG[platform];
|
|
46
|
+
return config?.hasNativeSDK || false;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Gets the auth endpoint URL for a platform
|
|
51
|
+
*/
|
|
52
|
+
export const getAuthEndpoint = (platform: string): string => {
|
|
53
|
+
const config = PLATFORM_AUTH_CONFIG[platform];
|
|
54
|
+
return config?.authEndpoint || '';
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Gets the color associated with a platform
|
|
59
|
+
*/
|
|
60
|
+
export const getPlatformColor = (platform: string): string => {
|
|
61
|
+
const config = PLATFORM_AUTH_CONFIG[platform];
|
|
62
|
+
return config?.color || '#000000';
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Initiates the OAuth flow for a platform using Onairos proxy
|
|
67
|
+
* @param platform The platform to authenticate with
|
|
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
|
|
70
|
+
*/
|
|
71
|
+
export const initiateOAuth = async (platform: string, userEmail: string): Promise<string | null> => {
|
|
72
|
+
try {
|
|
73
|
+
// Check if the platform is supported
|
|
74
|
+
if (!PLATFORM_AUTH_CONFIG[platform]) {
|
|
75
|
+
throw new Error(`Unsupported platform: ${platform}`);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
console.log(`Initiating OAuth for ${platform} with user: ${userEmail}`);
|
|
79
|
+
|
|
80
|
+
// Prepare the request body according to Onairos proxy schema
|
|
81
|
+
const requestBody = {
|
|
82
|
+
session: {
|
|
83
|
+
username: userEmail || 'anonymous@example.com',
|
|
84
|
+
platform: platform,
|
|
85
|
+
timestamp: new Date().toISOString(),
|
|
86
|
+
},
|
|
87
|
+
};
|
|
88
|
+
|
|
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
|
+
const response = await fetch(PLATFORM_AUTH_CONFIG[platform].authEndpoint, {
|
|
94
|
+
method: 'POST',
|
|
95
|
+
headers: {
|
|
96
|
+
'Content-Type': 'application/json',
|
|
97
|
+
'Accept': 'application/json',
|
|
98
|
+
},
|
|
99
|
+
body: JSON.stringify(requestBody),
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
if (!response.ok) {
|
|
103
|
+
throw new Error(`HTTP error! status: ${response.status}`);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// Parse the response
|
|
107
|
+
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
|
+
|
|
113
|
+
if (platform === 'youtube' && data.youtubeURL) {
|
|
114
|
+
oauthUrl = data.youtubeURL;
|
|
115
|
+
} else if (platform === 'reddit' && data.redditURL) {
|
|
116
|
+
oauthUrl = data.redditURL;
|
|
117
|
+
} else if (platform === 'pinterest' && data.pinterestURL) {
|
|
118
|
+
oauthUrl = data.pinterestURL;
|
|
119
|
+
} else if (platform === 'email' && data.emailURL) {
|
|
120
|
+
oauthUrl = data.emailURL;
|
|
121
|
+
} else if (platform === 'instagram' && data.instagramURL) {
|
|
122
|
+
oauthUrl = data.instagramURL;
|
|
123
|
+
} else if (data.url) {
|
|
124
|
+
// Generic fallback
|
|
125
|
+
oauthUrl = data.url;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
if (!oauthUrl) {
|
|
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;
|
|
134
|
+
} catch (error) {
|
|
135
|
+
console.error(`Error initiating OAuth for ${platform}:`, error);
|
|
136
|
+
throw error;
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Initiates the native SDK authentication flow for a platform
|
|
142
|
+
* @param platform The platform to authenticate with
|
|
143
|
+
* @returns A Promise that resolves to the authentication result
|
|
144
|
+
*/
|
|
145
|
+
export const initiateNativeAuth = async (platform: string): Promise<boolean> => {
|
|
146
|
+
try {
|
|
147
|
+
// Currently no platforms use native SDK - all go through Onairos proxy
|
|
148
|
+
console.log(`Native authentication not available for ${platform}, use OAuth flow instead`);
|
|
149
|
+
return false;
|
|
150
|
+
} catch (error) {
|
|
151
|
+
console.error(`Error initiating native auth for ${platform}:`, error);
|
|
152
|
+
throw error;
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Handles the OAuth callback
|
|
158
|
+
* @param url The callback URL
|
|
159
|
+
* @returns The authorization code extracted from the URL
|
|
160
|
+
*/
|
|
161
|
+
export const handleOAuthCallback = (url: string): string | null => {
|
|
162
|
+
try {
|
|
163
|
+
console.log('Handling OAuth callback URL:', url);
|
|
164
|
+
|
|
165
|
+
// Parse the URL
|
|
166
|
+
const parsedUrl = new URL(url);
|
|
167
|
+
|
|
168
|
+
// Extract the authorization code
|
|
169
|
+
const code = parsedUrl.searchParams.get('code');
|
|
170
|
+
console.log('Extracted authorization code:', code);
|
|
171
|
+
|
|
172
|
+
return code;
|
|
173
|
+
} catch (error) {
|
|
174
|
+
console.error('Error handling OAuth callback:', error);
|
|
175
|
+
return null;
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Checks if a URL is an OAuth callback
|
|
181
|
+
* @param url The URL to check
|
|
182
|
+
* @returns True if the URL is an OAuth callback
|
|
183
|
+
*/
|
|
184
|
+
export const isOAuthCallback = (url: string): boolean => {
|
|
185
|
+
// Updated to use correct deep link scheme
|
|
186
|
+
const isCallback = url.startsWith('onairosevents://auth/callback') ||
|
|
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
|
+
}
|
|
241
|
+
};
|