@capgo/capacitor-social-login 0.0.72 → 0.0.77-alpha.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/README.md +63 -43
- package/android/build.gradle +1 -0
- package/android/src/main/java/ee/forgr/capacitor/social/login/AppleProvider.java +9 -10
- package/android/src/main/java/ee/forgr/capacitor/social/login/FacebookProvider.java +33 -23
- package/android/src/main/java/ee/forgr/capacitor/social/login/GoogleProvider.java +641 -64
- package/android/src/main/java/ee/forgr/capacitor/social/login/ModifiedMainActivityForSocialLoginPlugin.java +5 -0
- package/android/src/main/java/ee/forgr/capacitor/social/login/SocialLoginPlugin.java +33 -1
- package/dist/docs.json +137 -93
- package/dist/esm/definitions.d.ts +55 -33
- package/dist/esm/definitions.js.map +1 -1
- package/dist/esm/web.d.ts +18 -3
- package/dist/esm/web.js +337 -69
- package/dist/esm/web.js.map +1 -1
- package/dist/plugin.cjs.js +337 -69
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +337 -69
- package/dist/plugin.js.map +1 -1
- package/ios/Sources/SocialLoginPlugin/GoogleProvider.swift +84 -38
- package/ios/Sources/SocialLoginPlugin/SocialLoginPlugin.swift +30 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -233,6 +233,7 @@ const res = await SocialLogin.login({
|
|
|
233
233
|
* [`getAuthorizationCode(...)`](#getauthorizationcode)
|
|
234
234
|
* [`refresh(...)`](#refresh)
|
|
235
235
|
* [Interfaces](#interfaces)
|
|
236
|
+
* [Type Aliases](#type-aliases)
|
|
236
237
|
|
|
237
238
|
</docgen-index>
|
|
238
239
|
|
|
@@ -257,16 +258,16 @@ Initialize the plugin
|
|
|
257
258
|
### login(...)
|
|
258
259
|
|
|
259
260
|
```typescript
|
|
260
|
-
login(options: LoginOptions) => Promise<
|
|
261
|
+
login<T extends "apple" | "google" | "facebook">(options: Extract<LoginOptions, { provider: T; }>) => Promise<{ provider: T; result: ProviderResponseMap[T]; }>
|
|
261
262
|
```
|
|
262
263
|
|
|
263
264
|
Login with the selected provider
|
|
264
265
|
|
|
265
|
-
| Param | Type
|
|
266
|
-
| ------------- |
|
|
267
|
-
| **`options`** | <code><a href="#
|
|
266
|
+
| Param | Type |
|
|
267
|
+
| ------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
268
|
+
| **`options`** | <code><a href="#extract">Extract</a><{ provider: 'facebook'; options: <a href="#facebookloginoptions">FacebookLoginOptions</a>; }, { provider: T; }> \| <a href="#extract">Extract</a><{ provider: 'google'; options: <a href="#googleloginoptions">GoogleLoginOptions</a>; }, { provider: T; }> \| <a href="#extract">Extract</a><{ provider: 'apple'; options: <a href="#appleprovideroptions">AppleProviderOptions</a>; }, { provider: T; }></code> |
|
|
268
269
|
|
|
269
|
-
**Returns:** <code>Promise<
|
|
270
|
+
**Returns:** <code>Promise<{ provider: T; result: ProviderResponseMap[T]; }></code>
|
|
270
271
|
|
|
271
272
|
--------------------
|
|
272
273
|
|
|
@@ -281,7 +282,7 @@ Logout
|
|
|
281
282
|
|
|
282
283
|
| Param | Type |
|
|
283
284
|
| ------------- | ------------------------------------------------------------- |
|
|
284
|
-
| **`options`** | <code>{ provider: '
|
|
285
|
+
| **`options`** | <code>{ provider: 'apple' \| 'google' \| 'facebook'; }</code> |
|
|
285
286
|
|
|
286
287
|
--------------------
|
|
287
288
|
|
|
@@ -340,19 +341,11 @@ Refresh the access token
|
|
|
340
341
|
|
|
341
342
|
#### InitializeOptions
|
|
342
343
|
|
|
343
|
-
| Prop | Type
|
|
344
|
-
| -------------- |
|
|
345
|
-
| **`facebook`** | <code>{ appId: string; clientToken: string; }</code>
|
|
346
|
-
| **`google`** | <code>{ iOSClientId?: string; iOSServerClientId?: string; webClientId?: string; }</code> |
|
|
347
|
-
| **`apple`** | <code>{ clientId?: string; redirectUrl?: string; }</code>
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
#### LoginResult
|
|
351
|
-
|
|
352
|
-
| Prop | Type | Description |
|
|
353
|
-
| -------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------- |
|
|
354
|
-
| **`provider`** | <code>'facebook' \| 'google' \| 'apple' \| 'twitter'</code> | Provider |
|
|
355
|
-
| **`result`** | <code><a href="#facebookloginresponse">FacebookLoginResponse</a> \| <a href="#googleloginresponse">GoogleLoginResponse</a> \| <a href="#appleproviderresponse">AppleProviderResponse</a></code> | Payload |
|
|
344
|
+
| Prop | Type |
|
|
345
|
+
| -------------- | ---------------------------------------------------------------------------------------------------------------------- |
|
|
346
|
+
| **`facebook`** | <code>{ appId: string; clientToken: string; }</code> |
|
|
347
|
+
| **`google`** | <code>{ iOSClientId?: string; iOSServerClientId?: string; webClientId?: string; mode?: 'online' \| 'offline'; }</code> |
|
|
348
|
+
| **`apple`** | <code>{ clientId?: string; redirectUrl?: string; }</code> |
|
|
356
349
|
|
|
357
350
|
|
|
358
351
|
#### FacebookLoginResponse
|
|
@@ -379,13 +372,22 @@ Refresh the access token
|
|
|
379
372
|
| **`userId`** | <code>string</code> |
|
|
380
373
|
|
|
381
374
|
|
|
382
|
-
####
|
|
375
|
+
#### GoogleLoginResponseOnline
|
|
376
|
+
|
|
377
|
+
| Prop | Type |
|
|
378
|
+
| ------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
379
|
+
| **`accessToken`** | <code><a href="#accesstoken">AccessToken</a> \| null</code> |
|
|
380
|
+
| **`idToken`** | <code>string \| null</code> |
|
|
381
|
+
| **`profile`** | <code>{ email: string \| null; familyName: string \| null; givenName: string \| null; id: string \| null; name: string \| null; imageUrl: string \| null; }</code> |
|
|
382
|
+
| **`responseType`** | <code>'online'</code> |
|
|
383
383
|
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
|
388
|
-
|
|
|
384
|
+
|
|
385
|
+
#### GoogleLoginResponseOffline
|
|
386
|
+
|
|
387
|
+
| Prop | Type |
|
|
388
|
+
| -------------------- | ---------------------- |
|
|
389
|
+
| **`serverAuthCode`** | <code>string</code> |
|
|
390
|
+
| **`responseType`** | <code>'offline'</code> |
|
|
389
391
|
|
|
390
392
|
|
|
391
393
|
#### AppleProviderResponse
|
|
@@ -397,14 +399,6 @@ Refresh the access token
|
|
|
397
399
|
| **`profile`** | <code>{ user: string; email: string \| null; givenName: string \| null; familyName: string \| null; }</code> |
|
|
398
400
|
|
|
399
401
|
|
|
400
|
-
#### LoginOptions
|
|
401
|
-
|
|
402
|
-
| Prop | Type | Description |
|
|
403
|
-
| -------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------- |
|
|
404
|
-
| **`provider`** | <code>'facebook' \| 'google' \| 'apple' \| 'twitter'</code> | Provider |
|
|
405
|
-
| **`options`** | <code><a href="#facebookloginoptions">FacebookLoginOptions</a> \| <a href="#googleloginoptions">GoogleLoginOptions</a> \| <a href="#appleprovideroptions">AppleProviderOptions</a></code> | Options |
|
|
406
|
-
|
|
407
|
-
|
|
408
402
|
#### FacebookLoginOptions
|
|
409
403
|
|
|
410
404
|
| Prop | Type | Description | Default |
|
|
@@ -416,11 +410,11 @@ Refresh the access token
|
|
|
416
410
|
|
|
417
411
|
#### GoogleLoginOptions
|
|
418
412
|
|
|
419
|
-
| Prop
|
|
420
|
-
|
|
|
421
|
-
| **`scopes`**
|
|
422
|
-
| **`nonce`**
|
|
423
|
-
| **`
|
|
413
|
+
| Prop | Type | Description | Default |
|
|
414
|
+
| ----------------------- | --------------------- | ---------------------------------------------------------------------------------------------------- | ------------------ |
|
|
415
|
+
| **`scopes`** | <code>string[]</code> | Specifies the scopes required for accessing Google APIs The default is defined in the configuration. | |
|
|
416
|
+
| **`nonce`** | <code>string</code> | Nonce | |
|
|
417
|
+
| **`forceRefreshToken`** | <code>boolean</code> | Force refresh token (only for Android) | <code>false</code> |
|
|
424
418
|
|
|
425
419
|
|
|
426
420
|
#### AppleProviderOptions
|
|
@@ -436,20 +430,46 @@ Refresh the access token
|
|
|
436
430
|
|
|
437
431
|
| Prop | Type | Description |
|
|
438
432
|
| -------------- | ---------------------------------------------- | ----------- |
|
|
439
|
-
| **`provider`** | <code>'
|
|
433
|
+
| **`provider`** | <code>'apple' \| 'google' \| 'facebook'</code> | Provider |
|
|
440
434
|
|
|
441
435
|
|
|
442
436
|
#### AuthorizationCode
|
|
443
437
|
|
|
444
|
-
| Prop
|
|
445
|
-
|
|
|
446
|
-
| **`jwt`**
|
|
438
|
+
| Prop | Type | Description |
|
|
439
|
+
| ----------------- | ------------------- | ------------ |
|
|
440
|
+
| **`jwt`** | <code>string</code> | Jwt |
|
|
441
|
+
| **`accessToken`** | <code>string</code> | Access Token |
|
|
447
442
|
|
|
448
443
|
|
|
449
444
|
#### AuthorizationCodeOptions
|
|
450
445
|
|
|
451
446
|
| Prop | Type | Description |
|
|
452
447
|
| -------------- | ---------------------------------------------- | ----------- |
|
|
453
|
-
| **`provider`** | <code>'
|
|
448
|
+
| **`provider`** | <code>'apple' \| 'google' \| 'facebook'</code> | Provider |
|
|
449
|
+
|
|
450
|
+
|
|
451
|
+
### Type Aliases
|
|
452
|
+
|
|
453
|
+
|
|
454
|
+
#### ProviderResponseMap
|
|
455
|
+
|
|
456
|
+
<code>{ facebook: <a href="#facebookloginresponse">FacebookLoginResponse</a>; google: <a href="#googleloginresponse">GoogleLoginResponse</a>; apple: <a href="#appleproviderresponse">AppleProviderResponse</a>; }</code>
|
|
457
|
+
|
|
458
|
+
|
|
459
|
+
#### GoogleLoginResponse
|
|
460
|
+
|
|
461
|
+
<code><a href="#googleloginresponseonline">GoogleLoginResponseOnline</a> | <a href="#googleloginresponseoffline">GoogleLoginResponseOffline</a></code>
|
|
462
|
+
|
|
463
|
+
|
|
464
|
+
#### LoginOptions
|
|
465
|
+
|
|
466
|
+
<code>{ provider: "facebook"; options: <a href="#facebookloginoptions">FacebookLoginOptions</a>; } | { provider: "google"; options: <a href="#googleloginoptions">GoogleLoginOptions</a>; } | { provider: "apple"; options: <a href="#appleprovideroptions">AppleProviderOptions</a>; }</code>
|
|
467
|
+
|
|
468
|
+
|
|
469
|
+
#### Extract
|
|
470
|
+
|
|
471
|
+
<a href="#extract">Extract</a> from T those types that are assignable to U
|
|
472
|
+
|
|
473
|
+
<code>T extends U ? T : never</code>
|
|
454
474
|
|
|
455
475
|
</docgen-api>
|
package/android/build.gradle
CHANGED
|
@@ -63,4 +63,5 @@ dependencies {
|
|
|
63
63
|
testImplementation "junit:junit:$junitVersion"
|
|
64
64
|
androidTestImplementation "androidx.test.ext:junit:$androidxJunitVersion"
|
|
65
65
|
androidTestImplementation "androidx.test.espresso:espresso-core:$androidxEspressoCoreVersion"
|
|
66
|
+
implementation 'androidx.concurrent:concurrent-futures:1.2.0'
|
|
66
67
|
}
|
|
@@ -189,16 +189,15 @@ public class AppleProvider implements SocialProvider {
|
|
|
189
189
|
}
|
|
190
190
|
}
|
|
191
191
|
|
|
192
|
-
this.appleAuthURLFull =
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
state;
|
|
192
|
+
this.appleAuthURLFull = AUTHURL +
|
|
193
|
+
"?client_id=" +
|
|
194
|
+
this.clientId +
|
|
195
|
+
"&redirect_uri=" +
|
|
196
|
+
this.redirectUrl +
|
|
197
|
+
"&response_type=code&scope=" +
|
|
198
|
+
scopes +
|
|
199
|
+
"&response_mode=form_post&state=" +
|
|
200
|
+
state;
|
|
202
201
|
|
|
203
202
|
if (nonce != null) {
|
|
204
203
|
this.appleAuthURLFull += "&nonce=" + nonce;
|
|
@@ -11,7 +11,6 @@ import com.facebook.FacebookCallback;
|
|
|
11
11
|
import com.facebook.FacebookException;
|
|
12
12
|
import com.facebook.FacebookSdk;
|
|
13
13
|
import com.facebook.GraphRequest;
|
|
14
|
-
import com.facebook.GraphResponse;
|
|
15
14
|
import com.facebook.login.LoginBehavior;
|
|
16
15
|
import com.facebook.login.LoginManager;
|
|
17
16
|
import com.facebook.login.LoginResult;
|
|
@@ -21,6 +20,7 @@ import com.getcapacitor.PluginCall;
|
|
|
21
20
|
import ee.forgr.capacitor.social.login.helpers.JsonHelper;
|
|
22
21
|
import ee.forgr.capacitor.social.login.helpers.SocialProvider;
|
|
23
22
|
import java.util.Collection;
|
|
23
|
+
import java.util.concurrent.CountDownLatch;
|
|
24
24
|
import org.json.JSONException;
|
|
25
25
|
import org.json.JSONObject;
|
|
26
26
|
|
|
@@ -212,38 +212,48 @@ public class FacebookProvider implements SocialProvider {
|
|
|
212
212
|
|
|
213
213
|
private JSObject createProfileObject(AccessToken accessToken) {
|
|
214
214
|
JSObject profileObject = new JSObject();
|
|
215
|
+
CountDownLatch latch = new CountDownLatch(1);
|
|
216
|
+
|
|
215
217
|
GraphRequest request = GraphRequest.newMeRequest(
|
|
216
218
|
accessToken,
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
JSONObject
|
|
232
|
-
if (
|
|
233
|
-
|
|
234
|
-
if (dataObject != null) {
|
|
235
|
-
profileObject.put("imageURL", dataObject.optString("url", ""));
|
|
236
|
-
}
|
|
219
|
+
(object, response) -> {
|
|
220
|
+
if (response.getError() != null) {
|
|
221
|
+
Log.e(
|
|
222
|
+
LOG_TAG,
|
|
223
|
+
"Error fetching profile",
|
|
224
|
+
response.getError().getException()
|
|
225
|
+
);
|
|
226
|
+
} else {
|
|
227
|
+
profileObject.put("userID", object.optString("id", ""));
|
|
228
|
+
profileObject.put("email", object.optString("email", ""));
|
|
229
|
+
profileObject.put("name", object.optString("name", ""));
|
|
230
|
+
|
|
231
|
+
JSONObject pictureObject = object.optJSONObject("picture");
|
|
232
|
+
if (pictureObject != null) {
|
|
233
|
+
JSONObject dataObject = pictureObject.optJSONObject("data");
|
|
234
|
+
if (dataObject != null) {
|
|
235
|
+
profileObject.put("imageURL", dataObject.optString("url", ""));
|
|
237
236
|
}
|
|
238
|
-
// Add other fields as needed
|
|
239
237
|
}
|
|
240
238
|
}
|
|
239
|
+
latch.countDown();
|
|
241
240
|
}
|
|
242
241
|
);
|
|
242
|
+
|
|
243
243
|
Bundle parameters = new Bundle();
|
|
244
244
|
parameters.putString("fields", "id,name,email,picture.type(large)");
|
|
245
245
|
request.setParameters(parameters);
|
|
246
|
-
|
|
246
|
+
|
|
247
|
+
new Thread(() -> {
|
|
248
|
+
request.executeAndWait();
|
|
249
|
+
}).start();
|
|
250
|
+
|
|
251
|
+
try {
|
|
252
|
+
latch.await();
|
|
253
|
+
} catch (InterruptedException e) {
|
|
254
|
+
Log.e(LOG_TAG, "Interrupted while waiting for profile fetch", e);
|
|
255
|
+
}
|
|
256
|
+
|
|
247
257
|
return profileObject;
|
|
248
258
|
}
|
|
249
259
|
}
|