@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 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<LoginResult>
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="#loginoptions">LoginOptions</a></code> |
266
+ | Param | Type |
267
+ | ------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
268
+ | **`options`** | <code><a href="#extract">Extract</a>&lt;{ provider: 'facebook'; options: <a href="#facebookloginoptions">FacebookLoginOptions</a>; }, { provider: T; }&gt; \| <a href="#extract">Extract</a>&lt;{ provider: 'google'; options: <a href="#googleloginoptions">GoogleLoginOptions</a>; }, { provider: T; }&gt; \| <a href="#extract">Extract</a>&lt;{ provider: 'apple'; options: <a href="#appleprovideroptions">AppleProviderOptions</a>; }, { provider: T; }&gt;</code> |
268
269
 
269
- **Returns:** <code>Promise&lt;<a href="#loginresult">LoginResult</a>&gt;</code>
270
+ **Returns:** <code>Promise&lt;{ provider: T; result: ProviderResponseMap[T]; }&gt;</code>
270
271
 
271
272
  --------------------
272
273
 
@@ -281,7 +282,7 @@ Logout
281
282
 
282
283
  | Param | Type |
283
284
  | ------------- | ------------------------------------------------------------- |
284
- | **`options`** | <code>{ provider: 'facebook' \| 'google' \| 'apple'; }</code> |
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
- #### GoogleLoginResponse
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
- | Prop | Type |
385
- | ----------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
386
- | **`accessToken`** | <code><a href="#accesstoken">AccessToken</a> \| null</code> |
387
- | **`idToken`** | <code>string \| null</code> |
388
- | **`profile`** | <code>{ email: string \| null; familyName: string \| null; givenName: string \| null; id: string \| null; name: string \| null; imageUrl: string \| null; }</code> |
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 | Type | Description | Default | Since |
420
- | ------------------------ | --------------------- | ---------------------------------------------------------------------------------------------------------------------------------------- | ------------------ | ------ |
421
- | **`scopes`** | <code>string[]</code> | Specifies the scopes required for accessing Google APIs The default is defined in the configuration. | | |
422
- | **`nonce`** | <code>string</code> | Nonce | | |
423
- | **`grantOfflineAccess`** | <code>boolean</code> | Set if your application needs to refresh access tokens when the user is not present at the browser. In response use `serverAuthCode` key | <code>false</code> | 0.0.69 |
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>'facebook' \| 'google' \| 'apple'</code> | Provider |
433
+ | **`provider`** | <code>'apple' \| 'google' \| 'facebook'</code> | Provider |
440
434
 
441
435
 
442
436
  #### AuthorizationCode
443
437
 
444
- | Prop | Type | Description |
445
- | --------- | ------------------- | ----------- |
446
- | **`jwt`** | <code>string</code> | 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>'facebook' \| 'google' \| 'apple'</code> | Provider |
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>
@@ -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
- AUTHURL +
194
- "?client_id=" +
195
- this.clientId +
196
- "&redirect_uri=" +
197
- this.redirectUrl +
198
- "&response_type=code&scope=" +
199
- scopes +
200
- "&response_mode=form_post&state=" +
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
- new GraphRequest.GraphJSONObjectCallback() {
218
- @Override
219
- public void onCompleted(JSONObject object, GraphResponse 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", ""));
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
- request.executeAndWait();
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
  }