@capgo/capacitor-social-login 8.7.5 → 8.7.7

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
@@ -311,49 +311,13 @@ const res = await SocialLogin.login({
311
311
 
312
312
  ### iOS configuration
313
313
 
314
- In file `ios/App/App/AppDelegate.swift` add or replace the following:
315
-
316
- ```swift
317
- import UIKit
318
- import Capacitor
319
- import FBSDKCoreKit
320
-
321
- @UIApplicationMain
322
- class AppDelegate: UIResponder, UIApplicationDelegate {
323
-
324
- var window: UIWindow?
325
-
326
- func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
327
- // Override point for customization after application launch.
328
- FBSDKCoreKit.ApplicationDelegate.shared.application(
329
- application,
330
- didFinishLaunchingWithOptions: launchOptions
331
- )
332
-
333
- return true
334
- }
314
+ #### Info.plist (all Capacitor versions)
335
315
 
336
- ...
316
+ Every app, with or without UIScene, needs these settings. Add the following in the `ios/App/App/Info.plist` file inside the outermost `<dict>`.
337
317
 
338
- func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey: Any] = [:]) -> Bool {
339
- // Called when the app was launched with a url. Feel free to add additional processing here,
340
- // but if you want the App API to support tracking app url opens, make sure to keep this call
341
- if (FBSDKCoreKit.ApplicationDelegate.shared.application(
342
- app,
343
- open: url,
344
- sourceApplication: options[UIApplication.OpenURLOptionsKey.sourceApplication] as? String,
345
- annotation: options[UIApplication.OpenURLOptionsKey.annotation]
346
- )) {
347
- return true;
348
- } else {
349
- return ApplicationDelegateProxy.shared.application(app, open: url, options: options)
350
- }
351
- }
352
- }
318
+ If `Info.plist` already has a `CFBundleURLTypes` key (for example from the Google setup), do not add a second one. Append only the Facebook `<dict>` (the one with `fb[APP_ID]`) to the existing `CFBundleURLTypes` array and keep every existing URL type, otherwise another provider's callback scheme can stop working.
353
319
 
354
- ```
355
-
356
- Add the following in the `ios/App/App/info.plist` file inside of the outermost `<dict>`:
320
+ The same applies to `LSApplicationQueriesSchemes`: if it already exists, do not add a second key. Append the Facebook `<string>` entries to the existing array and keep every existing scheme, otherwise `canOpenURL` checks for other integrations can stop working.
357
321
 
358
322
  ```xml
359
323
 
@@ -384,6 +348,78 @@ Add the following in the `ios/App/App/info.plist` file inside of the outermost `
384
348
 
385
349
  More information can be found here: https://developers.facebook.com/docs/facebook-login/ios
386
350
 
351
+ #### Capacitor 8.5+ (UIScene)
352
+
353
+ If your app uses `UIApplicationSceneManifest` (Capacitor 8.5+ / `npx cap migrate`), URL opens go to `SceneDelegate.swift`. Keep Facebook SDK startup in `AppDelegate.application(_:didFinishLaunchingWithOptions:)`, and forward all URL contexts to `SceneDelegateProxy` in `scene(_:openURLContexts:)`. Do not also call the Facebook SDK URL handler in SceneDelegate, or the URL reaches the SDK twice.
354
+
355
+ `AppDelegate.swift` (required for UIScene apps too; Facebook SDK still initializes at launch):
356
+
357
+ ```swift
358
+ import UIKit
359
+ import Capacitor
360
+ import FBSDKCoreKit
361
+
362
+ func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
363
+ FBSDKCoreKit.ApplicationDelegate.shared.application(
364
+ application,
365
+ didFinishLaunchingWithOptions: launchOptions
366
+ )
367
+ return true
368
+ }
369
+ ```
370
+
371
+ `SceneDelegate.swift` (URL opens only; no direct Facebook SDK calls):
372
+
373
+ ```swift
374
+ import UIKit
375
+ import Capacitor
376
+
377
+ func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {
378
+ // Forward every context. SceneDelegateProxy posts capacitorOpenURL, and this
379
+ // plugin's observer passes the URL to the Facebook SDK exactly once.
380
+ SceneDelegateProxy.shared.scene(scene, openURLContexts: URLContexts)
381
+ }
382
+ ```
383
+
384
+ This plugin calls the Facebook SDK URL handler when it receives Capacitor's `capacitorOpenURL` notification (custom schemes) and `capacitorOpenUniversalLink` (HTTPS App Links from `scene(_:continue:)`), so direct Facebook SDK calls in SceneDelegate are not needed. Forwarding every URL context to `SceneDelegateProxy` is still required: without it, `capacitorOpenURL` is never posted and the plugin never sees the callback.
385
+
386
+ #### Before Capacitor 8.5 (AppDelegate URL handler)
387
+
388
+ In file `ios/App/App/AppDelegate.swift` add or replace the following:
389
+
390
+ ```swift
391
+ import UIKit
392
+ import Capacitor
393
+ import FBSDKCoreKit
394
+
395
+ @UIApplicationMain
396
+ class AppDelegate: UIResponder, UIApplicationDelegate {
397
+
398
+ var window: UIWindow?
399
+
400
+ func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
401
+ // Override point for customization after application launch.
402
+ FBSDKCoreKit.ApplicationDelegate.shared.application(
403
+ application,
404
+ didFinishLaunchingWithOptions: launchOptions
405
+ )
406
+
407
+ return true
408
+ }
409
+
410
+ ...
411
+
412
+ func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey: Any] = [:]) -> Bool {
413
+ // Forward every URL so Capacitor posts capacitorOpenURL. This plugin's observer calls the Facebook SDK handler.
414
+ return ApplicationDelegateProxy.shared.application(app, open: url, options: options)
415
+ }
416
+ }
417
+
418
+ ```
419
+
420
+
421
+
422
+ #### Initialize the Facebook provider
387
423
 
388
424
  Then call the `initialize` method with the `facebook` provider
389
425
 
@@ -425,7 +461,7 @@ await SocialLogin.initialize({
425
461
  - `iOSClientId`: Required for iOS platform
426
462
  - `iOSServerClientId`: Required when using `mode: 'offline'` on iOS or when you need to verify the token on the server (should be the same value as `webClientId`)
427
463
  - `mode: 'offline'`: Returns only `serverAuthCode` for backend authentication, no user profile data, and `refresh()` is not available in-app. Exchange `serverAuthCode` on your backend and refresh there.
428
- - `mode: 'online'`: Returns user profile data and access tokens (default)
464
+ - `mode: 'online'`: Returns user profile data and access tokens (default). On Android, default online login still runs `AuthorizationClient` and returns an `accessToken` when Google provides one. Set `skipAuthOnlyAuthorizationAfterSignIn: true` in `initialize()` if authorize hangs on stock `BridgeActivity`, or if login rejects because authorization needs user interaction that stock `BridgeActivity` cannot route (then `accessToken` may be `null`; use `idToken` for auth).
429
465
 
430
466
  ### Android configuration
431
467
 
@@ -440,13 +476,39 @@ await SocialLogin.initialize({
440
476
  },
441
477
  });
442
478
  const res = await SocialLogin.login({
479
+ provider: 'google',
480
+ options: {},
481
+ });
482
+ ```
483
+
484
+ Optional hang workaround on stock `BridgeActivity` (skips authorize; `accessToken` may be `null`):
485
+
486
+ ```typescript
487
+ await SocialLogin.initialize({
488
+ google: {
489
+ webClientId: 'your-web-client-id',
490
+ skipAuthOnlyAuthorizationAfterSignIn: true,
491
+ },
492
+ });
493
+ ```
494
+
495
+ **Custom Google API scopes on Android** require a modified `MainActivity` that implements `ModifiedMainActivityForSocialLoginPlugin` and forwards `onActivityResult` to the plugin (see [example-app/android/.../MainActivity.java](example-app/android/app/src/main/java/app/capgo/plugin/SocialLogin/MainActivity.java)). On a stock `BridgeActivity`, do not pass a `scopes` array to `login()`; even `['email', 'profile']` is rejected because those scopes are already included by default.
496
+
497
+ ```typescript
498
+ // Only after MainActivity implements ModifiedMainActivityForSocialLoginPlugin:
499
+ const resWithScopes = await SocialLogin.login({
443
500
  provider: 'google',
444
501
  options: {
445
- scopes: ['email', 'profile'],
502
+ scopes: ['https://www.googleapis.com/auth/drive.readonly'],
446
503
  },
447
504
  });
448
505
  ```
449
506
 
507
+ ```typescript
508
+ // Misleading on stock BridgeActivity (will reject at runtime):
509
+ // await SocialLogin.login({ provider: 'google', options: { scopes: ['email', 'profile'] } });
510
+ ```
511
+
450
512
  #### Android troubleshooting (Credential Manager, SHA-1, and Firebase)
451
513
 
452
514
  On Android this plugin uses **Google Credential Manager** (`androidx.credentials` + Sign in with Google), not the legacy `GoogleSignInClient` API. Logcat errors such as `GetCredentialCustomException: [28444] Developer console is not set up correctly` come from that stack.
@@ -559,6 +621,12 @@ const res = await SocialLogin.login({
559
621
  });
560
622
  ```
561
623
 
624
+ #### iOS OAuth redirect URLs (Google Sign-In)
625
+
626
+ Google Sign-In completes through a custom URL scheme callback. On **Capacitor 8.5+** with the [UIScene lifecycle](https://capacitorjs.com/docs/updating/8-5), that callback is delivered to `SceneDelegate.scene(_:openURLContexts:)`, not `AppDelegate.application(_:open:options:)`. See [docs/setup_google.md](https://github.com/Cap-go/capacitor-social-login/blob/main/docs/setup_google.md#url-opens-with-capacitor-85-uiscene) for the `SceneDelegate.swift` snippet.
627
+
628
+ **Automatic handling:** This plugin listens for Capacitor's `capacitorOpenURL` notification (posted from both AppDelegate and SceneDelegate paths) and calls `GIDSignIn.sharedInstance.handle(url)` when the Google Sign-In SDK is linked. Direct `GIDSignIn.sharedInstance.handle(url)` calls in `SceneDelegate` or `AppDelegate` are not needed once `SocialLogin.initialize()` runs. Forwarding URL opens to `SceneDelegateProxy` (UIScene) or `ApplicationDelegateProxy` (AppDelegate) is still required, since that is what posts `capacitorOpenURL`.
629
+
562
630
  **Offline Mode Behavior:**
563
631
  When using `mode: 'offline'`, the login response will only contain:
564
632
  ```typescript
@@ -1114,7 +1182,33 @@ Get the current authorization code
1114
1182
  refresh(options: LoginOptions) => Promise<void>
1115
1183
  ```
1116
1184
 
1117
- Refresh the access token
1185
+ Refresh the access token for the logged-in provider.
1186
+
1187
+ **Google Android refresh behavior:**
1188
+ On Android, when the saved ID token is still valid and either no access token is stored or Google access
1189
+ token validation succeeds within the timeout, `refresh()` resolves without updating either token. That
1190
+ early return applies regardless of `skipAuthOnlyAuthorizationAfterSignIn`.
1191
+ If validation fails or times out, `refresh()` continues even when a token remains stored; with
1192
+ `skipAuthOnlyAuthorizationAfterSignIn: true` and default OIDC scopes, a successful credential refresh
1193
+ then clears that access token without obtaining a new one.
1194
+
1195
+ **Google Offline Mode Limitation:**
1196
+ This method is NOT supported when Google is initialized with `mode: 'offline'`.
1197
+ Offline mode only returns `serverAuthCode` for backend token exchange, so token refresh must happen on your backend.
1198
+ The plugin logs and rejects with a message explaining that you should send `serverAuthCode` to your backend,
1199
+ refresh the Google tokens there, or switch to `mode: 'online'` for client-side refresh.
1200
+
1201
+ **Google Android `skipAuthOnlyAuthorizationAfterSignIn`:**
1202
+ When initialize sets `google.skipAuthOnlyAuthorizationAfterSignIn: true` and only default OIDC scopes are
1203
+ requested, a refresh that runs past the early return skips `AuthorizationClient.authorize()`, updates the
1204
+ saved `idToken`, and clears any saved access token; no new access token is obtained. Enabling the option
1205
+ does not clear a stored access token while the early return applies (validation succeeded or no token
1206
+ stored). With default `false`, refresh still skips authorize on the early return when no access token is
1207
+ stored but the ID token is valid.
1208
+
1209
+ **Google Web Limitation:**
1210
+ On Web, Google `refresh()` is not implemented, even when using `mode: 'online'`.
1211
+ Call `login()` again on Web to obtain a fresh token instead.
1118
1212
 
1119
1213
  | Param | Type |
1120
1214
  | ------------- | ----------------------------------------------------- |
@@ -1393,16 +1487,16 @@ On user cancel or dismiss, the Promise rejects with `code === 'USER_CANCELLED'`.
1393
1487
 
1394
1488
  #### InitializeOptions
1395
1489
 
1396
- | Prop | Type | Description |
1397
- | -------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------ |
1398
- | **`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. |
1399
- | **`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. |
1400
- | **`linkedin`** | <code><a href="#linkedinproviderconfig">LinkedInProviderConfig</a></code> | LinkedIn configuration. Convenience wrapper that maps to the OAuth2 provider using LinkedIn defaults. |
1401
- | **`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`). |
1402
- | **`twitter`** | <code>{ clientId: string; redirectUrl: string; defaultScopes?: string[]; forceLogin?: boolean; audience?: string; }</code> | |
1403
- | **`facebook`** | <code>{ appId: string; clientToken?: string; locale?: string; }</code> | |
1404
- | **`google`** | <code>{ iOSClientId?: string; iOSServerClientId?: string; webClientId?: string; mode?: 'online' \| 'offline'; hostedDomain?: string; redirectUrl?: string; }</code> | |
1405
- | **`apple`** | <code>{ clientId?: string; redirectUrl?: string; useProperTokenExchange?: boolean; useBroadcastChannel?: boolean; }</code> | |
1490
+ | Prop | Type | Description |
1491
+ | -------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------ |
1492
+ | **`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. |
1493
+ | **`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. |
1494
+ | **`linkedin`** | <code><a href="#linkedinproviderconfig">LinkedInProviderConfig</a></code> | LinkedIn configuration. Convenience wrapper that maps to the OAuth2 provider using LinkedIn defaults. |
1495
+ | **`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`). |
1496
+ | **`twitter`** | <code>{ clientId: string; redirectUrl: string; defaultScopes?: string[]; forceLogin?: boolean; audience?: string; }</code> | |
1497
+ | **`facebook`** | <code>{ appId: string; clientToken?: string; locale?: string; }</code> | |
1498
+ | **`google`** | <code>{ iOSClientId?: string; iOSServerClientId?: string; webClientId?: string; mode?: 'online' \| 'offline'; hostedDomain?: string; redirectUrl?: string; skipAuthOnlyAuthorizationAfterSignIn?: boolean; }</code> | |
1499
+ | **`apple`** | <code>{ clientId?: string; redirectUrl?: string; useProperTokenExchange?: boolean; useBroadcastChannel?: boolean; }</code> | |
1406
1500
 
1407
1501
 
1408
1502
  #### OAuth2ProviderConfig
@@ -1504,12 +1598,12 @@ Uses TikTok OAuth 2.0 endpoints and `client_key` instead of `client_id`.
1504
1598
 
1505
1599
  #### GoogleLoginResponseOnline
1506
1600
 
1507
- | Prop | Type | Description |
1508
- | ------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
1509
- | **`accessToken`** | <code><a href="#accesstoken">AccessToken</a> \| null</code> | OAuth access token for Google APIs. May be `null` on Android when Credential Manager authentication succeeds but AuthorizationClient does not return an access token (authentication-only / ID-token login with default OIDC scopes). Use `idToken` for user authentication; request additional Google API scopes when an access token is required. |
1510
- | **`idToken`** | <code>string \| null</code> | OpenID Connect ID token (JWT). Includes an `email_verified` claim when the `email` scope is granted. Use `SocialLogin.decodeIdToken({ idToken })` to read claims on the client, but always verify the token signature, `iss`, `aud`, and `exp` on your backend before trusting `email_verified` for account linking. |
1511
- | **`profile`** | <code>{ email: string \| null; familyName: string \| null; givenName: string \| null; id: string \| null; name: string \| null; imageUrl: string \| null; }</code> | |
1512
- | **`responseType`** | <code>'online'</code> | |
1601
+ | Prop | Type | Description |
1602
+ | ------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
1603
+ | **`accessToken`** | <code><a href="#accesstoken">AccessToken</a> \| null</code> | OAuth access token for Google APIs. May be `null` on Android when AuthorizationClient does not return an access token, or when `skipAuthOnlyAuthorizationAfterSignIn` is enabled during initialize (opt-in). Use `idToken` for user authentication; request additional Google API scopes when an access token is required. |
1604
+ | **`idToken`** | <code>string \| null</code> | OpenID Connect ID token (JWT). Includes an `email_verified` claim when the `email` scope is granted. Use `SocialLogin.decodeIdToken({ idToken })` to read claims on the client, but always verify the token signature, `iss`, `aud`, and `exp` on your backend before trusting `email_verified` for account linking. |
1605
+ | **`profile`** | <code>{ email: string \| null; familyName: string \| null; givenName: string \| null; id: string \| null; name: string \| null; imageUrl: string \| null; }</code> | |
1606
+ | **`responseType`** | <code>'online'</code> | |
1513
1607
 
1514
1608
 
1515
1609
  #### GoogleLoginResponseOffline
@@ -1963,30 +2057,31 @@ Add this file in your app at: `ios/App/PrivacyInfo.xcprivacy`
1963
2057
  - Adjust the data types to match your app's usage and the SDK documentation.
1964
2058
  - See [Apple docs](https://developer.apple.com/documentation/bundleresources/privacy_manifest_files/) for all allowed keys and values.
1965
2059
 
1966
- ## Combine facebook and google URL handler in `AppDelegate.swift`
2060
+ ## Combine facebook and google URL handler
2061
+
2062
+ Use **AppDelegate** handlers only when your app does **not** use the Capacitor 8.5 UIScene manifest. With UIScene, forward all contexts from `SceneDelegate.scene(_:openURLContexts:)` to `SceneDelegateProxy.shared.scene(scene, openURLContexts:)` and let the plugin observer call the SDK handlers (see [Google iOS setup](./docs/setup_google.md#url-opens-with-capacitor-85-uiscene) and the Facebook iOS section above).
2063
+
2064
+ This plugin listens for Capacitor's `capacitorOpenURL` notification and calls the Facebook and Google URL handlers for you when those SDKs are linked. It also listens for `capacitorOpenUniversalLink` and routes matching Facebook App Links into the Facebook SDK (Google still uses the open URL path). Custom native URL code is optional.
2065
+
2066
+ ### AppDelegate.swift (pre-8.5 / no scene manifest)
1967
2067
 
1968
2068
  ```swift
1969
2069
  func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey: Any] = [:]) -> Bool {
1970
- // Called when the app was launched with a url. Feel free to add additional processing here,
1971
- // but if you want the App API to support tracking app url opens, make sure to keep this call
1972
-
1973
- // Return true if the URL was handled by either Facebook or Google authentication
1974
- // https://github.com/Cap-go/capacitor-social-login/blob/main/docs/setup_facebook.md#ios-setup
1975
- // https://github.com/Cap-go/capacitor-social-login/blob/main/docs/setup_google.md#using-google-login-on-ios
1976
- if FBSDKCoreKit.ApplicationDelegate.shared.application(
1977
- app,
1978
- open: url,
1979
- sourceApplication: options[UIApplication.OpenURLOptionsKey.sourceApplication] as? String,
1980
- annotation: options[UIApplication.OpenURLOptionsKey.annotation]
1981
- ) || GIDSignIn.sharedInstance.handle(url) {
1982
- return true
1983
- }
1984
-
1985
- // If URL wasn't handled by auth services, pass it to Capacitor for processing
2070
+ // Forward every URL so Capacitor posts capacitorOpenURL. This plugin's observer calls the Facebook and Google handlers.
1986
2071
  return ApplicationDelegateProxy.shared.application(app, open: url, options: options)
1987
2072
  }
1988
2073
  ```
1989
2074
 
2075
+ ### SceneDelegate.swift (Capacitor 8.5+)
2076
+
2077
+ ```swift
2078
+ func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {
2079
+ // Forward every context. The plugin observer calls the Facebook and Google
2080
+ // URL handlers once per URL, so do not call them here as well.
2081
+ SceneDelegateProxy.shared.scene(scene, openURLContexts: URLContexts)
2082
+ }
2083
+ ```
2084
+
1990
2085
  ### Credits
1991
2086
 
1992
2087
  This plugin implementation of google is based on [CapacitorGoogleAuth](https://github.com/CodetrixStudio/CapacitorGoogleAuth) with a lot of rework, the current maintainer is unreachable, we are thankful for his work and are now going forward on our own!
@@ -0,0 +1,80 @@
1
+ package ee.forgr.capacitor.social.login;
2
+
3
+ import android.app.Activity;
4
+
5
+ /**
6
+ * Pure decision helpers for Google AuthorizationClient usage after Credential Manager sign-in.
7
+ */
8
+ public final class GoogleAuthorizationDecision {
9
+
10
+ public static final long AUTHORIZATION_WAIT_SECONDS = 60L;
11
+
12
+ public static final long AUTHORIZATION_CONSENT_WAIT_SECONDS = 600L;
13
+
14
+ public static final String UNROUTABLE_AUTHORIZATION_RESOLUTION_MESSAGE =
15
+ "Google authorization requires user interaction, but the host Activity does not implement ModifiedMainActivityForSocialLoginPlugin and forward onActivityResult. For authentication-only scopes in online mode, set google.skipAuthOnlyAuthorizationAfterSignIn to true. For custom scopes or offline mode, update MainActivity as documented in the README.";
16
+
17
+ public static final String AUTHORIZATION_WAIT_TIMEOUT_MESSAGE =
18
+ "Timed out waiting for Google authorization after " + AUTHORIZATION_WAIT_SECONDS + " seconds";
19
+
20
+ public static final String AUTHORIZATION_CONSENT_WAIT_TIMEOUT_MESSAGE =
21
+ "Timed out waiting for Google authorization consent after " + AUTHORIZATION_CONSENT_WAIT_SECONDS + " seconds";
22
+
23
+ private GoogleAuthorizationDecision() {}
24
+
25
+ /**
26
+ * Authentication-only (OIDC) scopes that Credential Manager already covers via the ID token.
27
+ * AuthorizationClient is only needed when requesting additional Google API scopes.
28
+ */
29
+ public static boolean isAuthenticationOnlyScopes(String[] scopes) {
30
+ if (scopes == null || scopes.length == 0) {
31
+ return true;
32
+ }
33
+ for (String scope : scopes) {
34
+ if (scope == null || scope.isEmpty()) {
35
+ continue;
36
+ }
37
+ boolean isDefault =
38
+ scope.equals("openid") ||
39
+ scope.equals("https://www.googleapis.com/auth/userinfo.email") ||
40
+ scope.equals("https://www.googleapis.com/auth/userinfo.profile") ||
41
+ scope.equals("email") ||
42
+ scope.equals("profile");
43
+ if (!isDefault) {
44
+ return false;
45
+ }
46
+ }
47
+ return true;
48
+ }
49
+
50
+ /**
51
+ * Skip AuthorizationClient when online login already has an ID token and only default OIDC scopes are requested.
52
+ * Requires {@code skipAuthOnlyAuthorizationAfterSignIn} (opt-in, default false). Offline mode still needs authorize() for serverAuthCode.
53
+ */
54
+ public static boolean shouldSkipAuthorizationAfterCredentialSignIn(
55
+ GoogleProvider.GoogleProviderLoginType mode,
56
+ String[] scopes,
57
+ boolean skipAuthOnlyAuthorizationAfterSignIn
58
+ ) {
59
+ return (
60
+ skipAuthOnlyAuthorizationAfterSignIn &&
61
+ mode == GoogleProvider.GoogleProviderLoginType.ONLINE &&
62
+ isAuthenticationOnlyScopes(scopes)
63
+ );
64
+ }
65
+
66
+ public static boolean canRouteAuthorizationResolution(Activity activity) {
67
+ return activity instanceof ModifiedMainActivityForSocialLoginPlugin;
68
+ }
69
+
70
+ public static boolean isUnroutableAuthorizationResolutionFailure(Throwable error) {
71
+ Throwable current = error;
72
+ while (current != null) {
73
+ if (UNROUTABLE_AUTHORIZATION_RESOLUTION_MESSAGE.equals(current.getMessage())) {
74
+ return true;
75
+ }
76
+ current = current.getCause();
77
+ }
78
+ return false;
79
+ }
80
+ }