@capgo/capacitor-social-login 8.5.9 → 8.5.11

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.
@@ -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.9";
27
+ private final String pluginVersion = "8.5.11";
28
28
 
29
29
  public static String LOG_TAG = "CapgoSocialLogin";
30
30
  public HashMap<String, SocialProvider> socialProviderHashMap = new HashMap<>();
@@ -575,22 +575,31 @@ public class SocialLoginPlugin extends Plugin {
575
575
  return;
576
576
  }
577
577
  try {
578
- String[] parts = idToken.split("\\\\.");
579
- if (parts.length < 2) {
580
- call.reject("Invalid JWT");
581
- return;
582
- }
583
- byte[] decoded = Base64.decode(parts[1], Base64.URL_SAFE | Base64.NO_PADDING | Base64.NO_WRAP);
584
- String json = new String(decoded, StandardCharsets.UTF_8);
585
- JSONObject claims = new JSONObject(json);
578
+ JSONObject claims = decodeJwtClaims(idToken);
586
579
  JSObject ret = new JSObject();
587
580
  ret.put("claims", claims);
588
581
  call.resolve(ret);
582
+ } catch (JSONException e) {
583
+ call.reject("Invalid JWT");
589
584
  } catch (Exception e) {
590
585
  call.reject("Failed to decode idToken", e);
591
586
  }
592
587
  }
593
588
 
589
+ static JSONObject decodeJwtClaims(String idToken) throws JSONException {
590
+ byte[] decoded = Base64.decode(getJwtPayloadSegment(idToken), Base64.URL_SAFE | Base64.NO_PADDING | Base64.NO_WRAP);
591
+ String json = new String(decoded, StandardCharsets.UTF_8);
592
+ return new JSONObject(json);
593
+ }
594
+
595
+ static String getJwtPayloadSegment(String idToken) throws JSONException {
596
+ String[] parts = idToken.split("\\.");
597
+ if (parts.length < 2) {
598
+ throw new JSONException("Invalid JWT");
599
+ }
600
+ return parts[1];
601
+ }
602
+
594
603
  // Capacitor's PluginCall.getLong() only reads Java Long values. JS numbers that
595
604
  // fit in 32 bits cross the bridge as Integer, so Number coercion is required.
