@capgo/capacitor-social-login 0.0.72 → 0.0.76
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 +34 -29
- 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 +14 -0
- package/dist/docs.json +67 -84
- package/dist/esm/definitions.d.ts +32 -26
- package/dist/esm/definitions.js.map +1 -1
- package/dist/esm/web.d.ts +10 -2
- package/dist/esm/web.js +114 -45
- package/dist/esm/web.js.map +1 -1
- package/dist/plugin.cjs.js +114 -45
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +114 -45
- package/dist/plugin.js.map +1 -1
- package/ios/Sources/SocialLoginPlugin/GoogleProvider.swift +17 -29
- 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
|
|
|
@@ -347,14 +348,6 @@ Refresh the access token
|
|
|
347
348
|
| **`apple`** | <code>{ clientId?: string; redirectUrl?: string; }</code> |
|
|
348
349
|
|
|
349
350
|
|
|
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 |
|
|
356
|
-
|
|
357
|
-
|
|
358
351
|
#### FacebookLoginResponse
|
|
359
352
|
|
|
360
353
|
| Prop | Type |
|
|
@@ -397,14 +390,6 @@ Refresh the access token
|
|
|
397
390
|
| **`profile`** | <code>{ user: string; email: string \| null; givenName: string \| null; familyName: string \| null; }</code> |
|
|
398
391
|
|
|
399
392
|
|
|
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
393
|
#### FacebookLoginOptions
|
|
409
394
|
|
|
410
395
|
| Prop | Type | Description | Default |
|
|
@@ -416,11 +401,11 @@ Refresh the access token
|
|
|
416
401
|
|
|
417
402
|
#### GoogleLoginOptions
|
|
418
403
|
|
|
419
|
-
| Prop | Type | Description
|
|
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 |
|
|
404
|
+
| Prop | Type | Description | Default | Since |
|
|
405
|
+
| ------------------------ | --------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------ | ------ |
|
|
406
|
+
| **`scopes`** | <code>string[]</code> | Specifies the scopes required for accessing Google APIs The default is defined in the configuration. | | |
|
|
407
|
+
| **`nonce`** | <code>string</code> | Nonce | | |
|
|
408
|
+
| **`grantOfflineAccess`** | <code>boolean</code> | Set if your application needs to refresh access tokens when the user is not present at the browser. it will add offline_access to the scopes In response use `serverAuthCode` key | <code>false</code> | 0.0.69 |
|
|
424
409
|
|
|
425
410
|
|
|
426
411
|
#### AppleProviderOptions
|
|
@@ -436,7 +421,7 @@ Refresh the access token
|
|
|
436
421
|
|
|
437
422
|
| Prop | Type | Description |
|
|
438
423
|
| -------------- | ---------------------------------------------- | ----------- |
|
|
439
|
-
| **`provider`** | <code>'
|
|
424
|
+
| **`provider`** | <code>'apple' \| 'google' \| 'facebook'</code> | Provider |
|
|
440
425
|
|
|
441
426
|
|
|
442
427
|
#### AuthorizationCode
|
|
@@ -450,6 +435,26 @@ Refresh the access token
|
|
|
450
435
|
|
|
451
436
|
| Prop | Type | Description |
|
|
452
437
|
| -------------- | ---------------------------------------------- | ----------- |
|
|
453
|
-
| **`provider`** | <code>'
|
|
438
|
+
| **`provider`** | <code>'apple' \| 'google' \| 'facebook'</code> | Provider |
|
|
439
|
+
|
|
440
|
+
|
|
441
|
+
### Type Aliases
|
|
442
|
+
|
|
443
|
+
|
|
444
|
+
#### ProviderResponseMap
|
|
445
|
+
|
|
446
|
+
<code>{ facebook: <a href="#facebookloginresponse">FacebookLoginResponse</a>; google: <a href="#googleloginresponse">GoogleLoginResponse</a>; apple: <a href="#appleproviderresponse">AppleProviderResponse</a>; }</code>
|
|
447
|
+
|
|
448
|
+
|
|
449
|
+
#### LoginOptions
|
|
450
|
+
|
|
451
|
+
<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>
|
|
452
|
+
|
|
453
|
+
|
|
454
|
+
#### Extract
|
|
455
|
+
|
|
456
|
+
<a href="#extract">Extract</a> from T those types that are assignable to U
|
|
457
|
+
|
|
458
|
+
<code>T extends U ? T : never</code>
|
|
454
459
|
|
|
455
460
|
</docgen-api>
|
|
@@ -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
|
}
|
|
@@ -23,6 +23,8 @@ import com.google.android.libraries.identity.googleid.GetSignInWithGoogleOption;
|
|
|
23
23
|
import com.google.android.libraries.identity.googleid.GoogleIdTokenCredential;
|
|
24
24
|
import ee.forgr.capacitor.social.login.helpers.SocialProvider;
|
|
25
25
|
import java.io.IOException;
|
|
26
|
+
import java.util.HashSet;
|
|
27
|
+
import java.util.Set;
|
|
26
28
|
import java.util.concurrent.Callable;
|
|
27
29
|
import java.util.concurrent.Executor;
|
|
28
30
|
import java.util.concurrent.ExecutorService;
|
|
@@ -93,6 +95,18 @@ public class GoogleProvider implements SocialProvider {
|
|
|
93
95
|
|
|
94
96
|
// Extract scopes from the config
|
|
95
97
|
JSONArray scopesArray = config.optJSONArray("scopes");
|
|
98
|
+
boolean grantOfflineAccess = config.optBoolean("grantOfflineAccess", false);
|
|
99
|
+
if (grantOfflineAccess) {
|
|
100
|
+
scopesArray.put("offline_access");
|
|
101
|
+
}
|
|
102
|
+
// Remove duplicates from scopes array
|
|
103
|
+
if (scopesArray != null) {
|
|
104
|
+
Set<String> uniqueScopes = new HashSet<>();
|
|
105
|
+
for (int i = 0; i < scopesArray.length(); i++) {
|
|
106
|
+
uniqueScopes.add(scopesArray.optString(i));
|
|
107
|
+
}
|
|
108
|
+
scopesArray = new JSONArray(uniqueScopes);
|
|
109
|
+
}
|
|
96
110
|
if (scopesArray != null) {
|
|
97
111
|
this.scopes = new String[scopesArray.length()];
|
|
98
112
|
for (int i = 0; i < scopesArray.length(); i++) {
|
package/dist/docs.json
CHANGED
|
@@ -30,15 +30,15 @@
|
|
|
30
30
|
},
|
|
31
31
|
{
|
|
32
32
|
"name": "login",
|
|
33
|
-
"signature": "(options: LoginOptions) => Promise<
|
|
33
|
+
"signature": "<T extends \"apple\" | \"google\" | \"facebook\">(options: Extract<LoginOptions, { provider: T; }>) => Promise<{ provider: T; result: ProviderResponseMap[T]; }>",
|
|
34
34
|
"parameters": [
|
|
35
35
|
{
|
|
36
36
|
"name": "options",
|
|
37
37
|
"docs": "",
|
|
38
|
-
"type": "
|
|
38
|
+
"type": "Extract<{ provider: 'facebook'; options: FacebookLoginOptions; }, { provider: T; }> | Extract<{ provider: 'google'; options: GoogleLoginOptions; }, { provider: T; }> | Extract<{ provider: 'apple'; options: AppleProviderOptions; }, { provider: T; }>"
|
|
39
39
|
}
|
|
40
40
|
],
|
|
41
|
-
"returns": "Promise<
|
|
41
|
+
"returns": "Promise<{ provider: T; result: ProviderResponseMap[T]; }>",
|
|
42
42
|
"tags": [
|
|
43
43
|
{
|
|
44
44
|
"name": "description",
|
|
@@ -47,8 +47,10 @@
|
|
|
47
47
|
],
|
|
48
48
|
"docs": "Login with the selected provider",
|
|
49
49
|
"complexTypes": [
|
|
50
|
-
"
|
|
51
|
-
"
|
|
50
|
+
"T",
|
|
51
|
+
"ProviderResponseMap",
|
|
52
|
+
"LoginOptions",
|
|
53
|
+
"Extract"
|
|
52
54
|
],
|
|
53
55
|
"slug": "login"
|
|
54
56
|
},
|
|
@@ -59,7 +61,7 @@
|
|
|
59
61
|
{
|
|
60
62
|
"name": "options",
|
|
61
63
|
"docs": "",
|
|
62
|
-
"type": "{ provider: '
|
|
64
|
+
"type": "{ provider: 'apple' | 'google' | 'facebook'; }"
|
|
63
65
|
}
|
|
64
66
|
],
|
|
65
67
|
"returns": "Promise<void>",
|
|
@@ -177,43 +179,6 @@
|
|
|
177
179
|
}
|
|
178
180
|
]
|
|
179
181
|
},
|
|
180
|
-
{
|
|
181
|
-
"name": "LoginResult",
|
|
182
|
-
"slug": "loginresult",
|
|
183
|
-
"docs": "",
|
|
184
|
-
"tags": [],
|
|
185
|
-
"methods": [],
|
|
186
|
-
"properties": [
|
|
187
|
-
{
|
|
188
|
-
"name": "provider",
|
|
189
|
-
"tags": [
|
|
190
|
-
{
|
|
191
|
-
"text": "select provider to login with",
|
|
192
|
-
"name": "description"
|
|
193
|
-
}
|
|
194
|
-
],
|
|
195
|
-
"docs": "Provider",
|
|
196
|
-
"complexTypes": [],
|
|
197
|
-
"type": "'facebook' | 'google' | 'apple' | 'twitter'"
|
|
198
|
-
},
|
|
199
|
-
{
|
|
200
|
-
"name": "result",
|
|
201
|
-
"tags": [
|
|
202
|
-
{
|
|
203
|
-
"text": "payload to login with",
|
|
204
|
-
"name": "description"
|
|
205
|
-
}
|
|
206
|
-
],
|
|
207
|
-
"docs": "Payload",
|
|
208
|
-
"complexTypes": [
|
|
209
|
-
"FacebookLoginResponse",
|
|
210
|
-
"GoogleLoginResponse",
|
|
211
|
-
"AppleProviderResponse"
|
|
212
|
-
],
|
|
213
|
-
"type": "FacebookLoginResponse | GoogleLoginResponse | AppleProviderResponse"
|
|
214
|
-
}
|
|
215
|
-
]
|
|
216
|
-
},
|
|
217
182
|
{
|
|
218
183
|
"name": "FacebookLoginResponse",
|
|
219
184
|
"slug": "facebookloginresponse",
|
|
@@ -382,43 +347,6 @@
|
|
|
382
347
|
}
|
|
383
348
|
]
|
|
384
349
|
},
|
|
385
|
-
{
|
|
386
|
-
"name": "LoginOptions",
|
|
387
|
-
"slug": "loginoptions",
|
|
388
|
-
"docs": "",
|
|
389
|
-
"tags": [],
|
|
390
|
-
"methods": [],
|
|
391
|
-
"properties": [
|
|
392
|
-
{
|
|
393
|
-
"name": "provider",
|
|
394
|
-
"tags": [
|
|
395
|
-
{
|
|
396
|
-
"text": "select provider to login with",
|
|
397
|
-
"name": "description"
|
|
398
|
-
}
|
|
399
|
-
],
|
|
400
|
-
"docs": "Provider",
|
|
401
|
-
"complexTypes": [],
|
|
402
|
-
"type": "'facebook' | 'google' | 'apple' | 'twitter'"
|
|
403
|
-
},
|
|
404
|
-
{
|
|
405
|
-
"name": "options",
|
|
406
|
-
"tags": [
|
|
407
|
-
{
|
|
408
|
-
"text": "payload to login with",
|
|
409
|
-
"name": "description"
|
|
410
|
-
}
|
|
411
|
-
],
|
|
412
|
-
"docs": "Options",
|
|
413
|
-
"complexTypes": [
|
|
414
|
-
"FacebookLoginOptions",
|
|
415
|
-
"GoogleLoginOptions",
|
|
416
|
-
"AppleProviderOptions"
|
|
417
|
-
],
|
|
418
|
-
"type": "FacebookLoginOptions | GoogleLoginOptions | AppleProviderOptions"
|
|
419
|
-
}
|
|
420
|
-
]
|
|
421
|
-
},
|
|
422
350
|
{
|
|
423
351
|
"name": "FacebookLoginOptions",
|
|
424
352
|
"slug": "facebookloginoptions",
|
|
@@ -515,7 +443,7 @@
|
|
|
515
443
|
"name": "since"
|
|
516
444
|
}
|
|
517
445
|
],
|
|
518
|
-
"docs": "Set if your application needs to refresh access tokens when the user is not present at the browser
|
|
446
|
+
"docs": "Set if your application needs to refresh access tokens when the user is not present at the browser. it will add offline_access to the scopes\nIn response use `serverAuthCode` key",
|
|
519
447
|
"complexTypes": [],
|
|
520
448
|
"type": "boolean | undefined"
|
|
521
449
|
}
|
|
@@ -587,7 +515,7 @@
|
|
|
587
515
|
],
|
|
588
516
|
"docs": "Provider",
|
|
589
517
|
"complexTypes": [],
|
|
590
|
-
"type": "'
|
|
518
|
+
"type": "'apple' | 'google' | 'facebook'"
|
|
591
519
|
}
|
|
592
520
|
]
|
|
593
521
|
},
|
|
@@ -629,12 +557,67 @@
|
|
|
629
557
|
],
|
|
630
558
|
"docs": "Provider",
|
|
631
559
|
"complexTypes": [],
|
|
632
|
-
"type": "'
|
|
560
|
+
"type": "'apple' | 'google' | 'facebook'"
|
|
633
561
|
}
|
|
634
562
|
]
|
|
635
563
|
}
|
|
636
564
|
],
|
|
637
565
|
"enums": [],
|
|
638
|
-
"typeAliases": [
|
|
566
|
+
"typeAliases": [
|
|
567
|
+
{
|
|
568
|
+
"name": "ProviderResponseMap",
|
|
569
|
+
"slug": "providerresponsemap",
|
|
570
|
+
"docs": "",
|
|
571
|
+
"types": [
|
|
572
|
+
{
|
|
573
|
+
"text": "{\n facebook: FacebookLoginResponse;\n google: GoogleLoginResponse;\n apple: AppleProviderResponse;\n}",
|
|
574
|
+
"complexTypes": [
|
|
575
|
+
"FacebookLoginResponse",
|
|
576
|
+
"GoogleLoginResponse",
|
|
577
|
+
"AppleProviderResponse"
|
|
578
|
+
]
|
|
579
|
+
}
|
|
580
|
+
]
|
|
581
|
+
},
|
|
582
|
+
{
|
|
583
|
+
"name": "LoginOptions",
|
|
584
|
+
"slug": "loginoptions",
|
|
585
|
+
"docs": "",
|
|
586
|
+
"types": [
|
|
587
|
+
{
|
|
588
|
+
"text": "{\n provider: \"facebook\";\n options: FacebookLoginOptions;\n }",
|
|
589
|
+
"complexTypes": [
|
|
590
|
+
"FacebookLoginOptions"
|
|
591
|
+
]
|
|
592
|
+
},
|
|
593
|
+
{
|
|
594
|
+
"text": "{\n provider: \"google\";\n options: GoogleLoginOptions;\n }",
|
|
595
|
+
"complexTypes": [
|
|
596
|
+
"GoogleLoginOptions"
|
|
597
|
+
]
|
|
598
|
+
},
|
|
599
|
+
{
|
|
600
|
+
"text": "{\n provider: \"apple\";\n options: AppleProviderOptions;\n }",
|
|
601
|
+
"complexTypes": [
|
|
602
|
+
"AppleProviderOptions"
|
|
603
|
+
]
|
|
604
|
+
}
|
|
605
|
+
]
|
|
606
|
+
},
|
|
607
|
+
{
|
|
608
|
+
"name": "Extract",
|
|
609
|
+
"slug": "extract",
|
|
610
|
+
"docs": "Extract from T those types that are assignable to U",
|
|
611
|
+
"types": [
|
|
612
|
+
{
|
|
613
|
+
"text": "T extends U ? T : never",
|
|
614
|
+
"complexTypes": [
|
|
615
|
+
"T",
|
|
616
|
+
"U"
|
|
617
|
+
]
|
|
618
|
+
}
|
|
619
|
+
]
|
|
620
|
+
}
|
|
621
|
+
],
|
|
639
622
|
"pluginConfigs": []
|
|
640
623
|
}
|
|
@@ -75,7 +75,7 @@ export interface GoogleLoginOptions {
|
|
|
75
75
|
*/
|
|
76
76
|
nonce?: string;
|
|
77
77
|
/**
|
|
78
|
-
* Set if your application needs to refresh access tokens when the user is not present at the browser.
|
|
78
|
+
* Set if your application needs to refresh access tokens when the user is not present at the browser. it will add offline_access to the scopes
|
|
79
79
|
* In response use `serverAuthCode` key
|
|
80
80
|
*
|
|
81
81
|
* @default false
|
|
@@ -124,30 +124,26 @@ export interface AppleProviderResponse {
|
|
|
124
124
|
familyName: string | null;
|
|
125
125
|
};
|
|
126
126
|
}
|
|
127
|
-
export
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
provider: "
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
* @description payload to login with
|
|
148
|
-
*/
|
|
149
|
-
result: FacebookLoginResponse | GoogleLoginResponse | AppleProviderResponse;
|
|
150
|
-
}
|
|
127
|
+
export type LoginOptions = {
|
|
128
|
+
provider: "facebook";
|
|
129
|
+
options: FacebookLoginOptions;
|
|
130
|
+
} | {
|
|
131
|
+
provider: "google";
|
|
132
|
+
options: GoogleLoginOptions;
|
|
133
|
+
} | {
|
|
134
|
+
provider: "apple";
|
|
135
|
+
options: AppleProviderOptions;
|
|
136
|
+
};
|
|
137
|
+
export type LoginResult = {
|
|
138
|
+
provider: "facebook";
|
|
139
|
+
result: FacebookLoginResponse;
|
|
140
|
+
} | {
|
|
141
|
+
provider: "google";
|
|
142
|
+
result: GoogleLoginResponse;
|
|
143
|
+
} | {
|
|
144
|
+
provider: "apple";
|
|
145
|
+
result: AppleProviderResponse;
|
|
146
|
+
};
|
|
151
147
|
export interface AccessToken {
|
|
152
148
|
applicationId?: string;
|
|
153
149
|
declinedPermissions?: string[];
|
|
@@ -206,6 +202,11 @@ export interface isLoggedInOptions {
|
|
|
206
202
|
*/
|
|
207
203
|
provider: "apple" | "google" | "facebook";
|
|
208
204
|
}
|
|
205
|
+
export type ProviderResponseMap = {
|
|
206
|
+
facebook: FacebookLoginResponse;
|
|
207
|
+
google: GoogleLoginResponse;
|
|
208
|
+
apple: AppleProviderResponse;
|
|
209
|
+
};
|
|
209
210
|
export interface SocialLoginPlugin {
|
|
210
211
|
/**
|
|
211
212
|
* Initialize the plugin
|
|
@@ -216,7 +217,12 @@ export interface SocialLoginPlugin {
|
|
|
216
217
|
* Login with the selected provider
|
|
217
218
|
* @description login with the selected provider
|
|
218
219
|
*/
|
|
219
|
-
login(options: LoginOptions
|
|
220
|
+
login<T extends LoginOptions["provider"]>(options: Extract<LoginOptions, {
|
|
221
|
+
provider: T;
|
|
222
|
+
}>): Promise<{
|
|
223
|
+
provider: T;
|
|
224
|
+
result: ProviderResponseMap[T];
|
|
225
|
+
}>;
|
|
220
226
|
/**
|
|
221
227
|
* Logout
|
|
222
228
|
* @description logout the user
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["export interface InitializeOptions {\n facebook?: {\n /**\n * Facebook App ID, provided by Facebook for web, in mobile it's set in the native files\n */\n appId: string;\n /**\n * Facebook Client Token, provided by Facebook for web, in mobile it's set in the native files\n */\n clientToken: string;\n };\n\n google?: {\n /**\n * The app's client ID, found and created in the Google Developers Console.\n * For iOS.\n * @example xxxxxx-xxxxxxxxxxxxxxxxxx.apps.googleusercontent.com\n * @since 3.1.0\n */\n iOSClientId?: string;\n /**\n * The app's server client ID, found and created in the Google Developers Console.\n * For iOS.\n * @example xxxxxx-xxxxxxxxxxxxxxxxxx.apps.googleusercontent.com\n * @since 3.1.0\n */\n iOSServerClientId?: string;\n /**\n * The app's web client ID, found and created in the Google Developers Console.\n * For Android (and web in the future).\n * @example xxxxxx-xxxxxxxxxxxxxxxxxx.apps.googleusercontent.com\n * @since 3.1.0\n */\n webClientId?: string;\n };\n apple?: {\n /**\n * Apple Client ID, provided by Apple for web and Android\n */\n clientId?: string;\n /**\n * Apple Redirect URL, should be your backend url that is configured in your apple app, only for android\n */\n redirectUrl?: string;\n };\n}\n\nexport interface FacebookLoginOptions {\n /**\n * Permissions\n * @description select permissions to login with\n */\n permissions: string[];\n /**\n * Is Limited Login\n * @description use limited login for Facebook IOS\n * @default false\n */\n limitedLogin?: boolean;\n /**\n * Nonce\n * @description A custom nonce to use for the login request\n */\n nonce?: string;\n}\n\nexport interface GoogleLoginOptions {\n /**\n * Specifies the scopes required for accessing Google APIs\n * The default is defined in the configuration.\n * @example [\"profile\", \"email\"]\n * @see [Google OAuth2 Scopes](https://developers.google.com/identity/protocols/oauth2/scopes)\n */\n scopes?: string[];\n /**\n * Nonce\n * @description nonce\n */\n nonce?: string;\n /**\n * Set if your application needs to refresh access tokens when the user is not present at the browser
|
|
1
|
+
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["export interface InitializeOptions {\n facebook?: {\n /**\n * Facebook App ID, provided by Facebook for web, in mobile it's set in the native files\n */\n appId: string;\n /**\n * Facebook Client Token, provided by Facebook for web, in mobile it's set in the native files\n */\n clientToken: string;\n };\n\n google?: {\n /**\n * The app's client ID, found and created in the Google Developers Console.\n * For iOS.\n * @example xxxxxx-xxxxxxxxxxxxxxxxxx.apps.googleusercontent.com\n * @since 3.1.0\n */\n iOSClientId?: string;\n /**\n * The app's server client ID, found and created in the Google Developers Console.\n * For iOS.\n * @example xxxxxx-xxxxxxxxxxxxxxxxxx.apps.googleusercontent.com\n * @since 3.1.0\n */\n iOSServerClientId?: string;\n /**\n * The app's web client ID, found and created in the Google Developers Console.\n * For Android (and web in the future).\n * @example xxxxxx-xxxxxxxxxxxxxxxxxx.apps.googleusercontent.com\n * @since 3.1.0\n */\n webClientId?: string;\n };\n apple?: {\n /**\n * Apple Client ID, provided by Apple for web and Android\n */\n clientId?: string;\n /**\n * Apple Redirect URL, should be your backend url that is configured in your apple app, only for android\n */\n redirectUrl?: string;\n };\n}\n\nexport interface FacebookLoginOptions {\n /**\n * Permissions\n * @description select permissions to login with\n */\n permissions: string[];\n /**\n * Is Limited Login\n * @description use limited login for Facebook IOS\n * @default false\n */\n limitedLogin?: boolean;\n /**\n * Nonce\n * @description A custom nonce to use for the login request\n */\n nonce?: string;\n}\n\nexport interface GoogleLoginOptions {\n /**\n * Specifies the scopes required for accessing Google APIs\n * The default is defined in the configuration.\n * @example [\"profile\", \"email\"]\n * @see [Google OAuth2 Scopes](https://developers.google.com/identity/protocols/oauth2/scopes)\n */\n scopes?: string[];\n /**\n * Nonce\n * @description nonce\n */\n nonce?: string;\n /**\n * Set if your application needs to refresh access tokens when the user is not present at the browser. it will add offline_access to the scopes\n * In response use `serverAuthCode` key\n *\n * @default false\n * @since 0.0.69\n * */\n grantOfflineAccess?: boolean;\n}\n\nexport interface GoogleLoginResponse {\n accessToken: AccessToken | null;\n idToken: string | null;\n profile: {\n email: string | null;\n familyName: string | null;\n givenName: string | null;\n id: string | null;\n name: string | null;\n imageUrl: string | null;\n };\n}\n\nexport interface AppleProviderOptions {\n /**\n * Scopes\n * @description An array of scopes to request during login\n * @example [\"name\", \"email\"]\n * default: [\"name\", \"email\"]\n */\n scopes?: string[];\n /**\n * Nonce\n * @description nonce\n */\n nonce?: string;\n /**\n * State\n * @description state\n */\n state?: string;\n}\n\nexport interface AppleProviderResponse {\n accessToken: AccessToken | null;\n idToken: string | null;\n profile: {\n user: string;\n email: string | null;\n givenName: string | null;\n familyName: string | null;\n };\n}\n\nexport type LoginOptions =\n | {\n provider: \"facebook\";\n options: FacebookLoginOptions;\n }\n | {\n provider: \"google\";\n options: GoogleLoginOptions;\n }\n | {\n provider: \"apple\";\n options: AppleProviderOptions;\n };\n\nexport type LoginResult =\n | {\n provider: \"facebook\";\n result: FacebookLoginResponse;\n }\n | {\n provider: \"google\";\n result: GoogleLoginResponse;\n }\n | {\n provider: \"apple\";\n result: AppleProviderResponse;\n };\n\nexport interface AccessToken {\n applicationId?: string;\n declinedPermissions?: string[];\n expires?: string;\n isExpired?: boolean;\n lastRefresh?: string;\n permissions?: string[];\n token: string;\n refreshToken?: string;\n userId?: string;\n}\n\nexport interface FacebookLoginResponse {\n accessToken: AccessToken | null;\n idToken: string | null;\n profile: {\n userID: string;\n email: string | null;\n friendIDs: string[];\n birthday: string | null;\n ageRange: { min?: number; max?: number } | null;\n gender: string | null;\n location: { id: string; name: string } | null;\n hometown: { id: string; name: string } | null;\n profileURL: string | null;\n name: string | null;\n imageURL: string | null;\n };\n}\n\nexport interface AuthorizationCode {\n /**\n * Jwt\n * @description A JSON web token\n */\n jwt: string;\n}\n\nexport interface AuthorizationCodeOptions {\n /**\n * Provider\n * @description Provider for the authorization code\n */\n provider: \"apple\" | \"google\" | \"facebook\";\n}\n\nexport interface isLoggedInOptions {\n /**\n * Provider\n * @description Provider for the isLoggedIn\n */\n provider: \"apple\" | \"google\" | \"facebook\";\n}\n\n// Add a helper type to map providers to their response types\nexport type ProviderResponseMap = {\n facebook: FacebookLoginResponse;\n google: GoogleLoginResponse;\n apple: AppleProviderResponse;\n};\n\nexport interface SocialLoginPlugin {\n /**\n * Initialize the plugin\n * @description initialize the plugin with the required options\n */\n initialize(options: InitializeOptions): Promise<void>;\n /**\n * Login with the selected provider\n * @description login with the selected provider\n */\n login<T extends LoginOptions[\"provider\"]>(\n options: Extract<LoginOptions, { provider: T }>,\n ): Promise<{ provider: T; result: ProviderResponseMap[T] }>;\n /**\n * Logout\n * @description logout the user\n */\n logout(options: { provider: \"apple\" | \"google\" | \"facebook\" }): Promise<void>;\n /**\n * IsLoggedIn\n * @description logout the user\n */\n isLoggedIn(options: isLoggedInOptions): Promise<{ isLoggedIn: boolean }>;\n\n /**\n * Get the current access token\n * @description get the current access token\n */\n getAuthorizationCode(\n options: AuthorizationCodeOptions,\n ): Promise<AuthorizationCode>;\n /**\n * Refresh the access token\n * @description refresh the access token\n */\n refresh(options: LoginOptions): Promise<void>;\n}\n"]}
|
package/dist/esm/web.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { WebPlugin } from "@capacitor/core";
|
|
2
|
-
import type { SocialLoginPlugin, InitializeOptions, LoginOptions,
|
|
2
|
+
import type { SocialLoginPlugin, InitializeOptions, LoginOptions, AuthorizationCode, isLoggedInOptions, AuthorizationCodeOptions, ProviderResponseMap } from "./definitions";
|
|
3
3
|
export declare class SocialLoginWeb extends WebPlugin implements SocialLoginPlugin {
|
|
4
|
+
private static readonly OAUTH_STATE_KEY;
|
|
4
5
|
private googleClientId;
|
|
5
6
|
private appleClientId;
|
|
6
7
|
private googleScriptLoaded;
|
|
@@ -8,8 +9,15 @@ export declare class SocialLoginWeb extends WebPlugin implements SocialLoginPlug
|
|
|
8
9
|
private appleScriptUrl;
|
|
9
10
|
private facebookAppId;
|
|
10
11
|
private facebookScriptLoaded;
|
|
12
|
+
constructor();
|
|
13
|
+
private handleOAuthRedirect;
|
|
11
14
|
initialize(options: InitializeOptions): Promise<void>;
|
|
12
|
-
login(options: LoginOptions
|
|
15
|
+
login<T extends LoginOptions["provider"]>(options: Extract<LoginOptions, {
|
|
16
|
+
provider: T;
|
|
17
|
+
}>): Promise<{
|
|
18
|
+
provider: T;
|
|
19
|
+
result: ProviderResponseMap[T];
|
|
20
|
+
}>;
|
|
13
21
|
logout(options: {
|
|
14
22
|
provider: "apple" | "google" | "facebook";
|
|
15
23
|
}): Promise<void>;
|