@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.
@@ -1 +1 @@
1
- {"version":3,"file":"social-login.js","sourceRoot":"","sources":["../../src/social-login.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAIjD,MAAM,CAAC,MAAM,eAAe,GAAG,cAAc,CAAoB,aAAa,EAAE;IAC9E,GAAG,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC,cAAc,EAAE,CAAC;CAC/D,CAAC,CAAC","sourcesContent":["import { registerPlugin } from '@capacitor/core';\n\nimport type { SocialLoginPlugin } from './definitions';\n\nexport const SocialLoginBase = registerPlugin<SocialLoginPlugin>('SocialLogin', {\n web: () => import('./web').then((m) => new m.SocialLoginWeb()),\n});\n"]}
1
+ {"version":3,"file":"social-login.js","sourceRoot":"","sources":["../../src/social-login.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAkBjD,MAAM,8BAA8B,GAClC,0PAA0P,CAAC;AAE7P,MAAM,cAAc,GAAG,cAAc,CAAoB,aAAa,EAAE;IACtE,GAAG,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC,cAAc,EAAE,CAAC;CAC/D,CAAC,CAAC;AAEH,MAAM,iBAAiB;IAGrB;QACE,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC7C,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACzC,CAAC;IAED,KAAK,C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AAC,OAAO,CAAC,CAAC;IAC9D,CAAC;IAED,KAAK,CAAC,sBAAsB,CAAC,OAAuC;QAClE,OAAO,cAAc,CAAC,sBAAsB,CAAC,OAAO,CAAC,CAAC;IACxD,CAAC;IAED,KAAK,CAAC,oBAAoB,CAAC,OAA8C;QACvE,OAAO,cAAc,CAAC,oBAAoB,CAAC,OAAO,CAAC,CAAC;IACtD,CAAC;IAED,KAAK,CAAC,uBAAuB,CAAC,OAAwC;QACpE,OAAO,cAAc,CAAC,uBAAuB,CAAC,OAAO,CAAC,CAAC;IACzD,CAAC;IAED,KAAK,CAAC,oBAAoB,CAAiC,OAG1D;QACC,OAAO,cAAc,CAAC,oBAAoB,CAAC,OAAO,CAAC,CAAC;IACtD,CAAC;IAED,KAAK,CAAC,gBAAgB;QACpB,OAAO,cAAc,CAAC,gBAAgB,EAAE,CAAC;IAC3C,CAAC;IAED,KAAK,CAAC,gBAAgB,CAAC,OAAgC;QACrD,OAAO,cAAc,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC;IAClD,CAAC;CACF;AAED,MAAM,CAAC,MAAM,eAAe,GAAG,cAAc,CAAC;AAC9C,MAAM,CAAC,MAAM,WAAW,GAAG,IAAI,iBAAiB,EAAE,CAAC","sourcesContent":["import { registerPlugin } from '@capacitor/core';\n\nimport type {\n AuthorizationCode,\n AuthorizationCodeOptions,\n InitializeOptions,\n LoginOptions,\n OpenSecureWindowOptions,\n OpenSecureWindowResponse,\n OAuth2LoginResponse,\n ProviderResponseMap,\n ProviderSpecificCall,\n ProviderSpecificCallOptionsMap,\n ProviderSpecificCallResponseMap,\n SocialLoginPlugin,\n isLoggedInOptions,\n} from './definitions';\n\nconst GOOGLE_OFFLINE_REFRESH_MESSAGE =\n \"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.\";\n\nconst rawSocialLogin = registerPlugin<SocialLoginPlugin>('SocialLogin', {\n web: () => import('./web').then((m) => new m.SocialLoginWeb()),\n});\n\nclass SocialLoginClient implements SocialLoginPlugin {\n private initializeOptions?: InitializeOptions;\n\n constructor() {\n this.initialize = this.initialize.bind(this);\n this.refresh = this.refresh.bind(this);\n }\n\n async initialize(options: InitializeOptions): Promise<void> {\n await rawSocialLogin.initialize(options);\n this.initializeOptions = options;\n }\n\n async login<T extends LoginOptions['provider']>(\n options: Extract<LoginOptions, { provider: T }>,\n ): Promise<{ provider: T; result: ProviderResponseMap[T] }> {\n return rawSocialLogin.login(options);\n }\n\n async logout(options: {\n provider: 'apple' | 'google' | 'facebook' | 'twitter' | 'oauth2';\n providerId?: string;\n }): Promise<void> {\n return rawSocialLogin.logout(options);\n }\n\n async isLoggedIn(options: isLoggedInOptions): Promise<{ isLoggedIn: boolean }> {\n return rawSocialLogin.isLoggedIn(options);\n }\n\n async getAuthorizationCode(options: AuthorizationCodeOptions): Promise<AuthorizationCode> {\n return rawSocialLogin.getAuthorizationCode(options);\n }\n\n async refresh(options: LoginOptions): Promise<void> {\n if (options.provider === 'google' && this.initializeOptions?.google?.mode === 'offline') {\n console.warn(`[SocialLogin] ${GOOGLE_OFFLINE_REFRESH_MESSAGE}`);\n }\n return rawSocialLogin.refresh(options);\n }\n\n async refreshToken(options: {\n provider: 'oauth2';\n providerId: string;\n refreshToken?: string;\n additionalParameters?: Record<string, string>;\n }): Promise<OAuth2LoginResponse> {\n return rawSocialLogin.refreshToken(options);\n }\n\n async handleRedirectCallback() {\n return rawSocialLogin.handleRedirectCallback();\n }\n\n async decodeIdToken(options: { idToken?: string; token?: string }): Promise<{ claims: Record<string, any> }> {\n return rawSocialLogin.decodeIdToken(options);\n }\n\n async getAccessTokenExpirationDate(options: { accessTokenExpirationDate: number }): Promise<{ date: string }> {\n return rawSocialLogin.getAccessTokenExpirationDate(options);\n }\n\n async isAccessTokenAvailable(options: { accessToken: string | null }): Promise<{ isAvailable: boolean }> {\n return rawSocialLogin.isAccessTokenAvailable(options);\n }\n\n async isAccessTokenExpired(options: { accessTokenExpirationDate: number }): Promise<{ isExpired: boolean }> {\n return rawSocialLogin.isAccessTokenExpired(options);\n }\n\n async isRefreshTokenAvailable(options: { refreshToken: string | null }): Promise<{ isAvailable: boolean }> {\n return rawSocialLogin.isRefreshTokenAvailable(options);\n }\n\n async providerSpecificCall<T extends ProviderSpecificCall>(options: {\n call: T;\n options: ProviderSpecificCallOptionsMap[T];\n }): Promise<ProviderSpecificCallResponseMap[T]> {\n return rawSocialLogin.providerSpecificCall(options);\n }\n\n async getPluginVersion(): Promise<{ version: string }> {\n return rawSocialLogin.getPluginVersion();\n }\n\n async openSecureWindow(options: OpenSecureWindowOptions): Promise<OpenSecureWindowResponse> {\n return rawSocialLogin.openSecureWindow(options);\n }\n}\n\nexport const SocialLoginBase = rawSocialLogin;\nexport const SocialLogin = new SocialLoginClient();\n"]}
@@ -2,9 +2,71 @@
2
2
 
3
3
  var core = require('@capacitor/core');
4
4
 
5
- const SocialLoginBase = core.registerPlugin('SocialLogin', {
5
+ 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.";
6
+ const rawSocialLogin = core.registerPlugin('SocialLogin', {
6
7
  web: () => Promise.resolve().then(function () { return web; }).then((m) => new m.SocialLoginWeb()),
7
8
  });
9
+ class SocialLoginClient {
10
+ constructor() {
11
+ this.initialize = this.initialize.bind(this);
12
+ this.refresh = this.refresh.bind(this);
13
+ }
14
+ async initialize(options) {
15
+ await rawSocialLogin.initialize(options);
16
+ this.initializeOptions = options;
17
+ }
18
+ async login(options) {
19
+ return rawSocialLogin.login(options);
20
+ }
21
+ async logout(options) {
22
+ return rawSocialLogin.logout(options);
23
+ }
24
+ async isLoggedIn(options) {
25
+ return rawSocialLogin.isLoggedIn(options);
26
+ }
27
+ async getAuthorizationCode(options) {
28
+ return rawSocialLogin.getAuthorizationCode(options);
29
+ }
30
+ async refresh(options) {
31
+ var _a, _b;
32
+ 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') {
33
+ console.warn(`[SocialLogin] ${GOOGLE_OFFLINE_REFRESH_MESSAGE$1}`);
34
+ }
35
+ return rawSocialLogin.refresh(options);
36
+ }
37
+ async refreshToken(options) {
38
+ return rawSocialLogin.refreshToken(options);
39
+ }
40
+ async handleRedirectCallback() {
41
+ return rawSocialLogin.handleRedirectCallback();
42
+ }
43
+ async decodeIdToken(options) {
44
+ return rawSocialLogin.decodeIdToken(options);
45
+ }
46
+ async getAccessTokenExpirationDate(options) {
47
+ return rawSocialLogin.getAccessTokenExpirationDate(options);
48
+ }
49
+ async isAccessTokenAvailable(options) {
50
+ return rawSocialLogin.isAccessTokenAvailable(options);
51
+ }
52
+ async isAccessTokenExpired(options) {
53
+ return rawSocialLogin.isAccessTokenExpired(options);
54
+ }
55
+ async isRefreshTokenAvailable(options) {
56
+ return rawSocialLogin.isRefreshTokenAvailable(options);
57
+ }
58
+ async providerSpecificCall(options) {
59
+ return rawSocialLogin.providerSpecificCall(options);
60
+ }
61
+ async getPluginVersion() {
62
+ return rawSocialLogin.getPluginVersion();
63
+ }
64
+ async openSecureWindow(options) {
65
+ return rawSocialLogin.openSecureWindow(options);
66
+ }
67
+ }
68
+ const SocialLoginBase = rawSocialLogin;
69
+ const SocialLogin = new SocialLoginClient();
8
70
 
9
71
  /******************************************************************************
10
72
  Copyright (c) Microsoft Corporation.
@@ -469,6 +531,7 @@ class FacebookSocialLogin extends BaseSocialLogin {
469
531
  }
470
532
  }
471
533
 
534
+ 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.";
472
535
  class GoogleSocialLogin extends BaseSocialLogin {
473
536
  constructor() {
474
537
  super(...arguments);
@@ -585,8 +648,11 @@ class GoogleSocialLogin extends BaseSocialLogin {
585
648
  }
586
649
  }
587
650
  async refresh() {
588
- // For Google, we can prompt for re-authentication
589
- return Promise.reject('Not implemented');
651
+ if (this.loginType === 'offline') {
652
+ console.warn(`[SocialLogin] ${GOOGLE_OFFLINE_REFRESH_MESSAGE}`);
653
+ return Promise.reject(new Error(GOOGLE_OFFLINE_REFRESH_MESSAGE));
654
+ }
655
+ return Promise.reject(new Error('Google refresh is not implemented on web. Use login() again to obtain a new token.'));
590
656
  }
591
657
  handleOAuthRedirect(url) {
592
658
  const paramsRaw = url.searchParams;
@@ -789,13 +855,21 @@ class GoogleSocialLogin extends BaseSocialLogin {
789
855
  reject(new Error('Failed to open popup'));
790
856
  return;
791
857
  }
792
- const cleanup = () => {
858
+ const cleanup = (shouldClose = false) => {
793
859
  window.removeEventListener('message', handleMessage);
794
860
  clearInterval(popupClosedInterval);
795
861
  clearTimeout(timeoutHandle);
796
862
  if (broadcastChannel) {
797
863
  broadcastChannel.close();
798
864
  }
865
+ if (shouldClose) {
866
+ try {
867
+ popup.close();
868
+ }
869
+ catch (_a) {
870
+ // Ignore cross-origin errors when closing the popup
871
+ }
872
+ }
799
873
  };
800
874
  const processOAuthResponse = (data) => {
801
875
  if (this.loginType === 'online') {
@@ -846,11 +920,11 @@ class GoogleSocialLogin extends BaseSocialLogin {
846
920
  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')))
847
921
  return;
848
922
  if (((_c = event.data) === null || _c === void 0 ? void 0 : _c.type) === 'oauth-response') {
849
- cleanup();
923
+ cleanup(true);
850
924
  processOAuthResponse(event.data);
851
925
  }
852
926
  else if (((_d = event.data) === null || _d === void 0 ? void 0 : _d.type) === 'oauth-error') {
853
- cleanup();
927
+ cleanup(true);
854
928
  const errorMessage = event.data.error || 'User cancelled the OAuth flow';
855
929
  reject(new Error(errorMessage));
856
930
  }
@@ -864,11 +938,11 @@ class GoogleSocialLogin extends BaseSocialLogin {
864
938
  if ((_a = data === null || data === void 0 ? void 0 : data.source) === null || _a === void 0 ? void 0 : _a.toString().startsWith('angular'))
865
939
  return;
866
940
  if ((data === null || data === void 0 ? void 0 : data.type) === 'oauth-response') {
867
- cleanup();
941
+ cleanup(true);
868
942
  processOAuthResponse(data);
869
943
  }
870
944
  else if ((data === null || data === void 0 ? void 0 : data.type) === 'oauth-error') {
871
- cleanup();
945
+ cleanup(true);
872
946
  const errorMessage = data.error || 'User cancelled the OAuth flow';
873
947
  reject(new Error(errorMessage));
874
948
  }
@@ -877,13 +951,7 @@ class GoogleSocialLogin extends BaseSocialLogin {
877
951
  window.addEventListener('message', handleMessage);
878
952
  // Timeout after 5 minutes
879
953
  timeoutHandle = setTimeout(() => {
880
- cleanup();
881
- try {
882
- popup.close();
883
- }
884
- catch (_a) {
885
- // Ignore cross-origin errors when closing
886
- }
954
+ cleanup(true);
887
955
  reject(new Error('OAuth timeout'));
888
956
  }, 300000);
889
957
  popupClosedInterval = setInterval(() => {
@@ -943,6 +1011,7 @@ class OAuth2SocialLogin extends BaseSocialLogin {
943
1011
  }
944
1012
  return {
945
1013
  appId,
1014
+ clientSecret: config.clientSecret,
946
1015
  issuerUrl: config.issuerUrl,
947
1016
  authorizationBaseUrl,
948
1017
  accessTokenEndpoint,
@@ -1405,6 +1474,9 @@ class OAuth2SocialLogin extends BaseSocialLogin {
1405
1474
  if (config.pkceEnabled) {
1406
1475
  params.set('code_verifier', pending.codeVerifier);
1407
1476
  }
1477
+ if (config.clientSecret) {
1478
+ params.set('client_secret', config.clientSecret);
1479
+ }
1408
1480
  if (config.additionalTokenParameters) {
1409
1481
  for (const [k, v] of Object.entries(config.additionalTokenParameters)) {
1410
1482
  params.set(k, v);
@@ -1436,6 +1508,9 @@ class OAuth2SocialLogin extends BaseSocialLogin {
1436
1508
  refresh_token: refreshToken,
1437
1509
  client_id: config.appId,
1438
1510
  });
1511
+ if (config.clientSecret) {
1512
+ params.set('client_secret', config.clientSecret);
1513
+ }
1439
1514
  if (config.additionalTokenParameters) {
1440
1515
  for (const [k, v] of Object.entries(config.additionalTokenParameters)) {
1441
1516
  params.set(k, v);
@@ -2258,7 +2333,8 @@ var web = /*#__PURE__*/Object.freeze({
2258
2333
  SocialLoginWeb: SocialLoginWeb
2259
2334
  });
2260
2335
 
2261
- exports.SocialLogin = SocialLoginBase;
2336
+ exports.SocialLogin = SocialLogin;
2262
2337
  exports.SocialLoginAuthConnect = SocialLoginAuthConnect;
2338
+ exports.SocialLoginBase = SocialLoginBase;
2263
2339
  exports.createAuthConnectClient = createAuthConnectClient;
2264
2340
  //# sourceMappingURL=plugin.cjs.js.map