capacitor-auth-manager 2.4.4 → 3.1.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.
- package/AI-INTEGRATION-GUIDE.md +176 -0
- package/CHANGELOG.md +143 -0
- package/CapacitorAuthManager.podspec +3 -3
- package/README.md +99 -76
- package/android/build.gradle +23 -25
- package/android/consumer-rules.pro +14 -0
- package/android/proguard-rules.pro +5 -30
- package/android/src/main/AndroidManifest.xml +4 -9
- package/android/src/main/java/com/aoneahsan/capacitor_auth_manager/ActivityLauncher.java +26 -0
- package/android/src/main/java/com/aoneahsan/capacitor_auth_manager/AuthErrorCodes.java +32 -0
- package/android/src/main/java/com/aoneahsan/capacitor_auth_manager/AuthException.java +34 -0
- package/android/src/main/java/com/aoneahsan/capacitor_auth_manager/AuthStorage.java +46 -25
- package/android/src/main/java/com/aoneahsan/capacitor_auth_manager/CapacitorAuthManager.java +62 -40
- package/android/src/main/java/com/aoneahsan/capacitor_auth_manager/CapacitorAuthManagerPlugin.java +124 -66
- package/android/src/main/java/com/aoneahsan/capacitor_auth_manager/GoogleAuthProvider.java +225 -374
- package/android/src/main/java/com/aoneahsan/capacitor_auth_manager/GoogleCredentialManagerSignIn.java +175 -0
- package/android/src/main/java/com/aoneahsan/capacitor_auth_manager/GoogleLegacySignIn.java +133 -0
- package/android/src/main/java/com/aoneahsan/capacitor_auth_manager/GoogleProfileCallback.java +8 -0
- package/android/src/main/java/com/aoneahsan/capacitor_auth_manager/GoogleResultMapper.java +158 -0
- package/android/src/main/java/com/aoneahsan/capacitor_auth_manager/ProviderFactory.java +11 -3
- package/android/src/main/java/com/aoneahsan/capacitor_auth_manager/SigningDiagnostics.java +76 -0
- package/dist/angular.cjs.js +421 -3376
- package/dist/core.cjs.js +589 -149
- package/dist/esm/angular/auth.guard.d.ts +1 -1
- package/dist/esm/angular/auth.module.d.ts +1 -1
- package/dist/esm/angular/auth.module.js +1 -1
- package/dist/esm/angular/auth.service.d.ts +2 -2
- package/dist/esm/angular/auth.service.js +1 -1
- package/dist/esm/angular/index.d.ts +4 -4
- package/dist/esm/angular/index.js +4 -4
- package/dist/esm/capacitor-plugin.d.ts +2 -3
- package/dist/esm/capacitor-plugin.js +14 -4
- package/dist/esm/core/auth-manager.d.ts +20 -2
- package/dist/esm/core/auth-manager.js +68 -12
- package/dist/esm/core/index.d.ts +5 -4
- package/dist/esm/core/index.js +5 -4
- package/dist/esm/core/provider-manifests.d.ts +1 -1
- package/dist/esm/core/provider-manifests.js +12 -13
- package/dist/esm/core/provider-registry.d.ts +8 -5
- package/dist/esm/core/provider-registry.js +41 -10
- package/dist/esm/core/types.d.ts +2 -2
- package/dist/esm/definitions.d.ts +29 -0
- package/dist/esm/index.d.ts +12 -12
- package/dist/esm/index.js +7 -7
- package/dist/esm/package.json +1 -0
- package/dist/esm/providers/base-provider.d.ts +7 -8
- package/dist/esm/providers/base-provider.js +7 -8
- package/dist/esm/providers/native/google-native-provider.d.ts +13 -2
- package/dist/esm/providers/native/google-native-provider.js +50 -6
- package/dist/esm/providers/oauth-provider.d.ts +2 -2
- package/dist/esm/providers/oauth-provider.js +3 -3
- package/dist/esm/providers/provider-factory.d.ts +5 -5
- package/dist/esm/providers/provider-factory.js +2 -2
- package/dist/esm/providers/web/google-provider.d.ts +74 -18
- package/dist/esm/providers/web/google-provider.js +391 -117
- package/dist/esm/providers/web/index.d.ts +1 -1
- package/dist/esm/providers/web/index.js +1 -1
- package/dist/esm/react/hooks.d.ts +2 -2
- package/dist/esm/react/hooks.js +2 -2
- package/dist/esm/react/index.d.ts +3 -3
- package/dist/esm/react/index.js +3 -3
- package/dist/esm/react/types.d.ts +1 -1
- package/dist/esm/utils/auth-error.d.ts +1 -1
- package/dist/esm/utils/auth-error.js +1 -1
- package/dist/esm/utils/event-emitter.d.ts +1 -1
- package/dist/esm/utils/event-emitter.js +1 -1
- package/dist/esm/utils/pending-verification-store.js +1 -1
- package/dist/esm/utils/storage.d.ts +2 -2
- package/dist/esm/utils/storage.js +31 -7
- package/dist/esm/vue/composables.d.ts +2 -2
- package/dist/esm/vue/composables.js +1 -1
- package/dist/esm/vue/index.d.ts +2 -2
- package/dist/esm/vue/index.js +2 -2
- package/dist/esm/web.d.ts +1 -1
- package/dist/esm/web.js +6 -6
- package/dist/plugin.cjs.js +291 -2771
- package/dist/plugin.js +585 -147
- package/dist/providers-web.cjs.js +1317 -0
- package/dist/react.cjs.js +310 -3265
- package/dist/vue.cjs.js +266 -3221
- package/ios/Plugin/AuthStorage.swift +3 -1
- package/ios/Plugin/GoogleAuthProvider.swift +7 -4
- package/ios/Plugin/Models.swift +28 -0
- package/ios/Plugin/Plugin.swift +64 -40
- package/package.json +54 -32
- package/scripts/configure.js +71 -325
package/android/src/main/java/com/aoneahsan/capacitor_auth_manager/CapacitorAuthManagerPlugin.java
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
package com.aoneahsan.capacitor_auth_manager;
|
|
2
2
|
|
|
3
|
+
import android.content.Intent;
|
|
4
|
+
|
|
5
|
+
import androidx.activity.result.ActivityResult;
|
|
6
|
+
|
|
3
7
|
import com.getcapacitor.JSObject;
|
|
4
8
|
import com.getcapacitor.Plugin;
|
|
5
9
|
import com.getcapacitor.PluginCall;
|
|
6
10
|
import com.getcapacitor.PluginMethod;
|
|
11
|
+
import com.getcapacitor.annotation.ActivityCallback;
|
|
7
12
|
import com.getcapacitor.annotation.CapacitorPlugin;
|
|
8
13
|
|
|
9
14
|
@CapacitorPlugin(name = "CapacitorAuthManager")
|
|
@@ -11,9 +16,67 @@ public class CapacitorAuthManagerPlugin extends Plugin {
|
|
|
11
16
|
|
|
12
17
|
private CapacitorAuthManager implementation;
|
|
13
18
|
|
|
19
|
+
/** The signIn/linkAccount call in flight; an Activity started for a result attaches to it. */
|
|
20
|
+
private PluginCall activeSignInCall;
|
|
21
|
+
private ActivityLauncher.ResultHandler pendingActivityHandler;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Reject a call with the {@link AuthErrorCodes} value the failure carries, so JS receives a real
|
|
25
|
+
* {@code AuthError.code} instead of one guessed from the message text. A plain exception (nothing
|
|
26
|
+
* below it set a code) falls back to {@code fallbackCode}.
|
|
27
|
+
*/
|
|
28
|
+
private static void rejectWith(PluginCall call, Exception error, String fallbackCode) {
|
|
29
|
+
if (error == null) {
|
|
30
|
+
call.reject("Unknown error", AuthErrorCodes.INTERNAL_ERROR);
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
String message = error.getMessage() != null ? error.getMessage() : error.toString();
|
|
34
|
+
call.reject(message, AuthException.codeOf(error, fallbackCode));
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
private static void rejectWith(PluginCall call, Exception error) {
|
|
38
|
+
rejectWith(call, error, AuthErrorCodes.INTERNAL_ERROR);
|
|
39
|
+
}
|
|
40
|
+
|
|
14
41
|
@Override
|
|
15
42
|
public void load() {
|
|
16
43
|
implementation = new CapacitorAuthManager(getContext(), getActivity());
|
|
44
|
+
implementation.setActivityLauncher(this::launchForResult);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** {@link ActivityLauncher} for providers: Capacitor's result API, delivered to {@link #onProviderActivityResult}. */
|
|
48
|
+
private boolean launchForResult(Intent intent, ActivityLauncher.ResultHandler handler) {
|
|
49
|
+
PluginCall call = activeSignInCall;
|
|
50
|
+
if (call == null) {
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
pendingActivityHandler = handler;
|
|
54
|
+
startActivityForResult(call, intent, "onProviderActivityResult");
|
|
55
|
+
return true;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
@ActivityCallback
|
|
59
|
+
private void onProviderActivityResult(PluginCall call, ActivityResult result) {
|
|
60
|
+
ActivityLauncher.ResultHandler handler = pendingActivityHandler;
|
|
61
|
+
pendingActivityHandler = null;
|
|
62
|
+
if (handler != null) {
|
|
63
|
+
handler.onResult(result.getResultCode(), result.getData());
|
|
64
|
+
} else if (call != null) {
|
|
65
|
+
call.reject("Google sign-in result arrived with no pending request", AuthErrorCodes.INTERNAL_ERROR);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** Settles a sign-in call and releases it if an Activity result saved it on the bridge. */
|
|
70
|
+
private void settleSignIn(PluginCall call, CapacitorAuthManager.AuthResult<JSObject> result) {
|
|
71
|
+
if (activeSignInCall == call) {
|
|
72
|
+
activeSignInCall = null;
|
|
73
|
+
}
|
|
74
|
+
if (result.isSuccess()) {
|
|
75
|
+
call.resolve(result.getData());
|
|
76
|
+
} else {
|
|
77
|
+
rejectWith(call, result.getError());
|
|
78
|
+
}
|
|
79
|
+
getBridge().releaseCall(call);
|
|
17
80
|
}
|
|
18
81
|
|
|
19
82
|
@PluginMethod
|
|
@@ -27,7 +90,7 @@ public class CapacitorAuthManagerPlugin extends Plugin {
|
|
|
27
90
|
options = call.getData();
|
|
28
91
|
}
|
|
29
92
|
if (options == null) {
|
|
30
|
-
call.reject("Options are required");
|
|
93
|
+
call.reject("Options are required", AuthErrorCodes.MISSING_CONFIGURATION);
|
|
31
94
|
return;
|
|
32
95
|
}
|
|
33
96
|
|
|
@@ -35,11 +98,11 @@ public class CapacitorAuthManagerPlugin extends Plugin {
|
|
|
35
98
|
if (result.isSuccess()) {
|
|
36
99
|
call.resolve();
|
|
37
100
|
} else {
|
|
38
|
-
call
|
|
101
|
+
rejectWith(call, result.getError());
|
|
39
102
|
}
|
|
40
103
|
});
|
|
41
104
|
} catch (Exception e) {
|
|
42
|
-
call.reject("Failed to initialize: " + e.getMessage());
|
|
105
|
+
call.reject("Failed to initialize: " + e.getMessage(), AuthException.codeOf(e, AuthErrorCodes.PROVIDER_INIT_FAILED));
|
|
43
106
|
}
|
|
44
107
|
}
|
|
45
108
|
|
|
@@ -51,19 +114,14 @@ public class CapacitorAuthManagerPlugin extends Plugin {
|
|
|
51
114
|
JSObject options = call.getObject("options");
|
|
52
115
|
|
|
53
116
|
if (provider == null) {
|
|
54
|
-
call.reject("Provider is required");
|
|
117
|
+
call.reject("Provider is required", AuthErrorCodes.MISSING_CONFIGURATION);
|
|
55
118
|
return;
|
|
56
119
|
}
|
|
57
120
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
call.resolve(result.getData());
|
|
61
|
-
} else {
|
|
62
|
-
call.reject(result.getError().getMessage());
|
|
63
|
-
}
|
|
64
|
-
});
|
|
121
|
+
activeSignInCall = call;
|
|
122
|
+
implementation.signIn(provider, credentials, options, result -> settleSignIn(call, result));
|
|
65
123
|
} catch (Exception e) {
|
|
66
|
-
call.reject("Sign in failed: " + e.getMessage());
|
|
124
|
+
call.reject("Sign in failed: " + e.getMessage(), AuthException.codeOf(e, AuthErrorCodes.SIGN_IN_FAILED));
|
|
67
125
|
}
|
|
68
126
|
}
|
|
69
127
|
|
|
@@ -81,11 +139,11 @@ public class CapacitorAuthManagerPlugin extends Plugin {
|
|
|
81
139
|
if (result.isSuccess()) {
|
|
82
140
|
call.resolve();
|
|
83
141
|
} else {
|
|
84
|
-
call
|
|
142
|
+
rejectWith(call, result.getError());
|
|
85
143
|
}
|
|
86
144
|
});
|
|
87
145
|
} catch (Exception e) {
|
|
88
|
-
call.reject("Sign out failed: " + e.getMessage());
|
|
146
|
+
call.reject("Sign out failed: " + e.getMessage(), AuthException.codeOf(e, AuthErrorCodes.SIGN_OUT_FAILED));
|
|
89
147
|
}
|
|
90
148
|
}
|
|
91
149
|
|
|
@@ -101,11 +159,11 @@ public class CapacitorAuthManagerPlugin extends Plugin {
|
|
|
101
159
|
call.resolve(new JSObject());
|
|
102
160
|
}
|
|
103
161
|
} else {
|
|
104
|
-
call
|
|
162
|
+
rejectWith(call, result.getError());
|
|
105
163
|
}
|
|
106
164
|
});
|
|
107
165
|
} catch (Exception e) {
|
|
108
|
-
call.reject("Failed to get current user: " + e.getMessage());
|
|
166
|
+
call.reject("Failed to get current user: " + e.getMessage(), AuthException.codeOf(e, AuthErrorCodes.INTERNAL_ERROR));
|
|
109
167
|
}
|
|
110
168
|
}
|
|
111
169
|
|
|
@@ -123,11 +181,11 @@ public class CapacitorAuthManagerPlugin extends Plugin {
|
|
|
123
181
|
if (result.isSuccess()) {
|
|
124
182
|
call.resolve(result.getData());
|
|
125
183
|
} else {
|
|
126
|
-
call
|
|
184
|
+
rejectWith(call, result.getError());
|
|
127
185
|
}
|
|
128
186
|
});
|
|
129
187
|
} catch (Exception e) {
|
|
130
|
-
call.reject("Token refresh failed: " + e.getMessage());
|
|
188
|
+
call.reject("Token refresh failed: " + e.getMessage(), AuthException.codeOf(e, AuthErrorCodes.TOKEN_REFRESH_FAILED));
|
|
131
189
|
}
|
|
132
190
|
}
|
|
133
191
|
|
|
@@ -148,7 +206,7 @@ public class CapacitorAuthManagerPlugin extends Plugin {
|
|
|
148
206
|
ret.put("callbackId", callbackId);
|
|
149
207
|
call.resolve(ret);
|
|
150
208
|
} catch (Exception e) {
|
|
151
|
-
call.reject("Failed to add listener: " + e.getMessage());
|
|
209
|
+
call.reject("Failed to add listener: " + e.getMessage(), AuthException.codeOf(e, AuthErrorCodes.INTERNAL_ERROR));
|
|
152
210
|
}
|
|
153
211
|
}
|
|
154
212
|
|
|
@@ -158,7 +216,7 @@ public class CapacitorAuthManagerPlugin extends Plugin {
|
|
|
158
216
|
implementation.removeAllListeners();
|
|
159
217
|
call.resolve();
|
|
160
218
|
} catch (Exception e) {
|
|
161
|
-
call.reject("Failed to remove listeners: " + e.getMessage());
|
|
219
|
+
call.reject("Failed to remove listeners: " + e.getMessage(), AuthException.codeOf(e, AuthErrorCodes.INTERNAL_ERROR));
|
|
162
220
|
}
|
|
163
221
|
}
|
|
164
222
|
|
|
@@ -167,7 +225,7 @@ public class CapacitorAuthManagerPlugin extends Plugin {
|
|
|
167
225
|
try {
|
|
168
226
|
String provider = call.getString("provider");
|
|
169
227
|
if (provider == null) {
|
|
170
|
-
call.reject("Provider is required");
|
|
228
|
+
call.reject("Provider is required", AuthErrorCodes.MISSING_CONFIGURATION);
|
|
171
229
|
return;
|
|
172
230
|
}
|
|
173
231
|
|
|
@@ -175,11 +233,11 @@ public class CapacitorAuthManagerPlugin extends Plugin {
|
|
|
175
233
|
if (result.isSuccess()) {
|
|
176
234
|
call.resolve(result.getData());
|
|
177
235
|
} else {
|
|
178
|
-
call
|
|
236
|
+
rejectWith(call, result.getError());
|
|
179
237
|
}
|
|
180
238
|
});
|
|
181
239
|
} catch (Exception e) {
|
|
182
|
-
call.reject("Failed to check support: " + e.getMessage());
|
|
240
|
+
call.reject("Failed to check support: " + e.getMessage(), AuthException.codeOf(e, AuthErrorCodes.INTERNAL_ERROR));
|
|
183
241
|
}
|
|
184
242
|
}
|
|
185
243
|
|
|
@@ -190,7 +248,7 @@ public class CapacitorAuthManagerPlugin extends Plugin {
|
|
|
190
248
|
JSObject options = call.getObject("options");
|
|
191
249
|
|
|
192
250
|
if (provider == null || options == null) {
|
|
193
|
-
call.reject("Provider and options are required");
|
|
251
|
+
call.reject("Provider and options are required", AuthErrorCodes.MISSING_CONFIGURATION);
|
|
194
252
|
return;
|
|
195
253
|
}
|
|
196
254
|
|
|
@@ -198,11 +256,11 @@ public class CapacitorAuthManagerPlugin extends Plugin {
|
|
|
198
256
|
if (result.isSuccess()) {
|
|
199
257
|
call.resolve();
|
|
200
258
|
} else {
|
|
201
|
-
call
|
|
259
|
+
rejectWith(call, result.getError());
|
|
202
260
|
}
|
|
203
261
|
});
|
|
204
262
|
} catch (Exception e) {
|
|
205
|
-
call.reject("Configuration failed: " + e.getMessage());
|
|
263
|
+
call.reject("Configuration failed: " + e.getMessage(), AuthException.codeOf(e, AuthErrorCodes.MISSING_CONFIGURATION));
|
|
206
264
|
}
|
|
207
265
|
}
|
|
208
266
|
|
|
@@ -214,19 +272,14 @@ public class CapacitorAuthManagerPlugin extends Plugin {
|
|
|
214
272
|
JSObject options = call.getObject("options");
|
|
215
273
|
|
|
216
274
|
if (provider == null) {
|
|
217
|
-
call.reject("Provider is required");
|
|
275
|
+
call.reject("Provider is required", AuthErrorCodes.MISSING_CONFIGURATION);
|
|
218
276
|
return;
|
|
219
277
|
}
|
|
220
278
|
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
call.resolve(result.getData());
|
|
224
|
-
} else {
|
|
225
|
-
call.reject(result.getError().getMessage());
|
|
226
|
-
}
|
|
227
|
-
});
|
|
279
|
+
activeSignInCall = call;
|
|
280
|
+
implementation.linkAccount(provider, credentials, options, result -> settleSignIn(call, result));
|
|
228
281
|
} catch (Exception e) {
|
|
229
|
-
call.reject("Account linking failed: " + e.getMessage());
|
|
282
|
+
call.reject("Account linking failed: " + e.getMessage(), AuthException.codeOf(e, AuthErrorCodes.OPERATION_NOT_ALLOWED));
|
|
230
283
|
}
|
|
231
284
|
}
|
|
232
285
|
|
|
@@ -235,7 +288,7 @@ public class CapacitorAuthManagerPlugin extends Plugin {
|
|
|
235
288
|
try {
|
|
236
289
|
String provider = call.getString("provider");
|
|
237
290
|
if (provider == null) {
|
|
238
|
-
call.reject("Provider is required");
|
|
291
|
+
call.reject("Provider is required", AuthErrorCodes.MISSING_CONFIGURATION);
|
|
239
292
|
return;
|
|
240
293
|
}
|
|
241
294
|
|
|
@@ -243,11 +296,11 @@ public class CapacitorAuthManagerPlugin extends Plugin {
|
|
|
243
296
|
if (result.isSuccess()) {
|
|
244
297
|
call.resolve();
|
|
245
298
|
} else {
|
|
246
|
-
call
|
|
299
|
+
rejectWith(call, result.getError());
|
|
247
300
|
}
|
|
248
301
|
});
|
|
249
302
|
} catch (Exception e) {
|
|
250
|
-
call.reject("Account unlinking failed: " + e.getMessage());
|
|
303
|
+
call.reject("Account unlinking failed: " + e.getMessage(), AuthException.codeOf(e, AuthErrorCodes.OPERATION_NOT_ALLOWED));
|
|
251
304
|
}
|
|
252
305
|
}
|
|
253
306
|
|
|
@@ -258,7 +311,7 @@ public class CapacitorAuthManagerPlugin extends Plugin {
|
|
|
258
311
|
JSObject actionCodeSettings = call.getObject("actionCodeSettings");
|
|
259
312
|
|
|
260
313
|
if (email == null) {
|
|
261
|
-
call.reject("Email is required");
|
|
314
|
+
call.reject("Email is required", AuthErrorCodes.EMAIL_REQUIRED);
|
|
262
315
|
return;
|
|
263
316
|
}
|
|
264
317
|
|
|
@@ -266,11 +319,11 @@ public class CapacitorAuthManagerPlugin extends Plugin {
|
|
|
266
319
|
if (result.isSuccess()) {
|
|
267
320
|
call.resolve();
|
|
268
321
|
} else {
|
|
269
|
-
call
|
|
322
|
+
rejectWith(call, result.getError());
|
|
270
323
|
}
|
|
271
324
|
});
|
|
272
325
|
} catch (Exception e) {
|
|
273
|
-
call.reject("Failed to send password reset email: " + e.getMessage());
|
|
326
|
+
call.reject("Failed to send password reset email: " + e.getMessage(), AuthException.codeOf(e, AuthErrorCodes.OPERATION_NOT_ALLOWED));
|
|
274
327
|
}
|
|
275
328
|
}
|
|
276
329
|
|
|
@@ -283,11 +336,11 @@ public class CapacitorAuthManagerPlugin extends Plugin {
|
|
|
283
336
|
if (result.isSuccess()) {
|
|
284
337
|
call.resolve();
|
|
285
338
|
} else {
|
|
286
|
-
call
|
|
339
|
+
rejectWith(call, result.getError());
|
|
287
340
|
}
|
|
288
341
|
});
|
|
289
342
|
} catch (Exception e) {
|
|
290
|
-
call.reject("Failed to send email verification: " + e.getMessage());
|
|
343
|
+
call.reject("Failed to send email verification: " + e.getMessage(), AuthException.codeOf(e, AuthErrorCodes.OPERATION_NOT_ALLOWED));
|
|
291
344
|
}
|
|
292
345
|
}
|
|
293
346
|
|
|
@@ -299,7 +352,7 @@ public class CapacitorAuthManagerPlugin extends Plugin {
|
|
|
299
352
|
String testCode = call.getString("testCode");
|
|
300
353
|
|
|
301
354
|
if (phoneNumber == null) {
|
|
302
|
-
call.reject("Phone number is required");
|
|
355
|
+
call.reject("Phone number is required", AuthErrorCodes.PHONE_REQUIRED);
|
|
303
356
|
return;
|
|
304
357
|
}
|
|
305
358
|
|
|
@@ -307,11 +360,11 @@ public class CapacitorAuthManagerPlugin extends Plugin {
|
|
|
307
360
|
if (result.isSuccess()) {
|
|
308
361
|
call.resolve();
|
|
309
362
|
} else {
|
|
310
|
-
call
|
|
363
|
+
rejectWith(call, result.getError());
|
|
311
364
|
}
|
|
312
365
|
});
|
|
313
366
|
} catch (Exception e) {
|
|
314
|
-
call.reject("Failed to send SMS code: " + e.getMessage());
|
|
367
|
+
call.reject("Failed to send SMS code: " + e.getMessage(), AuthException.codeOf(e, AuthErrorCodes.OPERATION_NOT_ALLOWED));
|
|
315
368
|
}
|
|
316
369
|
}
|
|
317
370
|
|
|
@@ -323,7 +376,7 @@ public class CapacitorAuthManagerPlugin extends Plugin {
|
|
|
323
376
|
String verificationId = call.getString("verificationId");
|
|
324
377
|
|
|
325
378
|
if (phoneNumber == null || code == null) {
|
|
326
|
-
call.reject("Phone number and code are required");
|
|
379
|
+
call.reject("Phone number and code are required", AuthErrorCodes.CREDENTIALS_REQUIRED);
|
|
327
380
|
return;
|
|
328
381
|
}
|
|
329
382
|
|
|
@@ -331,11 +384,11 @@ public class CapacitorAuthManagerPlugin extends Plugin {
|
|
|
331
384
|
if (result.isSuccess()) {
|
|
332
385
|
call.resolve(result.getData());
|
|
333
386
|
} else {
|
|
334
|
-
call
|
|
387
|
+
rejectWith(call, result.getError());
|
|
335
388
|
}
|
|
336
389
|
});
|
|
337
390
|
} catch (Exception e) {
|
|
338
|
-
call.reject("SMS verification failed: " + e.getMessage());
|
|
391
|
+
call.reject("SMS verification failed: " + e.getMessage(), AuthException.codeOf(e, AuthErrorCodes.OPERATION_NOT_ALLOWED));
|
|
339
392
|
}
|
|
340
393
|
}
|
|
341
394
|
|
|
@@ -347,7 +400,7 @@ public class CapacitorAuthManagerPlugin extends Plugin {
|
|
|
347
400
|
String testCode = call.getString("testCode");
|
|
348
401
|
|
|
349
402
|
if (email == null) {
|
|
350
|
-
call.reject("Email is required");
|
|
403
|
+
call.reject("Email is required", AuthErrorCodes.EMAIL_REQUIRED);
|
|
351
404
|
return;
|
|
352
405
|
}
|
|
353
406
|
|
|
@@ -355,11 +408,11 @@ public class CapacitorAuthManagerPlugin extends Plugin {
|
|
|
355
408
|
if (result.isSuccess()) {
|
|
356
409
|
call.resolve();
|
|
357
410
|
} else {
|
|
358
|
-
call
|
|
411
|
+
rejectWith(call, result.getError());
|
|
359
412
|
}
|
|
360
413
|
});
|
|
361
414
|
} catch (Exception e) {
|
|
362
|
-
call.reject("Failed to send email code: " + e.getMessage());
|
|
415
|
+
call.reject("Failed to send email code: " + e.getMessage(), AuthException.codeOf(e, AuthErrorCodes.OPERATION_NOT_ALLOWED));
|
|
363
416
|
}
|
|
364
417
|
}
|
|
365
418
|
|
|
@@ -371,7 +424,7 @@ public class CapacitorAuthManagerPlugin extends Plugin {
|
|
|
371
424
|
String verificationId = call.getString("verificationId");
|
|
372
425
|
|
|
373
426
|
if (email == null || code == null) {
|
|
374
|
-
call.reject("Email and code are required");
|
|
427
|
+
call.reject("Email and code are required", AuthErrorCodes.CREDENTIALS_REQUIRED);
|
|
375
428
|
return;
|
|
376
429
|
}
|
|
377
430
|
|
|
@@ -379,11 +432,11 @@ public class CapacitorAuthManagerPlugin extends Plugin {
|
|
|
379
432
|
if (result.isSuccess()) {
|
|
380
433
|
call.resolve(result.getData());
|
|
381
434
|
} else {
|
|
382
|
-
call
|
|
435
|
+
rejectWith(call, result.getError());
|
|
383
436
|
}
|
|
384
437
|
});
|
|
385
438
|
} catch (Exception e) {
|
|
386
|
-
call.reject("Email verification failed: " + e.getMessage());
|
|
439
|
+
call.reject("Email verification failed: " + e.getMessage(), AuthException.codeOf(e, AuthErrorCodes.OPERATION_NOT_ALLOWED));
|
|
387
440
|
}
|
|
388
441
|
}
|
|
389
442
|
|
|
@@ -399,11 +452,11 @@ public class CapacitorAuthManagerPlugin extends Plugin {
|
|
|
399
452
|
if (result.isSuccess()) {
|
|
400
453
|
call.resolve(result.getData());
|
|
401
454
|
} else {
|
|
402
|
-
call
|
|
455
|
+
rejectWith(call, result.getError());
|
|
403
456
|
}
|
|
404
457
|
});
|
|
405
458
|
} catch (Exception e) {
|
|
406
|
-
call.reject("Profile update failed: " + e.getMessage());
|
|
459
|
+
call.reject("Profile update failed: " + e.getMessage(), AuthException.codeOf(e, AuthErrorCodes.OPERATION_NOT_ALLOWED));
|
|
407
460
|
}
|
|
408
461
|
}
|
|
409
462
|
|
|
@@ -416,18 +469,23 @@ public class CapacitorAuthManagerPlugin extends Plugin {
|
|
|
416
469
|
if (result.isSuccess()) {
|
|
417
470
|
call.resolve();
|
|
418
471
|
} else {
|
|
419
|
-
call
|
|
472
|
+
rejectWith(call, result.getError());
|
|
420
473
|
}
|
|
421
474
|
});
|
|
422
475
|
} catch (Exception e) {
|
|
423
|
-
call.reject("Account deletion failed: " + e.getMessage());
|
|
476
|
+
call.reject("Account deletion failed: " + e.getMessage(), AuthException.codeOf(e, AuthErrorCodes.OPERATION_NOT_ALLOWED));
|
|
424
477
|
}
|
|
425
478
|
}
|
|
426
479
|
|
|
427
480
|
@PluginMethod
|
|
428
481
|
public void getIdToken(PluginCall call) {
|
|
429
482
|
try {
|
|
483
|
+
// JS passes { provider, forceRefresh } at the top level; fall back to the call data so
|
|
484
|
+
// both reach the orchestrator (it reads options.provider / options.forceRefresh).
|
|
430
485
|
JSObject options = call.getObject("options");
|
|
486
|
+
if (options == null) {
|
|
487
|
+
options = call.getData();
|
|
488
|
+
}
|
|
431
489
|
|
|
432
490
|
implementation.getIdToken(options, result -> {
|
|
433
491
|
if (result.isSuccess()) {
|
|
@@ -435,11 +493,11 @@ public class CapacitorAuthManagerPlugin extends Plugin {
|
|
|
435
493
|
ret.put("token", result.getData().getString("token"));
|
|
436
494
|
call.resolve(ret);
|
|
437
495
|
} else {
|
|
438
|
-
call
|
|
496
|
+
rejectWith(call, result.getError());
|
|
439
497
|
}
|
|
440
498
|
});
|
|
441
499
|
} catch (Exception e) {
|
|
442
|
-
call.reject("Failed to get ID token: " + e.getMessage());
|
|
500
|
+
call.reject("Failed to get ID token: " + e.getMessage(), AuthException.codeOf(e, AuthErrorCodes.INTERNAL_ERROR));
|
|
443
501
|
}
|
|
444
502
|
}
|
|
445
503
|
|
|
@@ -450,7 +508,7 @@ public class CapacitorAuthManagerPlugin extends Plugin {
|
|
|
450
508
|
JSObject parameters = call.getObject("parameters");
|
|
451
509
|
|
|
452
510
|
if (provider == null || parameters == null) {
|
|
453
|
-
call.reject("Provider and parameters are required");
|
|
511
|
+
call.reject("Provider and parameters are required", AuthErrorCodes.MISSING_CONFIGURATION);
|
|
454
512
|
return;
|
|
455
513
|
}
|
|
456
514
|
|
|
@@ -458,11 +516,11 @@ public class CapacitorAuthManagerPlugin extends Plugin {
|
|
|
458
516
|
if (result.isSuccess()) {
|
|
459
517
|
call.resolve();
|
|
460
518
|
} else {
|
|
461
|
-
call
|
|
519
|
+
rejectWith(call, result.getError());
|
|
462
520
|
}
|
|
463
521
|
});
|
|
464
522
|
} catch (Exception e) {
|
|
465
|
-
call.reject("Failed to set custom parameters: " + e.getMessage());
|
|
523
|
+
call.reject("Failed to set custom parameters: " + e.getMessage(), AuthException.codeOf(e, AuthErrorCodes.INTERNAL_ERROR));
|
|
466
524
|
}
|
|
467
525
|
}
|
|
468
526
|
|
|
@@ -480,11 +538,11 @@ public class CapacitorAuthManagerPlugin extends Plugin {
|
|
|
480
538
|
if (result.isSuccess()) {
|
|
481
539
|
call.resolve();
|
|
482
540
|
} else {
|
|
483
|
-
call
|
|
541
|
+
rejectWith(call, result.getError());
|
|
484
542
|
}
|
|
485
543
|
});
|
|
486
544
|
} catch (Exception e) {
|
|
487
|
-
call.reject("Access revocation failed: " + e.getMessage());
|
|
545
|
+
call.reject("Access revocation failed: " + e.getMessage(), AuthException.codeOf(e, AuthErrorCodes.OPERATION_NOT_ALLOWED));
|
|
488
546
|
}
|
|
489
547
|
}
|
|
490
548
|
}
|