596
605
  static Long longOptionFromCall(PluginCall call, String key) {
@@ -201,23 +201,30 @@ class AppleProvider: NSObject, ASAuthorizationControllerDelegate, ASAuthorizatio
201
201
  func login(payload: [String: Any], completion: @escaping (Result<AppleProviderResponse, Error>) -> Void) {
202
202
  self.completion = completion
203
203
 
204
- let appleIDProvider = ASAuthorizationAppleIDProvider()
205
- let request = appleIDProvider.createRequest()
204
+ DispatchQueue.main.async { [weak self] in
205
+ guard let self = self else {
206
+ completion(.failure(NSError(domain: "AppleProvider", code: -1, userInfo: [NSLocalizedDescriptionKey: "AppleProvider was deallocated before login could run."])))
207
+ return
208
+ }
206
209
 
207
- if let scopes = payload["scopes"] as? [ASAuthorization.Scope] {
208
- request.requestedScopes = scopes
209
- } else {
210
- request.requestedScopes = [.fullName, .email]
211
- }
210
+ let appleIDProvider = ASAuthorizationAppleIDProvider()
211
+ let request = appleIDProvider.createRequest()
212
212
 
213
- if let nonce = payload["nonce"] as? String {
214
- request.nonce = nonce
215
- }
213
+ if let scopes = payload["scopes"] as? [ASAuthorization.Scope] {
214
+ request.requestedScopes = scopes
215
+ } else {
216
+ request.requestedScopes = [.fullName, .email]
217
+ }
216
218
 
217
- let authorizationController = ASAuthorizationController(authorizationRequests: [request])
218
- authorizationController.delegate = self
219
- authorizationController.presentationContextProvider = self
220
- authorizationController.performRequests()
219
+ if let nonce = payload["nonce"] as? String {
220
+ request.nonce = nonce
221
+ }
222
+
223
+ let authorizationController = ASAuthorizationController(authorizationRequests: [request])
224
+ authorizationController.delegate = self
225
+ authorizationController.presentationContextProvider = self
226
+ authorizationController.performRequests()
227
+ }
221
228
  }
222
229
 
223
230
  func logout(completion: @escaping (Result<Void, Error>) -> Void) {
@@ -608,7 +615,11 @@ class AppleProvider: NSObject, ASAuthorizationControllerDelegate, ASAuthorizatio
608
615
  // MARK: - ASAuthorizationControllerPresentationContextProviding
609
616
 
610
617
  func presentationAnchor(for controller: ASAuthorizationController) -> ASPresentationAnchor {
611
- return UIApplication.shared.windows.first!
618
+ let windows = UIApplication.shared.connectedScenes
619
+ .compactMap { $0 as? UIWindowScene }
620
+ .filter { $0.activationState == .foregroundActive || $0.activationState == .foregroundInactive }
621
+ .flatMap { $0.windows }
622
+ return windows.first { $0.isKeyWindow } ?? windows.first ?? UIApplication.shared.windows.first ?? ASPresentationAnchor()
612
623
  }
613
624
 
614
625
  private func persistName(userId: String, givenName: String?, familyName: String?) {
@@ -99,10 +99,12 @@ class FacebookProvider {
99
99
  }
100
100
 
101
101
  private func isLimitedLoginSession() -> Bool {
102
- guard let authToken = AuthenticationToken.current else {
103
- return false
104
- }
105
- return !authToken.tokenString.isEmpty
102
+ // A classic (.enabled) login also yields an AuthenticationToken: FBSDK always inserts
103
+ // `openid` into the requested permissions and asks for an id_token in response_type,
104
+ // so the presence of that token says nothing about the tracking mode.
105
+ // Only the absence of a Graph access token identifies a Limited Login session -
106
+ // including when Facebook forces limited because ATT was not granted.
107
+ return AccessToken.current == nil
106
108
  }
107
109
 
108
110
  private func createLoginResponse() -> FacebookLoginResponse {
@@ -218,10 +220,13 @@ class FacebookProvider {
218
220
  }
219
221
 
220
222
  func getAuthorizationCode(completion: @escaping (Result<(accessToken: String?, jwt: String?), Error>) -> Void) {
221
- if let authToken = AuthenticationToken.current, !authToken.tokenString.isEmpty {
222
- completion(.success((accessToken: nil, jwt: authToken.tokenString)))
223
- } else if let accessToken = AccessToken.current, !accessToken.isExpired {
223
+ // Prefer the Graph access token: a classic login populates both tokens, and callers
224
+ // asking for an authorization code need the Graph one. Falling through to the OIDC
225
+ // token first hands out a JWT that cannot read pages or mint page tokens.
226
+ if let accessToken = AccessToken.current, !accessToken.isExpired {
224
227
  completion(.success((accessToken: accessToken.tokenString, jwt: nil)))
228
+ } else if let authToken = AuthenticationToken.current, !authToken.tokenString.isEmpty {
229
+ completion(.success((accessToken: nil, jwt: authToken.tokenString)))
225
230
  } else {
226
231
  completion(.failure(NSError(domain: "FacebookProvider", code: 0, userInfo: [NSLocalizedDescriptionKey: "No Facebook authorization code available"])))
227
232
  }
@@ -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.9"
19
+ private let pluginVersion: String = "8.5.11"
20
20
  public let identifier = "SocialLoginPlugin"
21
21
  public let jsName = "SocialLogin"
22
22
  private static let userCancelledCode = "USER_CANCELLED"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capgo/capacitor-social-login",
3
- "version": "8.5.9",
3
+ "version": "8.5.11",
4
4
  "description": "All social logins in one plugin",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",