@capgo/capacitor-social-login 1.2.6 → 7.1.6

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.
@@ -13,9 +13,9 @@ Pod::Spec.new do |s|
13
13
  s.source_files = 'ios/Sources/**/*.{swift,h,m,c,cc,mm,cpp}'
14
14
  s.ios.deployment_target = '14.0'
15
15
  s.dependency 'Capacitor'
16
- s.dependency 'FBSDKCoreKit', '17.1.0'
17
- s.dependency 'FBSDKLoginKit', '17.1.0'
16
+ s.dependency 'FBSDKCoreKit', '17.4.0'
17
+ s.dependency 'FBSDKLoginKit', '17.4.0'
18
18
  s.dependency 'GoogleSignIn', '~> 8.0.0'
19
- s.dependency 'Alamofire'
19
+ s.dependency 'Alamofire', '~> 5.10.2'
20
20
  s.swift_version = '5.1'
21
21
  end
package/Package.swift CHANGED
@@ -10,9 +10,9 @@ let package = Package(
10
10
  targets: ["SocialLoginPlugin"])
11
11
  ],
12
12
  dependencies: [
13
- .package(url: "https://github.com/ionic-team/capacitor-swift-pm.git", from: "7.0.0"),
13
+ .package(url: "https://github.com/ionic-team/capacitor-swift-pm.git", from: "7.0.1"),
14
14
  // FBSDKCoreKit and FBSDKLoginKit
15
- .package(url: "https://github.com/facebook/facebook-ios-sdk.git", .upToNextMajor(from: "18.0.0")),
15
+ .package(url: "https://github.com/facebook/facebook-ios-sdk.git", .upToNextMajor(from: "17.4.0")),
16
16
  // Add Google Sign-In dependency
17
17
  .package(url: "https://github.com/google/GoogleSignIn-iOS.git", .upToNextMajor(from: "8.0.0")),
18
18
  // Alamofire
package/README.md CHANGED
@@ -221,7 +221,7 @@ Call the `initialize` method with the `google` provider
221
221
  await SocialLogin.initialize({
222
222
  google: {
223
223
  iOSClientId: 'your-client-id', // the iOS client id
224
- iOSServerClientId: 'your-server-client-id', // the iOS server client id (optional)
224
+ iOSServerClientId: 'your-server-client-id', // the iOS server client id (required in mode offline)
225
225
  },
226
226
  });
227
227
  const res = await SocialLogin.login({
@@ -232,6 +232,10 @@ const res = await SocialLogin.login({
232
232
  });
233
233
  ```
234
234
 
235
+ ### Web
236
+
237
+ Initialize method create a script tag with google lib, we canot knwo when it's ready so be sure to do it early in web otherwise it will fail
238
+
235
239
  ## API
236
240
 
237
241
  <docgen-index>
@@ -351,11 +355,11 @@ Refresh the access token
351
355
 
352
356
  #### InitializeOptions
353
357
 
354
- | Prop | Type |
355
- | -------------- | ---------------------------------------------------------------------------------------------------------------------- |
356
- | **`facebook`** | <code>{ appId: string; clientToken: string; }</code> |
357
- | **`google`** | <code>{ iOSClientId?: string; iOSServerClientId?: string; webClientId?: string; mode?: 'online' \| 'offline'; }</code> |
358
- | **`apple`** | <code>{ clientId?: string; redirectUrl?: string; }</code> |
358
+ | Prop | Type |
359
+ | -------------- | --------------------------------------------------------------------------------------------------------------------------------------------- |
360
+ | **`facebook`** | <code>{ appId: string; clientToken: string; }</code> |
361
+ | **`google`** | <code>{ iOSClientId?: string; iOSServerClientId?: string; webClientId?: string; mode?: 'online' \| 'offline'; hostedDomain?: string; }</code> |
362
+ | **`apple`** | <code>{ clientId?: string; redirectUrl?: string; }</code> |
359
363
 
360
364
 
361
365
  #### FacebookLoginResponse
@@ -52,7 +52,7 @@ dependencies {
52
52
  implementation fileTree(dir: 'libs', include: ['*.jar'])
53
53
  implementation project(':capacitor-android')
54
54
  implementation "androidx.appcompat:appcompat:$androidxAppCompatVersion"
55
- implementation 'com.facebook.android:facebook-login:18.0.1'
55
+ implementation 'com.facebook.android:facebook-login:18.0.2'
56
56
  implementation 'com.squareup.okhttp3:okhttp:4.12.0'
57
57
  implementation 'com.auth0.android:jwtdecode:2.0.2'
58
58
  implementation "androidx.credentials:credentials:1.3.0"
@@ -76,6 +76,7 @@ public class GoogleProvider implements SocialProvider {
76
76
  private String idToken = null;
77
77
  private String accessToken = null;
78
78
  private GoogleProviderLoginType mode = GoogleProviderLoginType.ONLINE;
79
+ private String hostedDomain = null;
79
80
 
80
81
  public enum GoogleProviderLoginType {
81
82
  ONLINE,
@@ -91,10 +92,11 @@ public class GoogleProvider implements SocialProvider {
91
92
  }
92
93
  }
93
94
 
94
- public void initialize(String clientId, GoogleProviderLoginType mode) {
95
+ public void initialize(String clientId, GoogleProviderLoginType mode, String hostedDomain) {
95
96
  this.credentialManager = CredentialManager.create(activity);
96
97
  this.clientId = clientId;
97
98
  this.mode = mode;
99
+ this.hostedDomain = hostedDomain;
98
100
 
99
101
  String data = context.getSharedPreferences(SHARED_PREFERENCE_NAME, Context.MODE_PRIVATE).getString(GOOGLE_DATA_PREFERENCE, null);
100
102
 
@@ -281,7 +283,7 @@ public class GoogleProvider implements SocialProvider {
281
283
  return;
282
284
  }
283
285
 
284
- String nonce = call.getString("nonce");
286
+ String nonce = config.optString("nonce");
285
287
 
286
288
  // Extract scopes from the config
287
289
  JSONArray scopesArray = config.optJSONArray("scopes");
@@ -338,6 +340,10 @@ public class GoogleProvider implements SocialProvider {
338
340
  googleIdOptionBuilder.setNonce(nonce);
339
341
  }
340
342
 
343
+ if (this.hostedDomain != null && !this.hostedDomain.isEmpty()) {
344
+ googleIdOptionBuilder.setHostedDomainFilter(this.hostedDomain);
345
+ }
346
+
341
347
  GetSignInWithGoogleOption googleIdOptionFiltered = googleIdOptionBuilder.build();
342
348
  GetCredentialRequest filteredRequest = new GetCredentialRequest.Builder().addCredentialOption(googleIdOptionFiltered).build();
343
349
 
@@ -59,6 +59,7 @@ public class SocialLoginPlugin extends Plugin {
59
59
  call.reject("google.clientId is null or empty");
60
60
  return;
61
61
  }
62
+ String hostedDomain = google.getString("hostedDomain");
62
63
  String modestr = google.getString("mode", "online");
63
64
  GoogleProvider.GoogleProviderLoginType mode = null;
64
65
  switch (modestr) {
@@ -72,7 +73,7 @@ public class SocialLoginPlugin extends Plugin {
72
73
  call.reject("google.mode != (online || offline)");
73
74
  return;
74
75
  }
75
- googleProvider.initialize(googleClientId, mode);
76
+ googleProvider.initialize(googleClientId, mode, hostedDomain);
76
77
  this.socialProviderHashMap.put("google", googleProvider);
77
78
  }
78
79
 
package/dist/docs.json CHANGED
@@ -168,7 +168,7 @@
168
168
  "tags": [],
169
169
  "docs": "",
170
170
  "complexTypes": [],
171
- "type": "{ iOSClientId?: string | undefined; iOSServerClientId?: string | undefined; webClientId?: string | undefined; mode?: 'online' | 'offline' | undefined; } | undefined"
171
+ "type": "{ iOSClientId?: string | undefined; iOSServerClientId?: string | undefined; webClientId?: string | undefined; mode?: 'online' | 'offline' | undefined; hostedDomain?: string | undefined; } | undefined"
172
172
  },
173
173
  {
174
174
  "name": "apple",
@@ -18,7 +18,7 @@ export interface InitializeOptions {
18
18
  */
19
19
  iOSClientId?: string;
20
20
  /**
21
- * The app's server client ID, found and created in the Google Developers Console.
21
+ * The app's server client ID, required for offline mode, found and created in the Google Developers Console.
22
22
  * For iOS.
23
23
  * @example xxxxxx-xxxxxxxxxxxxxxxxxx.apps.googleusercontent.com
24
24
  * @since 3.1.0
@@ -32,11 +32,16 @@ export interface InitializeOptions {
32
32
  */
33
33
  webClientId?: string;
34
34
  /**
35
- * The login mode, can be online or offline.
35
+ * The login mode, can be online or offline. In offline mode, the user will be able to login without an internet connection. It requires iOSServerClientId to be set.
36
36
  * @example offline
37
37
  * @since 3.1.0
38
38
  */
39
39
  mode?: 'online' | 'offline';
40
+ /**
41
+ * Filter visible accounts by hosted domain
42
+ * @description filter visible accounts by hosted domain
43
+ */
44
+ hostedDomain?: string;
40
45
  };
41
46
  apple?: {
42
47
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["export interface InitializeOptions {\n facebook?: {\n /**\n * Facebook App ID, provided by Facebook for web, in mobile it's set in the native files\n */\n appId: string;\n /**\n * Facebook Client Token, provided by Facebook for web, in mobile it's set in the native files\n */\n clientToken: string;\n };\n\n google?: {\n /**\n * The app's client ID, found and created in the Google Developers Console.\n * For iOS.\n * @example xxxxxx-xxxxxxxxxxxxxxxxxx.apps.googleusercontent.com\n * @since 3.1.0\n */\n iOSClientId?: string;\n /**\n * The app's server client ID, found and created in the Google Developers Console.\n * For iOS.\n * @example xxxxxx-xxxxxxxxxxxxxxxxxx.apps.googleusercontent.com\n * @since 3.1.0\n */\n iOSServerClientId?: string;\n /**\n * The app's web client ID, found and created in the Google Developers Console.\n * For Android (and web in the future).\n * @example xxxxxx-xxxxxxxxxxxxxxxxxx.apps.googleusercontent.com\n * @since 3.1.0\n */\n webClientId?: string;\n /**\n * The login mode, can be online or offline.\n * @example offline\n * @since 3.1.0\n */\n mode?: 'online' | 'offline';\n };\n apple?: {\n /**\n * Apple Client ID, provided by Apple for web and Android\n */\n clientId?: string;\n /**\n * Apple Redirect URL, should be your backend url that is configured in your apple app, only for android\n */\n redirectUrl?: string;\n };\n}\n\nexport interface FacebookLoginOptions {\n /**\n * Permissions\n * @description select permissions to login with\n */\n permissions: string[];\n /**\n * Is Limited Login\n * @description use limited login for Facebook IOS\n * @default false\n */\n limitedLogin?: boolean;\n /**\n * Nonce\n * @description A custom nonce to use for the login request\n */\n nonce?: string;\n}\n\nexport interface GoogleLoginOptions {\n /**\n * Specifies the scopes required for accessing Google APIs\n * The default is defined in the configuration.\n * @example [\"profile\", \"email\"]\n * @see [Google OAuth2 Scopes](https://developers.google.com/identity/protocols/oauth2/scopes)\n */\n scopes?: string[];\n /**\n * Nonce\n * @description nonce\n */\n nonce?: string;\n /**\n * Force refresh token (only for Android)\n * @description force refresh token\n * @default false\n */\n forceRefreshToken?: boolean;\n /**\n * Disable one-tap login (web only)\n * @description disable one-tap login\n * @default false\n */\n disableOneTap?: boolean;\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\nexport interface AppleProviderResponse {\n accessToken: AccessToken | null;\n idToken: string | null;\n profile: {\n user: string;\n email: string | null;\n givenName: string | null;\n familyName: string | null;\n };\n}\n\nexport type LoginOptions =\n | {\n provider: 'facebook';\n options: FacebookLoginOptions;\n }\n | {\n provider: 'google';\n options: GoogleLoginOptions;\n }\n | {\n provider: 'apple';\n options: AppleProviderOptions;\n };\n\nexport type LoginResult =\n | {\n provider: 'facebook';\n result: FacebookLoginResponse;\n }\n | {\n provider: 'google';\n result: GoogleLoginResponse;\n }\n | {\n provider: 'apple';\n result: AppleProviderResponse;\n };\n\nexport interface AccessToken {\n applicationId?: string;\n declinedPermissions?: string[];\n expires?: string;\n isExpired?: boolean;\n lastRefresh?: string;\n permissions?: string[];\n token: string;\n refreshToken?: string;\n userId?: string;\n}\n\nexport interface FacebookLoginResponse {\n accessToken: AccessToken | null;\n idToken: string | null;\n profile: {\n userID: string;\n email: string | null;\n friendIDs: string[];\n birthday: string | null;\n ageRange: { min?: number; max?: number } | null;\n gender: string | null;\n location: { id: string; name: string } | null;\n hometown: { id: string; name: string } | null;\n profileURL: string | null;\n name: string | null;\n imageURL: string | null;\n };\n}\n\nexport interface AuthorizationCode {\n /**\n * Jwt\n * @description A JSON web token\n */\n jwt?: string;\n /**\n * 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';\n}\n\nexport interface isLoggedInOptions {\n /**\n * Provider\n * @description Provider for the isLoggedIn\n */\n provider: 'apple' | 'google' | 'facebook';\n}\n\n// Add a helper type to map providers to their response types\nexport type ProviderResponseMap = {\n facebook: FacebookLoginResponse;\n google: GoogleLoginResponse;\n apple: AppleProviderResponse;\n};\n\nexport interface SocialLoginPlugin {\n /**\n * Initialize the plugin\n * @description initialize the plugin with the required options\n */\n initialize(options: InitializeOptions): Promise<void>;\n /**\n * Login with the selected provider\n * @description login with the selected provider\n */\n login<T extends LoginOptions['provider']>(\n options: Extract<LoginOptions, { provider: T }>,\n ): Promise<{ provider: T; result: ProviderResponseMap[T] }>;\n /**\n * Logout\n * @description logout the user\n */\n logout(options: { provider: 'apple' | 'google' | 'facebook' }): Promise<void>;\n /**\n * IsLoggedIn\n * @description logout the user\n */\n isLoggedIn(options: isLoggedInOptions): Promise<{ isLoggedIn: boolean }>;\n\n /**\n * Get the current access token\n * @description get the current access token\n */\n getAuthorizationCode(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"]}
1
+ {"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["export interface InitializeOptions {\n facebook?: {\n /**\n * Facebook App ID, provided by Facebook for web, in mobile it's set in the native files\n */\n appId: string;\n /**\n * Facebook Client Token, provided by Facebook for web, in mobile it's set in the native files\n */\n clientToken: string;\n };\n\n google?: {\n /**\n * The app's client ID, found and created in the Google Developers Console.\n * For iOS.\n * @example xxxxxx-xxxxxxxxxxxxxxxxxx.apps.googleusercontent.com\n * @since 3.1.0\n */\n iOSClientId?: string;\n /**\n * The app's server client ID, required for offline mode, found and created in the Google Developers Console.\n * For iOS.\n * @example xxxxxx-xxxxxxxxxxxxxxxxxx.apps.googleusercontent.com\n * @since 3.1.0\n */\n iOSServerClientId?: string;\n /**\n * The app's web client ID, found and created in the Google Developers Console.\n * For Android (and web in the future).\n * @example xxxxxx-xxxxxxxxxxxxxxxxxx.apps.googleusercontent.com\n * @since 3.1.0\n */\n webClientId?: string;\n /**\n * The login mode, can be online or offline. In offline mode, the user will be able to login without an internet connection. It requires iOSServerClientId to be set.\n * @example offline\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 apple?: {\n /**\n * Apple Client ID, provided by Apple for web and Android\n */\n clientId?: string;\n /**\n * Apple Redirect URL, should be your backend url that is configured in your apple app, only for android\n */\n redirectUrl?: string;\n };\n}\n\nexport interface FacebookLoginOptions {\n /**\n * Permissions\n * @description select permissions to login with\n */\n permissions: string[];\n /**\n * Is Limited Login\n * @description use limited login for Facebook IOS\n * @default false\n */\n limitedLogin?: boolean;\n /**\n * Nonce\n * @description A custom nonce to use for the login request\n */\n nonce?: string;\n}\n\nexport interface GoogleLoginOptions {\n /**\n * Specifies the scopes required for accessing Google APIs\n * The default is defined in the configuration.\n * @example [\"profile\", \"email\"]\n * @see [Google OAuth2 Scopes](https://developers.google.com/identity/protocols/oauth2/scopes)\n */\n scopes?: string[];\n /**\n * Nonce\n * @description nonce\n */\n nonce?: string;\n /**\n * Force refresh token (only for Android)\n * @description force refresh token\n * @default false\n */\n forceRefreshToken?: boolean;\n /**\n * Disable one-tap login (web only)\n * @description disable one-tap login\n * @default false\n */\n disableOneTap?: boolean;\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\nexport interface AppleProviderResponse {\n accessToken: AccessToken | null;\n idToken: string | null;\n profile: {\n user: string;\n email: string | null;\n givenName: string | null;\n familyName: string | null;\n };\n}\n\nexport type LoginOptions =\n | {\n provider: 'facebook';\n options: FacebookLoginOptions;\n }\n | {\n provider: 'google';\n options: GoogleLoginOptions;\n }\n | {\n provider: 'apple';\n options: AppleProviderOptions;\n };\n\nexport type LoginResult =\n | {\n provider: 'facebook';\n result: FacebookLoginResponse;\n }\n | {\n provider: 'google';\n result: GoogleLoginResponse;\n }\n | {\n provider: 'apple';\n result: AppleProviderResponse;\n };\n\nexport interface AccessToken {\n applicationId?: string;\n declinedPermissions?: string[];\n expires?: string;\n isExpired?: boolean;\n lastRefresh?: string;\n permissions?: string[];\n token: string;\n refreshToken?: string;\n userId?: string;\n}\n\nexport interface FacebookLoginResponse {\n accessToken: AccessToken | null;\n idToken: string | null;\n profile: {\n userID: string;\n email: string | null;\n friendIDs: string[];\n birthday: string | null;\n ageRange: { min?: number; max?: number } | null;\n gender: string | null;\n location: { id: string; name: string } | null;\n hometown: { id: string; name: string } | null;\n profileURL: string | null;\n name: string | null;\n imageURL: string | null;\n };\n}\n\nexport interface AuthorizationCode {\n /**\n * Jwt\n * @description A JSON web token\n */\n jwt?: string;\n /**\n * 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';\n}\n\nexport interface isLoggedInOptions {\n /**\n * Provider\n * @description Provider for the isLoggedIn\n */\n provider: 'apple' | 'google' | 'facebook';\n}\n\n// Add a helper type to map providers to their response types\nexport type ProviderResponseMap = {\n facebook: FacebookLoginResponse;\n google: GoogleLoginResponse;\n apple: AppleProviderResponse;\n};\n\nexport interface SocialLoginPlugin {\n /**\n * Initialize the plugin\n * @description initialize the plugin with the required options\n */\n initialize(options: InitializeOptions): Promise<void>;\n /**\n * Login with the selected provider\n * @description login with the selected provider\n */\n login<T extends LoginOptions['provider']>(\n options: Extract<LoginOptions, { provider: T }>,\n ): Promise<{ provider: T; result: ProviderResponseMap[T] }>;\n /**\n * Logout\n * @description logout the user\n */\n logout(options: { provider: 'apple' | 'google' | 'facebook' }): Promise<void>;\n /**\n * IsLoggedIn\n * @description logout the user\n */\n isLoggedIn(options: isLoggedInOptions): Promise<{ isLoggedIn: boolean }>;\n\n /**\n * Get the current access token\n * @description get the current access token\n */\n getAuthorizationCode(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"]}
package/dist/esm/web.d.ts CHANGED
@@ -3,6 +3,7 @@ import type { SocialLoginPlugin, InitializeOptions, LoginOptions, AuthorizationC
3
3
  export declare class SocialLoginWeb extends WebPlugin implements SocialLoginPlugin {
4
4
  private static readonly OAUTH_STATE_KEY;
5
5
  private googleClientId;
6
+ private googleHostedDomain?;
6
7
  private appleClientId;
7
8
  private googleScriptLoaded;
8
9
  private googleLoginType;
package/dist/esm/web.js CHANGED
@@ -74,6 +74,7 @@ export class SocialLoginWeb extends WebPlugin {
74
74
  if (options.google.mode) {
75
75
  this.googleLoginType = options.google.mode;
76
76
  }
77
+ this.googleHostedDomain = options.google.hostedDomain;
77
78
  await this.loadGoogleScript();
78
79
  }
79
80
  if ((_b = options.apple) === null || _b === void 0 ? void 0 : _b.clientId) {
@@ -352,11 +353,12 @@ export class SocialLoginWeb extends WebPlugin {
352
353
  }
353
354
  if (scopes.length > 3 || this.googleLoginType === 'offline' || options.disableOneTap) {
354
355
  // If scopes are provided, directly use the traditional OAuth flow
355
- return this.fallbackToTraditionalOAuth(scopes);
356
+ return this.fallbackToTraditionalOAuth(scopes, this.googleHostedDomain);
356
357
  }
357
358
  return new Promise((resolve, reject) => {
358
359
  google.accounts.id.initialize({
359
360
  client_id: this.googleClientId,
361
+ hd: this.googleHostedDomain,
360
362
  callback: (response) => {
361
363
  console.log('google.accounts.id.initialize callback', response);
362
364
  if (response.error) {
@@ -387,7 +389,7 @@ export class SocialLoginWeb extends WebPlugin {
387
389
  if (notification.isNotDisplayed() || notification.isSkippedMoment()) {
388
390
  console.log('OneTap is not displayed or skipped');
389
391
  // Fallback to traditional OAuth if One Tap is not available
390
- this.fallbackToTraditionalOAuth(scopes)
392
+ this.fallbackToTraditionalOAuth(scopes, this.googleHostedDomain)
391
393
  .then((r) => resolve({ provider: 'google', result: r.result }))
392
394
  .catch(reject);
393
395
  }
@@ -561,7 +563,7 @@ export class SocialLoginWeb extends WebPlugin {
561
563
  }, { scope: options.permissions.join(',') });
562
564
  });
563
565
  }
564
- async fallbackToTraditionalOAuth(scopes) {
566
+ async fallbackToTraditionalOAuth(scopes, hostedDomain) {
565
567
  const uniqueScopes = [...new Set([...scopes, 'openid'])];
566
568
  const params = new URLSearchParams({
567
569
  client_id: this.googleClientId,
@@ -572,6 +574,9 @@ export class SocialLoginWeb extends WebPlugin {
572
574
  include_granted_scopes: 'true',
573
575
  state: 'popup',
574
576
  });
577
+ if (hostedDomain !== undefined) {
578
+ params.append('hd', hostedDomain);
579
+ }
575
580
  const url = `https://accounts.google.com/o/oauth2/v2/auth?${params.toString()}`;
576
581
  const width = 500;
577
582
  const height = 600;
@@ -1 +1 @@
1
- {"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AA+B5C,MAAM,OAAO,cAAe,SAAQ,SAAS;IAa3C;;QACE,KAAK,EAAE,CAAC;QAXF,mBAAc,GAAkB,IAAI,CAAC;QACrC,kBAAa,GAAkB,IAAI,CAAC;QACpC,uBAAkB,GAAG,KAAK,CAAC;QAC3B,oBAAe,GAAyB,QAAQ,CAAC;QACjD,sBAAiB,GAAG,KAAK,CAAC;QAC1B,mBAAc,GAAG,sFAAsF,CAAC;QACxG,6BAAwB,GAAG,gDAAgD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AAC,gBAAgB,CAAC,SAAS,EAAE,aAAa,CAAC,CAAC;YAElD,0BAA0B;YAC1B,UAAU,CAAC,GAAG,EAAE;gBACd,MAAM,CAAC,mBAAmB,CAAC,SAAS,EAAE,aAAa,CAAC,CAAC;gBACrD,KAAK,CAAC,KAAK,EAAE,CAAC;gBACd,MAAM,CAAC,IAAI,KAAK,CAAC,eAAe,CAAC,CAAC,CAAC;YACrC,CAAC,EAAE,MAAM,CAAC,CAAC;QACb,CAAC,CAAC,CAAC;IACL,CAAC;;AA/rBuB,8BAAe,GAAG,4BAA4B,AAA/B,CAAgC","sourcesContent":["import { WebPlugin } from '@capacitor/core';\n\nimport type {\n SocialLoginPlugin,\n InitializeOptions,\n LoginOptions,\n LoginResult,\n AuthorizationCode,\n GoogleLoginResponse,\n AppleProviderResponse,\n isLoggedInOptions,\n AuthorizationCodeOptions,\n FacebookLoginOptions,\n FacebookLoginResponse,\n GoogleLoginOptions,\n ProviderResponseMap,\n} from './definitions';\n\ndeclare const AppleID: any;\n\ndeclare const FB: {\n init(options: any): void;\n login(\n callback: (response: { status: string; authResponse: { accessToken: string; userID: string } }) => void,\n options?: { scope: string },\n ): void;\n logout(callback: () => void): void;\n api(path: string, params: { fields: string }, callback: (response: any) => void): void;\n getLoginStatus(callback: (response: { status: string; authResponse?: { accessToken: string } }) => void): void;\n};\n\nexport class SocialLoginWeb extends WebPlugin implements SocialLoginPlugin {\n private static readonly OAUTH_STATE_KEY = 'social_login_oauth_pending';\n\n private googleClientId: string | null = null;\n private appleClientId: string | null = null;\n private googleScriptLoaded = false;\n private googleLoginType: 'online' | 'offline' = 'online';\n private appleScriptLoaded = false;\n private appleScriptUrl = 'https://appleid.cdn-apple.com/appleauth/static/jsapi/appleid/1/en_US/appleid.auth.js';\n private GOOGLE_TOKEN_REQUEST_URL = 'https://www.googleapis.com/oauth2/v3/tokeninfo';\n private facebookAppId: string | null = null;\n private facebookScriptLoaded = false;\n\n constructor() {\n super();\n // Set up listener for OAuth redirects if we have a pending OAuth flow\n if (localStorage.getItem(SocialLoginWeb.OAUTH_STATE_KEY)) {\n console.log('OAUTH_STATE_KEY found');\n const result = this.handleOAuthRedirect();\n if (result) {\n window.opener?.postMessage(\n {\n type: 'oauth-response',\n ...result.result,\n },\n window.location.origin,\n );\n window.close();\n }\n }\n }\n\n private handleOAuthRedirect() {\n const paramsRaw = new URL(window.location.href).searchParams;\n const code = paramsRaw.get('code');\n if (code && paramsRaw.has('scope')) {\n return {\n provider: 'google' as const,\n result: {\n provider: 'google' as const,\n result: {\n serverAuthCode: code,\n },\n },\n };\n }\n\n const hash = window.location.hash.substring(1);\n console.log('handleOAuthRedirect', window.location.hash);\n if (!hash) return;\n console.log('handleOAuthRedirect ok');\n\n const params = new URLSearchParams(hash);\n const accessToken = params.get('access_token');\n const idToken = params.get('id_token');\n\n if (accessToken && idToken) {\n localStorage.removeItem(SocialLoginWeb.OAUTH_STATE_KEY);\n const profile = this.parseJwt(idToken);\n return {\n provider: 'google' as const,\n result: {\n accessToken: {\n token: accessToken,\n },\n idToken,\n profile: {\n email: profile.email || null,\n familyName: profile.family_name || null,\n givenName: profile.given_name || null,\n id: profile.sub || null,\n name: profile.name || null,\n imageUrl: profile.picture || null,\n },\n },\n };\n }\n return null;\n }\n\n async initialize(options: InitializeOptions): Promise<void> {\n if (options.google?.webClientId) {\n this.googleClientId = options.google.webClientId;\n if (options.google.mode) {\n this.googleLoginType = options.google.mode;\n }\n\n await this.loadGoogleScript();\n }\n if (options.apple?.clientId) {\n this.appleClientId = options.apple.clientId;\n await this.loadAppleScript();\n }\n if (options.facebook?.appId) {\n this.facebookAppId = options.facebook.appId;\n await this.loadFacebookScript();\n FB.init({\n appId: this.facebookAppId,\n version: 'v17.0',\n xfbml: true,\n cookie: true,\n });\n }\n // Implement initialization for other providers if needed\n }\n\n async login<T extends LoginOptions['provider']>(\n options: Extract<LoginOptions, { provider: T }>,\n ): Promise<{ provider: T; result: ProviderResponseMap[T] }> {\n switch (options.provider) {\n case 'google':\n return this.loginWithGoogle(options.options) as Promise<{\n provider: T;\n result: ProviderResponseMap[T];\n }>;\n case 'apple':\n return this.loginWithApple(options.options) as Promise<{\n provider: T;\n result: ProviderResponseMap[T];\n }>;\n case 'facebook':\n return this.loginWithFacebook(options.options as FacebookLoginOptions) as Promise<{\n provider: T;\n result: ProviderResponseMap[T];\n }>;\n default:\n throw new Error(`Login for ${options.provider} is not implemented on web`);\n }\n }\n\n async logout(options: { provider: 'apple' | 'google' | 'facebook' }): Promise<void> {\n switch (options.provider) {\n case 'google':\n if (this.googleLoginType === 'offline') {\n return Promise.reject(\"Offline login doesn't store tokens. logout is not available\");\n }\n // Google doesn't have a specific logout method for web\n // We can revoke the token if we have it stored\n console.log('Google logout: Id token should be revoked on the client side if stored');\n // eslint-disable-next-line\n const state = this.getGoogleState();\n if (!state) return;\n await this.rawLogoutGoogle(state.accessToken);\n break;\n case 'apple':\n // Apple doesn't provide a logout method for web\n console.log('Apple logout: Session should be managed on the client side');\n break;\n case 'facebook':\n return new Promise<void>((resolve) => {\n FB.logout(() => resolve());\n });\n default:\n throw new Error(`Logout for ${options.provider} is not implemented`);\n }\n }\n\n private async accessTokenIsValid(accessToken: string): Promise<boolean> {\n const url = `${this.GOOGLE_TOKEN_REQUEST_URL}?access_token=${encodeURIComponent(accessToken)}`;\n\n try {\n // Make the GET request using fetch\n const response = await fetch(url);\n\n // Check if the response is successful\n if (!response.ok) {\n console.log(\n `Invalid response from ${this.GOOGLE_TOKEN_REQUEST_URL}. Response not successful. Status code: ${response.status}. Assuming that the token is not valid`,\n );\n return false;\n }\n\n // Get the response body as text\n const responseBody = await response.text();\n\n if (!responseBody) {\n console.error(`Invalid response from ${this.GOOGLE_TOKEN_REQUEST_URL}. Response body is null`);\n throw new Error(`Invalid response from ${this.GOOGLE_TOKEN_REQUEST_URL}. Response body is null`);\n }\n\n // Parse the response body as JSON\n let jsonObject: any;\n try {\n jsonObject = JSON.parse(responseBody);\n } catch (e) {\n console.error(\n `Invalid response from ${this.GOOGLE_TOKEN_REQUEST_URL}. Response body is not valid JSON. Error: ${e}`,\n );\n throw new Error(\n `Invalid response from ${this.GOOGLE_TOKEN_REQUEST_URL}. Response body is not valid JSON. Error: ${e}`,\n );\n }\n\n // Extract the 'expires_in' field\n const expiresInStr = jsonObject['expires_in'];\n\n if (expiresInStr === undefined || expiresInStr === null) {\n console.error(\n `Invalid response from ${this.GOOGLE_TOKEN_REQUEST_URL}. Response JSON does not include 'expires_in'.`,\n );\n throw new Error(\n `Invalid response from ${this.GOOGLE_TOKEN_REQUEST_URL}. Response JSON does not include 'expires_in'.`,\n );\n }\n\n // Parse 'expires_in' as an integer\n let expiresInInt: number;\n try {\n expiresInInt = parseInt(expiresInStr, 10);\n if (isNaN(expiresInInt)) {\n throw new Error(`'expires_in' is not a valid integer`);\n }\n } catch (e) {\n console.error(\n `Invalid response from ${this.GOOGLE_TOKEN_REQUEST_URL}. 'expires_in': ${expiresInStr} is not a valid integer. Error: ${e}`,\n );\n throw new Error(\n `Invalid response from ${this.GOOGLE_TOKEN_REQUEST_URL}. 'expires_in': ${expiresInStr} is not a valid integer. Error: ${e}`,\n );\n }\n\n // Determine if the access token is valid based on 'expires_in'\n return expiresInInt > 5;\n } catch (error) {\n console.error(error);\n throw error;\n }\n }\n\n private idTokenValid(idToken: string): boolean {\n try {\n const parsed = this.parseJwt(idToken);\n const currentTime = Math.ceil(Date.now() / 1000) + 5; // Convert current time to seconds since epoch\n return parsed.exp && currentTime < parsed.exp;\n } catch (e) {\n return false;\n }\n }\n\n private async rawLogoutGoogle(accessToken: string, tokenValid: boolean | null = null) {\n if (tokenValid === null) {\n tokenValid = await this.accessTokenIsValid(accessToken);\n }\n\n if (tokenValid === true) {\n return new Promise<void>((resolve, reject) => {\n try {\n google.accounts.oauth2.revoke(accessToken, async () => {\n this.clearStateGoogle();\n resolve();\n });\n } catch (e) {\n reject(e);\n }\n });\n } else {\n this.clearStateGoogle();\n return;\n }\n }\n\n async isLoggedIn(options: isLoggedInOptions): Promise<{ isLoggedIn: boolean }> {\n switch (options.provider) {\n case 'google':\n if (this.googleLoginType === 'offline') {\n return Promise.reject(\"Offline login doesn't store tokens. isLoggedIn is not available\");\n }\n // For Google, we can check if there's a valid token\n // eslint-disable-next-line\n const state = this.getGoogleState();\n if (!state) return { isLoggedIn: false };\n\n try {\n // todo: cache accessTokenIsValid calls\n const isValidAccessToken = await this.accessTokenIsValid(state.accessToken);\n const isValidIdToken = this.idTokenValid(state.idToken);\n if (isValidAccessToken && isValidIdToken) {\n return { isLoggedIn: true };\n } else {\n try {\n await this.rawLogoutGoogle(state.accessToken, false);\n } catch (e) {\n console.error('Access token is not valid, but cannot logout', e);\n }\n return { isLoggedIn: false };\n }\n } catch (e) {\n return Promise.reject(e);\n }\n case 'apple':\n // Apple doesn't provide a method to check login status on web\n console.log('Apple login status should be managed on the client side');\n return { isLoggedIn: false };\n case 'facebook':\n return new Promise((resolve) => {\n FB.getLoginStatus((response) => {\n resolve({ isLoggedIn: response.status === 'connected' });\n });\n });\n default:\n throw new Error(`isLoggedIn for ${options.provider} is not implemented`);\n }\n }\n\n async getAuthorizationCode(options: AuthorizationCodeOptions): Promise<AuthorizationCode> {\n switch (options.provider) {\n case 'google':\n if (this.googleLoginType === 'offline') {\n return Promise.reject(\"Offline login doesn't store tokens. getAuthorizationCode is not available\");\n }\n // For Google, we can use the id_token as the authorization code\n // eslint-disable-next-line\n const state = this.getGoogleState();\n if (!state) throw new Error('No Google authorization code available');\n\n try {\n // todo: cache accessTokenIsValid calls\n const isValidAccessToken = await this.accessTokenIsValid(state.accessToken);\n const isValidIdToken = this.idTokenValid(state.idToken);\n if (isValidAccessToken && isValidIdToken) {\n return { accessToken: state.accessToken, jwt: state.idToken };\n } else {\n try {\n await this.rawLogoutGoogle(state.accessToken, false);\n } catch (e) {\n console.error('Access token is not valid, but cannot logout', e);\n }\n throw new Error('No Google authorization code available');\n }\n } catch (e) {\n return Promise.reject(e);\n }\n case 'apple':\n // Apple authorization code should be obtained during login\n console.log('Apple authorization code should be stored during login');\n throw new Error('Apple authorization code not available');\n case 'facebook':\n return new Promise((resolve, reject) => {\n FB.getLoginStatus((response) => {\n if (response.status === 'connected') {\n resolve({ jwt: response.authResponse?.accessToken || '' });\n } else {\n reject(new Error('No Facebook authorization code available'));\n }\n });\n });\n default:\n throw new Error(`getAuthorizationCode for ${options.provider} is not implemented`);\n }\n }\n\n async refresh(options: LoginOptions): Promise<void> {\n switch (options.provider) {\n case 'google':\n // For Google, we can prompt for re-authentication\n return Promise.reject('Not implemented');\n case 'apple':\n // Apple doesn't provide a refresh method for web\n console.log('Apple refresh not available on web');\n break;\n case 'facebook':\n await this.loginWithFacebook(options.options as FacebookLoginOptions);\n break;\n default:\n throw new Error(`Refresh for ${(options as any).provider} is not implemented`);\n }\n }\n\n private loginWithGoogle<T extends 'google'>(\n options: GoogleLoginOptions,\n ): Promise<{ provider: T; result: ProviderResponseMap[T] }> {\n if (!this.googleClientId) {\n throw new Error('Google Client ID not set. Call initialize() first.');\n }\n\n let scopes = options.scopes || [];\n\n if (scopes.length > 0) {\n // If scopes are provided, directly use the traditional OAuth flow\n if (!scopes.includes('https://www.googleapis.com/auth/userinfo.email')) {\n scopes.push('https://www.googleapis.com/auth/userinfo.email');\n }\n if (!scopes.includes('https://www.googleapis.com/auth/userinfo.profile')) {\n scopes.push('https://www.googleapis.com/auth/userinfo.profile');\n }\n if (!scopes.includes('openid')) {\n scopes.push('openid');\n }\n } else {\n scopes = [\n 'https://www.googleapis.com/auth/userinfo.email',\n 'https://www.googleapis.com/auth/userinfo.profile',\n 'openid',\n ];\n }\n\n if (scopes.length > 3 || this.googleLoginType === 'offline' || options.disableOneTap) {\n // If scopes are provided, directly use the traditional OAuth flow\n return this.fallbackToTraditionalOAuth(scopes);\n }\n\n return new Promise((resolve, reject) => {\n google.accounts.id.initialize({\n client_id: this.googleClientId!,\n callback: (response) => {\n console.log('google.accounts.id.initialize callback', response);\n if ((response as any).error) {\n // we use any because type fail but we need to double check if that works\n reject((response as any).error);\n } else {\n const payload = this.parseJwt(response.credential);\n const result: GoogleLoginResponse = {\n accessToken: null,\n responseType: 'online',\n idToken: response.credential,\n profile: {\n email: payload.email || null,\n familyName: payload.family_name || null,\n givenName: payload.given_name || null,\n id: payload.sub || null,\n name: payload.name || null,\n imageUrl: payload.picture || null,\n },\n };\n resolve({ provider: 'google' as T, result });\n }\n },\n auto_select: true,\n });\n\n google.accounts.id.prompt((notification) => {\n if (notification.isNotDisplayed() || notification.isSkippedMoment()) {\n console.log('OneTap is not displayed or skipped');\n // Fallback to traditional OAuth if One Tap is not available\n this.fallbackToTraditionalOAuth(scopes)\n .then((r) => resolve({ provider: 'google' as T, result: r.result }))\n .catch(reject);\n } else {\n console.log('OneTap is displayed');\n }\n });\n });\n }\n\n private parseJwt(token: string) {\n const base64Url = token.split('.')[1];\n const base64 = base64Url.replace(/-/g, '+').replace(/_/g, '/');\n const jsonPayload = decodeURIComponent(\n atob(base64)\n .split('')\n .map((c) => {\n return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);\n })\n .join(''),\n );\n return JSON.parse(jsonPayload);\n }\n\n private async loadGoogleScript(): Promise<void> {\n if (this.googleScriptLoaded) return;\n\n return new Promise((resolve, reject) => {\n const script = document.createElement('script');\n script.src = 'https://accounts.google.com/gsi/client';\n script.async = true;\n script.onload = () => {\n this.googleScriptLoaded = true;\n resolve();\n };\n script.onerror = reject;\n document.body.appendChild(script);\n });\n }\n\n private async loginWithApple(options: any): Promise<LoginResult> {\n if (!this.appleClientId) {\n throw new Error('Apple Client ID not set. Call initialize() first.');\n }\n\n if (!this.appleScriptLoaded) {\n throw new Error('Apple Sign-In script not loaded.');\n }\n\n return new Promise((resolve, reject) => {\n AppleID.auth.init({\n clientId: this.appleClientId!,\n scope: options.scopes?.join(' ') || 'name email',\n redirectURI: options.redirectUrl || window.location.href,\n state: options.state,\n nonce: options.nonce,\n usePopup: true,\n });\n\n AppleID.auth\n .signIn()\n .then((res: any) => {\n const result: AppleProviderResponse = {\n profile: {\n user: res.user?.name?.firstName ? `${res.user.name.firstName} ${res.user.name.lastName}` : '',\n email: res.user?.email || null,\n givenName: res.user?.name?.firstName || null,\n familyName: res.user?.name?.lastName || null,\n },\n accessToken: {\n token: res.authorization.code, // TODO: to fix and find the correct token\n },\n idToken: res.authorization.id_token || null,\n };\n resolve({ provider: 'apple', result });\n })\n .catch((error: any) => {\n reject(error);\n });\n });\n }\n\n private async loadAppleScript(): Promise<void> {\n if (this.appleScriptLoaded) return;\n\n return new Promise((resolve, reject) => {\n const script = document.createElement('script');\n script.src = this.appleScriptUrl;\n script.async = true;\n script.onload = () => {\n this.appleScriptLoaded = true;\n resolve();\n };\n script.onerror = reject;\n document.body.appendChild(script);\n });\n }\n\n private persistStateGoogle(accessToken: string, idToken: string) {\n try {\n window.localStorage.setItem('capgo_social_login_google_state', JSON.stringify({ accessToken, idToken }));\n } catch (e) {\n console.error('Cannot persist state google', e);\n }\n }\n\n private clearStateGoogle() {\n try {\n window.localStorage.removeItem('capgo_social_login_google_state');\n } catch (e) {\n console.error('Cannot clear state google', e);\n }\n }\n\n private getGoogleState(): { accessToken: string; idToken: string } | null {\n try {\n const state = window.localStorage.getItem('capgo_social_login_google_state');\n if (!state) return null;\n const { accessToken, idToken } = JSON.parse(state);\n return { accessToken, idToken };\n } catch (e) {\n console.error('Cannot get state google', e);\n return null;\n }\n }\n\n private async loadFacebookScript(): Promise<void> {\n if (this.facebookScriptLoaded) return;\n\n return new Promise((resolve, reject) => {\n const script = document.createElement('script');\n script.src = 'https://connect.facebook.net/en_US/sdk.js';\n script.async = true;\n script.defer = true;\n script.onload = () => {\n this.facebookScriptLoaded = true;\n resolve();\n };\n script.onerror = reject;\n document.body.appendChild(script);\n });\n }\n\n private async loginWithFacebook(options: FacebookLoginOptions): Promise<LoginResult> {\n if (!this.facebookAppId) {\n throw new Error('Facebook App ID not set. Call initialize() first.');\n }\n\n return new Promise((resolve, reject) => {\n FB.login(\n (response) => {\n if (response.status === 'connected') {\n FB.api('/me', { fields: 'id,name,email,picture' }, (userInfo: any) => {\n const result: FacebookLoginResponse = {\n accessToken: {\n token: response.authResponse.accessToken,\n userId: response.authResponse.userID,\n },\n profile: {\n userID: userInfo.id,\n name: userInfo.name,\n email: userInfo.email || null,\n imageURL: userInfo.picture?.data?.url || null,\n friendIDs: [],\n birthday: null,\n ageRange: null,\n gender: null,\n location: null,\n hometown: null,\n profileURL: null,\n },\n idToken: null,\n };\n resolve({ provider: 'facebook', result });\n });\n } else {\n reject(new Error('Facebook login failed'));\n }\n },\n { scope: options.permissions.join(',') },\n );\n });\n }\n\n private async fallbackToTraditionalOAuth<T extends 'google'>(\n scopes: string[],\n ): Promise<{ provider: T; result: ProviderResponseMap[T] }> {\n const uniqueScopes = [...new Set([...scopes, 'openid'])];\n\n const params = new URLSearchParams({\n client_id: this.googleClientId!,\n redirect_uri: window.location.href,\n response_type: this.googleLoginType === 'offline' ? 'code' : 'token id_token',\n scope: uniqueScopes.join(' '),\n nonce: Math.random().toString(36).substring(2),\n include_granted_scopes: 'true',\n state: 'popup',\n });\n\n const url = `https://accounts.google.com/o/oauth2/v2/auth?${params.toString()}`;\n const width = 500;\n const height = 600;\n const left = window.screenX + (window.outerWidth - width) / 2;\n const top = window.screenY + (window.outerHeight - height) / 2;\n localStorage.setItem(SocialLoginWeb.OAUTH_STATE_KEY, 'true');\n const popup = window.open(url, 'Google Sign In', `width=${width},height=${height},left=${left},top=${top},popup=1`);\n\n // This may never return...\n return new Promise((resolve, reject) => {\n if (!popup) {\n reject(new Error('Failed to open popup'));\n return;\n }\n\n const handleMessage = (event: MessageEvent) => {\n if (event.origin !== window.location.origin) return;\n\n if (event.data?.type === 'oauth-response') {\n window.removeEventListener('message', handleMessage);\n\n if (this.googleLoginType === 'online') {\n const { accessToken, idToken } = event.data;\n if (accessToken && idToken) {\n const profile = this.parseJwt(idToken);\n this.persistStateGoogle(accessToken.token, idToken);\n resolve({\n provider: 'google' as T,\n result: {\n accessToken: {\n token: accessToken.token,\n },\n idToken,\n profile: {\n email: profile.email || null,\n familyName: profile.family_name || null,\n givenName: profile.given_name || null,\n id: profile.sub || null,\n name: profile.name || null,\n imageUrl: profile.picture || null,\n },\n responseType: 'online',\n },\n });\n }\n } else {\n const { serverAuthCode } = event.data.result as {\n serverAuthCode: string;\n };\n resolve({\n provider: 'google' as T,\n result: {\n responseType: 'offline',\n serverAuthCode,\n },\n });\n }\n } else {\n reject(new Error('Login failed'));\n }\n };\n\n window.addEventListener('message', handleMessage);\n\n // Timeout after 5 minutes\n setTimeout(() => {\n window.removeEventListener('message', handleMessage);\n popup.close();\n reject(new Error('OAuth timeout'));\n }, 300000);\n });\n }\n}\n"]}
1
+ {"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AA+B5C,MAAM,OAAO,cAAe,SAAQ,SAAS;IAc3C;;QACE,KAAK,EAAE,CAAC;QAZF,mBAAc,GAAkB,IAAI,CAAC;QAErC,kBAAa,GAAkB,IAAI,CAAC;QACpC,uBAAkB,GAAG,KAAK,CAAC;QAC3B,oBAAe,GAAyB,QAAQ,CAAC;QACjD,sBAAiB,GAAG,KAAK,CAAC;QAC1B,mBAAc,GAAG,sFAAsF,CAAC;QACxG,6BAAwB,GAAG,gDAAgD,CAAC;QAC5E,kBAAa,GAAkB,IAAI,CAAC;QACpC,yBAAoB,GAAG,KAAK,CAAC;QAInC,sEAAsE;QACtE,IAAI,YAAY,CAAC,OAAO,CAAC,cAAc,CAAC,eAAe,CAAC,EAAE,CAAC;YACzD,OAAO,CAAC,GAAG,CAAC,uBAAuB,CAAC,CAAC;YACrC,MAAM,MAAM,GAAG,IAAI,CAAC,mBAAmB,EAAE,CAAC;YAC1C,IAAI,MAAM,EAAE,CAAC;gBACX,MAAA,MAAM,CAAC,MAAM,0CAAE,WAAW,iBAEtB,IAAI,EAAE,gBAAgB,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AC,GAAG,EAAE;gBACd,MAAM,CAAC,mBAAmB,CAAC,SAAS,EAAE,aAAa,CAAC,CAAC;gBACrD,KAAK,CAAC,KAAK,EAAE,CAAC;gBACd,MAAM,CAAC,IAAI,KAAK,CAAC,eAAe,CAAC,CAAC,CAAC;YACrC,CAAC,EAAE,MAAM,CAAC,CAAC;QACb,CAAC,CAAC,CAAC;IACL,CAAC;;AAtsBuB,8BAAe,GAAG,4BAA4B,AAA/B,CAAgC","sourcesContent":["import { WebPlugin } from '@capacitor/core';\n\nimport type {\n SocialLoginPlugin,\n InitializeOptions,\n LoginOptions,\n LoginResult,\n AuthorizationCode,\n GoogleLoginResponse,\n AppleProviderResponse,\n isLoggedInOptions,\n AuthorizationCodeOptions,\n FacebookLoginOptions,\n FacebookLoginResponse,\n GoogleLoginOptions,\n ProviderResponseMap,\n} from './definitions';\n\ndeclare const AppleID: any;\n\ndeclare const FB: {\n init(options: any): void;\n login(\n callback: (response: { status: string; authResponse: { accessToken: string; userID: string } }) => void,\n options?: { scope: string },\n ): void;\n logout(callback: () => void): void;\n api(path: string, params: { fields: string }, callback: (response: any) => void): void;\n getLoginStatus(callback: (response: { status: string; authResponse?: { accessToken: string } }) => void): void;\n};\n\nexport class SocialLoginWeb extends WebPlugin implements SocialLoginPlugin {\n private static readonly OAUTH_STATE_KEY = 'social_login_oauth_pending';\n\n private googleClientId: string | null = null;\n private googleHostedDomain?: string;\n private appleClientId: string | null = null;\n private googleScriptLoaded = false;\n private googleLoginType: 'online' | 'offline' = 'online';\n private appleScriptLoaded = false;\n private appleScriptUrl = 'https://appleid.cdn-apple.com/appleauth/static/jsapi/appleid/1/en_US/appleid.auth.js';\n private GOOGLE_TOKEN_REQUEST_URL = 'https://www.googleapis.com/oauth2/v3/tokeninfo';\n private facebookAppId: string | null = null;\n private facebookScriptLoaded = false;\n\n constructor() {\n super();\n // Set up listener for OAuth redirects if we have a pending OAuth flow\n if (localStorage.getItem(SocialLoginWeb.OAUTH_STATE_KEY)) {\n console.log('OAUTH_STATE_KEY found');\n const result = this.handleOAuthRedirect();\n if (result) {\n window.opener?.postMessage(\n {\n type: 'oauth-response',\n ...result.result,\n },\n window.location.origin,\n );\n window.close();\n }\n }\n }\n\n private handleOAuthRedirect() {\n const paramsRaw = new URL(window.location.href).searchParams;\n const code = paramsRaw.get('code');\n if (code && paramsRaw.has('scope')) {\n return {\n provider: 'google' as const,\n result: {\n provider: 'google' as const,\n result: {\n serverAuthCode: code,\n },\n },\n };\n }\n\n const hash = window.location.hash.substring(1);\n console.log('handleOAuthRedirect', window.location.hash);\n if (!hash) return;\n console.log('handleOAuthRedirect ok');\n\n const params = new URLSearchParams(hash);\n const accessToken = params.get('access_token');\n const idToken = params.get('id_token');\n\n if (accessToken && idToken) {\n localStorage.removeItem(SocialLoginWeb.OAUTH_STATE_KEY);\n const profile = this.parseJwt(idToken);\n return {\n provider: 'google' as const,\n result: {\n accessToken: {\n token: accessToken,\n },\n idToken,\n profile: {\n email: profile.email || null,\n familyName: profile.family_name || null,\n givenName: profile.given_name || null,\n id: profile.sub || null,\n name: profile.name || null,\n imageUrl: profile.picture || null,\n },\n },\n };\n }\n return null;\n }\n\n async initialize(options: InitializeOptions): Promise<void> {\n if (options.google?.webClientId) {\n this.googleClientId = options.google.webClientId;\n if (options.google.mode) {\n this.googleLoginType = options.google.mode;\n }\n this.googleHostedDomain = options.google.hostedDomain;\n\n await this.loadGoogleScript();\n }\n if (options.apple?.clientId) {\n this.appleClientId = options.apple.clientId;\n await this.loadAppleScript();\n }\n if (options.facebook?.appId) {\n this.facebookAppId = options.facebook.appId;\n await this.loadFacebookScript();\n FB.init({\n appId: this.facebookAppId,\n version: 'v17.0',\n xfbml: true,\n cookie: true,\n });\n }\n // Implement initialization for other providers if needed\n }\n\n async login<T extends LoginOptions['provider']>(\n options: Extract<LoginOptions, { provider: T }>,\n ): Promise<{ provider: T; result: ProviderResponseMap[T] }> {\n switch (options.provider) {\n case 'google':\n return this.loginWithGoogle(options.options) as Promise<{\n provider: T;\n result: ProviderResponseMap[T];\n }>;\n case 'apple':\n return this.loginWithApple(options.options) as Promise<{\n provider: T;\n result: ProviderResponseMap[T];\n }>;\n case 'facebook':\n return this.loginWithFacebook(options.options as FacebookLoginOptions) as Promise<{\n provider: T;\n result: ProviderResponseMap[T];\n }>;\n default:\n throw new Error(`Login for ${options.provider} is not implemented on web`);\n }\n }\n\n async logout(options: { provider: 'apple' | 'google' | 'facebook' }): Promise<void> {\n switch (options.provider) {\n case 'google':\n if (this.googleLoginType === 'offline') {\n return Promise.reject(\"Offline login doesn't store tokens. logout is not available\");\n }\n // Google doesn't have a specific logout method for web\n // We can revoke the token if we have it stored\n console.log('Google logout: Id token should be revoked on the client side if stored');\n // eslint-disable-next-line\n const state = this.getGoogleState();\n if (!state) return;\n await this.rawLogoutGoogle(state.accessToken);\n break;\n case 'apple':\n // Apple doesn't provide a logout method for web\n console.log('Apple logout: Session should be managed on the client side');\n break;\n case 'facebook':\n return new Promise<void>((resolve) => {\n FB.logout(() => resolve());\n });\n default:\n throw new Error(`Logout for ${options.provider} is not implemented`);\n }\n }\n\n private async accessTokenIsValid(accessToken: string): Promise<boolean> {\n const url = `${this.GOOGLE_TOKEN_REQUEST_URL}?access_token=${encodeURIComponent(accessToken)}`;\n\n try {\n // Make the GET request using fetch\n const response = await fetch(url);\n\n // Check if the response is successful\n if (!response.ok) {\n console.log(\n `Invalid response from ${this.GOOGLE_TOKEN_REQUEST_URL}. Response not successful. Status code: ${response.status}. Assuming that the token is not valid`,\n );\n return false;\n }\n\n // Get the response body as text\n const responseBody = await response.text();\n\n if (!responseBody) {\n console.error(`Invalid response from ${this.GOOGLE_TOKEN_REQUEST_URL}. Response body is null`);\n throw new Error(`Invalid response from ${this.GOOGLE_TOKEN_REQUEST_URL}. Response body is null`);\n }\n\n // Parse the response body as JSON\n let jsonObject: any;\n try {\n jsonObject = JSON.parse(responseBody);\n } catch (e) {\n console.error(\n `Invalid response from ${this.GOOGLE_TOKEN_REQUEST_URL}. Response body is not valid JSON. Error: ${e}`,\n );\n throw new Error(\n `Invalid response from ${this.GOOGLE_TOKEN_REQUEST_URL}. Response body is not valid JSON. Error: ${e}`,\n );\n }\n\n // Extract the 'expires_in' field\n const expiresInStr = jsonObject['expires_in'];\n\n if (expiresInStr === undefined || expiresInStr === null) {\n console.error(\n `Invalid response from ${this.GOOGLE_TOKEN_REQUEST_URL}. Response JSON does not include 'expires_in'.`,\n );\n throw new Error(\n `Invalid response from ${this.GOOGLE_TOKEN_REQUEST_URL}. Response JSON does not include 'expires_in'.`,\n );\n }\n\n // Parse 'expires_in' as an integer\n let expiresInInt: number;\n try {\n expiresInInt = parseInt(expiresInStr, 10);\n if (isNaN(expiresInInt)) {\n throw new Error(`'expires_in' is not a valid integer`);\n }\n } catch (e) {\n console.error(\n `Invalid response from ${this.GOOGLE_TOKEN_REQUEST_URL}. 'expires_in': ${expiresInStr} is not a valid integer. Error: ${e}`,\n );\n throw new Error(\n `Invalid response from ${this.GOOGLE_TOKEN_REQUEST_URL}. 'expires_in': ${expiresInStr} is not a valid integer. Error: ${e}`,\n );\n }\n\n // Determine if the access token is valid based on 'expires_in'\n return expiresInInt > 5;\n } catch (error) {\n console.error(error);\n throw error;\n }\n }\n\n private idTokenValid(idToken: string): boolean {\n try {\n const parsed = this.parseJwt(idToken);\n const currentTime = Math.ceil(Date.now() / 1000) + 5; // Convert current time to seconds since epoch\n return parsed.exp && currentTime < parsed.exp;\n } catch (e) {\n return false;\n }\n }\n\n private async rawLogoutGoogle(accessToken: string, tokenValid: boolean | null = null) {\n if (tokenValid === null) {\n tokenValid = await this.accessTokenIsValid(accessToken);\n }\n\n if (tokenValid === true) {\n return new Promise<void>((resolve, reject) => {\n try {\n google.accounts.oauth2.revoke(accessToken, async () => {\n this.clearStateGoogle();\n resolve();\n });\n } catch (e) {\n reject(e);\n }\n });\n } else {\n this.clearStateGoogle();\n return;\n }\n }\n\n async isLoggedIn(options: isLoggedInOptions): Promise<{ isLoggedIn: boolean }> {\n switch (options.provider) {\n case 'google':\n if (this.googleLoginType === 'offline') {\n return Promise.reject(\"Offline login doesn't store tokens. isLoggedIn is not available\");\n }\n // For Google, we can check if there's a valid token\n // eslint-disable-next-line\n const state = this.getGoogleState();\n if (!state) return { isLoggedIn: false };\n\n try {\n // todo: cache accessTokenIsValid calls\n const isValidAccessToken = await this.accessTokenIsValid(state.accessToken);\n const isValidIdToken = this.idTokenValid(state.idToken);\n if (isValidAccessToken && isValidIdToken) {\n return { isLoggedIn: true };\n } else {\n try {\n await this.rawLogoutGoogle(state.accessToken, false);\n } catch (e) {\n console.error('Access token is not valid, but cannot logout', e);\n }\n return { isLoggedIn: false };\n }\n } catch (e) {\n return Promise.reject(e);\n }\n case 'apple':\n // Apple doesn't provide a method to check login status on web\n console.log('Apple login status should be managed on the client side');\n return { isLoggedIn: false };\n case 'facebook':\n return new Promise((resolve) => {\n FB.getLoginStatus((response) => {\n resolve({ isLoggedIn: response.status === 'connected' });\n });\n });\n default:\n throw new Error(`isLoggedIn for ${options.provider} is not implemented`);\n }\n }\n\n async getAuthorizationCode(options: AuthorizationCodeOptions): Promise<AuthorizationCode> {\n switch (options.provider) {\n case 'google':\n if (this.googleLoginType === 'offline') {\n return Promise.reject(\"Offline login doesn't store tokens. getAuthorizationCode is not available\");\n }\n // For Google, we can use the id_token as the authorization code\n // eslint-disable-next-line\n const state = this.getGoogleState();\n if (!state) throw new Error('No Google authorization code available');\n\n try {\n // todo: cache accessTokenIsValid calls\n const isValidAccessToken = await this.accessTokenIsValid(state.accessToken);\n const isValidIdToken = this.idTokenValid(state.idToken);\n if (isValidAccessToken && isValidIdToken) {\n return { accessToken: state.accessToken, jwt: state.idToken };\n } else {\n try {\n await this.rawLogoutGoogle(state.accessToken, false);\n } catch (e) {\n console.error('Access token is not valid, but cannot logout', e);\n }\n throw new Error('No Google authorization code available');\n }\n } catch (e) {\n return Promise.reject(e);\n }\n case 'apple':\n // Apple authorization code should be obtained during login\n console.log('Apple authorization code should be stored during login');\n throw new Error('Apple authorization code not available');\n case 'facebook':\n return new Promise((resolve, reject) => {\n FB.getLoginStatus((response) => {\n if (response.status === 'connected') {\n resolve({ jwt: response.authResponse?.accessToken || '' });\n } else {\n reject(new Error('No Facebook authorization code available'));\n }\n });\n });\n default:\n throw new Error(`getAuthorizationCode for ${options.provider} is not implemented`);\n }\n }\n\n async refresh(options: LoginOptions): Promise<void> {\n switch (options.provider) {\n case 'google':\n // For Google, we can prompt for re-authentication\n return Promise.reject('Not implemented');\n case 'apple':\n // Apple doesn't provide a refresh method for web\n console.log('Apple refresh not available on web');\n break;\n case 'facebook':\n await this.loginWithFacebook(options.options as FacebookLoginOptions);\n break;\n default:\n throw new Error(`Refresh for ${(options as any).provider} is not implemented`);\n }\n }\n\n private loginWithGoogle<T extends 'google'>(\n options: GoogleLoginOptions,\n ): Promise<{ provider: T; result: ProviderResponseMap[T] }> {\n if (!this.googleClientId) {\n throw new Error('Google Client ID not set. Call initialize() first.');\n }\n\n let scopes = options.scopes || [];\n\n if (scopes.length > 0) {\n // If scopes are provided, directly use the traditional OAuth flow\n if (!scopes.includes('https://www.googleapis.com/auth/userinfo.email')) {\n scopes.push('https://www.googleapis.com/auth/userinfo.email');\n }\n if (!scopes.includes('https://www.googleapis.com/auth/userinfo.profile')) {\n scopes.push('https://www.googleapis.com/auth/userinfo.profile');\n }\n if (!scopes.includes('openid')) {\n scopes.push('openid');\n }\n } else {\n scopes = [\n 'https://www.googleapis.com/auth/userinfo.email',\n 'https://www.googleapis.com/auth/userinfo.profile',\n 'openid',\n ];\n }\n\n if (scopes.length > 3 || this.googleLoginType === 'offline' || options.disableOneTap) {\n // If scopes are provided, directly use the traditional OAuth flow\n return this.fallbackToTraditionalOAuth(scopes, this.googleHostedDomain);\n }\n\n return new Promise((resolve, reject) => {\n google.accounts.id.initialize({\n client_id: this.googleClientId!,\n hd: this.googleHostedDomain,\n callback: (response) => {\n console.log('google.accounts.id.initialize callback', response);\n if ((response as any).error) {\n // we use any because type fail but we need to double check if that works\n reject((response as any).error);\n } else {\n const payload = this.parseJwt(response.credential);\n const result: GoogleLoginResponse = {\n accessToken: null,\n responseType: 'online',\n idToken: response.credential,\n profile: {\n email: payload.email || null,\n familyName: payload.family_name || null,\n givenName: payload.given_name || null,\n id: payload.sub || null,\n name: payload.name || null,\n imageUrl: payload.picture || null,\n },\n };\n resolve({ provider: 'google' as T, result });\n }\n },\n auto_select: true,\n });\n\n google.accounts.id.prompt((notification) => {\n if (notification.isNotDisplayed() || notification.isSkippedMoment()) {\n console.log('OneTap is not displayed or skipped');\n // Fallback to traditional OAuth if One Tap is not available\n this.fallbackToTraditionalOAuth(scopes, this.googleHostedDomain)\n .then((r) => resolve({ provider: 'google' as T, result: r.result }))\n .catch(reject);\n } else {\n console.log('OneTap is displayed');\n }\n });\n });\n }\n\n private parseJwt(token: string) {\n const base64Url = token.split('.')[1];\n const base64 = base64Url.replace(/-/g, '+').replace(/_/g, '/');\n const jsonPayload = decodeURIComponent(\n atob(base64)\n .split('')\n .map((c) => {\n return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);\n })\n .join(''),\n );\n return JSON.parse(jsonPayload);\n }\n\n private async loadGoogleScript(): Promise<void> {\n if (this.googleScriptLoaded) return;\n\n return new Promise((resolve, reject) => {\n const script = document.createElement('script');\n script.src = 'https://accounts.google.com/gsi/client';\n script.async = true;\n script.onload = () => {\n this.googleScriptLoaded = true;\n resolve();\n };\n script.onerror = reject;\n document.body.appendChild(script);\n });\n }\n\n private async loginWithApple(options: any): Promise<LoginResult> {\n if (!this.appleClientId) {\n throw new Error('Apple Client ID not set. Call initialize() first.');\n }\n\n if (!this.appleScriptLoaded) {\n throw new Error('Apple Sign-In script not loaded.');\n }\n\n return new Promise((resolve, reject) => {\n AppleID.auth.init({\n clientId: this.appleClientId!,\n scope: options.scopes?.join(' ') || 'name email',\n redirectURI: options.redirectUrl || window.location.href,\n state: options.state,\n nonce: options.nonce,\n usePopup: true,\n });\n\n AppleID.auth\n .signIn()\n .then((res: any) => {\n const result: AppleProviderResponse = {\n profile: {\n user: res.user?.name?.firstName ? `${res.user.name.firstName} ${res.user.name.lastName}` : '',\n email: res.user?.email || null,\n givenName: res.user?.name?.firstName || null,\n familyName: res.user?.name?.lastName || null,\n },\n accessToken: {\n token: res.authorization.code, // TODO: to fix and find the correct token\n },\n idToken: res.authorization.id_token || null,\n };\n resolve({ provider: 'apple', result });\n })\n .catch((error: any) => {\n reject(error);\n });\n });\n }\n\n private async loadAppleScript(): Promise<void> {\n if (this.appleScriptLoaded) return;\n\n return new Promise((resolve, reject) => {\n const script = document.createElement('script');\n script.src = this.appleScriptUrl;\n script.async = true;\n script.onload = () => {\n this.appleScriptLoaded = true;\n resolve();\n };\n script.onerror = reject;\n document.body.appendChild(script);\n });\n }\n\n private persistStateGoogle(accessToken: string, idToken: string) {\n try {\n window.localStorage.setItem('capgo_social_login_google_state', JSON.stringify({ accessToken, idToken }));\n } catch (e) {\n console.error('Cannot persist state google', e);\n }\n }\n\n private clearStateGoogle() {\n try {\n window.localStorage.removeItem('capgo_social_login_google_state');\n } catch (e) {\n console.error('Cannot clear state google', e);\n }\n }\n\n private getGoogleState(): { accessToken: string; idToken: string } | null {\n try {\n const state = window.localStorage.getItem('capgo_social_login_google_state');\n if (!state) return null;\n const { accessToken, idToken } = JSON.parse(state);\n return { accessToken, idToken };\n } catch (e) {\n console.error('Cannot get state google', e);\n return null;\n }\n }\n\n private async loadFacebookScript(): Promise<void> {\n if (this.facebookScriptLoaded) return;\n\n return new Promise((resolve, reject) => {\n const script = document.createElement('script');\n script.src = 'https://connect.facebook.net/en_US/sdk.js';\n script.async = true;\n script.defer = true;\n script.onload = () => {\n this.facebookScriptLoaded = true;\n resolve();\n };\n script.onerror = reject;\n document.body.appendChild(script);\n });\n }\n\n private async loginWithFacebook(options: FacebookLoginOptions): Promise<LoginResult> {\n if (!this.facebookAppId) {\n throw new Error('Facebook App ID not set. Call initialize() first.');\n }\n\n return new Promise((resolve, reject) => {\n FB.login(\n (response) => {\n if (response.status === 'connected') {\n FB.api('/me', { fields: 'id,name,email,picture' }, (userInfo: any) => {\n const result: FacebookLoginResponse = {\n accessToken: {\n token: response.authResponse.accessToken,\n userId: response.authResponse.userID,\n },\n profile: {\n userID: userInfo.id,\n name: userInfo.name,\n email: userInfo.email || null,\n imageURL: userInfo.picture?.data?.url || null,\n friendIDs: [],\n birthday: null,\n ageRange: null,\n gender: null,\n location: null,\n hometown: null,\n profileURL: null,\n },\n idToken: null,\n };\n resolve({ provider: 'facebook', result });\n });\n } else {\n reject(new Error('Facebook login failed'));\n }\n },\n { scope: options.permissions.join(',') },\n );\n });\n }\n\n private async fallbackToTraditionalOAuth<T extends 'google'>(\n scopes: string[],\n hostedDomain?: string,\n ): Promise<{ provider: T; result: ProviderResponseMap[T] }> {\n const uniqueScopes = [...new Set([...scopes, 'openid'])];\n\n const params = new URLSearchParams({\n client_id: this.googleClientId!,\n redirect_uri: window.location.href,\n response_type: this.googleLoginType === 'offline' ? 'code' : 'token id_token',\n scope: uniqueScopes.join(' '),\n nonce: Math.random().toString(36).substring(2),\n include_granted_scopes: 'true',\n state: 'popup',\n });\n if (hostedDomain !== undefined) {\n params.append('hd', hostedDomain);\n }\n\n const url = `https://accounts.google.com/o/oauth2/v2/auth?${params.toString()}`;\n const width = 500;\n const height = 600;\n const left = window.screenX + (window.outerWidth - width) / 2;\n const top = window.screenY + (window.outerHeight - height) / 2;\n localStorage.setItem(SocialLoginWeb.OAUTH_STATE_KEY, 'true');\n const popup = window.open(url, 'Google Sign In', `width=${width},height=${height},left=${left},top=${top},popup=1`);\n\n // This may never return...\n return new Promise((resolve, reject) => {\n if (!popup) {\n reject(new Error('Failed to open popup'));\n return;\n }\n\n const handleMessage = (event: MessageEvent) => {\n if (event.origin !== window.location.origin) return;\n\n if (event.data?.type === 'oauth-response') {\n window.removeEventListener('message', handleMessage);\n\n if (this.googleLoginType === 'online') {\n const { accessToken, idToken } = event.data;\n if (accessToken && idToken) {\n const profile = this.parseJwt(idToken);\n this.persistStateGoogle(accessToken.token, idToken);\n resolve({\n provider: 'google' as T,\n result: {\n accessToken: {\n token: accessToken.token,\n },\n idToken,\n profile: {\n email: profile.email || null,\n familyName: profile.family_name || null,\n givenName: profile.given_name || null,\n id: profile.sub || null,\n name: profile.name || null,\n imageUrl: profile.picture || null,\n },\n responseType: 'online',\n },\n });\n }\n } else {\n const { serverAuthCode } = event.data.result as {\n serverAuthCode: string;\n };\n resolve({\n provider: 'google' as T,\n result: {\n responseType: 'offline',\n serverAuthCode,\n },\n });\n }\n } else {\n reject(new Error('Login failed'));\n }\n };\n\n window.addEventListener('message', handleMessage);\n\n // Timeout after 5 minutes\n setTimeout(() => {\n window.removeEventListener('message', handleMessage);\n popup.close();\n reject(new Error('OAuth timeout'));\n }, 300000);\n });\n }\n}\n"]}