@capgo/capacitor-social-login 8.7.11 → 8.7.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1499,16 +1499,16 @@ On user cancel or dismiss, the Promise rejects with `code === 'USER_CANCELLED'`.
1499
1499
 
1500
1500
  #### InitializeOptions
1501
1501
 
1502
- | Prop | Type | Description |
1503
- | -------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------ |
1504
- | **`oauth2`** | <code><a href="#record">Record</a>&lt;string, <a href="#oauth2providerconfig">OAuth2ProviderConfig</a>&gt;</code> | OAuth2 provider configurations. Supports multiple providers by using a <a href="#record">Record</a> with provider IDs as keys. |
1505
- | **`telegram`** | <code>{ botId: string; redirectUrl?: string; origin?: string; requestAccess?: 'read' \| 'write'; languageCode?: string; }</code> | Telegram Login Widget configuration. Uses Telegram's OAuth widget (`oauth.telegram.org`), not standard OAuth2. |
1506
- | **`linkedin`** | <code><a href="#linkedinproviderconfig">LinkedInProviderConfig</a></code> | LinkedIn configuration. Convenience wrapper that maps to the OAuth2 provider using LinkedIn defaults. |
1507
- | **`tiktok`** | <code><a href="#tiktokproviderconfig">TikTokProviderConfig</a></code> | TikTok Login Kit configuration. Convenience wrapper that maps to the OAuth2 provider using TikTok defaults (`client_key`). |
1508
- | **`twitter`** | <code>{ clientId: string; redirectUrl: string; defaultScopes?: string[]; forceLogin?: boolean; audience?: string; }</code> | |
1509
- | **`facebook`** | <code>{ appId: string; clientToken?: string; locale?: string; }</code> | |
1510
- | **`google`** | <code>{ iOSClientId?: string; iOSServerClientId?: string; webClientId?: string; mode?: 'online' \| 'offline'; hostedDomain?: string; redirectUrl?: string; skipAuthOnlyAuthorizationAfterSignIn?: boolean; }</code> | |
1511
- | **`apple`** | <code>{ clientId?: string; redirectUrl?: string; useProperTokenExchange?: boolean; useBroadcastChannel?: boolean; }</code> | |
1502
+ | Prop | Type | Description |
1503
+ | -------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
1504
+ | **`oauth2`** | <code><a href="#record">Record</a>&lt;string, <a href="#oauth2providerconfig">OAuth2ProviderConfig</a>&gt;</code> | OAuth2 provider configurations. Supports multiple providers by using a <a href="#record">Record</a> with provider IDs as keys. |
1505
+ | **`telegram`** | <code>{ botId: string; redirectUrl?: string; origin?: string; requestAccess?: 'read' \| 'write'; languageCode?: string; }</code> | Telegram Login Widget configuration. Uses Telegram's OAuth widget (`oauth.telegram.org`), not standard OAuth2. |
1506
+ | **`linkedin`** | <code><a href="#linkedinproviderconfig">LinkedInProviderConfig</a></code> | LinkedIn configuration. Convenience wrapper that maps to the OAuth2 provider using LinkedIn defaults. |
1507
+ | **`tiktok`** | <code><a href="#tiktokproviderconfig">TikTokProviderConfig</a></code> | TikTok Login Kit configuration. Convenience wrapper that maps to the OAuth2 provider using TikTok defaults (`client_key`). |
1508
+ | **`twitter`** | <code>{ clientId: string; redirectUrl: string; defaultScopes?: string[]; forceLogin?: boolean; audience?: string; }</code> | |
1509
+ | **`facebook`** | <code>{ appId: string; clientToken?: string; locale?: string; }</code> | |
1510
+ | **`google`** | <code>{ iOSClientId?: string; iOSServerClientId?: string; webClientId?: string; mode?: 'online' \| 'offline'; hostedDomain?: string; redirectUrl?: string; skipAuthOnlyAuthorizationAfterSignIn?: boolean; }</code> | Google Sign-In configuration. **Android `hostedDomain`:** When set, login uses the standard Sign in with Google UI (`options.style: 'bottom'` is overridden). Login rejects when `options.autoSelectEnabled` or `options.filterByAuthorizedAccounts` is `true` (Android only; see `hostedDomain` and `GoogleLoginOptions`). |
1511
+ | **`apple`** | <code>{ clientId?: string; redirectUrl?: string; useProperTokenExchange?: boolean; useBroadcastChannel?: boolean; }</code> | |
1512
1512
 
