capacitor-auth-manager 2.4.4 → 3.0.0

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.
Files changed (80) hide show
  1. package/AI-INTEGRATION-GUIDE.md +174 -0
  2. package/CHANGELOG.md +119 -0
  3. package/CapacitorAuthManager.podspec +3 -3
  4. package/README.md +91 -72
  5. package/android/build.gradle +17 -25
  6. package/android/consumer-rules.pro +2 -0
  7. package/android/proguard-rules.pro +5 -30
  8. package/android/src/main/AndroidManifest.xml +4 -9
  9. package/android/src/main/java/com/aoneahsan/capacitor_auth_manager/AuthErrorCodes.java +32 -0
  10. package/android/src/main/java/com/aoneahsan/capacitor_auth_manager/AuthException.java +34 -0
  11. package/android/src/main/java/com/aoneahsan/capacitor_auth_manager/AuthStorage.java +46 -25
  12. package/android/src/main/java/com/aoneahsan/capacitor_auth_manager/CapacitorAuthManager.java +54 -38
  13. package/android/src/main/java/com/aoneahsan/capacitor_auth_manager/CapacitorAuthManagerPlugin.java +77 -54
  14. package/android/src/main/java/com/aoneahsan/capacitor_auth_manager/GoogleAuthProvider.java +171 -41
  15. package/android/src/main/java/com/aoneahsan/capacitor_auth_manager/ProviderFactory.java +5 -0
  16. package/dist/angular.cjs.js +421 -3376
  17. package/dist/core.cjs.js +589 -149
  18. package/dist/esm/angular/auth.guard.d.ts +1 -1
  19. package/dist/esm/angular/auth.module.d.ts +1 -1
  20. package/dist/esm/angular/auth.module.js +1 -1
  21. package/dist/esm/angular/auth.service.d.ts +2 -2
  22. package/dist/esm/angular/auth.service.js +1 -1
  23. package/dist/esm/angular/index.d.ts +4 -4
  24. package/dist/esm/angular/index.js +4 -4
  25. package/dist/esm/capacitor-plugin.d.ts +2 -3
  26. package/dist/esm/capacitor-plugin.js +14 -4
  27. package/dist/esm/core/auth-manager.d.ts +20 -2
  28. package/dist/esm/core/auth-manager.js +68 -12
  29. package/dist/esm/core/index.d.ts +5 -4
  30. package/dist/esm/core/index.js +5 -4
  31. package/dist/esm/core/provider-manifests.d.ts +1 -1
  32. package/dist/esm/core/provider-manifests.js +12 -13
  33. package/dist/esm/core/provider-registry.d.ts +8 -5
  34. package/dist/esm/core/provider-registry.js +41 -10
  35. package/dist/esm/core/types.d.ts +2 -2
  36. package/dist/esm/definitions.d.ts +26 -0
  37. package/dist/esm/index.d.ts +12 -12
  38. package/dist/esm/index.js +7 -7
  39. package/dist/esm/package.json +1 -0
  40. package/dist/esm/providers/base-provider.d.ts +7 -8
  41. package/dist/esm/providers/base-provider.js +7 -8
  42. package/dist/esm/providers/native/google-native-provider.d.ts +13 -2
  43. package/dist/esm/providers/native/google-native-provider.js +50 -6
  44. package/dist/esm/providers/oauth-provider.d.ts +2 -2
  45. package/dist/esm/providers/oauth-provider.js +3 -3
  46. package/dist/esm/providers/provider-factory.d.ts +5 -5
  47. package/dist/esm/providers/provider-factory.js +2 -2
  48. package/dist/esm/providers/web/google-provider.d.ts +74 -18
  49. package/dist/esm/providers/web/google-provider.js +391 -117
  50. package/dist/esm/providers/web/index.d.ts +1 -1
  51. package/dist/esm/providers/web/index.js +1 -1
  52. package/dist/esm/react/hooks.d.ts +2 -2
  53. package/dist/esm/react/hooks.js +2 -2
  54. package/dist/esm/react/index.d.ts +3 -3
  55. package/dist/esm/react/index.js +3 -3
  56. package/dist/esm/react/types.d.ts +1 -1
  57. package/dist/esm/utils/auth-error.d.ts +1 -1
  58. package/dist/esm/utils/auth-error.js +1 -1
  59. package/dist/esm/utils/event-emitter.d.ts +1 -1
  60. package/dist/esm/utils/event-emitter.js +1 -1
  61. package/dist/esm/utils/pending-verification-store.js +1 -1
  62. package/dist/esm/utils/storage.d.ts +2 -2
  63. package/dist/esm/utils/storage.js +31 -7
  64. package/dist/esm/vue/composables.d.ts +2 -2
  65. package/dist/esm/vue/composables.js +1 -1
  66. package/dist/esm/vue/index.d.ts +2 -2
  67. package/dist/esm/vue/index.js +2 -2
  68. package/dist/esm/web.d.ts +1 -1
  69. package/dist/esm/web.js +6 -6
  70. package/dist/plugin.cjs.js +291 -2771
  71. package/dist/plugin.js +585 -147
  72. package/dist/providers-web.cjs.js +1317 -0
  73. package/dist/react.cjs.js +310 -3265
  74. package/dist/vue.cjs.js +266 -3221
  75. package/ios/Plugin/AuthStorage.swift +3 -1
  76. package/ios/Plugin/GoogleAuthProvider.swift +7 -4
  77. package/ios/Plugin/Models.swift +28 -0
  78. package/ios/Plugin/Plugin.swift +64 -40
  79. package/package.json +55 -33
  80. package/scripts/configure.js +71 -325
