@capgo/capacitor-social-login 8.5.12 → 8.5.14
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 +36 -18
- package/android/src/main/java/ee/forgr/capacitor/social/login/SocialLoginPlugin.java +1 -1
- package/ios/Sources/SocialLoginPlugin/AppleProvider.swift +3 -5
- package/ios/Sources/SocialLoginPlugin/GoogleProvider.swift +10 -4
- package/ios/Sources/SocialLoginPlugin/OAuth2Provider.swift +4 -2
- package/ios/Sources/SocialLoginPlugin/PresentationWindowResolver.swift +33 -0
- package/ios/Sources/SocialLoginPlugin/SocialLoginPlugin.swift +10 -5
- package/ios/Sources/SocialLoginPlugin/TelegramProvider.swift +3 -6
- package/ios/Sources/SocialLoginPlugin/TwitterProvider.swift +3 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,11 +1,29 @@
|
|
|
1
1
|
# @capgo/capacitor-social-login
|
|
2
|
-
|
|
2
|
+
|
|
3
|
+
Add Google, Apple, Facebook and other social sign-ins to your Capacitor app with one plugin and one API across iOS, Android and the web.
|
|
4
|
+
|
|
5
|
+
<a href="https://capgo.app/?ref=plugin_social_login"><img src="https://capgo.app/readme-banner.svg?repo=Cap-go/capacitor-social-login" alt="Capgo - Instant updates for Capacitor" /></a>
|
|
3
6
|
|
|
4
7
|
<div align="center">
|
|
5
|
-
<
|
|
6
|
-
<h2><a href="https://capgo.app/
|
|
8
|
+
<p><b>Capgo</b>: push fixes to your Capacitor users in minutes, build signed iOS and Android apps without a Mac, and roll back in one click.</p>
|
|
9
|
+
<h2><a href="https://capgo.app/register/?ref=plugin_social_login">➡️ Get started for free</a></h2>
|
|
10
|
+
<p>14-day unlimited free trial. No credit card required</p>
|
|
11
|
+
<p><a href="https://capgo.app/consulting/?ref=plugin_social_login">Missing a feature? We'll build the plugin for you 💪</a></p>
|
|
7
12
|
</div>
|
|
8
13
|
|
|
14
|
+
<p align="center">
|
|
15
|
+
<img src="https://raw.githubusercontent.com/Cap-go/capacitor-social-login/main/assets/github-social-preview.png" alt="@capgo/capacitor-social-login for Capacitor apps" width="300" />
|
|
16
|
+
</p>
|
|
17
|
+
|
|
18
|
+
## Key features
|
|
19
|
+
|
|
20
|
+
- **Many providers**: Google, Apple, Facebook, Twitter (X), LinkedIn, TikTok, Telegram and generic OAuth2.
|
|
21
|
+
- **One API**: `initialize()`, `login()`, `logout()`, `isLoggedIn()` and `getAuthorizationCode()`.
|
|
22
|
+
- **Tokens**: `refresh()`, `refreshToken()`, `decodeIdToken()` and expiry helpers.
|
|
23
|
+
- **Native sign-in**: Sign in with Apple, Google Sign-In and the Facebook SDK on iOS, Credential Manager on Android.
|
|
24
|
+
- **Web OAuth**: `handleRedirectCallback()` and `openSecureWindow()` for redirect and popup flows.
|
|
25
|
+
- **Platforms**: iOS, Android and Web. Check the docs for each provider's setup on each platform.
|
|
26
|
+
|
|
9
27
|
## Fork Information
|
|
10
28
|
This plugin is a fork of [@codetrix-studio/capacitor-google-auth](https://github.com/CodetrixStudio/CapacitorGoogleAuth). We created this fork because the original plugin is "virtually" archived with no way to reach the maintainer in any medium, and only one person (@reslear) has write rights but doesn't handle native code.
|
|
11
29
|
|
|
@@ -117,7 +135,7 @@ export default config;
|
|
|
117
135
|
- **Important**: Disabling a provider (`false`) will make it unavailable at runtime, regardless of whether it actually adds any dependencies. The provider will be disabled even if it uses only system APIs.
|
|
118
136
|
- This configuration only affects iOS and Android platforms; it does not affect the web platform.
|
|
119
137
|
- **Important**: Using `false` means the dependency won't be bundled, but the plugin code still compiles against it. Ensure the consuming app includes the dependency if needed.
|
|
120
|
-
- **Facebook**: When `facebook: false`, the Facebook SDK is omitted and the plugin compiles a provider stub in its own package
|
|
138
|
+
- **Facebook**: When `facebook: false`, the Facebook SDK is omitted and the plugin compiles a provider stub in its own package, no `com.facebook.*` classes are shipped (avoids privacy-scanner false positives).
|
|
121
139
|
- **Apple (iOS)**: `apple: true` enables Sign in with Apple (AuthenticationServices). Redirect URL and backend token exchange use Foundation URLSession, so no third-party networking library is required. `apple: false` disables Apple authentication at runtime, including basic Sign in with Apple, consistent with the rule above that `false` providers are unavailable at runtime.
|
|
122
140
|
- Apple Sign-In on Android uses OAuth flow without external SDK dependencies
|
|
123
141
|
- Twitter uses standard OAuth 2.0 flow without external SDK dependencies
|
|
@@ -441,15 +459,15 @@ You need **two kinds** of OAuth 2.0 client IDs:
|
|
|
441
459
|
| Client type | Used for | Where it goes |
|
|
442
460
|
|-------------|----------|---------------|
|
|
443
461
|
| **Web application** | Server / ID token audience | `webClientId` in `SocialLogin.initialize()` |
|
|
444
|
-
| **Android** (one per signing key) | Proves your APK is allowed to call Google | Google Cloud Console only
|
|
462
|
+
| **Android** (one per signing key) | Proves your APK is allowed to call Google | Google Cloud Console only, **do not** pass this ID to `webClientId` |
|
|
445
463
|
|
|
446
464
|
Common mistake: using the **Android** client ID as `webClientId`. Credential Manager requires the **Web** client ID there. The Android client only needs the correct **package name + SHA-1** registered in the console.
|
|
447
465
|
|
|
448
466
|
Create one Android OAuth client for **each** certificate that signs builds you test:
|
|
449
467
|
|
|
450
|
-
- **Debug
|
|
451
|
-
- **Release
|
|
452
|
-
- **Play App Signing
|
|
468
|
+
- **Debug**, from `./gradlew signingReport` (debug variant)
|
|
469
|
+
- **Release**, from the APK/AAB you actually install (see below)
|
|
470
|
+
- **Play App Signing**, from Play Console → **App integrity** → **App signing key certificate** (required for Play Store builds even if your upload key SHA-1 is already registered)
|
|
453
471
|
|
|
454
472
|
The `applicationId` in `android/app/build.gradle` must match the Android OAuth client package name exactly (including any `.debug` suffix if you use one).
|
|
455
473
|
|
|
@@ -464,13 +482,13 @@ This almost always means Google rejected the combination of **installed APK sign
|
|
|
464
482
|
1. Confirm `webClientId` is the **Web application** client ID (ends with `.apps.googleusercontent.com`).
|
|
465
483
|
2. Run the app, reproduce the failure, and read Logcat (`GoogleProvider`) for `signingSha1=` and `package=`.
|
|
466
484
|
3. In [Google Cloud Console → Credentials](https://console.cloud.google.com/apis/credentials), open your **Android** OAuth client and verify that **exact** package name and SHA-1 are listed.
|
|
467
|
-
4. If testing a **release** build, register the SHA-1 from that build
|
|
485
|
+
4. If testing a **release** build, register the SHA-1 from that build, not only the debug keystore.
|
|
468
486
|
5. If the app is distributed via **Play Store**, also register the **Play App Signing** SHA-1.
|
|
469
487
|
6. Ensure Web and Android clients live in the **same** Google Cloud project.
|
|
470
488
|
7. If consent screen is in Testing, confirm the Google account is a **test user**.
|
|
471
489
|
8. Wait and retry after console changes.
|
|
472
490
|
|
|
473
|
-
`USER_CANCELLED` after picking an account on a misconfigured debug build can still be a SHA-1 / client-ID mismatch
|
|
491
|
+
`USER_CANCELLED` after picking an account on a misconfigured debug build can still be a SHA-1 / client-ID mismatch, fix the console setup above first.
|
|
474
492
|
|
|
475
493
|
##### Error `[16] Account reauth failed`
|
|
476
494
|
|
|
@@ -480,14 +498,14 @@ This error comes from Google Credential Manager when re-authenticating a cached
|
|
|
480
498
|
|
|
481
499
|
If the retry still fails for specific users, check:
|
|
482
500
|
|
|
483
|
-
1. **OAuth consent screen
|
|
484
|
-
2. **Testing mode
|
|
485
|
-
3. **Sign in with Google setting
|
|
486
|
-
4. **Family Link / supervised accounts
|
|
487
|
-
5. **Play App Signing SHA-1
|
|
488
|
-
6. **Explicit override
|
|
501
|
+
1. **OAuth consent screen**, must be **External** (Internal / Workspace-only blocks consumer `@gmail.com` accounts).
|
|
502
|
+
2. **Testing mode**, every failing Google account must be listed under **Audience → Test users**.
|
|
503
|
+
3. **Sign in with Google setting**, the user may have disabled your app under Google Account → **Sign in with Google**.
|
|
504
|
+
4. **Family Link / supervised accounts**, ensure `filterByAuthorizedAccounts` is not explicitly set to `true` (the default is `false`; see [Family Link section](#google-sign-in-with-family-link-supervised-accounts) below).
|
|
505
|
+
5. **Play App Signing SHA-1**, still required for Play Store builds even when most users succeed (some device/account paths are stricter).
|
|
506
|
+
6. **Explicit override**, if your app sets `filterByAuthorizedAccounts: true`, set it back to `false` for affected users; the default already skips authorized-account filtering.
|
|
489
507
|
|
|
490
|
-
After a failure, filter Logcat for `GoogleProvider
|
|
508
|
+
After a failure, filter Logcat for `GoogleProvider`, the plugin logs `package`, `signingSha1`, and `webClientId`.
|
|
491
509
|
|
|
492
510
|
##### Extract SHA-1 from the build you install
|
|
493
511
|
|
|
@@ -860,7 +878,7 @@ Then run `npx cap sync`. The plugin uses stub classes instead of the real Facebo
|
|
|
860
878
|
|
|
861
879
|
On Android, this error comes from **Google Credential Manager** when the installed APK's signing certificate, package name, or `webClientId` does not match Google Cloud Console.
|
|
862
880
|
|
|
863
|
-
See [Android troubleshooting (Credential Manager, SHA-1, and Firebase)](#android-troubleshooting-credential-manager-sha-1-and-firebase) for the full checklist. After a failed login, filter Logcat for `GoogleProvider
|
|
881
|
+
See [Android troubleshooting (Credential Manager, SHA-1, and Firebase)](#android-troubleshooting-credential-manager-sha-1-and-firebase) for the full checklist. After a failed login, filter Logcat for `GoogleProvider`, the plugin prints `package`, `signingSha1`, and `webClientId` to compare with your OAuth clients.
|
|
864
882
|
|
|
865
883
|
### Google Sign-In `[16] Account reauth failed` (Android)
|
|
866
884
|
|
|
@@ -24,7 +24,7 @@ import org.json.JSONObject;
|
|
|
24
24
|
@CapacitorPlugin(name = "SocialLogin")
|
|
25
25
|
public class SocialLoginPlugin extends Plugin {
|
|
26
26
|
|
|
27
|
-
private final String pluginVersion = "8.5.
|
|
27
|
+
private final String pluginVersion = "8.5.14";
|
|
28
28
|
|
|
29
29
|
public static String LOG_TAG = "CapgoSocialLogin";
|
|
30
30
|
public HashMap<String, SocialProvider> socialProviderHashMap = new HashMap<>();
|
|
@@ -145,6 +145,8 @@ private enum AppleProviderHTTP {
|
|
|
145
145
|
// Basic Sign in with Apple uses AuthenticationServices only.
|
|
146
146
|
// redirectUrl / backend token-exchange flows use URLSession (Foundation).
|
|
147
147
|
class AppleProvider: NSObject, ASAuthorizationControllerDelegate, ASAuthorizationControllerPresentationContextProviding {
|
|
148
|
+
/// Capacitor bridge view controller, used to present in the scene that started the call.
|
|
149
|
+
weak var hostViewController: UIViewController?
|
|
148
150
|
private var completion: ((Result<AppleProviderResponse, Error>) -> Void)?
|
|
149
151
|
|
|
150
152
|
// Instance variables
|
|
@@ -689,11 +691,7 @@ class AppleProvider: NSObject, ASAuthorizationControllerDelegate, ASAuthorizatio
|
|
|
689
691
|
// MARK: - ASAuthorizationControllerPresentationContextProviding
|
|
690
692
|
|
|
691
693
|
func presentationAnchor(for controller: ASAuthorizationController) -> ASPresentationAnchor {
|
|
692
|
-
|
|
693
|
-
.compactMap { $0 as? UIWindowScene }
|
|
694
|
-
.filter { $0.activationState == .foregroundActive || $0.activationState == .foregroundInactive }
|
|
695
|
-
.flatMap { $0.windows }
|
|
696
|
-
return windows.first { $0.isKeyWindow } ?? windows.first ?? UIApplication.shared.windows.first ?? ASPresentationAnchor()
|
|
694
|
+
return PresentationWindowResolver.window(hostViewController: hostViewController) ?? ASPresentationAnchor()
|
|
697
695
|
}
|
|
698
696
|
|
|
699
697
|
private func persistName(userId: String, givenName: String?, familyName: String?) {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import Foundation
|
|
2
|
+
import UIKit
|
|
2
3
|
|
|
3
4
|
#if canImport(GoogleSignIn)
|
|
4
5
|
import GoogleSignIn
|
|
@@ -11,6 +12,8 @@ enum GoogleProviderLoginType {
|
|
|
11
12
|
|
|
12
13
|
#if canImport(GoogleSignIn)
|
|
13
14
|
class GoogleProvider {
|
|
15
|
+
/// Capacitor bridge view controller, used to present in the scene that started the call.
|
|
16
|
+
weak var hostViewController: UIViewController?
|
|
14
17
|
var configuration: GIDConfiguration!
|
|
15
18
|
var forceAuthCode: Bool = false
|
|
16
19
|
var additionalScopes: [String]!
|
|
@@ -38,7 +41,8 @@ class GoogleProvider {
|
|
|
38
41
|
}
|
|
39
42
|
|
|
40
43
|
func login() {
|
|
41
|
-
guard let presentingVc =
|
|
44
|
+
guard let presentingVc = PresentationWindowResolver
|
|
45
|
+
.window(hostViewController: self.hostViewController)?.rootViewController else {
|
|
42
46
|
completion(.failure(NSError(domain: "GoogleProvider", code: 0, userInfo: [NSLocalizedDescriptionKey: "No presenting view controller found"])))
|
|
43
47
|
return
|
|
44
48
|
}
|
|
@@ -71,7 +75,7 @@ class GoogleProvider {
|
|
|
71
75
|
completion(.failure(NSError(domain: "GoogleProvider", code: 0, userInfo: [NSLocalizedDescriptionKey: "Cannot find serverAuthCode, make sure to set iOSServerClientId in the configuration"])))
|
|
72
76
|
return
|
|
73
77
|
}
|
|
74
|
-
completion(.success(self.createOfflineResponse(serverAuthCode:
|
|
78
|
+
completion(.success(self.createOfflineResponse(serverAuthCode: serverAuthCode)))
|
|
75
79
|
} else {
|
|
76
80
|
completion(.success(self.mode == .ONLINE ? self.createOnlineLoginResponse(user: result.user) : self.createOfflineResponse(serverAuthCode: result.serverAuthCode ?? "")))
|
|
77
81
|
}
|
|
@@ -80,8 +84,8 @@ class GoogleProvider {
|
|
|
80
84
|
|
|
81
85
|
if GIDSignIn.sharedInstance.hasPreviousSignIn() && !self.forceAuthCode && self.mode != .OFFLINE {
|
|
82
86
|
GIDSignIn.sharedInstance.restorePreviousSignIn { user, error in
|
|
83
|
-
if
|
|
84
|
-
//
|
|
87
|
+
if error != nil {
|
|
88
|
+
// Retry interactive login when restoring the previous session fails.
|
|
85
89
|
login()
|
|
86
90
|
return
|
|
87
91
|
}
|
|
@@ -245,6 +249,8 @@ class GoogleProvider {
|
|
|
245
249
|
#else
|
|
246
250
|
// Stub class when GoogleSignIn is not available
|
|
247
251
|
class GoogleProvider {
|
|
252
|
+
weak var hostViewController: UIViewController?
|
|
253
|
+
|
|
248
254
|
func initialize(clientId: String, mode: GoogleProviderLoginType, serverClientId: String? = nil, hostedDomain: String? = nil) {
|
|
249
255
|
fatalError("Google Sign-In is not available. Include GoogleSignIn dependency in your Podfile.")
|
|
250
256
|
}
|
|
@@ -65,6 +65,8 @@ struct OAuth2ProviderConfig {
|
|
|
65
65
|
}
|
|
66
66
|
|
|
67
67
|
class OAuth2Provider: NSObject {
|
|
68
|
+
/// Capacitor bridge view controller, used to present in the scene that started the call.
|
|
69
|
+
weak var hostViewController: UIViewController?
|
|
68
70
|
private var providers: [String: OAuth2ProviderConfig] = [:]
|
|
69
71
|
private var currentSession: ASWebAuthenticationSession?
|
|
70
72
|
private var currentState: String?
|
|
@@ -577,7 +579,7 @@ class OAuth2Provider: NSObject {
|
|
|
577
579
|
let effectiveRefreshToken = tokenResponse.refresh_token ?? fallbackRefreshToken
|
|
578
580
|
|
|
579
581
|
// Fetch resource data if configured
|
|
580
|
-
if
|
|
582
|
+
if config.resourceUrl != nil {
|
|
581
583
|
fetchResource(config: config, accessToken: tokenResponse.access_token) { [weak self] resourceResult in
|
|
582
584
|
guard let self = self else { return }
|
|
583
585
|
|
|
@@ -756,7 +758,7 @@ class OAuth2Provider: NSObject {
|
|
|
756
758
|
|
|
757
759
|
extension OAuth2Provider: ASWebAuthenticationPresentationContextProviding {
|
|
758
760
|
func presentationAnchor(for session: ASWebAuthenticationSession) -> ASPresentationAnchor {
|
|
759
|
-
return
|
|
761
|
+
return PresentationWindowResolver.window(hostViewController: hostViewController) ?? ASPresentationAnchor()
|
|
760
762
|
}
|
|
761
763
|
}
|
|
762
764
|
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import UIKit
|
|
2
|
+
|
|
3
|
+
/// Resolves the window that authentication UI should be presented from.
|
|
4
|
+
///
|
|
5
|
+
/// Order:
|
|
6
|
+
/// 1. The window hosting the Capacitor bridge view controller, so multi-scene iPad apps present
|
|
7
|
+
/// in the scene that started the call instead of an arbitrary key window.
|
|
8
|
+
/// 2. A key window in a foreground-active scene, then in a foreground-inactive scene
|
|
9
|
+
/// (scene transitions, system sheets).
|
|
10
|
+
/// 3. The application key window, then any application window, for app-delegate hosts
|
|
11
|
+
/// that have no matching connected scene.
|
|
12
|
+
enum PresentationWindowResolver {
|
|
13
|
+
static func window(hostViewController: UIViewController?) -> UIWindow? {
|
|
14
|
+
if let hostWindow = hostViewController?.viewIfLoaded?.window {
|
|
15
|
+
return hostWindow
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
let scenes = UIApplication.shared.connectedScenes.compactMap { $0 as? UIWindowScene }
|
|
19
|
+
for state in [UIScene.ActivationState.foregroundActive, .foregroundInactive] {
|
|
20
|
+
let windows = scenes.filter { $0.activationState == state }.flatMap { $0.windows }
|
|
21
|
+
if let window = preferredWindow(from: windows) {
|
|
22
|
+
return window
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return preferredWindow(from: UIApplication.shared.windows)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
private static func preferredWindow(from windows: [UIWindow]) -> UIWindow? {
|
|
30
|
+
let visible = windows.filter { !$0.isHidden && $0.alpha > 0 }
|
|
31
|
+
return visible.first(where: { $0.isKeyWindow }) ?? visible.first
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -16,7 +16,7 @@ import GoogleSignIn
|
|
|
16
16
|
*/
|
|
17
17
|
@objc(SocialLoginPlugin)
|
|
18
18
|
public class SocialLoginPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
19
|
-
private let pluginVersion: String = "8.5.
|
|
19
|
+
private let pluginVersion: String = "8.5.14"
|
|
20
20
|
public let identifier = "SocialLoginPlugin"
|
|
21
21
|
public let jsName = "SocialLogin"
|
|
22
22
|
private static let userCancelledCode = "USER_CANCELLED"
|
|
@@ -471,6 +471,7 @@ public class SocialLoginPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
471
471
|
call.reject("Google Sign-In provider is disabled. Dependencies are not available. Ensure Google Sign-In dependencies are included in your Podfile")
|
|
472
472
|
return
|
|
473
473
|
}
|
|
474
|
+
gProvider.hostViewController = self.bridge?.viewController
|
|
474
475
|
gProvider.login(payload: payload) { (result: Result<GoogleLoginResponse, Error>) in
|
|
475
476
|
self.handleLoginResult(result, call: call)
|
|
476
477
|
}
|
|
@@ -479,14 +480,17 @@ public class SocialLoginPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
479
480
|
call.reject("Apple Sign-In provider is disabled in capacitor.config")
|
|
480
481
|
return
|
|
481
482
|
}
|
|
483
|
+
apple.hostViewController = self.bridge?.viewController
|
|
482
484
|
apple.login(payload: payload) { (result: Result<AppleProviderResponse, Error>) in
|
|
483
485
|
self.handleLoginResult(result, call: call)
|
|
484
486
|
}
|
|
485
487
|
case "twitter":
|
|
488
|
+
twitter.hostViewController = self.bridge?.viewController
|
|
486
489
|
twitter.login(payload: payload) { (result: Result<TwitterProfileResponse, Error>) in
|
|
487
490
|
self.handleLoginResult(result, call: call)
|
|
488
491
|
}
|
|
489
492
|
case "telegram":
|
|
493
|
+
telegram.hostViewController = self.bridge?.viewController
|
|
490
494
|
telegram.login(payload: payload) { (result: Result<TelegramLoginResponse, Error>) in
|
|
491
495
|
self.handleLoginResult(result, call: call)
|
|
492
496
|
}
|
|
@@ -495,6 +499,7 @@ public class SocialLoginPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
495
499
|
call.reject("providerId is required for oauth2 login")
|
|
496
500
|
return
|
|
497
501
|
}
|
|
502
|
+
oauth2.hostViewController = self.bridge?.viewController
|
|
498
503
|
oauth2.login(providerId: providerId, payload: payload) { (result: Result<OAuth2LoginResponse, Error>) in
|
|
499
504
|
self.handleLoginResult(result, call: call)
|
|
500
505
|
}
|
|
@@ -846,9 +851,9 @@ public class SocialLoginPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
846
851
|
if let user = response as? SocialLoginUser {
|
|
847
852
|
call.resolve([
|
|
848
853
|
"accessToken": user.accessToken,
|
|
849
|
-
"idToken": user.idToken,
|
|
850
|
-
"refreshToken": user.refreshToken,
|
|
851
|
-
"expiresIn": user.expiresIn
|
|
854
|
+
"idToken": user.idToken ?? NSNull(),
|
|
855
|
+
"refreshToken": user.refreshToken ?? NSNull(),
|
|
856
|
+
"expiresIn": user.expiresIn ?? NSNull()
|
|
852
857
|
])
|
|
853
858
|
} else if let twitterResponse = response as? TwitterProfileResponse {
|
|
854
859
|
call.resolve([
|
|
@@ -1019,7 +1024,7 @@ public class SocialLoginPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
1019
1024
|
"expires": oauth2Response.accessToken.expires ?? NSNull(),
|
|
1020
1025
|
"refreshToken": oauth2Response.accessToken.refreshToken ?? NSNull()
|
|
1021
1026
|
]
|
|
1022
|
-
|
|
1027
|
+
let oauth2Result: [String: Any] = [
|
|
1023
1028
|
"providerId": oauth2Response.providerId,
|
|
1024
1029
|
"accessToken": accessToken,
|
|
1025
1030
|
"idToken": oauth2Response.idToken ?? NSNull(),
|
|
@@ -33,6 +33,8 @@ private struct TelegramProfileStored: Codable {
|
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
class TelegramProvider: NSObject {
|
|
36
|
+
/// Capacitor bridge view controller, used to present in the scene that started the call.
|
|
37
|
+
weak var hostViewController: UIViewController?
|
|
36
38
|
private var botId: String?
|
|
37
39
|
private var requestAccess: String = "write"
|
|
38
40
|
private var origin: String?
|
|
@@ -250,11 +252,6 @@ class TelegramProvider: NSObject {
|
|
|
250
252
|
|
|
251
253
|
extension TelegramProvider: ASWebAuthenticationPresentationContextProviding {
|
|
252
254
|
func presentationAnchor(for session: ASWebAuthenticationSession) -> ASPresentationAnchor {
|
|
253
|
-
|
|
254
|
-
let active = scenes.first { $0.activationState == .foregroundActive } ?? scenes.first
|
|
255
|
-
if let window = active?.windows.first(where: { $0.isKeyWindow }) ?? active?.windows.first {
|
|
256
|
-
return window
|
|
257
|
-
}
|
|
258
|
-
return ASPresentationAnchor()
|
|
255
|
+
return PresentationWindowResolver.window(hostViewController: hostViewController) ?? ASPresentationAnchor()
|
|
259
256
|
}
|
|
260
257
|
}
|
|
@@ -49,6 +49,8 @@ struct TwitterStoredTokens: Codable {
|
|
|
49
49
|
}
|
|
50
50
|
|
|
51
51
|
class TwitterProvider: NSObject {
|
|
52
|
+
/// Capacitor bridge view controller, used to present in the scene that started the call.
|
|
53
|
+
weak var hostViewController: UIViewController?
|
|
52
54
|
private var clientId: String?
|
|
53
55
|
private var redirectUri: String?
|
|
54
56
|
private var defaultScopes = ["tweet.read", "users.read"]
|
|
@@ -362,7 +364,7 @@ class TwitterProvider: NSObject {
|
|
|
362
364
|
|
|
363
365
|
extension TwitterProvider: ASWebAuthenticationPresentationContextProviding {
|
|
364
366
|
func presentationAnchor(for session: ASWebAuthenticationSession) -> ASPresentationAnchor {
|
|
365
|
-
return
|
|
367
|
+
return PresentationWindowResolver.window(hostViewController: hostViewController) ?? ASPresentationAnchor()
|
|
366
368
|
}
|
|
367
369
|
}
|
|
368
370
|
|