@capgo/capacitor-social-login 8.2.21 → 8.2.23
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 +74 -0
- package/android/build.gradle +2 -1
- package/android/src/main/java/ee/forgr/capacitor/social/login/SocialLoginPlugin.java +93 -1
- package/dist/docs.json +70 -0
- package/dist/esm/definitions.d.ts +66 -0
- package/dist/esm/definitions.js.map +1 -1
- package/dist/esm/web.d.ts +2 -1
- package/dist/esm/web.js +33 -0
- package/dist/esm/web.js.map +1 -1
- package/dist/plugin.cjs.js +33 -0
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +33 -0
- package/dist/plugin.js.map +1 -1
- package/ios/Sources/SocialLoginPlugin/SocialLoginPlugin.swift +64 -2
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -625,6 +625,7 @@ For iOS, it will store data in the Keychain, which is Apple's secure credential
|
|
|
625
625
|
* [`refresh(...)`](#refresh)
|
|
626
626
|
* [`providerSpecificCall(...)`](#providerspecificcall)
|
|
627
627
|
* [`getPluginVersion()`](#getpluginversion)
|
|
628
|
+
* [`openSecureWindow(...)`](#opensecurewindow)
|
|
628
629
|
* [Interfaces](#interfaces)
|
|
629
630
|
* [Type Aliases](#type-aliases)
|
|
630
631
|
|
|
@@ -759,6 +760,63 @@ Get the native Capacitor plugin version
|
|
|
759
760
|
--------------------
|
|
760
761
|
|
|
761
762
|
|
|
763
|
+
### openSecureWindow(...)
|
|
764
|
+
|
|
765
|
+
```typescript
|
|
766
|
+
openSecureWindow(options: OpenSecureWindowOptions) => Promise<OpenSecureWindowResponse>
|
|
767
|
+
```
|
|
768
|
+
|
|
769
|
+
Opens a secured window for OAuth2 authentication.
|
|
770
|
+
For web, you should have the code in the redirected page to use a broadcast channel to send the redirected url to the app
|
|
771
|
+
Something like:
|
|
772
|
+
```html
|
|
773
|
+
<html>
|
|
774
|
+
<head></head>
|
|
775
|
+
<body>
|
|
776
|
+
<script>
|
|
777
|
+
const searchParams = new URLSearchParams(location.search)
|
|
778
|
+
if (searchParams.has("code")) {
|
|
779
|
+
new BroadcastChannel("my-channel-name").postMessage(location.href);
|
|
780
|
+
window.close();
|
|
781
|
+
}
|
|
782
|
+
</script>
|
|
783
|
+
</body>
|
|
784
|
+
</html>
|
|
785
|
+
```
|
|
786
|
+
For mobile, you should have a redirect uri that opens the app, something like: `myapp://oauth_callback/`
|
|
787
|
+
And make sure to register it in the app's info.plist:
|
|
788
|
+
```xml
|
|
789
|
+
<key>CFBundleURLTypes</key>
|
|
790
|
+
<array>
|
|
791
|
+
<dict>
|
|
792
|
+
<key>CFBundleURLSchemes</key>
|
|
793
|
+
<array>
|
|
794
|
+
<string>myapp</string>
|
|
795
|
+
</array>
|
|
796
|
+
</dict>
|
|
797
|
+
</array>
|
|
798
|
+
```
|
|
799
|
+
And in the AndroidManifest.xml file:
|
|
800
|
+
```xml
|
|
801
|
+
<activity>
|
|
802
|
+
<intent-filter>
|
|
803
|
+
<action android:name="android.intent.action.VIEW" />
|
|
804
|
+
<category android:name="android.intent.category.DEFAULT" />
|
|
805
|
+
<category android:name="android.intent.category.BROWSABLE" />
|
|
806
|
+
<data android:host="oauth_callback" android:scheme="myapp" />
|
|
807
|
+
</intent-filter>
|
|
808
|
+
</activity>
|
|
809
|
+
```
|
|
810
|
+
|
|
811
|
+
| Param | Type | Description |
|
|
812
|
+
| ------------- | --------------------------------------------------------------------------- | ------------------------------------------- |
|
|
813
|
+
| **`options`** | <code><a href="#opensecurewindowoptions">OpenSecureWindowOptions</a></code> | - the options for the openSecureWindow call |
|
|
814
|
+
|
|
815
|
+
**Returns:** <code>Promise<<a href="#opensecurewindowresponse">OpenSecureWindowResponse</a>></code>
|
|
816
|
+
|
|
817
|
+
--------------------
|
|
818
|
+
|
|
819
|
+
|
|
762
820
|
### Interfaces
|
|
763
821
|
|
|
764
822
|
|
|
@@ -985,6 +1043,22 @@ Configuration for a single OAuth2 provider instance
|
|
|
985
1043
|
| **`fields`** | <code>string[]</code> | Fields to retrieve from Facebook profile |
|
|
986
1044
|
|
|
987
1045
|
|
|
1046
|
+
#### OpenSecureWindowResponse
|
|
1047
|
+
|
|
1048
|
+
| Prop | Type | Description |
|
|
1049
|
+
| ------------------- | ------------------- | --------------------------------------- |
|
|
1050
|
+
| **`redirectedUri`** | <code>string</code> | The result of the openSecureWindow call |
|
|
1051
|
+
|
|
1052
|
+
|
|
1053
|
+
#### OpenSecureWindowOptions
|
|
1054
|
+
|
|
1055
|
+
| Prop | Type | Description |
|
|
1056
|
+
| -------------------------- | ------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
1057
|
+
| **`authEndpoint`** | <code>string</code> | The endpoint to open |
|
|
1058
|
+
| **`redirectUri`** | <code>string</code> | The redirect URI to use for the openSecureWindow call. This will be checked to make sure it matches the redirect URI after the window finishes the redirection. |
|
|
1059
|
+
| **`broadcastChannelName`** | <code>string</code> | The name of the broadcast channel to listen to, relevant only for web |
|
|
1060
|
+
|
|
1061
|
+
|
|
988
1062
|
### Type Aliases
|
|
989
1063
|
|
|
990
1064
|
|
package/android/build.gradle
CHANGED
|
@@ -69,8 +69,9 @@ dependencies {
|
|
|
69
69
|
implementation "androidx.appcompat:appcompat:$androidxAppCompatVersion"
|
|
70
70
|
implementation 'com.squareup.okhttp3:okhttp:4.12.0'
|
|
71
71
|
implementation 'com.auth0.android:jwtdecode:2.0.2'
|
|
72
|
-
implementation
|
|
72
|
+
implementation 'androidx.credentials:credentials:1.5.0'
|
|
73
73
|
implementation 'androidx.concurrent:concurrent-futures:1.3.0'
|
|
74
|
+
implementation 'androidx.browser:browser:1.9.0'
|
|
74
75
|
|
|
75
76
|
// Read provider configuration from gradle.properties (set by hook script)
|
|
76
77
|
def googleDependencyType = project.findProperty('socialLogin.google.dependencyType') ?: 'implementation'
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
package ee.forgr.capacitor.social.login;
|
|
2
2
|
|
|
3
3
|
import android.content.Intent;
|
|
4
|
+
import android.net.Uri;
|
|
4
5
|
import android.util.Log;
|
|
6
|
+
import androidx.browser.customtabs.CustomTabsIntent;
|
|
5
7
|
import com.getcapacitor.JSArray;
|
|
6
8
|
import com.getcapacitor.JSObject;
|
|
7
9
|
import com.getcapacitor.Plugin;
|
|
@@ -18,12 +20,15 @@ import org.json.JSONObject;
|
|
|
18
20
|
@CapacitorPlugin(name = "SocialLogin")
|
|
19
21
|
public class SocialLoginPlugin extends Plugin {
|
|
20
22
|
|
|
21
|
-
private final String pluginVersion = "8.2.
|
|
23
|
+
private final String pluginVersion = "8.2.23";
|
|
22
24
|
|
|
23
25
|
public static String LOG_TAG = "CapgoSocialLogin";
|
|
24
26
|
|
|
25
27
|
public HashMap<String, SocialProvider> socialProviderHashMap = new HashMap<>();
|
|
26
28
|
|
|
29
|
+
private PluginCall openSecureWindowSavedCall;
|
|
30
|
+
private String openSecureWindowRedirectUri;
|
|
31
|
+
|
|
27
32
|
@PluginMethod
|
|
28
33
|
public void initialize(PluginCall call) {
|
|
29
34
|
// Set plugin instance for config access
|
|
@@ -424,4 +429,91 @@ public class SocialLoginPlugin extends Plugin {
|
|
|
424
429
|
call.reject("Could not get plugin version", e);
|
|
425
430
|
}
|
|
426
431
|
}
|
|
432
|
+
|
|
433
|
+
@PluginMethod
|
|
434
|
+
public void openSecureWindow(PluginCall call) {
|
|
435
|
+
String authEndpoint = call.getString("authEndpoint");
|
|
436
|
+
|
|
437
|
+
if (authEndpoint == null || authEndpoint.isEmpty()) {
|
|
438
|
+
call.reject("Auth endpoint is required");
|
|
439
|
+
return;
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
String redirectUri = call.getString("redirectUri");
|
|
443
|
+
if (redirectUri == null || redirectUri.isEmpty()) {
|
|
444
|
+
call.reject("Redirect URI is required");
|
|
445
|
+
return;
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
openSecureWindowSavedCall = call;
|
|
449
|
+
openSecureWindowRedirectUri = redirectUri;
|
|
450
|
+
|
|
451
|
+
// Launch OAuth in custom tab
|
|
452
|
+
launchCustomTab(authEndpoint);
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
private void launchCustomTab(String url) {
|
|
456
|
+
CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
|
|
457
|
+
|
|
458
|
+
CustomTabsIntent customTabsIntent = builder.build();
|
|
459
|
+
customTabsIntent.intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
|
|
460
|
+
customTabsIntent.intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
|
461
|
+
customTabsIntent.intent.putExtra("android.support.customtabs.extra.ENABLE_URLBAR_HIDING", true);
|
|
462
|
+
customTabsIntent.intent.putExtra("android.support.customtabs.extra.EXTRA_ENABLE_INSTANT_APPS", false);
|
|
463
|
+
customTabsIntent.intent.putExtra("android.support.customtabs.extra.SEND_TO_EXTERNAL_HANDLER", false);
|
|
464
|
+
customTabsIntent.intent.putExtra("androidx.browser.customtabs.extra.SHARE_STATE", 2);
|
|
465
|
+
customTabsIntent.intent.putExtra("androidx.browser.customtabs.extra.DISABLE_BACKGROUND_INTERACTION", false);
|
|
466
|
+
customTabsIntent.intent.putExtra("org.chromium.chrome.browser.customtabs.EXTRA_DISABLE_DOWNLOAD_BUTTON", true);
|
|
467
|
+
customTabsIntent.intent.putExtra("org.chromium.chrome.browser.customtabs.EXTRA_DISABLE_STAR_BUTTON", true);
|
|
468
|
+
|
|
469
|
+
customTabsIntent.launchUrl(getActivity(), Uri.parse(url));
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
@Override
|
|
473
|
+
protected void handleOnResume() {
|
|
474
|
+
super.handleOnResume();
|
|
475
|
+
|
|
476
|
+
// If we have a saved call and user returned without callback, reject
|
|
477
|
+
if (openSecureWindowSavedCall != null) {
|
|
478
|
+
openSecureWindowSavedCall.reject("OAuth cancelled or no callback received");
|
|
479
|
+
openSecureWindowSavedCall = null;
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
@Override
|
|
484
|
+
protected void handleOnNewIntent(Intent intent) {
|
|
485
|
+
super.handleOnNewIntent(intent);
|
|
486
|
+
|
|
487
|
+
if (intent == null || !Intent.ACTION_VIEW.equals(intent.getAction())) {
|
|
488
|
+
return;
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
Uri uri = intent.getData();
|
|
492
|
+
if (uri == null) {
|
|
493
|
+
return;
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
if (openSecureWindowRedirectUri == null) {
|
|
497
|
+
return;
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
if (uri.getHost() == null || !uri.toString().startsWith(openSecureWindowRedirectUri)) {
|
|
501
|
+
return;
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
try {
|
|
505
|
+
// Resolve the original call with the callback url
|
|
506
|
+
if (openSecureWindowSavedCall != null) {
|
|
507
|
+
final JSObject ret = new JSObject();
|
|
508
|
+
ret.put("redirectedUri", uri.toString());
|
|
509
|
+
openSecureWindowSavedCall.resolve(ret);
|
|
510
|
+
openSecureWindowSavedCall = null;
|
|
511
|
+
}
|
|
512
|
+
} catch (Exception e) {
|
|
513
|
+
if (openSecureWindowSavedCall != null) {
|
|
514
|
+
openSecureWindowSavedCall.reject("Failed to process OAuth callback", e);
|
|
515
|
+
openSecureWindowSavedCall = null;
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
}
|
|
427
519
|
}
|
package/dist/docs.json
CHANGED
|
@@ -201,6 +201,30 @@
|
|
|
201
201
|
"docs": "Get the native Capacitor plugin version",
|
|
202
202
|
"complexTypes": [],
|
|
203
203
|
"slug": "getpluginversion"
|
|
204
|
+
},
|
|
205
|
+
{
|
|
206
|
+
"name": "openSecureWindow",
|
|
207
|
+
"signature": "(options: OpenSecureWindowOptions) => Promise<OpenSecureWindowResponse>",
|
|
208
|
+
"parameters": [
|
|
209
|
+
{
|
|
210
|
+
"name": "options",
|
|
211
|
+
"docs": "- the options for the openSecureWindow call",
|
|
212
|
+
"type": "OpenSecureWindowOptions"
|
|
213
|
+
}
|
|
214
|
+
],
|
|
215
|
+
"returns": "Promise<OpenSecureWindowResponse>",
|
|
216
|
+
"tags": [
|
|
217
|
+
{
|
|
218
|
+
"name": "param",
|
|
219
|
+
"text": "options - the options for the openSecureWindow call"
|
|
220
|
+
}
|
|
221
|
+
],
|
|
222
|
+
"docs": "Opens a secured window for OAuth2 authentication.\nFor web, you should have the code in the redirected page to use a broadcast channel to send the redirected url to the app\nSomething like:\n```html\n<html>\n<head></head>\n<body>\n<script>\n const searchParams = new URLSearchParams(location.search)\n if (searchParams.has(\"code\")) {\n new BroadcastChannel(\"my-channel-name\").postMessage(location.href);\n window.close();\n }\n</script>\n</body>\n</html>\n```\nFor mobile, you should have a redirect uri that opens the app, something like: `myapp://oauth_callback/`\nAnd make sure to register it in the app's info.plist:\n```xml\n<key>CFBundleURLTypes</key>\n<array>\n <dict>\n <key>CFBundleURLSchemes</key>\n <array>\n <string>myapp</string>\n </array>\n </dict>\n</array>\n```\nAnd in the AndroidManifest.xml file:\n```xml\n<activity>\n <intent-filter>\n <action android:name=\"android.intent.action.VIEW\" />\n <category android:name=\"android.intent.category.DEFAULT\" />\n <category android:name=\"android.intent.category.BROWSABLE\" />\n <data android:host=\"oauth_callback\" android:scheme=\"myapp\" />\n </intent-filter>\n</activity>\n```",
|
|
223
|
+
"complexTypes": [
|
|
224
|
+
"OpenSecureWindowResponse",
|
|
225
|
+
"OpenSecureWindowOptions"
|
|
226
|
+
],
|
|
227
|
+
"slug": "opensecurewindow"
|
|
204
228
|
}
|
|
205
229
|
],
|
|
206
230
|
"properties": []
|
|
@@ -1351,6 +1375,52 @@
|
|
|
1351
1375
|
"type": "string[] | undefined"
|
|
1352
1376
|
}
|
|
1353
1377
|
]
|
|
1378
|
+
},
|
|
1379
|
+
{
|
|
1380
|
+
"name": "OpenSecureWindowResponse",
|
|
1381
|
+
"slug": "opensecurewindowresponse",
|
|
1382
|
+
"docs": "",
|
|
1383
|
+
"tags": [],
|
|
1384
|
+
"methods": [],
|
|
1385
|
+
"properties": [
|
|
1386
|
+
{
|
|
1387
|
+
"name": "redirectedUri",
|
|
1388
|
+
"tags": [],
|
|
1389
|
+
"docs": "The result of the openSecureWindow call",
|
|
1390
|
+
"complexTypes": [],
|
|
1391
|
+
"type": "string"
|
|
1392
|
+
}
|
|
1393
|
+
]
|
|
1394
|
+
},
|
|
1395
|
+
{
|
|
1396
|
+
"name": "OpenSecureWindowOptions",
|
|
1397
|
+
"slug": "opensecurewindowoptions",
|
|
1398
|
+
"docs": "",
|
|
1399
|
+
"tags": [],
|
|
1400
|
+
"methods": [],
|
|
1401
|
+
"properties": [
|
|
1402
|
+
{
|
|
1403
|
+
"name": "authEndpoint",
|
|
1404
|
+
"tags": [],
|
|
1405
|
+
"docs": "The endpoint to open",
|
|
1406
|
+
"complexTypes": [],
|
|
1407
|
+
"type": "string"
|
|
1408
|
+
},
|
|
1409
|
+
{
|
|
1410
|
+
"name": "redirectUri",
|
|
1411
|
+
"tags": [],
|
|
1412
|
+
"docs": "The redirect URI to use for the openSecureWindow call.\nThis will be checked to make sure it matches the redirect URI after the window finishes the redirection.",
|
|
1413
|
+
"complexTypes": [],
|
|
1414
|
+
"type": "string"
|
|
1415
|
+
},
|
|
1416
|
+
{
|
|
1417
|
+
"name": "broadcastChannelName",
|
|
1418
|
+
"tags": [],
|
|
1419
|
+
"docs": "The name of the broadcast channel to listen to, relevant only for web",
|
|
1420
|
+
"complexTypes": [],
|
|
1421
|
+
"type": "string | undefined"
|
|
1422
|
+
}
|
|
1423
|
+
]
|
|
1354
1424
|
}
|
|
1355
1425
|
],
|
|
1356
1426
|
"enums": [],
|
|
@@ -676,6 +676,27 @@ export interface FacebookGetProfileResponse {
|
|
|
676
676
|
[key: string]: any;
|
|
677
677
|
};
|
|
678
678
|
}
|
|
679
|
+
export interface OpenSecureWindowOptions {
|
|
680
|
+
/**
|
|
681
|
+
* The endpoint to open
|
|
682
|
+
*/
|
|
683
|
+
authEndpoint: string;
|
|
684
|
+
/**
|
|
685
|
+
* The redirect URI to use for the openSecureWindow call.
|
|
686
|
+
* This will be checked to make sure it matches the redirect URI after the window finishes the redirection.
|
|
687
|
+
*/
|
|
688
|
+
redirectUri: string;
|
|
689
|
+
/**
|
|
690
|
+
* The name of the broadcast channel to listen to, relevant only for web
|
|
691
|
+
*/
|
|
692
|
+
broadcastChannelName?: string;
|
|
693
|
+
}
|
|
694
|
+
export interface OpenSecureWindowResponse {
|
|
695
|
+
/**
|
|
696
|
+
* The result of the openSecureWindow call
|
|
697
|
+
*/
|
|
698
|
+
redirectedUri: string;
|
|
699
|
+
}
|
|
679
700
|
export type FacebookRequestTrackingOptions = Record<string, never>;
|
|
680
701
|
export interface FacebookRequestTrackingResponse {
|
|
681
702
|
/**
|
|
@@ -776,4 +797,49 @@ export interface SocialLoginPlugin {
|
|
|
776
797
|
getPluginVersion(): Promise<{
|
|
777
798
|
version: string;
|
|
778
799
|
}>;
|
|
800
|
+
/**
|
|
801
|
+
* Opens a secured window for OAuth2 authentication.
|
|
802
|
+
* For web, you should have the code in the redirected page to use a broadcast channel to send the redirected url to the app
|
|
803
|
+
* Something like:
|
|
804
|
+
* ```html
|
|
805
|
+
* <html>
|
|
806
|
+
* <head></head>
|
|
807
|
+
* <body>
|
|
808
|
+
* <script>
|
|
809
|
+
* const searchParams = new URLSearchParams(location.search)
|
|
810
|
+
* if (searchParams.has("code")) {
|
|
811
|
+
* new BroadcastChannel("my-channel-name").postMessage(location.href);
|
|
812
|
+
* window.close();
|
|
813
|
+
* }
|
|
814
|
+
* </script>
|
|
815
|
+
* </body>
|
|
816
|
+
* </html>
|
|
817
|
+
* ```
|
|
818
|
+
* For mobile, you should have a redirect uri that opens the app, something like: `myapp://oauth_callback/`
|
|
819
|
+
* And make sure to register it in the app's info.plist:
|
|
820
|
+
* ```xml
|
|
821
|
+
* <key>CFBundleURLTypes</key>
|
|
822
|
+
* <array>
|
|
823
|
+
* <dict>
|
|
824
|
+
* <key>CFBundleURLSchemes</key>
|
|
825
|
+
* <array>
|
|
826
|
+
* <string>myapp</string>
|
|
827
|
+
* </array>
|
|
828
|
+
* </dict>
|
|
829
|
+
* </array>
|
|
830
|
+
* ```
|
|
831
|
+
* And in the AndroidManifest.xml file:
|
|
832
|
+
* ```xml
|
|
833
|
+
* <activity>
|
|
834
|
+
* <intent-filter>
|
|
835
|
+
* <action android:name="android.intent.action.VIEW" />
|
|
836
|
+
* <category android:name="android.intent.category.DEFAULT" />
|
|
837
|
+
* <category android:name="android.intent.category.BROWSABLE" />
|
|
838
|
+
* <data android:host="oauth_callback" android:scheme="myapp" />
|
|
839
|
+
* </intent-filter>
|
|
840
|
+
* </activity>
|
|
841
|
+
* ```
|
|
842
|
+
* @param options - the options for the openSecureWindow call
|
|
843
|
+
*/
|
|
844
|
+
openSecureWindow(options: OpenSecureWindowOptions): Promise<OpenSecureWindowResponse>;
|
|
779
845
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * Configuration for a single OAuth2 provider instance\n */\nexport interface OAuth2ProviderConfig {\n /**\n * The OAuth 2.0 client identifier (App ID / Client ID)\n * @example 'your-client-id'\n */\n appId: string;\n /**\n * The base URL of the authorization endpoint\n * @example 'https://accounts.example.com/oauth2/authorize'\n */\n authorizationBaseUrl: string;\n /**\n * The URL to exchange the authorization code for tokens\n * Required for authorization code flow\n * @example 'https://accounts.example.com/oauth2/token'\n */\n accessTokenEndpoint?: string;\n /**\n * Redirect URL that receives the OAuth callback\n * @example 'myapp://oauth/callback'\n */\n redirectUrl: string;\n /**\n * Optional URL to fetch user profile/resource data after authentication\n * The access token will be sent as Bearer token in the Authorization header\n * @example 'https://api.example.com/userinfo'\n */\n resourceUrl?: string;\n /**\n * The OAuth response type\n * - 'code': Authorization Code flow (recommended, requires accessTokenEndpoint)\n * - 'token': Implicit flow (less secure, tokens returned directly)\n * @default 'code'\n */\n responseType?: 'code' | 'token';\n /**\n * Enable PKCE (Proof Key for Code Exchange)\n * Strongly recommended for public clients (mobile/web apps)\n * @default true\n */\n pkceEnabled?: boolean;\n /**\n * Default scopes to request during authorization\n * @example 'openid profile email'\n */\n scope?: string;\n /**\n * Additional parameters to include in the authorization request\n * @example { prompt: 'consent', login_hint: 'user@example.com' }\n */\n additionalParameters?: Record<string, string>;\n /**\n * Additional headers to include when fetching the resource URL\n * @example { 'X-Custom-Header': 'value' }\n */\n additionalResourceHeaders?: Record<string, string>;\n /**\n * Custom logout URL for ending the session\n * @example 'https://accounts.example.com/logout'\n */\n logoutUrl?: string;\n /**\n * Enable debug logging\n * @default false\n */\n logsEnabled?: boolean;\n}\n\nexport interface InitializeOptions {\n /**\n * OAuth2 provider configurations.\n * Supports multiple providers by using a Record with provider IDs as keys.\n * @example\n * {\n * github: { appId: '...', authorizationBaseUrl: 'https://github.com/login/oauth/authorize', ... },\n * azure: { appId: '...', authorizationBaseUrl: 'https://login.microsoftonline.com/.../oauth2/v2.0/authorize', ... }\n * }\n */\n oauth2?: Record<string, OAuth2ProviderConfig>;\n twitter?: {\n /**\n * The OAuth 2.0 client identifier issued by X (Twitter) Developer Portal\n * @example 'Y2xpZW50SWQ'\n */\n clientId: string;\n /**\n * Redirect URL that is registered inside the X Developer Portal.\n * The plugin uses this URL on every platform to receive the authorization code.\n * @example 'myapp://auth/x'\n */\n redirectUrl: string;\n /**\n * Default scopes appended to every login request when no custom scopes are provided.\n * @description Defaults to the minimum required scopes for Log in with X.\n * @default ['tweet.read','users.read']\n */\n defaultScopes?: string[];\n /**\n * Force the consent screen to show on every login attempt.\n * Mirrors X's `force_login=true` flag.\n * @default false\n */\n forceLogin?: boolean;\n /**\n * Optional audience value when your application has been approved for multi-tenant access.\n */\n audience?: string;\n };\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 * Locale\n * @description The locale to use for the Facebook SDK (e.g., 'en_US', 'fr_FR', 'es_ES')\n * @default 'en_US'\n * @example 'fr_FR'\n */\n locale?: string;\n };\n\n google?: {\n /**\n * The app's client ID, found and created in the Google Developers Console.\n * Required for iOS platform.\n * @example xxxxxx-xxxxxxxxxxxxxxxxxx.apps.googleusercontent.com\n * @since 3.1.0\n */\n iOSClientId?: string;\n /**\n * The app's server client ID, required for offline mode on iOS.\n * Should be the same value as webClientId.\n * Found and created in the Google Developers Console.\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 * Required for Android and Web platforms.\n * @example xxxxxx-xxxxxxxxxxxxxxxxxx.apps.googleusercontent.com\n * @since 3.1.0\n */\n webClientId?: string;\n /**\n * The login mode, can be online or offline.\n *\n * **Online mode (default):**\n * - Returns user profile data and access tokens\n * - Supports all methods: login, logout, isLoggedIn, getAuthorizationCode\n *\n * **Offline mode:**\n * - Returns only serverAuthCode for backend authentication\n * - No user profile data available\n * - **Limitations:** The following methods are NOT supported in offline mode:\n * - `logout()` - Will reject with \"not implemented when using offline mode\"\n * - `isLoggedIn()` - Will reject with \"not implemented when using offline mode\"\n * - `getAuthorizationCode()` - Will reject with \"not implemented when using offline mode\"\n * - Only `login()` method works in offline mode, returning serverAuthCode only\n * - Requires `iOSServerClientId` to be set on iOS\n *\n * @example 'offline'\n * @default 'online'\n * @since 3.1.0\n */\n mode?: 'online' | 'offline';\n /**\n * Filter visible accounts by hosted domain\n * @description filter visible accounts by hosted domain\n */\n hostedDomain?: string;\n /**\n * Google Redirect URL, should be your backend url that is configured in your google app\n */\n redirectUrl?: 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\n *\n * **Note**: Use empty string `''` for iOS to prevent redirect.\n * **Note**: Not required when using Broadcast Channel mode on Android.\n */\n redirectUrl?: string;\n /**\n * Use proper token exchange for Apple Sign-In\n * @description Controls how Apple Sign-In tokens are handled and what gets returned:\n *\n * **When `true` (Recommended for new implementations):**\n * - Exchanges authorization code for proper access tokens via Apple's token endpoint\n * - `idToken`: JWT containing user identity information (email, name, user ID)\n * - `accessToken.token`: Proper access token from Apple (short-lived, ~1 hour)\n * - `authorizationCode`: Raw authorization code for backend token exchange\n *\n * **When `false` (Default - Legacy mode):**\n * - Uses authorization code directly as access token for backward compatibility\n * - `idToken`: JWT containing user identity information (email, name, user ID)\n * - `accessToken.token`: The authorization code itself (not a real access token)\n * - `authorizationCode`: undefined\n *\n * @default false\n * @example\n * // Enable proper token exchange (recommended)\n * useProperTokenExchange: true\n * // Result: idToken=JWT, accessToken=real_token, authorizationCode=present\n *\n * // Legacy mode (backward compatibility)\n * useProperTokenExchange: false\n * // Result: idToken=JWT, accessToken=auth_code, authorizationCode=undefined\n */\n useProperTokenExchange?: boolean;\n /**\n * Use Broadcast Channel for Android Apple Sign-In (Recommended)\n * @description When enabled, Android uses Broadcast Channel API instead of URL redirects.\n * This eliminates the need for redirect URL configuration and server-side setup.\n *\n * **Benefits:**\n * - No redirect URL configuration required\n * - No backend server needed for Android\n * - Simpler setup and more reliable communication\n * - Direct client-server communication via Broadcast Channel\n *\n * **When `true`:**\n * - Uses Broadcast Channel for authentication flow\n * - `redirectUrl` is ignored\n * - Requires Broadcast Channel compatible backend or direct token handling\n *\n * **When `false` (Default - Legacy mode):**\n * - Uses traditional URL redirect flow\n * - Requires `redirectUrl` configuration\n * - Requires backend server for token exchange\n *\n * @default false\n * @since 7.10.0\n * @example\n * // Enable Broadcast Channel mode (recommended for new Android implementations)\n * useBroadcastChannel: true\n * // Result: Simplified setup, no redirect URL needed\n *\n * // Legacy mode (backward compatibility)\n * useBroadcastChannel: false\n * // Result: Traditional URL redirect flow with server-side setup\n */\n useBroadcastChannel?: boolean;\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 only. Important: This is iOS-only and doesn't affect Android.\n * Even if set to false, Facebook will automatically force it to true if App Tracking Transparency (ATT) permission is not granted.\n * Developers should always be prepared to handle both limited and full login scenarios.\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 TwitterLoginOptions {\n /**\n * Additional scopes to request during login.\n * If omitted the plugin falls back to the default scopes configured during initialization.\n * @example ['tweet.read','users.read','offline.access']\n */\n scopes?: string[];\n /**\n * Provide a custom OAuth state value.\n * When not provided the plugin generates a cryptographically random value.\n */\n state?: string;\n /**\n * Provide a pre-computed PKCE code verifier (mostly used for testing).\n * When omitted the plugin generates a secure verifier automatically.\n */\n codeVerifier?: string;\n /**\n * Override the redirect URI for a single login call.\n * Useful when the same app supports multiple callback URLs per platform.\n */\n redirectUrl?: string;\n /**\n * Force the consent screen on every attempt, maps to `force_login=true`.\n */\n forceLogin?: boolean;\n}\n\nexport interface OAuth2LoginOptions {\n /**\n * The provider ID as configured in initialize()\n * This is required to identify which OAuth2 provider to use\n * @example 'github', 'azure', 'keycloak'\n */\n providerId: string;\n /**\n * Override the scopes for this login request\n * If not provided, uses the scopes from initialization\n */\n scope?: string;\n /**\n * Custom state parameter for CSRF protection\n * If not provided, a random value is generated\n */\n state?: string;\n /**\n * Override PKCE code verifier (for testing purposes)\n * If not provided, a secure random verifier is generated\n */\n codeVerifier?: string;\n /**\n * Override redirect URL for this login request\n */\n redirectUrl?: string;\n /**\n * Additional parameters to add to the authorization URL\n */\n additionalParameters?: Record<string, string>;\n}\n\nexport interface OAuth2LoginResponse {\n /**\n * The provider ID that was used for this login\n */\n providerId: string;\n /**\n * The access token received from the OAuth provider\n */\n accessToken: AccessToken | null;\n /**\n * The ID token (JWT) if provided by the OAuth server (e.g., OpenID Connect)\n */\n idToken: string | null;\n /**\n * The refresh token if provided (requires appropriate scope like offline_access)\n */\n refreshToken: string | null;\n /**\n * Resource data fetched from resourceUrl if configured\n * Contains the raw JSON response from the resource endpoint\n */\n resourceData: Record<string, unknown> | null;\n /**\n * The scopes that were granted\n */\n scope: string[];\n /**\n * Token type (usually 'bearer')\n */\n tokenType: string;\n /**\n * Token expiration time in seconds\n */\n expiresIn: number | null;\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 * Force refresh token (only for Android)\n * @description force refresh token\n * @default false\n * @note On Android, the OS caches access tokens, and if a token is invalid (e.g., user revoked app access), the plugin might return an invalid accessToken. Using getAuthorizationCode() is recommended to ensure the token is valid.\n */\n forceRefreshToken?: boolean;\n /**\n * Force account selection prompt (iOS)\n * @description forces the account selection prompt to appear on iOS\n * @default false\n */\n forcePrompt?: boolean;\n /**\n * Style\n * @description style\n * @default 'standard'\n */\n style?: 'bottom' | 'standard';\n /**\n * Filter by authorized accounts (Android only)\n * @description Only show accounts that have previously been used to sign in to the app.\n * This option is only available for the 'bottom' style.\n * Note: For Family Link supervised accounts, this should be set to false.\n * @default true\n */\n filterByAuthorizedAccounts?: boolean;\n /**\n * Auto select enabled (Android only)\n * @description Automatically select the account if only one Google account is available.\n * This option is only available for the 'bottom' style.\n * @default false\n */\n autoSelectEnabled?: boolean;\n /**\n * Prompt parameter for Google OAuth (Web only)\n * @description A space-delimited, case-sensitive list of prompts to present the user.\n * If you don't specify this parameter, the user will be prompted only the first time your project requests access.\n *\n * **Possible values:**\n * - `none`: Don't display any authentication or consent screens. Must not be specified with other values.\n * - `consent`: Prompt the user for consent.\n * - `select_account`: Prompt the user to select an account.\n *\n * **Examples:**\n * - `prompt: 'consent'` - Always show consent screen\n * - `prompt: 'select_account'` - Always show account selection\n * - `prompt: 'consent select_account'` - Show both consent and account selection\n *\n * **Note:** This parameter only affects web platform behavior. Mobile platforms use their own native prompts.\n *\n * @example 'consent'\n * @example 'select_account'\n * @example 'consent select_account'\n * @see [Google OAuth2 Prompt Parameter](https://developers.google.com/identity/protocols/oauth2/openid-connect#prompt)\n * @since 7.12.0\n */\n prompt?: 'none' | 'consent' | 'select_account' | 'consent select_account' | 'select_account consent';\n}\n\nexport interface GoogleLoginResponseOnline {\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 responseType: 'online';\n}\n\nexport interface GoogleLoginResponseOffline {\n serverAuthCode: string;\n responseType: 'offline';\n}\n\nexport type GoogleLoginResponse = GoogleLoginResponseOnline | GoogleLoginResponseOffline;\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 * Use Broadcast Channel for authentication flow\n * @description When enabled, uses Broadcast Channel API for communication instead of URL redirects.\n * Only applicable on platforms that support Broadcast Channel (Android).\n * @default false\n */\n useBroadcastChannel?: boolean;\n}\n\nexport interface AppleProviderResponse {\n /**\n * Access token from Apple\n * @description Content depends on `useProperTokenExchange` setting:\n * - When `useProperTokenExchange: true`: Real access token from Apple (~1 hour validity)\n * - When `useProperTokenExchange: false`: Contains authorization code as token (legacy mode)\n * Use `idToken` for user authentication, `accessToken` for API calls when properly exchanged.\n */\n accessToken: AccessToken | null;\n\n /**\n * Identity token (JWT) from Apple\n * @description Always contains the JWT with user identity information including:\n * - User ID (sub claim)\n * - Email (if user granted permission)\n * - Name components (if user granted permission)\n * - Email verification status\n * This is the primary token for user authentication and should be verified on your backend.\n */\n idToken: string | null;\n\n /**\n * User profile information\n * @description Basic user profile data extracted from the identity token and Apple response:\n * - `user`: Apple's user identifier (sub claim from idToken)\n * - `email`: User's email address (if permission granted)\n * - `givenName`: User's first name (if permission granted)\n * - `familyName`: User's last name (if permission granted)\n */\n profile: {\n user: string;\n email: string | null;\n givenName: string | null;\n familyName: string | null;\n };\n\n /**\n * Authorization code for proper token exchange (when useProperTokenExchange is enabled)\n * @description Only present when `useProperTokenExchange` is `true`. This code should be exchanged\n * for proper access tokens on your backend using Apple's token endpoint. Use this for secure\n * server-side token validation and to obtain refresh tokens.\n * @see https://developer.apple.com/documentation/sign_in_with_apple/tokenresponse\n */\n authorizationCode?: string;\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 | {\n provider: 'twitter';\n options: TwitterLoginOptions;\n }\n | {\n provider: 'oauth2';\n options: OAuth2LoginOptions;\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 | {\n provider: 'twitter';\n result: TwitterLoginResponse;\n }\n | {\n provider: 'oauth2';\n result: OAuth2LoginResponse;\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 tokenType?: 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 TwitterProfile {\n id: string;\n username: string;\n name: string | null;\n profileImageUrl: string | null;\n verified: boolean;\n email?: string | null;\n}\n\nexport interface TwitterLoginResponse {\n accessToken: AccessToken | null;\n refreshToken?: string | null;\n scope: string[];\n tokenType: 'bearer';\n expiresIn?: number | null;\n profile: TwitterProfile;\n}\n\nexport interface AuthorizationCode {\n /**\n * Jwt\n * @description A JSON web token\n */\n jwt?: string;\n /**\n * Access Token\n * @description An access token\n */\n accessToken?: string;\n}\n\nexport interface AuthorizationCodeOptions {\n /**\n * Provider\n * @description Provider for the authorization code\n */\n provider: 'apple' | 'google' | 'facebook' | 'twitter' | 'oauth2';\n /**\n * Provider ID for OAuth2 providers (required when provider is 'oauth2')\n * @description The ID used when configuring the OAuth2 provider in initialize()\n */\n providerId?: string;\n}\n\nexport interface isLoggedInOptions {\n /**\n * Provider\n * @description Provider for the isLoggedIn\n */\n provider: 'apple' | 'google' | 'facebook' | 'twitter' | 'oauth2';\n /**\n * Provider ID for OAuth2 providers (required when provider is 'oauth2')\n * @description The ID used when configuring the OAuth2 provider in initialize()\n */\n providerId?: string;\n}\n\n// Define the provider-specific call types\nexport type ProviderSpecificCall = 'facebook#getProfile' | 'facebook#requestTracking';\n\n// Define the options and response types for each specific call\nexport interface FacebookGetProfileOptions {\n /**\n * Fields to retrieve from Facebook profile\n * @example [\"id\", \"name\", \"email\", \"picture\"]\n */\n fields?: string[];\n}\n\nexport interface FacebookGetProfileResponse {\n /**\n * Facebook profile data\n */\n profile: {\n id: string | null;\n name: string | null;\n email: string | null;\n first_name: string | null;\n last_name: string | null;\n picture?: {\n data: {\n height: number | null;\n is_silhouette: boolean | null;\n url: string | null;\n width: number | null;\n };\n } | null;\n [key: string]: any; // For additional fields that might be requested\n };\n}\n\nexport type FacebookRequestTrackingOptions = Record<string, never>;\n\nexport interface FacebookRequestTrackingResponse {\n /**\n * App tracking authorization status\n */\n status: 'authorized' | 'denied' | 'notDetermined' | 'restricted';\n}\n\n// Map call strings to their options and response types\nexport type ProviderSpecificCallOptionsMap = {\n 'facebook#getProfile': FacebookGetProfileOptions;\n 'facebook#requestTracking': FacebookRequestTrackingOptions;\n};\n\nexport type ProviderSpecificCallResponseMap = {\n 'facebook#getProfile': FacebookGetProfileResponse;\n 'facebook#requestTracking': FacebookRequestTrackingResponse;\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 twitter: TwitterLoginResponse;\n oauth2: OAuth2LoginResponse;\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 from the specified provider\n *\n * **Google Offline Mode Limitation:**\n * This method is NOT supported when Google is initialized with `mode: 'offline'`.\n * It will reject with error: \"logout is not implemented when using offline mode\"\n *\n * @throws Error if Google provider is in offline mode\n */\n logout(options: {\n provider: 'apple' | 'google' | 'facebook' | 'twitter' | 'oauth2';\n providerId?: string;\n }): Promise<void>;\n /**\n * IsLoggedIn\n * @description Check if the user is currently logged in with the specified provider\n *\n * **Google Offline Mode Limitation:**\n * This method is NOT supported when Google is initialized with `mode: 'offline'`.\n * It will reject with error: \"isLoggedIn is not implemented when using offline mode\"\n *\n * @throws Error if Google provider is in offline mode\n */\n isLoggedIn(options: isLoggedInOptions): Promise<{ isLoggedIn: boolean }>;\n\n /**\n * Get the current authorization code\n * @description Get the authorization code for server-side authentication\n *\n * **Google Offline Mode Limitation:**\n * This method is NOT supported when Google is initialized with `mode: 'offline'`.\n * It will reject with error: \"getAuthorizationCode is not implemented when using offline mode\"\n *\n * In offline mode, the authorization code (serverAuthCode) is already returned by the `login()` method.\n *\n * @throws Error if Google provider is in offline mode\n */\n getAuthorizationCode(options: AuthorizationCodeOptions): Promise<AuthorizationCode>;\n /**\n * Refresh the access token\n * @description refresh the access token\n */\n refresh(options: LoginOptions): Promise<void>;\n\n /**\n * Execute provider-specific calls\n * @description Execute a provider-specific functionality\n */\n providerSpecificCall<T extends ProviderSpecificCall>(options: {\n call: T;\n options: ProviderSpecificCallOptionsMap[T];\n }): Promise<ProviderSpecificCallResponseMap[T]>;\n\n /**\n * Get the native Capacitor plugin version\n *\n * @returns {Promise<{ id: string }>} an Promise with version for this device\n * @throws An error if the something went wrong\n */\n getPluginVersion(): Promise<{ version: string }>;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * Configuration for a single OAuth2 provider instance\n */\nexport interface OAuth2ProviderConfig {\n /**\n * The OAuth 2.0 client identifier (App ID / Client ID)\n * @example 'your-client-id'\n */\n appId: string;\n /**\n * The base URL of the authorization endpoint\n * @example 'https://accounts.example.com/oauth2/authorize'\n */\n authorizationBaseUrl: string;\n /**\n * The URL to exchange the authorization code for tokens\n * Required for authorization code flow\n * @example 'https://accounts.example.com/oauth2/token'\n */\n accessTokenEndpoint?: string;\n /**\n * Redirect URL that receives the OAuth callback\n * @example 'myapp://oauth/callback'\n */\n redirectUrl: string;\n /**\n * Optional URL to fetch user profile/resource data after authentication\n * The access token will be sent as Bearer token in the Authorization header\n * @example 'https://api.example.com/userinfo'\n */\n resourceUrl?: string;\n /**\n * The OAuth response type\n * - 'code': Authorization Code flow (recommended, requires accessTokenEndpoint)\n * - 'token': Implicit flow (less secure, tokens returned directly)\n * @default 'code'\n */\n responseType?: 'code' | 'token';\n /**\n * Enable PKCE (Proof Key for Code Exchange)\n * Strongly recommended for public clients (mobile/web apps)\n * @default true\n */\n pkceEnabled?: boolean;\n /**\n * Default scopes to request during authorization\n * @example 'openid profile email'\n */\n scope?: string;\n /**\n * Additional parameters to include in the authorization request\n * @example { prompt: 'consent', login_hint: 'user@example.com' }\n */\n additionalParameters?: Record<string, string>;\n /**\n * Additional headers to include when fetching the resource URL\n * @example { 'X-Custom-Header': 'value' }\n */\n additionalResourceHeaders?: Record<string, string>;\n /**\n * Custom logout URL for ending the session\n * @example 'https://accounts.example.com/logout'\n */\n logoutUrl?: string;\n /**\n * Enable debug logging\n * @default false\n */\n logsEnabled?: boolean;\n}\n\nexport interface InitializeOptions {\n /**\n * OAuth2 provider configurations.\n * Supports multiple providers by using a Record with provider IDs as keys.\n * @example\n * {\n * github: { appId: '...', authorizationBaseUrl: 'https://github.com/login/oauth/authorize', ... },\n * azure: { appId: '...', authorizationBaseUrl: 'https://login.microsoftonline.com/.../oauth2/v2.0/authorize', ... }\n * }\n */\n oauth2?: Record<string, OAuth2ProviderConfig>;\n twitter?: {\n /**\n * The OAuth 2.0 client identifier issued by X (Twitter) Developer Portal\n * @example 'Y2xpZW50SWQ'\n */\n clientId: string;\n /**\n * Redirect URL that is registered inside the X Developer Portal.\n * The plugin uses this URL on every platform to receive the authorization code.\n * @example 'myapp://auth/x'\n */\n redirectUrl: string;\n /**\n * Default scopes appended to every login request when no custom scopes are provided.\n * @description Defaults to the minimum required scopes for Log in with X.\n * @default ['tweet.read','users.read']\n */\n defaultScopes?: string[];\n /**\n * Force the consent screen to show on every login attempt.\n * Mirrors X's `force_login=true` flag.\n * @default false\n */\n forceLogin?: boolean;\n /**\n * Optional audience value when your application has been approved for multi-tenant access.\n */\n audience?: string;\n };\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 * Locale\n * @description The locale to use for the Facebook SDK (e.g., 'en_US', 'fr_FR', 'es_ES')\n * @default 'en_US'\n * @example 'fr_FR'\n */\n locale?: string;\n };\n\n google?: {\n /**\n * The app's client ID, found and created in the Google Developers Console.\n * Required for iOS platform.\n * @example xxxxxx-xxxxxxxxxxxxxxxxxx.apps.googleusercontent.com\n * @since 3.1.0\n */\n iOSClientId?: string;\n /**\n * The app's server client ID, required for offline mode on iOS.\n * Should be the same value as webClientId.\n * Found and created in the Google Developers Console.\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 * Required for Android and Web platforms.\n * @example xxxxxx-xxxxxxxxxxxxxxxxxx.apps.googleusercontent.com\n * @since 3.1.0\n */\n webClientId?: string;\n /**\n * The login mode, can be online or offline.\n *\n * **Online mode (default):**\n * - Returns user profile data and access tokens\n * - Supports all methods: login, logout, isLoggedIn, getAuthorizationCode\n *\n * **Offline mode:**\n * - Returns only serverAuthCode for backend authentication\n * - No user profile data available\n * - **Limitations:** The following methods are NOT supported in offline mode:\n * - `logout()` - Will reject with \"not implemented when using offline mode\"\n * - `isLoggedIn()` - Will reject with \"not implemented when using offline mode\"\n * - `getAuthorizationCode()` - Will reject with \"not implemented when using offline mode\"\n * - Only `login()` method works in offline mode, returning serverAuthCode only\n * - Requires `iOSServerClientId` to be set on iOS\n *\n * @example 'offline'\n * @default 'online'\n * @since 3.1.0\n */\n mode?: 'online' | 'offline';\n /**\n * Filter visible accounts by hosted domain\n * @description filter visible accounts by hosted domain\n */\n hostedDomain?: string;\n /**\n * Google Redirect URL, should be your backend url that is configured in your google app\n */\n redirectUrl?: 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\n *\n * **Note**: Use empty string `''` for iOS to prevent redirect.\n * **Note**: Not required when using Broadcast Channel mode on Android.\n */\n redirectUrl?: string;\n /**\n * Use proper token exchange for Apple Sign-In\n * @description Controls how Apple Sign-In tokens are handled and what gets returned:\n *\n * **When `true` (Recommended for new implementations):**\n * - Exchanges authorization code for proper access tokens via Apple's token endpoint\n * - `idToken`: JWT containing user identity information (email, name, user ID)\n * - `accessToken.token`: Proper access token from Apple (short-lived, ~1 hour)\n * - `authorizationCode`: Raw authorization code for backend token exchange\n *\n * **When `false` (Default - Legacy mode):**\n * - Uses authorization code directly as access token for backward compatibility\n * - `idToken`: JWT containing user identity information (email, name, user ID)\n * - `accessToken.token`: The authorization code itself (not a real access token)\n * - `authorizationCode`: undefined\n *\n * @default false\n * @example\n * // Enable proper token exchange (recommended)\n * useProperTokenExchange: true\n * // Result: idToken=JWT, accessToken=real_token, authorizationCode=present\n *\n * // Legacy mode (backward compatibility)\n * useProperTokenExchange: false\n * // Result: idToken=JWT, accessToken=auth_code, authorizationCode=undefined\n */\n useProperTokenExchange?: boolean;\n /**\n * Use Broadcast Channel for Android Apple Sign-In (Recommended)\n * @description When enabled, Android uses Broadcast Channel API instead of URL redirects.\n * This eliminates the need for redirect URL configuration and server-side setup.\n *\n * **Benefits:**\n * - No redirect URL configuration required\n * - No backend server needed for Android\n * - Simpler setup and more reliable communication\n * - Direct client-server communication via Broadcast Channel\n *\n * **When `true`:**\n * - Uses Broadcast Channel for authentication flow\n * - `redirectUrl` is ignored\n * - Requires Broadcast Channel compatible backend or direct token handling\n *\n * **When `false` (Default - Legacy mode):**\n * - Uses traditional URL redirect flow\n * - Requires `redirectUrl` configuration\n * - Requires backend server for token exchange\n *\n * @default false\n * @since 7.10.0\n * @example\n * // Enable Broadcast Channel mode (recommended for new Android implementations)\n * useBroadcastChannel: true\n * // Result: Simplified setup, no redirect URL needed\n *\n * // Legacy mode (backward compatibility)\n * useBroadcastChannel: false\n * // Result: Traditional URL redirect flow with server-side setup\n */\n useBroadcastChannel?: boolean;\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 only. Important: This is iOS-only and doesn't affect Android.\n * Even if set to false, Facebook will automatically force it to true if App Tracking Transparency (ATT) permission is not granted.\n * Developers should always be prepared to handle both limited and full login scenarios.\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 TwitterLoginOptions {\n /**\n * Additional scopes to request during login.\n * If omitted the plugin falls back to the default scopes configured during initialization.\n * @example ['tweet.read','users.read','offline.access']\n */\n scopes?: string[];\n /**\n * Provide a custom OAuth state value.\n * When not provided the plugin generates a cryptographically random value.\n */\n state?: string;\n /**\n * Provide a pre-computed PKCE code verifier (mostly used for testing).\n * When omitted the plugin generates a secure verifier automatically.\n */\n codeVerifier?: string;\n /**\n * Override the redirect URI for a single login call.\n * Useful when the same app supports multiple callback URLs per platform.\n */\n redirectUrl?: string;\n /**\n * Force the consent screen on every attempt, maps to `force_login=true`.\n */\n forceLogin?: boolean;\n}\n\nexport interface OAuth2LoginOptions {\n /**\n * The provider ID as configured in initialize()\n * This is required to identify which OAuth2 provider to use\n * @example 'github', 'azure', 'keycloak'\n */\n providerId: string;\n /**\n * Override the scopes for this login request\n * If not provided, uses the scopes from initialization\n */\n scope?: string;\n /**\n * Custom state parameter for CSRF protection\n * If not provided, a random value is generated\n */\n state?: string;\n /**\n * Override PKCE code verifier (for testing purposes)\n * If not provided, a secure random verifier is generated\n */\n codeVerifier?: string;\n /**\n * Override redirect URL for this login request\n */\n redirectUrl?: string;\n /**\n * Additional parameters to add to the authorization URL\n */\n additionalParameters?: Record<string, string>;\n}\n\nexport interface OAuth2LoginResponse {\n /**\n * The provider ID that was used for this login\n */\n providerId: string;\n /**\n * The access token received from the OAuth provider\n */\n accessToken: AccessToken | null;\n /**\n * The ID token (JWT) if provided by the OAuth server (e.g., OpenID Connect)\n */\n idToken: string | null;\n /**\n * The refresh token if provided (requires appropriate scope like offline_access)\n */\n refreshToken: string | null;\n /**\n * Resource data fetched from resourceUrl if configured\n * Contains the raw JSON response from the resource endpoint\n */\n resourceData: Record<string, unknown> | null;\n /**\n * The scopes that were granted\n */\n scope: string[];\n /**\n * Token type (usually 'bearer')\n */\n tokenType: string;\n /**\n * Token expiration time in seconds\n */\n expiresIn: number | null;\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 * Force refresh token (only for Android)\n * @description force refresh token\n * @default false\n * @note On Android, the OS caches access tokens, and if a token is invalid (e.g., user revoked app access), the plugin might return an invalid accessToken. Using getAuthorizationCode() is recommended to ensure the token is valid.\n */\n forceRefreshToken?: boolean;\n /**\n * Force account selection prompt (iOS)\n * @description forces the account selection prompt to appear on iOS\n * @default false\n */\n forcePrompt?: boolean;\n /**\n * Style\n * @description style\n * @default 'standard'\n */\n style?: 'bottom' | 'standard';\n /**\n * Filter by authorized accounts (Android only)\n * @description Only show accounts that have previously been used to sign in to the app.\n * This option is only available for the 'bottom' style.\n * Note: For Family Link supervised accounts, this should be set to false.\n * @default true\n */\n filterByAuthorizedAccounts?: boolean;\n /**\n * Auto select enabled (Android only)\n * @description Automatically select the account if only one Google account is available.\n * This option is only available for the 'bottom' style.\n * @default false\n */\n autoSelectEnabled?: boolean;\n /**\n * Prompt parameter for Google OAuth (Web only)\n * @description A space-delimited, case-sensitive list of prompts to present the user.\n * If you don't specify this parameter, the user will be prompted only the first time your project requests access.\n *\n * **Possible values:**\n * - `none`: Don't display any authentication or consent screens. Must not be specified with other values.\n * - `consent`: Prompt the user for consent.\n * - `select_account`: Prompt the user to select an account.\n *\n * **Examples:**\n * - `prompt: 'consent'` - Always show consent screen\n * - `prompt: 'select_account'` - Always show account selection\n * - `prompt: 'consent select_account'` - Show both consent and account selection\n *\n * **Note:** This parameter only affects web platform behavior. Mobile platforms use their own native prompts.\n *\n * @example 'consent'\n * @example 'select_account'\n * @example 'consent select_account'\n * @see [Google OAuth2 Prompt Parameter](https://developers.google.com/identity/protocols/oauth2/openid-connect#prompt)\n * @since 7.12.0\n */\n prompt?: 'none' | 'consent' | 'select_account' | 'consent select_account' | 'select_account consent';\n}\n\nexport interface GoogleLoginResponseOnline {\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 responseType: 'online';\n}\n\nexport interface GoogleLoginResponseOffline {\n serverAuthCode: string;\n responseType: 'offline';\n}\n\nexport type GoogleLoginResponse = GoogleLoginResponseOnline | GoogleLoginResponseOffline;\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 * Use Broadcast Channel for authentication flow\n * @description When enabled, uses Broadcast Channel API for communication instead of URL redirects.\n * Only applicable on platforms that support Broadcast Channel (Android).\n * @default false\n */\n useBroadcastChannel?: boolean;\n}\n\nexport interface AppleProviderResponse {\n /**\n * Access token from Apple\n * @description Content depends on `useProperTokenExchange` setting:\n * - When `useProperTokenExchange: true`: Real access token from Apple (~1 hour validity)\n * - When `useProperTokenExchange: false`: Contains authorization code as token (legacy mode)\n * Use `idToken` for user authentication, `accessToken` for API calls when properly exchanged.\n */\n accessToken: AccessToken | null;\n\n /**\n * Identity token (JWT) from Apple\n * @description Always contains the JWT with user identity information including:\n * - User ID (sub claim)\n * - Email (if user granted permission)\n * - Name components (if user granted permission)\n * - Email verification status\n * This is the primary token for user authentication and should be verified on your backend.\n */\n idToken: string | null;\n\n /**\n * User profile information\n * @description Basic user profile data extracted from the identity token and Apple response:\n * - `user`: Apple's user identifier (sub claim from idToken)\n * - `email`: User's email address (if permission granted)\n * - `givenName`: User's first name (if permission granted)\n * - `familyName`: User's last name (if permission granted)\n */\n profile: {\n user: string;\n email: string | null;\n givenName: string | null;\n familyName: string | null;\n };\n\n /**\n * Authorization code for proper token exchange (when useProperTokenExchange is enabled)\n * @description Only present when `useProperTokenExchange` is `true`. This code should be exchanged\n * for proper access tokens on your backend using Apple's token endpoint. Use this for secure\n * server-side token validation and to obtain refresh tokens.\n * @see https://developer.apple.com/documentation/sign_in_with_apple/tokenresponse\n */\n authorizationCode?: string;\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 | {\n provider: 'twitter';\n options: TwitterLoginOptions;\n }\n | {\n provider: 'oauth2';\n options: OAuth2LoginOptions;\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 | {\n provider: 'twitter';\n result: TwitterLoginResponse;\n }\n | {\n provider: 'oauth2';\n result: OAuth2LoginResponse;\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 tokenType?: 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 TwitterProfile {\n id: string;\n username: string;\n name: string | null;\n profileImageUrl: string | null;\n verified: boolean;\n email?: string | null;\n}\n\nexport interface TwitterLoginResponse {\n accessToken: AccessToken | null;\n refreshToken?: string | null;\n scope: string[];\n tokenType: 'bearer';\n expiresIn?: number | null;\n profile: TwitterProfile;\n}\n\nexport interface AuthorizationCode {\n /**\n * Jwt\n * @description A JSON web token\n */\n jwt?: string;\n /**\n * Access Token\n * @description An access token\n */\n accessToken?: string;\n}\n\nexport interface AuthorizationCodeOptions {\n /**\n * Provider\n * @description Provider for the authorization code\n */\n provider: 'apple' | 'google' | 'facebook' | 'twitter' | 'oauth2';\n /**\n * Provider ID for OAuth2 providers (required when provider is 'oauth2')\n * @description The ID used when configuring the OAuth2 provider in initialize()\n */\n providerId?: string;\n}\n\nexport interface isLoggedInOptions {\n /**\n * Provider\n * @description Provider for the isLoggedIn\n */\n provider: 'apple' | 'google' | 'facebook' | 'twitter' | 'oauth2';\n /**\n * Provider ID for OAuth2 providers (required when provider is 'oauth2')\n * @description The ID used when configuring the OAuth2 provider in initialize()\n */\n providerId?: string;\n}\n\n// Define the provider-specific call types\nexport type ProviderSpecificCall = 'facebook#getProfile' | 'facebook#requestTracking';\n\n// Define the options and response types for each specific call\nexport interface FacebookGetProfileOptions {\n /**\n * Fields to retrieve from Facebook profile\n * @example [\"id\", \"name\", \"email\", \"picture\"]\n */\n fields?: string[];\n}\n\nexport interface FacebookGetProfileResponse {\n /**\n * Facebook profile data\n */\n profile: {\n id: string | null;\n name: string | null;\n email: string | null;\n first_name: string | null;\n last_name: string | null;\n picture?: {\n data: {\n height: number | null;\n is_silhouette: boolean | null;\n url: string | null;\n width: number | null;\n };\n } | null;\n [key: string]: any; // For additional fields that might be requested\n };\n}\n\nexport interface OpenSecureWindowOptions {\n /**\n * The endpoint to open\n */\n authEndpoint: string;\n /**\n * The redirect URI to use for the openSecureWindow call.\n * This will be checked to make sure it matches the redirect URI after the window finishes the redirection.\n */\n redirectUri: string;\n /**\n * The name of the broadcast channel to listen to, relevant only for web\n */\n broadcastChannelName?: string;\n}\n\nexport interface OpenSecureWindowResponse {\n /**\n * The result of the openSecureWindow call\n */\n redirectedUri: string;\n}\n\nexport type FacebookRequestTrackingOptions = Record<string, never>;\n\nexport interface FacebookRequestTrackingResponse {\n /**\n * App tracking authorization status\n */\n status: 'authorized' | 'denied' | 'notDetermined' | 'restricted';\n}\n\n// Map call strings to their options and response types\nexport type ProviderSpecificCallOptionsMap = {\n 'facebook#getProfile': FacebookGetProfileOptions;\n 'facebook#requestTracking': FacebookRequestTrackingOptions;\n};\n\nexport type ProviderSpecificCallResponseMap = {\n 'facebook#getProfile': FacebookGetProfileResponse;\n 'facebook#requestTracking': FacebookRequestTrackingResponse;\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 twitter: TwitterLoginResponse;\n oauth2: OAuth2LoginResponse;\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 from the specified provider\n *\n * **Google Offline Mode Limitation:**\n * This method is NOT supported when Google is initialized with `mode: 'offline'`.\n * It will reject with error: \"logout is not implemented when using offline mode\"\n *\n * @throws Error if Google provider is in offline mode\n */\n logout(options: {\n provider: 'apple' | 'google' | 'facebook' | 'twitter' | 'oauth2';\n providerId?: string;\n }): Promise<void>;\n /**\n * IsLoggedIn\n * @description Check if the user is currently logged in with the specified provider\n *\n * **Google Offline Mode Limitation:**\n * This method is NOT supported when Google is initialized with `mode: 'offline'`.\n * It will reject with error: \"isLoggedIn is not implemented when using offline mode\"\n *\n * @throws Error if Google provider is in offline mode\n */\n isLoggedIn(options: isLoggedInOptions): Promise<{ isLoggedIn: boolean }>;\n\n /**\n * Get the current authorization code\n * @description Get the authorization code for server-side authentication\n *\n * **Google Offline Mode Limitation:**\n * This method is NOT supported when Google is initialized with `mode: 'offline'`.\n * It will reject with error: \"getAuthorizationCode is not implemented when using offline mode\"\n *\n * In offline mode, the authorization code (serverAuthCode) is already returned by the `login()` method.\n *\n * @throws Error if Google provider is in offline mode\n */\n getAuthorizationCode(options: AuthorizationCodeOptions): Promise<AuthorizationCode>;\n /**\n * Refresh the access token\n * @description refresh the access token\n */\n refresh(options: LoginOptions): Promise<void>;\n\n /**\n * Execute provider-specific calls\n * @description Execute a provider-specific functionality\n */\n providerSpecificCall<T extends ProviderSpecificCall>(options: {\n call: T;\n options: ProviderSpecificCallOptionsMap[T];\n }): Promise<ProviderSpecificCallResponseMap[T]>;\n\n /**\n * Get the native Capacitor plugin version\n *\n * @returns {Promise<{ id: string }>} an Promise with version for this device\n * @throws An error if the something went wrong\n */\n getPluginVersion(): Promise<{ version: string }>;\n\n /**\n * Opens a secured window for OAuth2 authentication.\n * For web, you should have the code in the redirected page to use a broadcast channel to send the redirected url to the app\n * Something like:\n * ```html\n * <html>\n * <head></head>\n * <body>\n * <script>\n * const searchParams = new URLSearchParams(location.search)\n * if (searchParams.has(\"code\")) {\n * new BroadcastChannel(\"my-channel-name\").postMessage(location.href);\n * window.close();\n * }\n * </script>\n * </body>\n * </html>\n * ```\n * For mobile, you should have a redirect uri that opens the app, something like: `myapp://oauth_callback/`\n * And make sure to register it in the app's info.plist:\n * ```xml\n * <key>CFBundleURLTypes</key>\n * <array>\n * <dict>\n * <key>CFBundleURLSchemes</key>\n * <array>\n * <string>myapp</string>\n * </array>\n * </dict>\n * </array>\n * ```\n * And in the AndroidManifest.xml file:\n * ```xml\n * <activity>\n * <intent-filter>\n * <action android:name=\"android.intent.action.VIEW\" />\n * <category android:name=\"android.intent.category.DEFAULT\" />\n * <category android:name=\"android.intent.category.BROWSABLE\" />\n * <data android:host=\"oauth_callback\" android:scheme=\"myapp\" />\n * </intent-filter>\n * </activity>\n * ```\n * @param options - the options for the openSecureWindow call\n */\n openSecureWindow(options: OpenSecureWindowOptions): Promise<OpenSecureWindowResponse>;\n}\n"]}
|
package/dist/esm/web.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { WebPlugin } from '@capacitor/core';
|
|
2
|
-
import type { SocialLoginPlugin, InitializeOptions, LoginOptions, AuthorizationCode, AuthorizationCodeOptions, isLoggedInOptions, ProviderResponseMap, ProviderSpecificCall, ProviderSpecificCallOptionsMap, ProviderSpecificCallResponseMap } from './definitions';
|
|
2
|
+
import type { SocialLoginPlugin, InitializeOptions, LoginOptions, AuthorizationCode, AuthorizationCodeOptions, isLoggedInOptions, ProviderResponseMap, ProviderSpecificCall, ProviderSpecificCallOptionsMap, ProviderSpecificCallResponseMap, OpenSecureWindowOptions, OpenSecureWindowResponse } from './definitions';
|
|
3
3
|
export declare class SocialLoginWeb extends WebPlugin implements SocialLoginPlugin {
|
|
4
4
|
private static readonly OAUTH_STATE_KEY;
|
|
5
5
|
private googleProvider;
|
|
@@ -32,4 +32,5 @@ export declare class SocialLoginWeb extends WebPlugin implements SocialLoginPlug
|
|
|
32
32
|
getPluginVersion(): Promise<{
|
|
33
33
|
version: string;
|
|
34
34
|
}>;
|
|
35
|
+
openSecureWindow(options: OpenSecureWindowOptions): Promise<OpenSecureWindowResponse>;
|
|
35
36
|
}
|
package/dist/esm/web.js
CHANGED
|
@@ -224,6 +224,39 @@ export class SocialLoginWeb extends WebPlugin {
|
|
|
224
224
|
async getPluginVersion() {
|
|
225
225
|
return { version: 'web' };
|
|
226
226
|
}
|
|
227
|
+
async openSecureWindow(options) {
|
|
228
|
+
const w = 600;
|
|
229
|
+
const h = 550;
|
|
230
|
+
const settings = [
|
|
231
|
+
['width', w],
|
|
232
|
+
['height', h],
|
|
233
|
+
['left', screen.width / 2 - w / 2],
|
|
234
|
+
['top', screen.height / 2 - h / 2],
|
|
235
|
+
]
|
|
236
|
+
.map((x) => x.join('='))
|
|
237
|
+
.join(',');
|
|
238
|
+
const popup = window.open(options.authEndpoint, 'Authorization', settings);
|
|
239
|
+
if (typeof popup.focus === 'function') {
|
|
240
|
+
popup.focus();
|
|
241
|
+
}
|
|
242
|
+
return new Promise((resolve, reject) => {
|
|
243
|
+
const bc = new BroadcastChannel(options.broadcastChannelName || 'oauth-channel');
|
|
244
|
+
bc.addEventListener('message', (event) => {
|
|
245
|
+
if (event.data.startsWith(options.redirectUri)) {
|
|
246
|
+
bc.close();
|
|
247
|
+
resolve({ redirectedUri: event.data });
|
|
248
|
+
}
|
|
249
|
+
else {
|
|
250
|
+
bc.close();
|
|
251
|
+
reject(new Error('Redirect URI does not match, expected ' + options.redirectUri + ' but got ' + event.data));
|
|
252
|
+
}
|
|
253
|
+
});
|
|
254
|
+
setTimeout(() => {
|
|
255
|
+
bc.close();
|
|
256
|
+
reject(new Error('The sign-in flow timed out'));
|
|
257
|
+
}, 5 * 60000);
|
|
258
|
+
});
|
|
259
|
+
}
|
|
227
260
|
}
|
|
228
261
|
SocialLoginWeb.OAUTH_STATE_KEY = 'social_login_oauth_pending';
|
|
229
262
|
//# sourceMappingURL=web.js.map
|