capacitor-auth-manager 0.0.1 ā 0.0.2
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/CapacitorAuthManager.podspec +36 -0
- package/Readme.md +542 -20
- package/android/build.gradle +79 -0
- package/android/gradle.properties +25 -0
- package/android/proguard-rules.pro +38 -0
- package/android/settings.gradle +2 -0
- package/android/src/main/AndroidManifest.xml +11 -0
- package/android/src/main/java/com/zaions/cap_auth_manager/AuthLogger.java +117 -0
- package/android/src/main/java/com/zaions/cap_auth_manager/AuthStorage.java +124 -0
- package/android/src/main/java/com/zaions/cap_auth_manager/BaseAuthProvider.java +16 -0
- package/android/src/main/java/com/zaions/cap_auth_manager/CapacitorAuthManager.java +385 -0
- package/android/src/main/java/com/zaions/cap_auth_manager/CapacitorAuthManagerPlugin.java +469 -0
- package/dist/esm/definitions.d.ts +521 -0
- package/dist/esm/definitions.js +103 -1
- package/dist/esm/definitions.js.map +1 -1
- package/dist/esm/index.d.ts +4 -0
- package/dist/esm/index.js +6 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/providers/base-provider.d.ts +43 -0
- package/dist/esm/providers/base-provider.js +112 -0
- package/dist/esm/providers/base-provider.js.map +1 -0
- package/dist/esm/providers/oauth-provider.d.ts +30 -0
- package/dist/esm/providers/oauth-provider.js +255 -0
- package/dist/esm/providers/oauth-provider.js.map +1 -0
- package/dist/esm/providers/provider-factory.d.ts +7 -0
- package/dist/esm/providers/provider-factory.js +76 -0
- package/dist/esm/providers/provider-factory.js.map +1 -0
- package/dist/esm/providers/web/apple-provider.d.ts +33 -0
- package/dist/esm/providers/web/apple-provider.js +270 -0
- package/dist/esm/providers/web/apple-provider.js.map +1 -0
- package/dist/esm/providers/web/google-provider.d.ts +27 -0
- package/dist/esm/providers/web/google-provider.js +258 -0
- package/dist/esm/providers/web/google-provider.js.map +1 -0
- package/dist/esm/utils/auth-error.d.ts +16 -0
- package/dist/esm/utils/auth-error.js +53 -0
- package/dist/esm/utils/auth-error.js.map +1 -0
- package/dist/esm/utils/event-emitter.d.ts +9 -0
- package/dist/esm/utils/event-emitter.js +28 -0
- package/dist/esm/utils/event-emitter.js.map +1 -0
- package/dist/esm/utils/logger.d.ts +19 -0
- package/dist/esm/utils/logger.js +48 -0
- package/dist/esm/utils/logger.js.map +1 -0
- package/dist/esm/utils/storage.d.ts +16 -0
- package/dist/esm/utils/storage.js +86 -0
- package/dist/esm/utils/storage.js.map +1 -0
- package/dist/esm/web.d.ts +43 -0
- package/dist/esm/web.js +374 -1
- package/dist/esm/web.js.map +1 -1
- package/dist/plugin.cjs.js +1650 -0
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +1652 -3
- package/dist/plugin.js.map +1 -1
- package/ios/Plugin/AuthLogger.swift +71 -0
- package/ios/Plugin/AuthStorage.swift +139 -0
- package/ios/Plugin/BaseAuthProvider.swift +33 -0
- package/ios/Plugin/CapacitorAuthManager.swift +406 -0
- package/ios/Plugin/Models.swift +376 -0
- package/ios/Plugin/Plugin.m +27 -0
- package/ios/Plugin/Plugin.swift +413 -0
- package/package.json +6 -2
- package/scripts/configure.js +295 -0
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
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) => new Promise((resolve) => rl.question(query, resolve));
|
|
14
|
+
|
|
15
|
+
async function configure() {
|
|
16
|
+
console.log('\nš Capacitor Auth Manager Configuration\n');
|
|
17
|
+
|
|
18
|
+
// Detect platform
|
|
19
|
+
const platform = await selectPlatform();
|
|
20
|
+
|
|
21
|
+
// Select providers
|
|
22
|
+
const providers = await selectProviders();
|
|
23
|
+
|
|
24
|
+
// Configure each provider
|
|
25
|
+
const configs = {};
|
|
26
|
+
for (const provider of providers) {
|
|
27
|
+
console.log(`\nš Configuring ${provider}...`);
|
|
28
|
+
configs[provider] = await configureProvider(provider);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// Generate configuration files
|
|
32
|
+
await generateConfigs(platform, configs);
|
|
33
|
+
|
|
34
|
+
// Update native projects
|
|
35
|
+
if (platform.includes('ios')) {
|
|
36
|
+
await configureIOS(configs);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (platform.includes('android')) {
|
|
40
|
+
await configureAndroid(configs);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
console.log('\nā
Configuration complete!\n');
|
|
44
|
+
console.log('Next steps:');
|
|
45
|
+
console.log('1. Review the generated configuration files');
|
|
46
|
+
console.log('2. Add your provider-specific credentials');
|
|
47
|
+
console.log('3. Run `npx cap sync` to update your native projects');
|
|
48
|
+
console.log('4. Follow the platform-specific setup instructions in the README\n');
|
|
49
|
+
|
|
50
|
+
rl.close();
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
async function selectPlatform() {
|
|
54
|
+
console.log('Which platforms are you targeting?');
|
|
55
|
+
console.log('1. iOS, Android, and Web');
|
|
56
|
+
console.log('2. iOS and Web');
|
|
57
|
+
console.log('3. Android and Web');
|
|
58
|
+
console.log('4. Web only');
|
|
59
|
+
|
|
60
|
+
const choice = await question('\nSelect platform (1-4): ');
|
|
61
|
+
|
|
62
|
+
switch (choice) {
|
|
63
|
+
case '1': return ['ios', 'android', 'web'];
|
|
64
|
+
case '2': return ['ios', 'web'];
|
|
65
|
+
case '3': return ['android', 'web'];
|
|
66
|
+
case '4': return ['web'];
|
|
67
|
+
default:
|
|
68
|
+
console.log('Invalid choice, defaulting to all platforms');
|
|
69
|
+
return ['ios', 'android', 'web'];
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
async function selectProviders() {
|
|
74
|
+
const allProviders = [
|
|
75
|
+
'google',
|
|
76
|
+
'apple',
|
|
77
|
+
'microsoft',
|
|
78
|
+
'facebook',
|
|
79
|
+
'github',
|
|
80
|
+
'slack',
|
|
81
|
+
'linkedin',
|
|
82
|
+
'firebase',
|
|
83
|
+
'email_magic_link',
|
|
84
|
+
'sms',
|
|
85
|
+
'email_password',
|
|
86
|
+
'phone_password',
|
|
87
|
+
'username_password',
|
|
88
|
+
'email_code',
|
|
89
|
+
'biometric'
|
|
90
|
+
];
|
|
91
|
+
|
|
92
|
+
console.log('\nAvailable authentication providers:');
|
|
93
|
+
allProviders.forEach((p, i) => console.log(`${i + 1}. ${p}`));
|
|
94
|
+
|
|
95
|
+
const input = await question('\nSelect providers (comma-separated numbers, or "all"): ');
|
|
96
|
+
|
|
97
|
+
if (input.toLowerCase() === 'all') {
|
|
98
|
+
return allProviders;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const indices = input.split(',').map(n => parseInt(n.trim()) - 1);
|
|
102
|
+
return indices.filter(i => i >= 0 && i < allProviders.length).map(i => allProviders[i]);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
async function configureProvider(provider) {
|
|
106
|
+
const config = {};
|
|
107
|
+
|
|
108
|
+
switch (provider) {
|
|
109
|
+
case 'google':
|
|
110
|
+
config.clientId = await question('Google Client ID (Web): ');
|
|
111
|
+
config.serverClientId = await question('Google Server Client ID (Android): ');
|
|
112
|
+
config.iosClientId = await question('Google iOS Client ID: ');
|
|
113
|
+
break;
|
|
114
|
+
|
|
115
|
+
case 'apple':
|
|
116
|
+
config.clientId = await question('Apple Service ID: ');
|
|
117
|
+
config.redirectUri = await question('Apple Redirect URI: ');
|
|
118
|
+
break;
|
|
119
|
+
|
|
120
|
+
case 'microsoft':
|
|
121
|
+
config.clientId = await question('Microsoft Azure Client ID: ');
|
|
122
|
+
config.tenantId = await question('Microsoft Tenant ID (or "common"): ');
|
|
123
|
+
config.redirectUri = await question('Microsoft Redirect URI: ');
|
|
124
|
+
break;
|
|
125
|
+
|
|
126
|
+
case 'facebook':
|
|
127
|
+
config.appId = await question('Facebook App ID: ');
|
|
128
|
+
config.appName = await question('Facebook App Name: ');
|
|
129
|
+
break;
|
|
130
|
+
|
|
131
|
+
case 'firebase':
|
|
132
|
+
config.apiKey = await question('Firebase API Key: ');
|
|
133
|
+
config.authDomain = await question('Firebase Auth Domain: ');
|
|
134
|
+
config.projectId = await question('Firebase Project ID: ');
|
|
135
|
+
config.appId = await question('Firebase App ID: ');
|
|
136
|
+
break;
|
|
137
|
+
|
|
138
|
+
case 'sms':
|
|
139
|
+
const smsProvider = await question('SMS Provider (twilio/firebase/custom): ');
|
|
140
|
+
config.provider = smsProvider;
|
|
141
|
+
if (smsProvider === 'twilio') {
|
|
142
|
+
config.accountSid = await question('Twilio Account SID: ');
|
|
143
|
+
config.authToken = await question('Twilio Auth Token: ');
|
|
144
|
+
config.fromNumber = await question('Twilio From Number: ');
|
|
145
|
+
}
|
|
146
|
+
break;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
return config;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
async function generateConfigs(platforms, configs) {
|
|
153
|
+
// Create auth config file
|
|
154
|
+
const authConfig = {
|
|
155
|
+
providers: Object.entries(configs).map(([provider, config]) => ({
|
|
156
|
+
provider,
|
|
157
|
+
options: config
|
|
158
|
+
})),
|
|
159
|
+
persistence: 'local',
|
|
160
|
+
autoRefreshToken: true,
|
|
161
|
+
enableLogging: process.env.NODE_ENV !== 'production'
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
const configPath = path.join(process.cwd(), 'capacitor-auth.config.json');
|
|
165
|
+
fs.writeFileSync(configPath, JSON.stringify(authConfig, null, 2));
|
|
166
|
+
console.log(`\nš Created ${configPath}`);
|
|
167
|
+
|
|
168
|
+
// Create example initialization file
|
|
169
|
+
const exampleCode = `import { CapacitorAuthManager } from 'capacitor-auth-manager';
|
|
170
|
+
import authConfig from './capacitor-auth.config.json';
|
|
171
|
+
|
|
172
|
+
export async function initializeAuth() {
|
|
173
|
+
await CapacitorAuthManager.initialize(authConfig);
|
|
174
|
+
|
|
175
|
+
// Add auth state listener
|
|
176
|
+
await CapacitorAuthManager.addAuthStateListener((user) => {
|
|
177
|
+
if (user) {
|
|
178
|
+
console.log('User signed in:', user.email);
|
|
179
|
+
} else {
|
|
180
|
+
console.log('User signed out');
|
|
181
|
+
}
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
// Call this in your app initialization
|
|
186
|
+
initializeAuth();
|
|
187
|
+
`;
|
|
188
|
+
|
|
189
|
+
const examplePath = path.join(process.cwd(), 'src', 'auth-init.ts');
|
|
190
|
+
if (!fs.existsSync(path.dirname(examplePath))) {
|
|
191
|
+
fs.mkdirSync(path.dirname(examplePath), { recursive: true });
|
|
192
|
+
}
|
|
193
|
+
fs.writeFileSync(examplePath, exampleCode);
|
|
194
|
+
console.log(`š Created ${examplePath}`);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
async function configureIOS(configs) {
|
|
198
|
+
console.log('\nš± Configuring iOS...');
|
|
199
|
+
|
|
200
|
+
const infoPlistPath = path.join(process.cwd(), 'ios', 'App', 'App', 'Info.plist');
|
|
201
|
+
if (!fs.existsSync(infoPlistPath)) {
|
|
202
|
+
console.log('ā ļø iOS Info.plist not found. Please configure manually.');
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
let plistAdditions = '\n<!-- Capacitor Auth Manager Configuration -->\n';
|
|
207
|
+
|
|
208
|
+
// Google Sign-In
|
|
209
|
+
if (configs.google) {
|
|
210
|
+
const reversedClientId = configs.google.iosClientId.split('.').reverse().join('.');
|
|
211
|
+
plistAdditions += `
|
|
212
|
+
<key>CFBundleURLTypes</key>
|
|
213
|
+
<array>
|
|
214
|
+
<dict>
|
|
215
|
+
<key>CFBundleURLSchemes</key>
|
|
216
|
+
<array>
|
|
217
|
+
<string>${reversedClientId}</string>
|
|
218
|
+
</array>
|
|
219
|
+
</dict>
|
|
220
|
+
</array>
|
|
221
|
+
`;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
// Facebook
|
|
225
|
+
if (configs.facebook) {
|
|
226
|
+
plistAdditions += `
|
|
227
|
+
<key>FacebookAppID</key>
|
|
228
|
+
<string>${configs.facebook.appId}</string>
|
|
229
|
+
<key>FacebookClientToken</key>
|
|
230
|
+
<string>CLIENT_TOKEN_HERE</string>
|
|
231
|
+
<key>FacebookDisplayName</key>
|
|
232
|
+
<string>${configs.facebook.appName}</string>
|
|
233
|
+
<key>LSApplicationQueriesSchemes</key>
|
|
234
|
+
<array>
|
|
235
|
+
<string>fbapi</string>
|
|
236
|
+
<string>fb-messenger-share-api</string>
|
|
237
|
+
<string>fbauth2</string>
|
|
238
|
+
<string>fbshareextension</string>
|
|
239
|
+
</array>
|
|
240
|
+
`;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
console.log('\nAdd the following to your Info.plist:');
|
|
244
|
+
console.log(plistAdditions);
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
async function configureAndroid(configs) {
|
|
248
|
+
console.log('\nš¤ Configuring Android...');
|
|
249
|
+
|
|
250
|
+
const stringsPath = path.join(process.cwd(), 'android', 'app', 'src', 'main', 'res', 'values', 'strings.xml');
|
|
251
|
+
if (!fs.existsSync(stringsPath)) {
|
|
252
|
+
console.log('ā ļø Android strings.xml not found. Please configure manually.');
|
|
253
|
+
return;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
let stringsAdditions = '\n <!-- Capacitor Auth Manager Configuration -->\n';
|
|
257
|
+
|
|
258
|
+
// Google Sign-In
|
|
259
|
+
if (configs.google && configs.google.serverClientId) {
|
|
260
|
+
stringsAdditions += ` <string name="default_web_client_id">${configs.google.serverClientId}</string>\n`;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
// Facebook
|
|
264
|
+
if (configs.facebook) {
|
|
265
|
+
stringsAdditions += ` <string name="facebook_app_id">${configs.facebook.appId}</string>\n`;
|
|
266
|
+
stringsAdditions += ` <string name="facebook_client_token">CLIENT_TOKEN_HERE</string>\n`;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
console.log('\nAdd the following to your strings.xml:');
|
|
270
|
+
console.log(stringsAdditions);
|
|
271
|
+
|
|
272
|
+
// Manifest additions
|
|
273
|
+
const manifestAdditions = `
|
|
274
|
+
<!-- Add to AndroidManifest.xml -->
|
|
275
|
+
${configs.google ? `
|
|
276
|
+
<meta-data
|
|
277
|
+
android:name="com.google.android.gms.auth.api.signin.GoogleSignInOptions"
|
|
278
|
+
android:value="@string/default_web_client_id" />
|
|
279
|
+
` : ''}
|
|
280
|
+
${configs.facebook ? `
|
|
281
|
+
<meta-data
|
|
282
|
+
android:name="com.facebook.sdk.ApplicationId"
|
|
283
|
+
android:value="@string/facebook_app_id"/>
|
|
284
|
+
<meta-data
|
|
285
|
+
android:name="com.facebook.sdk.ClientToken"
|
|
286
|
+
android:value="@string/facebook_client_token"/>
|
|
287
|
+
` : ''}
|
|
288
|
+
`;
|
|
289
|
+
|
|
290
|
+
console.log('\nAdd the following to your AndroidManifest.xml:');
|
|
291
|
+
console.log(manifestAdditions);
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
// Run configuration
|
|
295
|
+
configure().catch(console.error);
|