1513
1513
 
1514
1514
  #### OAuth2ProviderConfig
@@ -1706,16 +1706,16 @@ Uses TikTok OAuth 2.0 endpoints and `client_key` instead of `client_id`.
1706
1706
 
1707
1707
  #### GoogleLoginOptions
1708
1708
 
1709
- | Prop | Type | Description | Default | Since |
1710
- | -------------------------------- | ------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ----------------------- | ------ |
1711
- | **`scopes`** | <code>string[]</code> | Specifies the scopes required for accessing Google APIs The default is defined in the configuration. | | |
1712
- | **`nonce`** | <code>string</code> | Nonce. On iOS, a login with a nonce always shows the Google sign-in instead of restoring the previous sign-in: a restored ID token was minted without this nonce, so a backend that verifies it (for example Supabase `signInWithIdToken`) would reject the token. | | |
1713
- | **`forceRefreshToken`** | <code>boolean</code> | Force refresh token (only for Android) | <code>false</code> | |
1714
- | **`forcePrompt`** | <code>boolean</code> | Force account selection prompt (iOS) | <code>false</code> | |
1715
- | **`style`** | <code>'bottom' \| 'standard'</code> | Style | <code>'standard'</code> | |
1716
- | **`filterByAuthorizedAccounts`** | <code>boolean</code> | Filter by authorized accounts (Android only) | <code>false</code> | |
1717
- | **`autoSelectEnabled`** | <code>boolean</code> | Auto select enabled (Android only) | <code>false</code> | |
1718
- | **`prompt`** | <code>'none' \| 'consent' \| 'select_account' \| 'consent select_account' \| 'select_account consent'</code> | Prompt parameter for Google OAuth (Web only) | | 7.12.0 |
1709
+ | Prop | Type | Description | Default | Since |
1710
+ | -------------------------------- | ------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------- | ------ |
1711
+ | **`scopes`** | <code>string[]</code> | Specifies the scopes required for accessing Google APIs The default is defined in the configuration. | | |
1712
+ | **`nonce`** | <code>string</code> | Nonce. On iOS, a login with a nonce always shows the Google sign-in instead of restoring the previous sign-in: a restored ID token was minted without this nonce, so a backend that verifies it (for example Supabase `signInWithIdToken`) would reject the token. | | |
1713
+ | **`forceRefreshToken`** | <code>boolean</code> | Force refresh token (only for Android) | <code>false</code> | |
1714
+ | **`forcePrompt`** | <code>boolean</code> | Force account selection prompt (iOS) | <code>false</code> | |
1715
+ | **`style`** | <code>'bottom' \| 'standard'</code> | Google sign-in UI layout (Android only). When `initialize({ google: { hostedDomain } })` is set, Android forces `standard` for login (see `hostedDomain` on the Google provider config). `bottom` cannot apply the hosted-domain filter in this plugin. | <code>'standard'</code> | |
1716
+ | **`filterByAuthorizedAccounts`** | <code>boolean</code> | Filter by authorized accounts (Android only) Only show accounts that have previously been used to sign in to the app. This option is only available for the `bottom` style. When a hosted domain is configured in `initialize`, login rejects if this is `true` (Android only). Note: For Family Link supervised accounts, this should be set to false. | <code>false</code> | |
1717
+ | **`autoSelectEnabled`** | <code>boolean</code> | Auto select enabled (Android only) Automatically select the account if only one Google account is available. This option is only available for the `bottom` style. When a hosted domain is configured in `initialize`, login rejects if this is `true` (Android only). | <code>false</code> | |
1718
+ | **`prompt`** | <code>'none' \| 'consent' \| 'select_account' \| 'consent select_account' \| 'select_account consent'</code> | Prompt parameter for Google OAuth (Web only) | | 7.12.0 |
1719
1719
 
1720
1720
 
1721
1721
  #### AppleProviderOptions
