@capgo/capacitor-social-login 8.7.8 → 8.7.9

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.
@@ -29,7 +29,7 @@ import org.json.JSONTokener;
29
29
  @CapacitorPlugin(name = "SocialLogin")
30
30
  public class SocialLoginPlugin extends Plugin {
31
31
 
32
- private final String pluginVersion = "8.7.8";
32
+ private final String pluginVersion = "8.7.9";
33
33
 
34
34
  public static String LOG_TAG = "CapgoSocialLogin";
35
35
  private static final String USER_CANCELLED_CODE = "USER_CANCELLED";
@@ -383,7 +383,59 @@ class OAuth2Provider: NSObject {
383
383
  return
384
384
  }
385
385
 
386
- completion(.failure(NSError(domain: "OAuth2Provider", code: -8, userInfo: [NSLocalizedDescriptionKey: "No authorization code or access token in callback."])))
386
+ let description = missingAuthorizationCodeDescription(callbackURL: callbackURL, redirectUri: redirectUri)
387
+ completion(.failure(NSError(domain: "OAuth2Provider", code: -8, userInfo: [NSLocalizedDescriptionKey: description])))
388
+ }
389
+
390
+ private func missingAuthorizationCodeDescription(callbackURL: URL, redirectUri: String) -> String {
391
+ let base = "No authorization code or access token in callback."
392
+ guard !callbackMatchesRedirect(callbackURL, redirectUri: redirectUri) else {
393
+ return base
394
+ }
395
+ return "\(base) Received \(callbackOrigin(callbackURL))."
396
+ }
397
+
398
+ private func callbackMatchesRedirect(_ callbackURL: URL, redirectUri: String) -> Bool {
399
+ guard let expected = URL(string: redirectUri),
400
+ let expectedScheme = expected.scheme,
401
+ let actualScheme = callbackURL.scheme else {
402
+ return true
403
+ }
404
+ if expectedScheme.caseInsensitiveCompare(actualScheme) != .orderedSame {
405
+ return false
406
+ }
407
+ let expectedHost = expected.host ?? ""
408
+ let actualHost = callbackURL.host ?? ""
409
+ if expectedHost.caseInsensitiveCompare(actualHost) != .orderedSame {
410
+ return false
411
+ }
412
+ return callbackPath(expected) == callbackPath(callbackURL)
413
+ }
414
+
415
+ private func callbackOrigin(_ url: URL) -> String {
416
+ var origin = ""
417
+ if let scheme = url.scheme {
418
+ origin += "\(scheme):"
419
+ if url.host != nil {
420
+ origin += "//"
421
+ }
422
+ }
423
+ if let host = url.host {
424
+ origin += host
425
+ }
426
+ let path = callbackPath(url)
427
+ if !path.isEmpty {
428
+ if url.host != nil && !path.hasPrefix("/") {
429
+ origin += "/\(path)"
430
+ } else {
431
+ origin += path
432
+ }
433
+ }
434
+ return origin
435
+ }
436
+
437
+ private func callbackPath(_ url: URL) -> String {
438
+ URLComponents(url: url, resolvingAgainstBaseURL: false)?.percentEncodedPath ?? url.path
387
439
  }
388
440
 
389
441
  func logout(providerId: String, completion: @escaping (Result<Void, Error>) -> Void) {
@@ -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.7.8"
19
+ private let pluginVersion: String = "8.7.9"
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.7.8",
3
+ "version": "8.7.9",
4
4
  "description": "All social logins in one plugin",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",