@capgo/capacitor-social-login 8.3.16 → 8.3.18

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/dist/plugin.js CHANGED
@@ -1,9 +1,71 @@
1
1
  var capacitorCapacitorUpdater = (function (exports, core) {
2
2
  'use strict';
3
3
 
4
- const SocialLoginBase = core.registerPlugin('SocialLogin', {
4
+ const GOOGLE_OFFLINE_REFRESH_MESSAGE$1 = "Google refresh() is not available when using offline mode. Offline mode only returns serverAuthCode for backend token exchange. Send serverAuthCode to your backend and refresh tokens there, or switch google.mode to 'online' for client-side refresh.";
5
+ const rawSocialLogin = core.registerPlugin('SocialLogin', {
5
6
  web: () => Promise.resolve().then(function () { return web; }).then((m) => new m.SocialLoginWeb()),
6
7
  });
8
+ class SocialLoginClient {
9
+ constructor() {
10
+ this.initialize = this.initialize.bind(this);
11
+ this.refresh = this.refresh.bind(this);
12
+ }
13
+ async initialize(options) {
14
+ await rawSocialLogin.initialize(options);
15
+ this.initializeOptions = options;
16
+ }
17
+ async login(options) {
18
+ return rawSocialLogin.login(options);
19
+ }
20
+ async logout(options) {
21
+ return rawSocialLogin.logout(options);
22
+ }
23
+ async isLoggedIn(options) {
24
+ return rawSocialLogin.isLoggedIn(options);
25
+ }
26
+ async getAuthorizationCode(options) {
27
+ return rawSocialLogin.getAuthorizationCode(options);
28
+ }
29
+ async refresh(options) {
30
+ var _a, _b;
31
+ if (options.provider === 'google' && ((_b = (_a = this.initializeOptions) === null || _a === void 0 ? void 0 : _a.google) === null || _b === void 0 ? void 0 : _b.mode) === 'offline') {
32
+ console.warn(`[SocialLogin] ${GOOGLE_OFFLINE_REFRESH_MESSAGE$1}`);
33
+ }
34
+ return rawSocialLogin.refresh(options);
35
+ }
36
+ async refreshToken(options) {
37
+ return rawSocialLogin.refreshToken(options);
38
+ }
39
+ async handleRedirectCallback() {
40
+ return rawSocialLogin.handleRedirectCallback();
41
+ }
42
+ async decodeIdToken(options) {
43
+ return rawSocialLogin.decodeIdToken(options);
44
+ }
45
+ async getAccessTokenExpirationDate(options) {
46
+ return rawSocialLogin.getAccessTokenExpirationDate(options);
47
+ }
48
+ async isAccessTokenAvailable(options) {
49
+ return rawSocialLogin.isAccessTokenAvailable(options);
50
+ }
51
+ async isAccessTokenExpired(options) {
52
+ return rawSocialLogin.isAccessTokenExpired(options);
53
+ }
54
+ async isRefreshTokenAvailable(options) {
55
+ return rawSocialLogin.isRefreshTokenAvailable(options);
56
+ }
57
+ async providerSpecificCall(options) {
58
+ return rawSocialLogin.providerSpecificCall(options);
59
+ }
60
+ async getPluginVersion() {
61
+ return rawSocialLogin.getPluginVersion();
62
+ }
63
+ async openSecureWindow(options) {
64
+ return rawSocialLogin.openSecureWindow(options);
65
+ }
66
+ }
67
+ const SocialLoginBase = rawSocialLogin;
68
+ const SocialLogin = new SocialLoginClient();
7
69
 
8
70
  /******************************************************************************
9
71
  Copyright (c) Microsoft Corporation.
@@ -468,6 +530,7 @@ var capacitorCapacitorUpdater = (function (exports, core) {
468
530
  }
469
531
  }
470
532
 
533
+ const GOOGLE_OFFLINE_REFRESH_MESSAGE = "Google refresh() is not available when using offline mode. Offline mode only returns serverAuthCode for backend token exchange. Send serverAuthCode to your backend and refresh tokens there, or switch google.mode to 'online' for client-side refresh.";
471
534
  class GoogleSocialLogin extends BaseSocialLogin {
472
535
  constructor() {
473
536
  super(...arguments);
@@ -584,8 +647,11 @@ var capacitorCapacitorUpdater = (function (exports, core) {
584
647
  }
585
648
  }
586
649
  async refresh() {
587
- // For Google, we can prompt for re-authentication
588
- return Promise.reject('Not implemented');
650
+ if (this.loginType === 'offline') {
651
+ console.warn(`[SocialLogin] ${GOOGLE_OFFLINE_REFRESH_MESSAGE}`);
652
+ return Promise.reject(new Error(GOOGLE_OFFLINE_REFRESH_MESSAGE));
653
+ }
654
+ return Promise.reject(new Error('Google refresh is not implemented on web. Use login() again to obtain a new token.'));
589
655
  }
590
656
  handleOAuthRedirect(url) {
591
657
  const paramsRaw = url.searchParams;
@@ -788,13 +854,21 @@ var capacitorCapacitorUpdater = (function (exports, core) {
788
854
  reject(new Error('Failed to open popup'));
789
855
  return;
790
856
  }
791
- const cleanup = () => {
857
+ const cleanup = (shouldClose = false) => {
792
858
  window.removeEventListener('message', handleMessage);
793
859
  clearInterval(popupClosedInterval);
794
860
  clearTimeout(timeoutHandle);
795
861
  if (broadcastChannel) {
796
862
  broadcastChannel.close();
797
863
  }
864
+ if (shouldClose) {
865
+ try {
866
+ popup.close();
867
+ }
868
+ catch (_a) {
869
+ // Ignore cross-origin errors when closing the popup
870
+ }
871
+ }
798
872
  };
799
873
  const processOAuthResponse = (data) => {
800
874
  if (this.loginType === 'online') {
@@ -845,11 +919,11 @@ var capacitorCapacitorUpdater = (function (exports, core) {
845
919
  if (event.origin !== window.location.origin || ((_b = (_a = event.data) === null || _a === void 0 ? void 0 : _a.source) === null || _b === void 0 ? void 0 : _b.startsWith('angular')))
846
920
  return;
847
921
  if (((_c = event.data) === null || _c === void 0 ? void 0 : _c.type) === 'oauth-response') {
848
- cleanup();
922
+ cleanup(true);
849
923
  processOAuthResponse(event.data);
850
924
  }
851
925
  else if (((_d = event.data) === null || _d === void 0 ? void 0 : _d.type) === 'oauth-error') {
852
- cleanup();
926
+ cleanup(true);
853
927
  const errorMessage = event.data.error || 'User cancelled the OAuth flow';
854
928
  reject(new Error(errorMessage));
855
929
  }
@@ -863,11 +937,11 @@ var capacitorCapacitorUpdater = (function (exports, core) {
863
937
  if ((_a = data === null || data === void 0 ? void 0 : data.source) === null || _a === void 0 ? void 0 : _a.toString().startsWith('angular'))
864
938
  return;
865
939
  if ((data === null || data === void 0 ? void 0 : data.type) === 'oauth-response') {
866
- cleanup();
940
+ cleanup(true);
867
941
  processOAuthResponse(data);
868
942
  }
869
943
  else if ((data === null || data === void 0 ? void 0 : data.type) === 'oauth-error') {
870
- cleanup();
944
+ cleanup(true);
871
945
  const errorMessage = data.error || 'User cancelled the OAuth flow';
872
946
  reject(new Error(errorMessage));
873
947
  }
@@ -876,13 +950,7 @@ var capacitorCapacitorUpdater = (function (exports, core) {
876
950
  window.addEventListener('message', handleMessage);
877
951
  // Timeout after 5 minutes
878
952
  timeoutHandle = setTimeout(() => {
879
- cleanup();
880
- try {
881
- popup.close();
882
- }
883
- catch (_a) {
884
- // Ignore cross-origin errors when closing
885
- }
953
+ cleanup(true);
886
954
  reject(new Error('OAuth timeout'));
887
955
  }, 300000);
888
956
  popupClosedInterval = setInterval(() => {
@@ -942,6 +1010,7 @@ var capacitorCapacitorUpdater = (function (exports, core) {
942
1010
  }
943
1011
  return {
944
1012
  appId,
1013
+ clientSecret: config.clientSecret,
945
1014
  issuerUrl: config.issuerUrl,
946
1015
  authorizationBaseUrl,
947
1016
  accessTokenEndpoint,
@@ -1404,6 +1473,9 @@ var capacitorCapacitorUpdater = (function (exports, core) {
1404
1473
  if (config.pkceEnabled) {
1405
1474
  params.set('code_verifier', pending.codeVerifier);
1406
1475
  }
1476
+ if (config.clientSecret) {
1477
+ params.set('client_secret', config.clientSecret);
1478
+ }
1407
1479
  if (config.additionalTokenParameters) {
1408
1480
  for (const [k, v] of Object.entries(config.additionalTokenParameters)) {
1409
1481
  params.set(k, v);
@@ -1435,6 +1507,9 @@ var capacitorCapacitorUpdater = (function (exports, core) {
1435
1507
  refresh_token: refreshToken,
1436
1508
  client_id: config.appId,
1437
1509
  });
1510
+ if (config.clientSecret) {
1511
+ params.set('client_secret', config.clientSecret);
1512
+ }
1438
1513
  if (config.additionalTokenParameters) {
1439
1514
  for (const [k, v] of Object.entries(config.additionalTokenParameters)) {
1440
1515
  params.set(k, v);
@@ -2257,8 +2332,9 @@ var capacitorCapacitorUpdater = (function (exports, core) {
2257
2332
  SocialLoginWeb: SocialLoginWeb
2258
2333
  });
2259
2334
 
2260
- exports.SocialLogin = SocialLoginBase;
2335
+ exports.SocialLogin = SocialLogin;
2261
2336
  exports.SocialLoginAuthConnect = SocialLoginAuthConnect;
2337
+ exports.SocialLoginBase = SocialLoginBase;
2262
2338
  exports.createAuthConnectClient = createAuthConnectClient;
2263
2339
 
2264
2340
  return exports;