@@ -0,0 +1,41 @@
1
+ package ee.forgr.capacitor.social.login;
2
+
3
+ import android.util.Base64;
4
+ import org.json.JSONObject;
5
+
6
+ /**
7
+ * Hosted-domain helpers for Google sign-in and token refresh.
8
+ */
9
+ final class GoogleHostedDomainRules {
10
+
11
+ private GoogleHostedDomainRules() {}
12
+
13
+ static boolean hasConfiguredHostedDomain(String hostedDomain) {
14
+ return hostedDomain != null && !hostedDomain.isEmpty();
15
+ }
16
+
17
+ static boolean idTokenSatisfiesHostedDomain(String idToken, String hostedDomain) {
18
+ if (!hasConfiguredHostedDomain(hostedDomain)) {
19
+ return true;
20
+ }
21
+ if (idToken == null || idToken.isEmpty()) {
22
+ return false;
23
+ }
24
+ try {
25
+ String[] parts = idToken.split("\\.");
26
+ if (parts.length != 3) {
27
+ return false;
28
+ }
29
+ String payload = new String(Base64.decode(parts[1], Base64.URL_SAFE | Base64.NO_PADDING | Base64.NO_WRAP));
30
+ JSONObject parsed = new JSONObject(payload);
31
+ String normalizedDomain = hostedDomain.trim().toLowerCase();
32
+ if (!parsed.has("hd")) {
33
+ return false;
34
+ }
35
+ String hd = parsed.optString("hd", "").trim().toLowerCase();
36
+ return !hd.isEmpty() && hd.equals(normalizedDomain);
37
+ } catch (Exception e) {
38
+ return false;
39
+ }
40
+ }
41
+ }
@@ -0,0 +1,52 @@
1
+ package ee.forgr.capacitor.social.login;
2
+
3
+ /**
4
+ * Login UI rules when {@code hostedDomain} is configured on Android (standard Sign in with Google flow).
5
+ */
6
+ final class GoogleLoginHostedDomainUiRules {
7
+
8
+ static final String HOSTED_DOMAIN_INCOMPATIBLE_OPTIONS_MESSAGE =
9
+ "Google Sign-In: hostedDomain uses the standard Sign in with Google button flow and cannot be combined with autoSelectEnabled or filterByAuthorizedAccounts.";
10
+
11
+ private GoogleLoginHostedDomainUiRules() {}
12
+
13
+ static final class LoginUiDecision {
14
+
15
+ final boolean rejected;
16
+ final String rejectionMessage;
17
+ final boolean useBottomUi;
18
+
19
+ private LoginUiDecision(boolean rejected, String rejectionMessage, boolean useBottomUi) {
20
+ this.rejected = rejected;
21
+ this.rejectionMessage = rejectionMessage;
22
+ this.useBottomUi = useBottomUi;
23
+ }
24
+
25
+ static LoginUiDecision reject(String message) {
26
+ return new LoginUiDecision(true, message, false);
27
+ }
28
+
29
+ static LoginUiDecision proceed(boolean useBottomUi) {
30
+ return new LoginUiDecision(false, null, useBottomUi);
31
+ }
32
+
33
+ boolean usesGetSignInWithGoogleOption() {
34
+ return !useBottomUi;
35
+ }
36
+ }
37
+
38
+ static LoginUiDecision decideLoginUi(
39
+ boolean bottomUi,
40
+ boolean filterByAuthorizedAccounts,
41
+ boolean autoSelectEnabled,
42
+ String hostedDomain
43
+ ) {
44
+ if (!GoogleHostedDomainRules.hasConfiguredHostedDomain(hostedDomain)) {
45
+ return LoginUiDecision.proceed(bottomUi);
46
+ }
47
+ if (autoSelectEnabled || filterByAuthorizedAccounts) {
48
+ return LoginUiDecision.reject(HOSTED_DOMAIN_INCOMPATIBLE_OPTIONS_MESSAGE);
49
+ }
50
+ return LoginUiDecision.proceed(false);
51
+ }
52
+ }
@@ -54,6 +54,7 @@ import java.util.concurrent.Executors;
54
54
  import java.util.concurrent.TimeUnit;
55
55
  import java.util.concurrent.TimeoutException;
56
56
  import java.util.concurrent.atomic.AtomicBoolean;
57
+ import java.util.regex.Pattern;
57
58
  import org.json.JSONArray;
58
59
  import org.json.JSONException;
59
60
  import org.json.JSONObject;
