@capgo/capacitor-social-login 8.5.13 → 8.5.15
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 +1 -1
- 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
|
@@ -5,7 +5,7 @@ Add Google, Apple, Facebook and other social sign-ins to your Capacitor app with
|
|
|
5
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>
|
|
6
6
|
|
|
7
7
|
<div align="center">
|
|
8
|
-
<p><b>Capgo</b>:
|
|
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
9
|
<h2><a href="https://capgo.app/register/?ref=plugin_social_login">➡️ Get started for free</a></h2>
|
|
10
10
|
<p>14-day unlimited free trial. No credit card required</p>
|
|
11
11
|
<p><a href="https://capgo.app/consulting/?ref=plugin_social_login">Missing a feature? We'll build the plugin for you 💪</a></p>
|
|
@@ -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.15";
|
|
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.15"
|
|
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
|
|