@@ -1,339 +1,85 @@
1
1
  #!/usr/bin/env node
2
+ 'use strict';
3
+ const fs = require('node:fs');
4
+ const path = require('node:path');
5
+ const readline = require('node:readline/promises');
2
6
 
3
- const fs = require('fs');
4
- const path = require('path');
5
- const { execSync } = require('child_process');
6
- const readline = require('readline');
7
-
8
- const rl = readline.createInterface({
9
- input: process.stdin,
10
- output: process.stdout,
11
- });
12
-
13
- const question = (query) =>
14
- new Promise((resolve) => rl.question(query, resolve));
15
-
16
- async function configure() {
17
- console.log('\nšŸ” Capacitor Auth Manager Configuration\n');
18
-
19
- // Detect platform
20
- const platform = await selectPlatform();
21
-
22
- // Select providers
23
- const providers = await selectProviders();
24
-
25
- // Configure each provider
26
- const configs = {};
27
- for (const provider of providers) {
28
- console.log(`\nšŸ“‹ Configuring ${provider}...`);
29
- configs[provider] = await configureProvider(provider);
30
- }
31
-
32
- // Generate configuration files
33
- await generateConfigs(platform, configs);
34
-
35
- // Update native projects
36
- if (platform.includes('ios')) {
37
- await configureIOS(configs);
38
- }
39
-
40
- if (platform.includes('android')) {
41
- await configureAndroid(configs);
42
- }
43
-
44
- console.log('\nāœ… Configuration complete!\n');
45
- console.log('Next steps:');
46
- console.log('1. Review the generated configuration files');
47
- console.log('2. Add your provider-specific credentials');
48
- console.log('3. Run `npx cap sync` to update your native projects');
7
+ const args = process.argv.slice(2);
8
+ if (args.includes('--help') || args.includes('-h')) {
49
9
  console.log(
50
- '4. Follow the platform-specific setup instructions in the README\n'
10
+ 'Usage: capacitor-auth-configure [--dry-run]\nInteractive Google-only configuration helper. Creates capacitor-auth.config.json and src/auth-init.ts only when neither exists. Prints native setup instructions; never rewrites native projects. --dry-run prints without writing. Use AI-INTEGRATION-GUIDE.md for automated integration.'
51
11
  );
52
-
53
- rl.close();
54
- }
55
-
56
- async function selectPlatform() {
57
- console.log('Which platforms are you targeting?');
58
- console.log('1. iOS, Android, and Web');
59
- console.log('2. iOS and Web');
60
- console.log('3. Android and Web');
61
- console.log('4. Web only');
62
-
63
- const choice = await question('\nSelect platform (1-4): ');
64
-
65
- switch (choice) {
66
- case '1':
67
- return ['ios', 'android', 'web'];
68
- case '2':
69
- return ['ios', 'web'];
70
- case '3':
71
- return ['android', 'web'];
72
- case '4':
73
- return ['web'];
74
- default:
75
- console.log('Invalid choice, defaulting to all platforms');
76
- return ['ios', 'android', 'web'];
77
- }
78
- }
79
-
80
- async function selectProviders() {
81
- const allProviders = [
82
- 'google',
83
- 'apple',
84
- 'microsoft',
85
- 'facebook',
86
- 'github',
87
- 'slack',
88
- 'linkedin',
89
- 'firebase',
90
- 'email_magic_link',
91
- 'sms',
92
- 'email_password',
93
- 'phone_password',
94
- 'username_password',
95
- 'email_code',
96
- 'biometric',
97
- ];
98
-
99
- console.log('\nAvailable authentication providers:');
100
- allProviders.forEach((p, i) => console.log(`${i + 1}. ${p}`));
101
-
102
- const input = await question(
103
- '\nSelect providers (comma-separated numbers, or "all"): '
12
+ } else if (args.some((arg) => arg !== '--dry-run')) {
13
+ console.error('Unknown option. Run with --help.');
14
+ process.exitCode = 1;
15
+ } else if (!process.stdin.isTTY) {
16
+ console.error(
17
+ 'This helper needs an interactive terminal. Read AI-INTEGRATION-GUIDE.md for non-interactive setup.'
104
18
  );
105
-
106
- if (input.toLowerCase() === 'all') {
107
- return allProviders;
108
- }
109
-
110
- const indices = input.split(',').map((n) => parseInt(n.trim()) - 1);
111
- return indices
112
- .filter((i) => i >= 0 && i < allProviders.length)
113
- .map((i) => allProviders[i]);
19
+ process.exitCode = 1;
20
+ } else {
21
+ configure().catch((error) => {
22
+ console.error(error.message);
23
+ process.exitCode = 1;
24
+ });
114
25
  }
115
26
 
116
- async function configureProvider(provider) {
117
- const config = {};
118
-
119
- switch (provider) {
120
- case 'google':
121
- config.clientId = await question('Google Client ID (Web): ');
122
- config.serverClientId = await question(
123
- 'Google Server Client ID (Android): '
27
+ async function configure() {
28
+ const configPath = path.resolve('capacitor-auth.config.json');
29
+ const initPath = path.resolve('src/auth-init.ts');
30
+ const dryRun = args.includes('--dry-run');
31
+ if (!dryRun && [configPath, initPath].some((p) => fs.existsSync(p))) {
32
+ throw new Error(
33
+ 'Configuration already exists. Merge the documented Google options into your existing app; this helper never overwrites files.'
34
+ );
35
+ }
36
+ const rl = readline.createInterface({
37
+ input: process.stdin,
38
+ output: process.stdout,
39
+ });
40
+ try {
41
+ const clientId = (
42
+ await rl.question('Web OAuth client ID (also Android serverClientId): ')
43
+ ).trim();
44
+ const iosClientId = (
45
+ await rl.question('iOS OAuth client ID (leave blank for web/Android): ')
46
+ ).trim();
47
+ const valid = (value) =>
48
+ /^[a-zA-Z0-9-]+\.apps\.googleusercontent\.com$/.test(value);
49
+ if (!valid(clientId) || (iosClientId && !valid(iosClientId)))
50
+ throw new Error(
51
+ 'Use valid Google OAuth client IDs, never a client secret.'
124
52
  );
125
- config.iosClientId = await question('Google iOS Client ID: ');
126
- break;
127
-
128
- case 'apple':
129
- config.clientId = await question('Apple Service ID: ');
130
- config.redirectUri = await question('Apple Redirect URI: ');
131
- break;
132
-
133
- case 'microsoft':
134
- config.clientId = await question('Microsoft Azure Client ID: ');
135
- config.tenantId = await question('Microsoft Tenant ID (or "common"): ');
136
- config.redirectUri = await question('Microsoft Redirect URI: ');
137
- break;
138
-
139
- case 'facebook':
140
- config.appId = await question('Facebook App ID: ');
141
- config.appName = await question('Facebook App Name: ');
142
- break;
143
-
144
- case 'firebase':
145
- config.apiKey = await question('Firebase API Key: ');
146
- config.authDomain = await question('Firebase Auth Domain: ');
147
- config.projectId = await question('Firebase Project ID: ');
148
- config.appId = await question('Firebase App ID: ');
149
- break;
150
-
151
- case 'sms':
152
- const smsProvider = await question(
153
- 'SMS Provider (twilio/firebase/custom): '
53
+ const config = {
54
+ providers: {
55
+ google: {
56
+ clientId,
57
+ serverClientId: clientId,
58
+ ...(iosClientId ? { iosClientId } : {}),
59
+ },
60
+ },
61
+ };
62
+ const init =
63
+ "import { auth, AuthProvider } from 'capacitor-auth-manager';\nimport config from '../capacitor-auth.config.json';\n\nexport async function initializeAuth() {\n auth.configure({ providers: { google: { ...config.providers.google, webFlow: 'popup' } }, persistence: 'memory' });\n await auth.prepare(AuthProvider.GOOGLE);\n}\n";
64
+ console.log(JSON.stringify(config, null, 2));
65
+ if (!dryRun) {
66
+ fs.mkdirSync(path.dirname(initPath), { recursive: true });
67
+ fs.writeFileSync(configPath, JSON.stringify(config, null, 2) + '\n', {
68
+ flag: 'wx',
69
+ });
70
+ fs.writeFileSync(initPath, init, { flag: 'wx' });
71
+ console.log(
72
+ 'Created capacitor-auth.config.json and src/auth-init.ts. Enable JSON imports in your app toolchain.'
154
73
  );
155
- config.provider = smsProvider;
156
- if (smsProvider === 'twilio') {
157
- config.accountSid = await question('Twilio Account SID: ');
158
- config.authToken = await question('Twilio Auth Token: ');
159
- config.fromNumber = await question('Twilio From Number: ');
160
- }
161
- break;
162
- }
163
-
164
- return config;
165
- }
166
-
167
- async function generateConfigs(platforms, configs) {
168
- // Create auth config file
169
- const authConfig = {
170
- providers: Object.entries(configs).map(([provider, config]) => ({
171
- provider,
172
- options: config,
173
- })),
174
- persistence: 'local',
175
- autoRefreshToken: true,
176
- enableLogging: process.env.NODE_ENV !== 'production',
177
- };
178
-
179
- const configPath = path.join(process.cwd(), 'capacitor-auth.config.json');
180
- fs.writeFileSync(configPath, JSON.stringify(authConfig, null, 2));
181
- console.log(`\nšŸ“„ Created ${configPath}`);
182
-
183
- // Create example initialization file
184
- const exampleCode = `import { CapacitorAuthManager } from 'capacitor-auth-manager';
185
- import authConfig from './capacitor-auth.config.json';
186
-
187
- export async function initializeAuth() {
188
- await CapacitorAuthManager.initialize(authConfig);
189
-
190
- // Add auth state listener
191
- await CapacitorAuthManager.addAuthStateListener((user) => {
192
- if (user) {
193
- console.log('User signed in:', user.email);
194
- } else {
195
- console.log('User signed out');
196
74
  }
197
- });
198
- }
199
-
200
- // Call this in your app initialization
201
- initializeAuth();
202
- `;
203
-
204
- const examplePath = path.join(process.cwd(), 'src', 'auth-init.ts');
205
- if (!fs.existsSync(path.dirname(examplePath))) {
206
- fs.mkdirSync(path.dirname(examplePath), { recursive: true });
207
- }
208
- fs.writeFileSync(examplePath, exampleCode);
209
- console.log(`šŸ“„ Created ${examplePath}`);
210
- }
211
-
212
- async function configureIOS(configs) {
213
- console.log('\nšŸ“± Configuring iOS...');
214
-
215
- const infoPlistPath = path.join(
216
- process.cwd(),
217
- 'ios',
218
- 'App',
219
- 'App',
220
- 'Info.plist'
221
- );
222
- if (!fs.existsSync(infoPlistPath)) {
223
- console.log('āš ļø iOS Info.plist not found. Please configure manually.');
224
- return;
225
- }
226
-
227
- let plistAdditions = '\n<!-- Capacitor Auth Manager Configuration -->\n';
228
-
229
- // Google Sign-In
230
- if (configs.google) {
231
- const reversedClientId = configs.google.iosClientId
232
- .split('.')
233
- .reverse()
234
- .join('.');
235
- plistAdditions += `
236
- <key>CFBundleURLTypes</key>
237
- <array>
238
- <dict>
239
- <key>CFBundleURLSchemes</key>
240
- <array>
241
- <string>${reversedClientId}</string>
242
- </array>
243
- </dict>
244
- </array>
245
- `;
246
- }
247
-
248
- // Facebook
249
- if (configs.facebook) {
250
- plistAdditions += `
251
- <key>FacebookAppID</key>
252
- <string>${configs.facebook.appId}</string>
253
- <key>FacebookClientToken</key>
254
- <string>CLIENT_TOKEN_HERE</string>
255
- <key>FacebookDisplayName</key>
256
- <string>${configs.facebook.appName}</string>
257
- <key>LSApplicationQueriesSchemes</key>
258
- <array>
259
- <string>fbapi</string>
260
- <string>fb-messenger-share-api</string>
261
- <string>fbauth2</string>
262
- <string>fbshareextension</string>
263
- </array>
264
- `;
265
- }
266
-
267
- console.log('\nAdd the following to your Info.plist:');
268
- console.log(plistAdditions);
269
- }
270
-
271
- async function configureAndroid(configs) {
272
- console.log('\nšŸ¤– Configuring Android...');
273
-
274
- const stringsPath = path.join(
275
- process.cwd(),
276
- 'android',
277
- 'app',
278
- 'src',
279
- 'main',
280
- 'res',
281
- 'values',
282
- 'strings.xml'
283
- );
284
- if (!fs.existsSync(stringsPath)) {
75
+ if (iosClientId)
76
+ console.log(
77
+ `iOS Info.plist: GIDClientID = ${iosClientId}; CFBundleURLTypes URL scheme = ${iosClientId.split('.').reverse().join('.')}. Merge into existing URL types. Use CocoaPods and iOS 15+.`
78
+ );
285
79
  console.log(
286
- 'āš ļø Android strings.xml not found. Please configure manually.'
80
+ 'Register Android application ID and debug/release/Play signing fingerprints; register web origins. Run yarn cap sync after native setup. Initialize Firebase separately and follow AI-INTEGRATION-GUIDE.md for the credential handoff.'
287
81
  );
288
- return;
82
+ } finally {
83
+ rl.close();
289
84
  }
290
-
291
- let stringsAdditions =
292
- '\n <!-- Capacitor Auth Manager Configuration -->\n';
293
-
294
- // Google Sign-In
295
- if (configs.google && configs.google.serverClientId) {
296
- stringsAdditions += ` <string name="default_web_client_id">${configs.google.serverClientId}</string>\n`;
297
- }
298
-
299
- // Facebook
300
- if (configs.facebook) {
301
- stringsAdditions += ` <string name="facebook_app_id">${configs.facebook.appId}</string>\n`;
302
- stringsAdditions += ` <string name="facebook_client_token">CLIENT_TOKEN_HERE</string>\n`;
303
- }
304
-
305
- console.log('\nAdd the following to your strings.xml:');
306
- console.log(stringsAdditions);
307
-
308
- // Manifest additions
309
- const manifestAdditions = `
310
- <!-- Add to AndroidManifest.xml -->
311
- ${
312
- configs.google
313
- ? `
314
- <meta-data
315
- android:name="com.google.android.gms.auth.api.signin.GoogleSignInOptions"
316
- android:value="@string/default_web_client_id" />
317
- `
318
- : ''
319
85
  }
320
- ${
321
- configs.facebook
322
- ? `
323
- <meta-data
324
- android:name="com.facebook.sdk.ApplicationId"
325
- android:value="@string/facebook_app_id"/>
326
- <meta-data
327
- android:name="com.facebook.sdk.ClientToken"
328
- android:value="@string/facebook_client_token"/>
329
- `
330
- : ''
331
- }
332
- `;
333
-
334
- console.log('\nAdd the following to your AndroidManifest.xml:');
335
- console.log(manifestAdditions);
336
- }
337
-
338
- // Run configuration
339
- configure().catch(console.error);