@@ -210,6 +211,11 @@ public class GoogleProvider implements SocialProvider {
210
211
  String hostedDomain,
211
212
  boolean skipAuthOnlyAuthorizationAfterSignIn
212
213
  ) {
214
+ if (this.activity == null) {
215
+ throw new IllegalStateException(
216
+ "Google Sign-In requires an active Activity; initialize when the app has a foreground Activity."
217
+ );
218
+ }
213
219
  this.credentialManager = CredentialManager.create(activity);
214
220
  this.clientId = clientId;
215
221
  this.mode = mode;
@@ -445,8 +451,17 @@ public class GoogleProvider implements SocialProvider {
445
451
  return null;
446
452
  }
447
453
 
454
+ /**
455
+ * Starts Google Credential Manager sign-in using the current Activity context.
456
+ * Applies {@code hostedDomain} on {@code GetSignInWithGoogleOption} (standard UI). Hosted domain
457
+ * cannot be combined with {@code autoSelectEnabled} or {@code filterByAuthorizedAccounts}.
458
+ */
448
459
  @Override
449
460
  public void login(PluginCall call, JSONObject config) {
461
+ if (this.activity == null) {
462
+ call.reject("Google Sign-In requires an active Activity; call login when the app is in the foreground.");
463
+ return;
464
+ }
450
465
  if (this.clientId == null || this.clientId.isEmpty()) {
451
466
  call.reject("Google Sign-In failed: Client ID is not set");
452
467
  return;
@@ -504,19 +519,45 @@ public class GoogleProvider implements SocialProvider {
504
519
  // Build credential request
505
520
  GetCredentialRequest.Builder requestBuilder = new GetCredentialRequest.Builder();
506
521
 
522
+ GoogleLoginHostedDomainUiRules.LoginUiDecision loginUiDecision = GoogleLoginHostedDomainUiRules.decideLoginUi(
523
+ bottomUi,
524
+ filterByAuthorizedAccounts,
525
+ autoSelectEnabled,
526
+ this.hostedDomain
527
+ );
528
+ if (loginUiDecision.rejected) {
529
+ call.reject(loginUiDecision.rejectionMessage);
530
+ return;
531
+ }
532
+ boolean hasHostedDomain = GoogleHostedDomainRules.hasConfiguredHostedDomain(this.hostedDomain);
533
+ bottomUi = loginUiDecision.useBottomUi;
534
+ if (hasHostedDomain && options != null && options.has("style") && Objects.equals(options.optString("style"), "bottom")) {
535
+ Log.i(LOG_TAG, "hostedDomain is set; forcing standard Google sign-in UI so the domain filter can apply");
536
+ try {
537
+ options.put("style", "standard");
538
+ call.getData().put("options", options);
539
+ } catch (JSONException e) {
540
+ call.reject("Error parsing options: " + e.getMessage());
541
+ return;
542
+ }
543
+ }
544
+
545
+ boolean useGoogleIdOption = bottomUi;
546
+
507
547
  Log.i(
508
548
  LOG_TAG,
509
549
  String.format(
510
- "Google login request: ui=%s filterByAuthorizedAccounts=%s autoSelectEnabled=%s forcePrompt=%s nonceSet=%s",
550
+ "Google login request: ui=%s filterByAuthorizedAccounts=%s autoSelectEnabled=%s forcePrompt=%s nonceSet=%s hostedDomain=%s",
511
551
  bottomUi ? "bottom" : "standard",
512
552
  filterByAuthorizedAccounts,
513
553
  autoSelectEnabled,
514
554
  forcePrompt,
515
- !nonce.isEmpty()
555
+ !nonce.isEmpty(),
556
+ hasHostedDomain
516
557
  )
517
558
  );
518
559
 
519
- if (bottomUi) {
560
+ if (useGoogleIdOption) {
520
561
  GetGoogleIdOption.Builder googleIdOptionBuilder = new GetGoogleIdOption.Builder().setServerClientId(this.clientId);
521
562
  // Handle bottom UI specific options
522
563
  if (forcePrompt) {
@@ -544,7 +585,7 @@ public class GoogleProvider implements SocialProvider {
544
585
  if (!nonce.isEmpty()) {
545
586
  googleIdOptionBuilder.setNonce(nonce);
546
587
  }
547
- if (this.hostedDomain != null && !this.hostedDomain.isEmpty()) {
588
+ if (hasHostedDomain) {
548
589
  googleIdOptionBuilder.setHostedDomainFilter(this.hostedDomain);
549
590
  }
550
591
 
@@ -556,7 +597,7 @@ public class GoogleProvider implements SocialProvider {
556
597
  // Execute credential request
557
598
  Executor executor = Executors.newSingleThreadExecutor();
558
599
  credentialManager.getCredentialAsync(
559
- context,
600
+ activity,
560
601
  filteredRequest,
561
602
  null,
562
603
  executor,
@@ -647,6 +688,10 @@ public class GoogleProvider implements SocialProvider {
647
688
  }
648
689
  }
649
690
 
691
+ /**
692
+ * Requests Google OAuth authorization (and optional offline access) via the
693
+ * Authorization Client bound to the current Activity.
694
+ */
650
695
  private ListenableFuture<AuthorizationResult> getAuthorizationResult(
651
696
  Boolean forceRefreshToken,
652
697
  String googleAccountId,
@@ -687,7 +732,7 @@ public class GoogleProvider implements SocialProvider {
687
732
 
688
733
  AuthorizationRequest authorizationRequest = authorizationRequestBuilder.build();
689
734
 
690
- Identity.getAuthorizationClient(context)
735
+ Identity.getAuthorizationClient(activity)
691
736
  .authorize(authorizationRequest)
692
737
  .addOnSuccessListener((authorizationResult) -> {
693
738
  if (waitContext.isFinished()) {
@@ -937,8 +982,22 @@ public class GoogleProvider implements SocialProvider {
937
982
  }
938
983
  }
939
984
 
985
+ /**
986
+ * Returns true when a Credential Manager / OAuth error indicates an Android client
987
+ * misconfiguration (SHA-1 / package mismatch), including codes 28404 and 28444.
988
+ */
989
+ private static final Pattern CREDENTIAL_MANAGER_MISCONFIG_ERROR_CODE = Pattern.compile("(?:^|[^0-9])(28404|28444)(?:[^0-9]|$)");
990
+
940
991
  private boolean isDeveloperConsoleMisconfiguration(String message) {
941
- return message.contains("Developer console") || message.contains("28444") || message.contains("10:");
992
+ if (message == null || message.isEmpty()) {
993
+ return false;
994
+ }
995
+ // 28404/28444 and "10:" are common Credential Manager / OAuth client mismatch codes.
996
+ return (
997
+ message.contains("Developer console") ||
998
+ CREDENTIAL_MANAGER_MISCONFIG_ERROR_CODE.matcher(message).find() ||
999
+ message.contains("10:")
1000
+ );
942
1001
  }
943
1002
 
944
1003
  private boolean isAccountReauthFailed(String message) {
@@ -973,11 +1032,16 @@ public class GoogleProvider implements SocialProvider {
973
1032
  );
974
1033
  }
975
1034
 
1035
+ private void applyStandardSignInRetryOptions(JSONObject options, PluginCall call) throws JSONException {
1036
+ options.put("style", "standard");
1037
+ options.put("filterByAuthorizedAccounts", false);
1038
+ options.put("autoSelectEnabled", false);
1039
+ call.getData().put("options", options);
1040
+ }
1041
+
976
1042
  private void retryLoginAfterReauthFailure(PluginCall call, JSONObject config, JSONObject options) {
977
1043
  try {
978
- options.put("style", "standard");
979
- options.put("filterByAuthorizedAccounts", false);
980
- call.getData().put("options", options);
1044
+ applyStandardSignInRetryOptions(options, call);
981
1045
  } catch (JSONException ex) {
982
1046
  call.reject("Google Sign-In failed: " + ex.getMessage());
983
1047
  return;
@@ -1091,8 +1155,7 @@ public class GoogleProvider implements SocialProvider {
1091
1155
  // https://developer.android.com/reference/androidx/credentials/exceptions/NoCredentialException
1092
1156
  // Note: Family Link supervised accounts may cause this error when filterByAuthorizedAccounts is true
1093
1157
  try {
1094
- options.put("style", "standard");
1095
- call.getData().put("options", options);
1158
+ applyStandardSignInRetryOptions(options, call);
1096
1159
  } catch (JSONException ex) {
1097
1160
  call.reject("Google Sign-In failed: " + ex.getMessage());
1098
1161
  return;
@@ -1439,8 +1502,16 @@ public class GoogleProvider implements SocialProvider {
1439
1502
  }
1440
1503
  }
1441
1504
 
1505
+ /**
1506
+ * Refreshes Google ID/access tokens via Credential Manager using the current Activity,
1507
+ * then re-authorizes scopes when needed.
1508
+ */
1442
1509
  @Override
1443
1510
  public void refresh(PluginCall call) {
1511
+ if (this.activity == null) {
1512
+ call.reject("Google Sign-In requires an active Activity; call refresh when the app is in the foreground.");
1513
+ return;
1514
+ }
1444
1515
  if (this.mode == GoogleProviderLoginType.OFFLINE) {
1445
1516
  Log.w(LOG_TAG, OFFLINE_REFRESH_NOT_SUPPORTED_MESSAGE);
1446
1517
  call.reject(OFFLINE_REFRESH_NOT_SUPPORTED_MESSAGE);
@@ -1463,6 +1534,17 @@ public class GoogleProvider implements SocialProvider {
1463
1534
  accessOk = accessTokenIsValid(GoogleProvider.this.accessToken).get(7, TimeUnit.SECONDS);
1464
1535
  }
1465
1536
  if (isValidIdToken && accessOk) {
1537
+ if (
1538
+ GoogleHostedDomainRules.hasConfiguredHostedDomain(GoogleProvider.this.hostedDomain) &&
1539
+ !GoogleHostedDomainRules.idTokenSatisfiesHostedDomain(GoogleProvider.this.idToken, GoogleProvider.this.hostedDomain)
1540
+ ) {
1541
+ call.reject(
1542
+ "Failed to refresh tokens: signed-in account is outside the configured hosted domain (" +
1543
+ GoogleProvider.this.hostedDomain +
1544
+ ")."
1545
+ );
1546
+ return;
1547
+ }
1466
1548
  call.resolve();
1467
1549
  return;
1468
1550
  }
@@ -1491,7 +1573,7 @@ public class GoogleProvider implements SocialProvider {
1491
1573
 
1492
1574
  ExecutorService executor = Executors.newSingleThreadExecutor();
1493
1575
  credentialManager.getCredentialAsync(
1494
- context,
1576
+ activity,
1495
1577
  request,
1496
1578
  null,
1497
1579
  executor,
@@ -1515,6 +1597,19 @@ public class GoogleProvider implements SocialProvider {
1515
1597
  );
1516
1598
  String newIdToken = googleIdTokenCredential.getIdToken();
1517
1599
 
1600
+ if (
1601
+ GoogleHostedDomainRules.hasConfiguredHostedDomain(GoogleProvider.this.hostedDomain) &&
1602
+ !GoogleHostedDomainRules.idTokenSatisfiesHostedDomain(newIdToken, GoogleProvider.this.hostedDomain)
1603
+ ) {
1604
+ call.reject(
1605
+ "Failed to refresh tokens: signed-in account is outside the configured hosted domain (" +
1606
+ GoogleProvider.this.hostedDomain +
1607
+ ")."
1608
+ );
1609
+ executor.shutdown();
1610
+ return;
1611
+ }
1612
+
1518
1613
  if (
1519
1614
  GoogleAuthorizationDecision.shouldSkipAuthorizationAfterCredentialSignIn(
1520
1615
  GoogleProvider.this.mode,
@@ -29,7 +29,7 @@ import org.json.JSONTokener;
29
29
  @CapacitorPlugin(name = "SocialLogin")
30
30
  public class SocialLoginPlugin extends Plugin {
31
31
 
32
- private final String pluginVersion = "8.7.11";
32
+ private final String pluginVersion = "8.7.13";
33
33
 
34
34
  public static String LOG_TAG = "CapgoSocialLogin";
35
35
  private static final String USER_CANCELLED_CODE = "USER_CANCELLED";
@@ -202,6 +202,10 @@ public class SocialLoginPlugin extends Plugin {
202
202
 
203
203
  JSObject google = call.getObject("google");
204
204
  if (google != null) {
205
+ if (getActivity() == null) {
206
+ call.reject("Google Sign-In requires an active Activity; call initialize when the app has a foreground Activity.");
207
+ return;
208
+ }
205
209
  GoogleProvider googleProvider = new GoogleProvider(this.getActivity(), this.getContext());
206
210
  String googleClientId = google.getString("webClientId");
207
211
  if (googleClientId == null || googleClientId.isEmpty()) {
@@ -383,6 +387,11 @@ public class SocialLoginPlugin extends Plugin {
383
387
  return;
384
388
  }
385
389
 
390
+ if ("google".equals(providerStr) && getActivity() == null) {
391
+ call.reject("Google Sign-In requires an active Activity; call login when the app is in the foreground.");
392
+ return;
393
+ }
394
+
386
395
  provider.login(call, options);
387
396
  }
388
397
 
@@ -491,6 +500,11 @@ public class SocialLoginPlugin extends Plugin {
491
500
  return;
492
501
  }
493
502
 
503
+ if ("google".equals(providerStr) && getActivity() == null) {
504
+ call.reject("Google Sign-In requires an active Activity; call refresh when the app is in the foreground.");
505
+ return;
506
+ }
507
+
494
508
  provider.refresh(call);
495
509
  }
496
510
 
package/dist/docs.json CHANGED
@@ -431,7 +431,7 @@
431
431
  {
432
432
  "name": "google",
433
433
  "tags": [],
434
- "docs": "",
434
+ "docs": "Google Sign-In configuration.\n\n**Android `hostedDomain`:** When set, login uses the standard Sign in with Google UI\n(`options.style: 'bottom'` is overridden). Login rejects when `options.autoSelectEnabled` or\n`options.filterByAuthorizedAccounts` is `true` (Android only; see `hostedDomain` and\n`GoogleLoginOptions`).",
435
435
  "complexTypes": [],
436
436
  "type": "{ iOSClientId?: string | undefined; iOSServerClientId?: string | undefined; webClientId?: string | undefined; mode?: 'online' | 'offline' | undefined; hostedDomain?: string | undefined; redirectUrl?: string | undefined; skipAuthOnlyAuthorizationAfterSignIn?: boolean | undefined; } | undefined"
437
437
  },
@@ -1559,48 +1559,36 @@
1559
1559
  {
1560
1560
  "name": "style",
1561
1561
  "tags": [
1562
- {
1563
- "text": "style",
1564
- "name": "description"
1565
- },
1566
1562
  {
1567
1563
  "text": "'standard'",
1568
1564
  "name": "default"
1569
1565
  }
1570
1566
  ],
1571
- "docs": "Style",
1567
+ "docs": "Google sign-in UI layout (Android only).\n\nWhen `initialize({ google: { hostedDomain } })` is set, Android forces `standard` for login\n(see `hostedDomain` on the Google provider config). `bottom` cannot apply the hosted-domain\nfilter in this plugin.",
1572
1568
  "complexTypes": [],
1573
1569
  "type": "'bottom' | 'standard' | undefined"
1574
1570
  },
1575
1571
  {
1576
1572
  "name": "filterByAuthorizedAccounts",
1577
1573
  "tags": [
1578
- {
1579
- "text": "Only show accounts that have previously been used to sign in to the app.\nThis option is only available for the 'bottom' style.\nNote: For Family Link supervised accounts, this should be set to false.",
1580
- "name": "description"
1581
- },
1582
1574
  {
1583
1575
  "text": "false",
1584
1576
  "name": "default"
1585
1577
  }
1586
1578
  ],
1587
- "docs": "Filter by authorized accounts (Android only)",
1579
+ "docs": "Filter by authorized accounts (Android only)\n\nOnly show accounts that have previously been used to sign in to the app.\nThis option is only available for the `bottom` style.\n\nWhen a hosted domain is configured in `initialize`, login rejects if this is `true`\n(Android only).\n\nNote: For Family Link supervised accounts, this should be set to false.",
1588
1580
  "complexTypes": [],
1589
1581
  "type": "boolean | undefined"
1590
1582
  },
1591
1583
  {
1592
1584
  "name": "autoSelectEnabled",
1593
1585
  "tags": [
1594
- {
1595
- "text": "Automatically select the account if only one Google account is available.\nThis option is only available for the 'bottom' style.",
1596
- "name": "description"
1597
- },
1598
1586
  {
1599
1587
  "text": "false",
1600
1588
  "name": "default"
1601
1589
  }
1602
1590
  ],
1603
- "docs": "Auto select enabled (Android only)",
1591
+ "docs": "Auto select enabled (Android only)\n\nAutomatically select the account if only one Google account is available.\nThis option is only available for the `bottom` style.\n\nWhen a hosted domain is configured in `initialize`, login rejects if this is `true`\n(Android only).",
1604
1592
  "complexTypes": [],
1605
1593
  "type": "boolean | undefined"
1606
1594
  },
@@ -372,6 +372,14 @@ export interface InitializeOptions {
372
372
  */
373
373
  locale?: string;
374
374
  };
375
+ /**
376
+ * Google Sign-In configuration.
377
+ *
378
+ * **Android `hostedDomain`:** When set, login uses the standard Sign in with Google UI
379
+ * (`options.style: 'bottom'` is overridden). Login rejects when `options.autoSelectEnabled` or
380
+ * `options.filterByAuthorizedAccounts` is `true` (Android only; see `hostedDomain` and
381
+ * `GoogleLoginOptions`).
382
+ */
375
383
  google?: {
376
384
  /**
377
385
  * The app's client ID, found and created in the Google Developers Console.
@@ -420,8 +428,18 @@ export interface InitializeOptions {
420
428
  */
421
429
  mode?: 'online' | 'offline';
422
430
  /**
423
- * Filter visible accounts by hosted domain
424
- * @description filter visible accounts by hosted domain
431
+ * Restrict sign-in to a Google Workspace hosted domain (for example `example.com`).
432
+ *
433
+ * **Android only (login behavior):** When set during `initialize`, login uses the standard
434
+ * Sign in with Google UI (`GetSignInWithGoogleOption`) so `setHostedDomainFilter` can apply.
435
+ * `options.style: 'bottom'` is overridden to standard (logged at info). Login rejects when
436
+ * `options.autoSelectEnabled` or `options.filterByAuthorizedAccounts` is `true`, because the
437
+ * bottom-sheet flow (`GetGoogleIdOption`) cannot combine with hosted-domain filtering in this
438
+ * plugin. Refresh re-checks the ID token `hd` claim against this value.
439
+ *
440
+ * iOS and Web keep their existing hosted-domain behavior; the rejection above is Android only.
441
+ *
442
+ * @example 'example.com'
425
443
  */
426
444
  hostedDomain?: string;
427
445
  /**
@@ -765,23 +783,38 @@ export interface GoogleLoginOptions {
765
783
  */
766
784
  forcePrompt?: boolean;
767
785
  /**
768
- * Style
769
- * @description style
786
+ * Google sign-in UI layout (Android only).
787
+ *
788
+ * When `initialize({ google: { hostedDomain } })` is set, Android forces `standard` for login
789
+ * (see `hostedDomain` on the Google provider config). `bottom` cannot apply the hosted-domain
790
+ * filter in this plugin.
791
+ *
770
792
  * @default 'standard'
771
793
  */
772
794
  style?: 'bottom' | 'standard';
773
795
  /**
774
796
  * Filter by authorized accounts (Android only)
775
- * @description Only show accounts that have previously been used to sign in to the app.
776
- * This option is only available for the 'bottom' style.
797
+ *
798
+ * Only show accounts that have previously been used to sign in to the app.
799
+ * This option is only available for the `bottom` style.
800
+ *
801
+ * When a hosted domain is configured in `initialize`, login rejects if this is `true`
802
+ * (Android only).
803
+ *
777
804
  * Note: For Family Link supervised accounts, this should be set to false.
805
+ *
778
806
  * @default false
779
807
  */
780
808
  filterByAuthorizedAccounts?: boolean;
781
809
  /**
782
810
  * Auto select enabled (Android only)
783
- * @description Automatically select the account if only one Google account is available.
784
- * This option is only available for the 'bottom' style.
811
+ *
812
+ * Automatically select the account if only one Google account is available.
813
+ * This option is only available for the `bottom` style.
814
+ *
815
+ * When a hosted domain is configured in `initialize`, login rejects if this is `true`
816
+ * (Android only).
817
+ *
785
818
  * @default false
786
819
  */
787
820
  autoSelectEnabled?: boolean;