@capgo/capacitor-social-login 8.7.4 → 8.7.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.
- package/README.md +71 -19
- package/android/build.gradle +1 -2
- package/android/consumer-proguard-rules.pro +0 -9
- package/android/src/main/java/ee/forgr/capacitor/social/login/AppleProvider.java +56 -70
- package/android/src/main/java/ee/forgr/capacitor/social/login/GoogleAuthorizationDecision.java +80 -0
- package/android/src/main/java/ee/forgr/capacitor/social/login/GoogleProvider.java +342 -173
- package/android/src/main/java/ee/forgr/capacitor/social/login/OAuth2Provider.java +155 -171
- package/android/src/main/java/ee/forgr/capacitor/social/login/SocialLoginPlugin.java +57 -7
- package/android/src/main/java/ee/forgr/capacitor/social/login/TwitterProvider.java +98 -110
- package/android/src/main/java/ee/forgr/capacitor/social/login/helpers/DependencyAvailabilityChecker.java +4 -28
- package/android/src/main/java/ee/forgr/capacitor/social/login/helpers/PluginHttpClient.java +430 -0
- package/dist/docs.json +3 -7
- package/dist/esm/definitions.d.ts +37 -6
- package/dist/esm/definitions.js.map +1 -1
- package/ios/Sources/SocialLoginPlugin/SocialLoginPlugin.swift +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -425,7 +425,7 @@ await SocialLogin.initialize({
|
|
|
425
425
|
- `iOSClientId`: Required for iOS platform
|
|
426
426
|
- `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
427
|
- `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)
|
|
428
|
+
- `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
429
|
|
|
430
430
|
### Android configuration
|
|
431
431
|
|
|
@@ -440,13 +440,39 @@ await SocialLogin.initialize({
|
|
|
440
440
|
},
|
|
441
441
|
});
|
|
442
442
|
const res = await SocialLogin.login({
|
|
443
|
+
provider: 'google',
|
|
444
|
+
options: {},
|
|
445
|
+
});
|
|
446
|
+
```
|
|
447
|
+
|
|
448
|
+
Optional hang workaround on stock `BridgeActivity` (skips authorize; `accessToken` may be `null`):
|
|
449
|
+
|
|
450
|
+
```typescript
|
|
451
|
+
await SocialLogin.initialize({
|
|
452
|
+
google: {
|
|
453
|
+
webClientId: 'your-web-client-id',
|
|
454
|
+
skipAuthOnlyAuthorizationAfterSignIn: true,
|
|
455
|
+
},
|
|
456
|
+
});
|
|
457
|
+
```
|
|
458
|
+
|
|
459
|
+
**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.
|
|
460
|
+
|
|
461
|
+
```typescript
|
|
462
|
+
// Only after MainActivity implements ModifiedMainActivityForSocialLoginPlugin:
|
|
463
|
+
const resWithScopes = await SocialLogin.login({
|
|
443
464
|
provider: 'google',
|
|
444
465
|
options: {
|
|
445
|
-
scopes: ['
|
|
466
|
+
scopes: ['https://www.googleapis.com/auth/drive.readonly'],
|
|
446
467
|
},
|
|
447
468
|
});
|
|
448
469
|
```
|
|
449
470
|
|
|
471
|
+
```typescript
|
|
472
|
+
// Misleading on stock BridgeActivity (will reject at runtime):
|
|
473
|
+
// await SocialLogin.login({ provider: 'google', options: { scopes: ['email', 'profile'] } });
|
|
474
|
+
```
|
|
475
|
+
|
|
450
476
|
#### Android troubleshooting (Credential Manager, SHA-1, and Firebase)
|
|
451
477
|
|
|
452
478
|
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.
|
|
@@ -1114,7 +1140,33 @@ Get the current authorization code
|
|
|
1114
1140
|
refresh(options: LoginOptions) => Promise<void>
|
|
1115
1141
|
```
|
|
1116
1142
|
|
|
1117
|
-
Refresh the access token
|
|
1143
|
+
Refresh the access token for the logged-in provider.
|
|
1144
|
+
|
|
1145
|
+
**Google Android refresh behavior:**
|
|
1146
|
+
On Android, when the saved ID token is still valid and either no access token is stored or Google access
|
|
1147
|
+
token validation succeeds within the timeout, `refresh()` resolves without updating either token. That
|
|
1148
|
+
early return applies regardless of `skipAuthOnlyAuthorizationAfterSignIn`.
|
|
1149
|
+
If validation fails or times out, `refresh()` continues even when a token remains stored; with
|
|
1150
|
+
`skipAuthOnlyAuthorizationAfterSignIn: true` and default OIDC scopes, a successful credential refresh
|
|
1151
|
+
then clears that access token without obtaining a new one.
|
|
1152
|
+
|
|
1153
|
+
**Google Offline Mode Limitation:**
|
|
1154
|
+
This method is NOT supported when Google is initialized with `mode: 'offline'`.
|
|
1155
|
+
Offline mode only returns `serverAuthCode` for backend token exchange, so token refresh must happen on your backend.
|
|
1156
|
+
The plugin logs and rejects with a message explaining that you should send `serverAuthCode` to your backend,
|
|
1157
|
+
refresh the Google tokens there, or switch to `mode: 'online'` for client-side refresh.
|
|
1158
|
+
|
|
1159
|
+
**Google Android `skipAuthOnlyAuthorizationAfterSignIn`:**
|
|
1160
|
+
When initialize sets `google.skipAuthOnlyAuthorizationAfterSignIn: true` and only default OIDC scopes are
|
|
1161
|
+
requested, a refresh that runs past the early return skips `AuthorizationClient.authorize()`, updates the
|
|
1162
|
+
saved `idToken`, and clears any saved access token; no new access token is obtained. Enabling the option
|
|
1163
|
+
does not clear a stored access token while the early return applies (validation succeeded or no token
|
|
1164
|
+
stored). With default `false`, refresh still skips authorize on the early return when no access token is
|
|
1165
|
+
stored but the ID token is valid.
|
|
1166
|
+
|
|
1167
|
+
**Google Web Limitation:**
|
|
1168
|
+
On Web, Google `refresh()` is not implemented, even when using `mode: 'online'`.
|
|
1169
|
+
Call `login()` again on Web to obtain a fresh token instead.
|
|
1118
1170
|
|
|
1119
1171
|
| Param | Type |
|
|
1120
1172
|
| ------------- | ----------------------------------------------------- |
|
|
@@ -1393,16 +1445,16 @@ On user cancel or dismiss, the Promise rejects with `code === 'USER_CANCELLED'`.
|
|
|
1393
1445
|
|
|
1394
1446
|
#### InitializeOptions
|
|
1395
1447
|
|
|
1396
|
-
| Prop | Type
|
|
1397
|
-
| -------------- |
|
|
1398
|
-
| **`oauth2`** | <code><a href="#record">Record</a><string, <a href="#oauth2providerconfig">OAuth2ProviderConfig</a>></code>
|
|
1399
|
-
| **`telegram`** | <code>{ botId: string; redirectUrl?: string; origin?: string; requestAccess?: 'read' \| 'write'; languageCode?: string; }</code>
|
|
1400
|
-
| **`linkedin`** | <code><a href="#linkedinproviderconfig">LinkedInProviderConfig</a></code>
|
|
1401
|
-
| **`tiktok`** | <code><a href="#tiktokproviderconfig">TikTokProviderConfig</a></code>
|
|
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>
|
|
1448
|
+
| Prop | Type | Description |
|
|
1449
|
+
| -------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------ |
|
|
1450
|
+
| **`oauth2`** | <code><a href="#record">Record</a><string, <a href="#oauth2providerconfig">OAuth2ProviderConfig</a>></code> | OAuth2 provider configurations. Supports multiple providers by using a <a href="#record">Record</a> with provider IDs as keys. |
|
|
1451
|
+
| **`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. |
|
|
1452
|
+
| **`linkedin`** | <code><a href="#linkedinproviderconfig">LinkedInProviderConfig</a></code> | LinkedIn configuration. Convenience wrapper that maps to the OAuth2 provider using LinkedIn defaults. |
|
|
1453
|
+
| **`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`). |
|
|
1454
|
+
| **`twitter`** | <code>{ clientId: string; redirectUrl: string; defaultScopes?: string[]; forceLogin?: boolean; audience?: string; }</code> | |
|
|
1455
|
+
| **`facebook`** | <code>{ appId: string; clientToken?: string; locale?: string; }</code> | |
|
|
1456
|
+
| **`google`** | <code>{ iOSClientId?: string; iOSServerClientId?: string; webClientId?: string; mode?: 'online' \| 'offline'; hostedDomain?: string; redirectUrl?: string; skipAuthOnlyAuthorizationAfterSignIn?: boolean; }</code> | |
|
|
1457
|
+
| **`apple`** | <code>{ clientId?: string; redirectUrl?: string; useProperTokenExchange?: boolean; useBroadcastChannel?: boolean; }</code> | |
|
|
1406
1458
|
|
|
1407
1459
|
|
|
1408
1460
|
#### OAuth2ProviderConfig
|
|
@@ -1504,12 +1556,12 @@ Uses TikTok OAuth 2.0 endpoints and `client_key` instead of `client_id`.
|
|
|
1504
1556
|
|
|
1505
1557
|
#### GoogleLoginResponseOnline
|
|
1506
1558
|
|
|
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
|
|
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> |
|
|
1559
|
+
| Prop | Type | Description |
|
|
1560
|
+
| ------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
1561
|
+
| **`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. |
|
|
1562
|
+
| **`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. |
|
|
1563
|
+
| **`profile`** | <code>{ email: string \| null; familyName: string \| null; givenName: string \| null; id: string \| null; name: string \| null; imageUrl: string \| null; }</code> | |
|
|
1564
|
+
| **`responseType`** | <code>'online'</code> | |
|
|
1513
1565
|
|
|
1514
1566
|
|
|
1515
1567
|
#### GoogleLoginResponseOffline
|
package/android/build.gradle
CHANGED
|
@@ -70,8 +70,6 @@ dependencies {
|
|
|
70
70
|
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
|
71
71
|
implementation project(':capacitor-android')
|
|
72
72
|
implementation "androidx.appcompat:appcompat:$androidxAppCompatVersion"
|
|
73
|
-
implementation 'com.squareup.okhttp3:okhttp:4.12.0'
|
|
74
|
-
implementation 'com.auth0.android:jwtdecode:2.0.2'
|
|
75
73
|
implementation 'androidx.credentials:credentials:1.5.0'
|
|
76
74
|
implementation 'androidx.concurrent:concurrent-futures:1.3.0'
|
|
77
75
|
implementation 'androidx.browser:browser:1.9.0'
|
|
@@ -125,6 +123,7 @@ dependencies {
|
|
|
125
123
|
// Test dependencies (always included)
|
|
126
124
|
testImplementation "junit:junit:$junitVersion"
|
|
127
125
|
testImplementation "org.json:json:20240303"
|
|
126
|
+
testImplementation 'org.robolectric:robolectric:4.14.1'
|
|
128
127
|
androidTestImplementation "androidx.test.ext:junit:$androidxJunitVersion"
|
|
129
128
|
androidTestImplementation "androidx.test.espresso:espresso-core:$androidxEspressoCoreVersion"
|
|
130
129
|
}
|
|
@@ -15,15 +15,6 @@
|
|
|
15
15
|
-keep class com.getcapacitor.** { *; }
|
|
16
16
|
-keepclassmembers class com.getcapacitor.** { *; }
|
|
17
17
|
|
|
18
|
-
# OkHttp (used for OAuth2/Twitter token endpoints)
|
|
19
|
-
-dontwarn okhttp3.**
|
|
20
|
-
-dontwarn okio.**
|
|
21
|
-
-keep class okhttp3.** { *; }
|
|
22
|
-
-keep interface okhttp3.** { *; }
|
|
23
|
-
|
|
24
|
-
# JWT Decode library (used for Apple Sign-In)
|
|
25
|
-
-keep class com.auth0.android.jwt.** { *; }
|
|
26
|
-
|
|
27
18
|
# Google Sign-In (if included)
|
|
28
19
|
-keep class com.google.android.gms.auth.** { *; }
|
|
29
20
|
-keep class com.google.android.libraries.identity.googleid.** { *; }
|
|
@@ -32,20 +32,15 @@ import androidx.browser.customtabs.CustomTabsIntent;
|
|
|
32
32
|
import androidx.browser.customtabs.CustomTabsServiceConnection;
|
|
33
33
|
import androidx.browser.customtabs.CustomTabsSession;
|
|
34
34
|
import androidx.browser.trusted.TrustedWebActivityIntentBuilder;
|
|
35
|
-
import com.auth0.android.jwt.JWT;
|
|
36
35
|
import com.getcapacitor.JSObject;
|
|
37
36
|
import com.getcapacitor.PluginCall;
|
|
38
37
|
import com.google.androidbrowserhelper.trusted.TwaLauncher;
|
|
38
|
+
import ee.forgr.capacitor.social.login.helpers.PluginHttpClient;
|
|
39
39
|
import ee.forgr.capacitor.social.login.helpers.SocialProvider;
|
|
40
40
|
import java.io.IOException;
|
|
41
|
-
import java.util.
|
|
41
|
+
import java.util.LinkedHashMap;
|
|
42
|
+
import java.util.Map;
|
|
42
43
|
import java.util.UUID;
|
|
43
|
-
import okhttp3.Call;
|
|
44
|
-
import okhttp3.Callback;
|
|
45
|
-
import okhttp3.FormBody;
|
|
46
|
-
import okhttp3.OkHttpClient;
|
|
47
|
-
import okhttp3.Request;
|
|
48
|
-
import okhttp3.Response;
|
|
49
44
|
import org.json.JSONArray;
|
|
50
45
|
import org.json.JSONException;
|
|
51
46
|
import org.json.JSONObject;
|
|
@@ -313,8 +308,7 @@ public class AppleProvider implements SocialProvider {
|
|
|
313
308
|
public void isLoggedIn(PluginCall call) {
|
|
314
309
|
if (this.idToken != null && !this.idToken.isEmpty()) {
|
|
315
310
|
try {
|
|
316
|
-
|
|
317
|
-
boolean isLoggedIn = !jwt.isExpired(0);
|
|
311
|
+
boolean isLoggedIn = !SocialLoginPlugin.isJwtExpired(this.idToken, 0);
|
|
318
312
|
call.resolve(new JSObject().put("isLoggedIn", isLoggedIn));
|
|
319
313
|
} catch (Exception e) {
|
|
320
314
|
call.reject("Error checking login status", e);
|
|
@@ -404,76 +398,68 @@ public class AppleProvider implements SocialProvider {
|
|
|
404
398
|
}
|
|
405
399
|
|
|
406
400
|
private void requestForAccessToken(String code, String clientSecret) {
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
clearPendingLoginCall();
|
|
427
|
-
} else {
|
|
428
|
-
Log.e(SocialLoginPlugin.LOG_TAG, "Cannot get access_token: lastcall is null. Error: " + e.getMessage(), e);
|
|
429
|
-
}
|
|
401
|
+
Map<String, String> form = new LinkedHashMap<>();
|
|
402
|
+
form.put("grant_type", "authorization_code");
|
|
403
|
+
form.put("code", code);
|
|
404
|
+
form.put("redirect_uri", redirectUrl);
|
|
405
|
+
form.put("client_id", clientId);
|
|
406
|
+
form.put("client_secret", clientSecret);
|
|
407
|
+
|
|
408
|
+
PluginHttpClient.DEFAULT.enqueuePostForm(
|
|
409
|
+
TOKENURL,
|
|
410
|
+
form,
|
|
411
|
+
null,
|
|
412
|
+
new PluginHttpClient.Callback() {
|
|
413
|
+
@Override
|
|
414
|
+
public void onFailure(IOException e) {
|
|
415
|
+
if (AppleProvider.this.lastcall != null) {
|
|
416
|
+
AppleProvider.this.lastcall.reject("Cannot get access_token", e);
|
|
417
|
+
clearPendingLoginCall();
|
|
418
|
+
} else {
|
|
419
|
+
Log.e(SocialLoginPlugin.LOG_TAG, "Cannot get access_token: lastcall is null. Error: " + e.getMessage(), e);
|
|
430
420
|
}
|
|
421
|
+
}
|
|
431
422
|
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
JSONObject jsonObject = (JSONObject) new JSONTokener(responseData).nextValue();
|
|
439
|
-
String accessToken = jsonObject.getString("access_token");
|
|
440
|
-
String refreshToken = jsonObject.getString("refresh_token");
|
|
441
|
-
String idToken = jsonObject.getString("id_token");
|
|
423
|
+
@Override
|
|
424
|
+
public void onResponse(int code, String responseData) throws IOException {
|
|
425
|
+
try {
|
|
426
|
+
if (!PluginHttpClient.isSuccessfulHttpCode(code)) {
|
|
427
|
+
throw new IOException("Unexpected code " + code);
|
|
428
|
+
}
|
|
442
429
|
|
|
443
|
-
|
|
430
|
+
JSONObject jsonObject = (JSONObject) new JSONTokener(responseData).nextValue();
|
|
431
|
+
String accessToken = jsonObject.getString("access_token");
|
|
432
|
+
String refreshToken = jsonObject.getString("refresh_token");
|
|
433
|
+
String idToken = jsonObject.getString("id_token");
|
|
444
434
|
|
|
445
|
-
|
|
446
|
-
JSObject result = new JSObject();
|
|
447
|
-
result.put("accessToken", createAccessTokenObject(accessToken));
|
|
448
|
-
result.put("profile", createProfileObject(idToken));
|
|
449
|
-
result.put("idToken", idToken);
|
|
435
|
+
persistState(idToken, refreshToken, accessToken);
|
|
450
436
|
|
|
451
|
-
|
|
452
|
-
|
|
437
|
+
JSObject result = new JSObject();
|
|
438
|
+
result.put("accessToken", createAccessTokenObject(accessToken));
|
|
439
|
+
result.put("profile", createProfileObject(idToken));
|
|
440
|
+
result.put("idToken", idToken);
|
|
453
441
|
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
442
|
+
JSObject appleResponse = new JSObject();
|
|
443
|
+
appleResponse.put("provider", "apple");
|
|
444
|
+
appleResponse.put("result", result);
|
|
457
445
|
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
}
|
|
471
|
-
} finally {
|
|
472
|
-
response.close();
|
|
446
|
+
if (AppleProvider.this.lastcall != null) {
|
|
447
|
+
AppleProvider.this.lastcall.resolve(appleResponse);
|
|
448
|
+
clearPendingLoginCall();
|
|
449
|
+
} else {
|
|
450
|
+
Log.e(SocialLoginPlugin.LOG_TAG, "Cannot resolve access_token response: lastcall is null");
|
|
451
|
+
}
|
|
452
|
+
} catch (Exception e) {
|
|
453
|
+
if (AppleProvider.this.lastcall != null) {
|
|
454
|
+
AppleProvider.this.lastcall.reject("Cannot get access_token", e);
|
|
455
|
+
clearPendingLoginCall();
|
|
456
|
+
} else {
|
|
457
|
+
Log.e(SocialLoginPlugin.LOG_TAG, "Cannot get access_token: lastcall is null. Error: " + e.getMessage(), e);
|
|
473
458
|
}
|
|
474
459
|
}
|
|
475
460
|
}
|
|
476
|
-
|
|
461
|
+
}
|
|
462
|
+
);
|
|
477
463
|
}
|
|
478
464
|
|
|
479
465
|
private void persistState(String idToken, String refreshToken, String accessToken) throws JSONException {
|
package/android/src/main/java/ee/forgr/capacitor/social/login/GoogleAuthorizationDecision.java
ADDED
|
@@ -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
|
+
}
|