@capgo/capacitor-social-login 8.7.6 → 8.7.8
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 +112 -57
- package/android/src/main/java/ee/forgr/capacitor/social/login/SocialLoginPlugin.java +1 -1
- package/ios/Sources/SocialLoginPlugin/SocialLoginOpenURLHandler.swift +174 -0
- package/ios/Sources/SocialLoginPlugin/SocialLoginPlugin.swift +28 -1
- package/ios/Tests/SocialLoginPluginTests/SocialLoginOpenURLHandlerTests.swift +89 -0
- package/ios/Tests/SocialLoginPluginTests/SocialLoginPluginTests.swift +0 -10
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -16,6 +16,18 @@ Add Google, Apple, Facebook and other social sign-ins to your Capacitor app with
|
|
|
16
16
|
<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" />
|
|
17
17
|
</p>
|
|
18
18
|
|
|
19
|
+
## Built and maintained with AI
|
|
20
|
+
|
|
21
|
+
We build, improve and fix our plugins with heavy use of AI, so issues usually get fixed in under a day and pull requests get feedback the same day. A human still reviews and merges 50+ pull requests daily.
|
|
22
|
+
|
|
23
|
+
- Most plugin issues get a fix pull request the same day, often within a couple of hours, and are usually resolved in one to two days.
|
|
24
|
+
- Every pull request goes through our AI review system, usually within minutes.
|
|
25
|
+
- Our AI pre-checks tests, code review, conventions and security, then a human validates and merges.
|
|
26
|
+
- A human, Martin, reviews and merges 50+ pull requests every day.
|
|
27
|
+
- In the last 90 days, 95% of plugin issues were resolved.
|
|
28
|
+
|
|
29
|
+
[Learn more about how we build with AI](https://capgo.app/docs/plugins/ai-engineering/)
|
|
30
|
+
|
|
19
31
|
## Key features
|
|
20
32
|
|
|
21
33
|
- **Many providers**: Google, Apple, Facebook, Twitter (X), LinkedIn, TikTok, Telegram and generic OAuth2.
|
|
@@ -311,49 +323,13 @@ const res = await SocialLogin.login({
|
|
|
311
323
|
|
|
312
324
|
### iOS configuration
|
|
313
325
|
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
```swift
|
|
317
|
-
import UIKit
|
|
318
|
-
import Capacitor
|
|
319
|
-
import FBSDKCoreKit
|
|
320
|
-
|
|
321
|
-
@UIApplicationMain
|
|
322
|
-
class AppDelegate: UIResponder, UIApplicationDelegate {
|
|
323
|
-
|
|
324
|
-
var window: UIWindow?
|
|
325
|
-
|
|
326
|
-
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
|
|
327
|
-
// Override point for customization after application launch.
|
|
328
|
-
FBSDKCoreKit.ApplicationDelegate.shared.application(
|
|
329
|
-
application,
|
|
330
|
-
didFinishLaunchingWithOptions: launchOptions
|
|
331
|
-
)
|
|
332
|
-
|
|
333
|
-
return true
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
...
|
|
326
|
+
#### Info.plist (all Capacitor versions)
|
|
337
327
|
|
|
338
|
-
|
|
339
|
-
// Called when the app was launched with a url. Feel free to add additional processing here,
|
|
340
|
-
// but if you want the App API to support tracking app url opens, make sure to keep this call
|
|
341
|
-
if (FBSDKCoreKit.ApplicationDelegate.shared.application(
|
|
342
|
-
app,
|
|
343
|
-
open: url,
|
|
344
|
-
sourceApplication: options[UIApplication.OpenURLOptionsKey.sourceApplication] as? String,
|
|
345
|
-
annotation: options[UIApplication.OpenURLOptionsKey.annotation]
|
|
346
|
-
)) {
|
|
347
|
-
return true;
|
|
348
|
-
} else {
|
|
349
|
-
return ApplicationDelegateProxy.shared.application(app, open: url, options: options)
|
|
350
|
-
}
|
|
351
|
-
}
|
|
352
|
-
}
|
|
328
|
+
Every app, with or without UIScene, needs these settings. Add the following in the `ios/App/App/Info.plist` file inside the outermost `<dict>`.
|
|
353
329
|
|
|
354
|
-
|
|
330
|
+
If `Info.plist` already has a `CFBundleURLTypes` key (for example from the Google setup), do not add a second one. Append only the Facebook `<dict>` (the one with `fb[APP_ID]`) to the existing `CFBundleURLTypes` array and keep every existing URL type, otherwise another provider's callback scheme can stop working.
|
|
355
331
|
|
|
356
|
-
|
|
332
|
+
The same applies to `LSApplicationQueriesSchemes`: if it already exists, do not add a second key. Append the Facebook `<string>` entries to the existing array and keep every existing scheme, otherwise `canOpenURL` checks for other integrations can stop working.
|
|
357
333
|
|
|
358
334
|
```xml
|
|
359
335
|
|
|
@@ -384,6 +360,78 @@ Add the following in the `ios/App/App/info.plist` file inside of the outermost `
|
|
|
384
360
|
|
|
385
361
|
More information can be found here: https://developers.facebook.com/docs/facebook-login/ios
|
|
386
362
|
|
|
363
|
+
#### Capacitor 8.5+ (UIScene)
|
|
364
|
+
|
|
365
|
+
If your app uses `UIApplicationSceneManifest` (Capacitor 8.5+ / `npx cap migrate`), URL opens go to `SceneDelegate.swift`. Keep Facebook SDK startup in `AppDelegate.application(_:didFinishLaunchingWithOptions:)`, and forward all URL contexts to `SceneDelegateProxy` in `scene(_:openURLContexts:)`. Do not also call the Facebook SDK URL handler in SceneDelegate, or the URL reaches the SDK twice.
|
|
366
|
+
|
|
367
|
+
`AppDelegate.swift` (required for UIScene apps too; Facebook SDK still initializes at launch):
|
|
368
|
+
|
|
369
|
+
```swift
|
|
370
|
+
import UIKit
|
|
371
|
+
import Capacitor
|
|
372
|
+
import FBSDKCoreKit
|
|
373
|
+
|
|
374
|
+
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
|
|
375
|
+
FBSDKCoreKit.ApplicationDelegate.shared.application(
|
|
376
|
+
application,
|
|
377
|
+
didFinishLaunchingWithOptions: launchOptions
|
|
378
|
+
)
|
|
379
|
+
return true
|
|
380
|
+
}
|
|
381
|
+
```
|
|
382
|
+
|
|
383
|
+
`SceneDelegate.swift` (URL opens only; no direct Facebook SDK calls):
|
|
384
|
+
|
|
385
|
+
```swift
|
|
386
|
+
import UIKit
|
|
387
|
+
import Capacitor
|
|
388
|
+
|
|
389
|
+
func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {
|
|
390
|
+
// Forward every context. SceneDelegateProxy posts capacitorOpenURL, and this
|
|
391
|
+
// plugin's observer passes the URL to the Facebook SDK exactly once.
|
|
392
|
+
SceneDelegateProxy.shared.scene(scene, openURLContexts: URLContexts)
|
|
393
|
+
}
|
|
394
|
+
```
|
|
395
|
+
|
|
396
|
+
This plugin calls the Facebook SDK URL handler when it receives Capacitor's `capacitorOpenURL` notification (custom schemes) and `capacitorOpenUniversalLink` (HTTPS App Links from `scene(_:continue:)`), so direct Facebook SDK calls in SceneDelegate are not needed. Forwarding every URL context to `SceneDelegateProxy` is still required: without it, `capacitorOpenURL` is never posted and the plugin never sees the callback.
|
|
397
|
+
|
|
398
|
+
#### Before Capacitor 8.5 (AppDelegate URL handler)
|
|
399
|
+
|
|
400
|
+
In file `ios/App/App/AppDelegate.swift` add or replace the following:
|
|
401
|
+
|
|
402
|
+
```swift
|
|
403
|
+
import UIKit
|
|
404
|
+
import Capacitor
|
|
405
|
+
import FBSDKCoreKit
|
|
406
|
+
|
|
407
|
+
@UIApplicationMain
|
|
408
|
+
class AppDelegate: UIResponder, UIApplicationDelegate {
|
|
409
|
+
|
|
410
|
+
var window: UIWindow?
|
|
411
|
+
|
|
412
|
+
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
|
|
413
|
+
// Override point for customization after application launch.
|
|
414
|
+
FBSDKCoreKit.ApplicationDelegate.shared.application(
|
|
415
|
+
application,
|
|
416
|
+
didFinishLaunchingWithOptions: launchOptions
|
|
417
|
+
)
|
|
418
|
+
|
|
419
|
+
return true
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
...
|
|
423
|
+
|
|
424
|
+
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey: Any] = [:]) -> Bool {
|
|
425
|
+
// Forward every URL so Capacitor posts capacitorOpenURL. This plugin's observer calls the Facebook SDK handler.
|
|
426
|
+
return ApplicationDelegateProxy.shared.application(app, open: url, options: options)
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
```
|
|
431
|
+
|
|
432
|
+
|
|
433
|
+
|
|
434
|
+
#### Initialize the Facebook provider
|
|
387
435
|
|
|
388
436
|
Then call the `initialize` method with the `facebook` provider
|
|
389
437
|
|
|
@@ -585,6 +633,12 @@ const res = await SocialLogin.login({
|
|
|
585
633
|
});
|
|
586
634
|
```
|
|
587
635
|
|
|
636
|
+
#### iOS OAuth redirect URLs (Google Sign-In)
|
|
637
|
+
|
|
638
|
+
Google Sign-In completes through a custom URL scheme callback. On **Capacitor 8.5+** with the [UIScene lifecycle](https://capacitorjs.com/docs/updating/8-5), that callback is delivered to `SceneDelegate.scene(_:openURLContexts:)`, not `AppDelegate.application(_:open:options:)`. See [docs/setup_google.md](https://github.com/Cap-go/capacitor-social-login/blob/main/docs/setup_google.md#url-opens-with-capacitor-85-uiscene) for the `SceneDelegate.swift` snippet.
|
|
639
|
+
|
|
640
|
+
**Automatic handling:** This plugin listens for Capacitor's `capacitorOpenURL` notification (posted from both AppDelegate and SceneDelegate paths) and calls `GIDSignIn.sharedInstance.handle(url)` when the Google Sign-In SDK is linked. Direct `GIDSignIn.sharedInstance.handle(url)` calls in `SceneDelegate` or `AppDelegate` are not needed once `SocialLogin.initialize()` runs. Forwarding URL opens to `SceneDelegateProxy` (UIScene) or `ApplicationDelegateProxy` (AppDelegate) is still required, since that is what posts `capacitorOpenURL`.
|
|
641
|
+
|
|
588
642
|
**Offline Mode Behavior:**
|
|
589
643
|
When using `mode: 'offline'`, the login response will only contain:
|
|
590
644
|
```typescript
|
|
@@ -2015,30 +2069,31 @@ Add this file in your app at: `ios/App/PrivacyInfo.xcprivacy`
|
|
|
2015
2069
|
- Adjust the data types to match your app's usage and the SDK documentation.
|
|
2016
2070
|
- See [Apple docs](https://developer.apple.com/documentation/bundleresources/privacy_manifest_files/) for all allowed keys and values.
|
|
2017
2071
|
|
|
2018
|
-
## Combine facebook and google URL handler
|
|
2072
|
+
## Combine facebook and google URL handler
|
|
2073
|
+
|
|
2074
|
+
Use **AppDelegate** handlers only when your app does **not** use the Capacitor 8.5 UIScene manifest. With UIScene, forward all contexts from `SceneDelegate.scene(_:openURLContexts:)` to `SceneDelegateProxy.shared.scene(scene, openURLContexts:)` and let the plugin observer call the SDK handlers (see [Google iOS setup](./docs/setup_google.md#url-opens-with-capacitor-85-uiscene) and the Facebook iOS section above).
|
|
2075
|
+
|
|
2076
|
+
This plugin listens for Capacitor's `capacitorOpenURL` notification and calls the Facebook and Google URL handlers for you when those SDKs are linked. It also listens for `capacitorOpenUniversalLink` and routes matching Facebook App Links into the Facebook SDK (Google still uses the open URL path). Custom native URL code is optional.
|
|
2077
|
+
|
|
2078
|
+
### AppDelegate.swift (pre-8.5 / no scene manifest)
|
|
2019
2079
|
|
|
2020
2080
|
```swift
|
|
2021
2081
|
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey: Any] = [:]) -> Bool {
|
|
2022
|
-
//
|
|
2023
|
-
// but if you want the App API to support tracking app url opens, make sure to keep this call
|
|
2024
|
-
|
|
2025
|
-
// Return true if the URL was handled by either Facebook or Google authentication
|
|
2026
|
-
// https://github.com/Cap-go/capacitor-social-login/blob/main/docs/setup_facebook.md#ios-setup
|
|
2027
|
-
// https://github.com/Cap-go/capacitor-social-login/blob/main/docs/setup_google.md#using-google-login-on-ios
|
|
2028
|
-
if FBSDKCoreKit.ApplicationDelegate.shared.application(
|
|
2029
|
-
app,
|
|
2030
|
-
open: url,
|
|
2031
|
-
sourceApplication: options[UIApplication.OpenURLOptionsKey.sourceApplication] as? String,
|
|
2032
|
-
annotation: options[UIApplication.OpenURLOptionsKey.annotation]
|
|
2033
|
-
) || GIDSignIn.sharedInstance.handle(url) {
|
|
2034
|
-
return true
|
|
2035
|
-
}
|
|
2036
|
-
|
|
2037
|
-
// If URL wasn't handled by auth services, pass it to Capacitor for processing
|
|
2082
|
+
// Forward every URL so Capacitor posts capacitorOpenURL. This plugin's observer calls the Facebook and Google handlers.
|
|
2038
2083
|
return ApplicationDelegateProxy.shared.application(app, open: url, options: options)
|
|
2039
2084
|
}
|
|
2040
2085
|
```
|
|
2041
2086
|
|
|
2087
|
+
### SceneDelegate.swift (Capacitor 8.5+)
|
|
2088
|
+
|
|
2089
|
+
```swift
|
|
2090
|
+
func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {
|
|
2091
|
+
// Forward every context. The plugin observer calls the Facebook and Google
|
|
2092
|
+
// URL handlers once per URL, so do not call them here as well.
|
|
2093
|
+
SceneDelegateProxy.shared.scene(scene, openURLContexts: URLContexts)
|
|
2094
|
+
}
|
|
2095
|
+
```
|
|
2096
|
+
|
|
2042
2097
|
### Credits
|
|
2043
2098
|
|
|
2044
2099
|
This plugin implementation of google is based on [CapacitorGoogleAuth](https://github.com/CodetrixStudio/CapacitorGoogleAuth) with a lot of rework, the current maintainer is unreachable, we are thankful for his work and are now going forward on our own!
|
|
@@ -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.
|
|
32
|
+
private final String pluginVersion = "8.7.8";
|
|
33
33
|
|
|
34
34
|
public static String LOG_TAG = "CapgoSocialLogin";
|
|
35
35
|
private static final String USER_CANCELLED_CODE = "USER_CANCELLED";
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
import UIKit
|
|
3
|
+
import Capacitor
|
|
4
|
+
|
|
5
|
+
#if canImport(FBSDKCoreKit)
|
|
6
|
+
import FBSDKCoreKit
|
|
7
|
+
#endif
|
|
8
|
+
|
|
9
|
+
#if canImport(GoogleSignIn)
|
|
10
|
+
import GoogleSignIn
|
|
11
|
+
#endif
|
|
12
|
+
|
|
13
|
+
enum SocialLoginOpenURLHandler {
|
|
14
|
+
/// True after `SocialLogin.initialize()` includes Facebook settings.
|
|
15
|
+
static var isFacebookIntegrationConfigured = false
|
|
16
|
+
|
|
17
|
+
/// Facebook custom schemes are `fb{app-id}`; also accept https hosts Facebook uses for redirects.
|
|
18
|
+
/// Kept outside FBSDK `canImport` so unit tests compile when Facebook deps are disabled.
|
|
19
|
+
static func isLikelyFacebookOpenURL(_ url: URL) -> Bool {
|
|
20
|
+
if let scheme = url.scheme?.lowercased(), scheme.hasPrefix("fb") {
|
|
21
|
+
return true
|
|
22
|
+
}
|
|
23
|
+
let host = (url.host ?? "").lowercased()
|
|
24
|
+
return host == "facebook.com"
|
|
25
|
+
|| host.hasSuffix(".facebook.com")
|
|
26
|
+
|| host == "fb.com"
|
|
27
|
+
|| host.hasSuffix(".fb.com")
|
|
28
|
+
|| host == "fb.me"
|
|
29
|
+
|| host.hasSuffix(".fb.me")
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/// URLs safe to pass to Facebook SDK `ApplicationDelegate`.
|
|
33
|
+
/// Only Facebook OAuth schemes (`fb…`) and Facebook HTTPS hosts are trusted.
|
|
34
|
+
/// Do not treat `al_applink_data` alone as proof of trust: any sender can add that marker
|
|
35
|
+
/// (for example `myapp://callback?code=secret&al_applink_data=%7B%7D`), and the SDK may log
|
|
36
|
+
/// the full URL. Custom-domain App Links need an explicit host allowlist before they can be
|
|
37
|
+
/// forwarded; until then they are rejected here.
|
|
38
|
+
static func shouldDeliverURLToFacebookSDK(_ url: URL) -> Bool {
|
|
39
|
+
return isLikelyFacebookOpenURL(url)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
#if canImport(FBSDKCoreKit)
|
|
43
|
+
private static var pendingFacebookOpenURLs: [(url: URL, options: [UIApplication.OpenURLOptionsKey: Any])] = []
|
|
44
|
+
private static var pendingFacebookUniversalLinkURLs: [URL] = []
|
|
45
|
+
|
|
46
|
+
private static func deliverFacebookOpenURL(_ url: URL, options: [UIApplication.OpenURLOptionsKey: Any]) {
|
|
47
|
+
_ = ApplicationDelegate.shared.application(
|
|
48
|
+
UIApplication.shared,
|
|
49
|
+
open: url,
|
|
50
|
+
sourceApplication: options[.sourceApplication] as? String,
|
|
51
|
+
annotation: options[.annotation]
|
|
52
|
+
)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/// Facebook SDK `application(_:continue:)` expects an `NSUserActivity` with type browsing web.
|
|
56
|
+
private static func deliverFacebookUniversalLinkURL(_ url: URL) {
|
|
57
|
+
let activity = NSUserActivity(activityType: NSUserActivityTypeBrowsingWeb)
|
|
58
|
+
activity.webpageURL = url
|
|
59
|
+
_ = ApplicationDelegate.shared.application(UIApplication.shared, continue: activity)
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/// Delivers Facebook OAuth URLs that arrived before `initialize()` completed.
|
|
63
|
+
static func flushPendingFacebookOpenURLIfNeeded() {
|
|
64
|
+
assert(Thread.isMainThread)
|
|
65
|
+
guard isFacebookIntegrationConfigured, !pendingFacebookOpenURLs.isEmpty else {
|
|
66
|
+
return
|
|
67
|
+
}
|
|
68
|
+
let pending = pendingFacebookOpenURLs
|
|
69
|
+
pendingFacebookOpenURLs.removeAll()
|
|
70
|
+
for item in pending {
|
|
71
|
+
deliverFacebookOpenURL(item.url, options: item.options)
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
private static func flushPendingFacebookUniversalLinkURLsIfNeeded() {
|
|
76
|
+
assert(Thread.isMainThread)
|
|
77
|
+
guard isFacebookIntegrationConfigured, !pendingFacebookUniversalLinkURLs.isEmpty else {
|
|
78
|
+
return
|
|
79
|
+
}
|
|
80
|
+
let pending = pendingFacebookUniversalLinkURLs
|
|
81
|
+
pendingFacebookUniversalLinkURLs.removeAll()
|
|
82
|
+
for url in pending {
|
|
83
|
+
deliverFacebookUniversalLinkURL(url)
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/// Call after Facebook `initialize()` from the plugin. Runs on the main queue.
|
|
88
|
+
static func markFacebookIntegrationConfiguredAndFlushPending() {
|
|
89
|
+
let apply = {
|
|
90
|
+
isFacebookIntegrationConfigured = true
|
|
91
|
+
flushPendingFacebookOpenURLIfNeeded()
|
|
92
|
+
flushPendingFacebookUniversalLinkURLsIfNeeded()
|
|
93
|
+
}
|
|
94
|
+
if Thread.isMainThread {
|
|
95
|
+
apply()
|
|
96
|
+
} else {
|
|
97
|
+
DispatchQueue.main.sync(execute: apply)
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
#endif
|
|
101
|
+
|
|
102
|
+
static func parseOpenURLNotification(_ notification: Notification) -> (url: URL, options: [UIApplication.OpenURLOptionsKey: Any])? {
|
|
103
|
+
guard let data = notification.object as? [String: Any],
|
|
104
|
+
let url = data["url"] as? URL else {
|
|
105
|
+
return nil
|
|
106
|
+
}
|
|
107
|
+
let options = data["options"] as? [UIApplication.OpenURLOptionsKey: Any] ?? [:]
|
|
108
|
+
return (url, options)
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/// Capacitor posts universal links with `["url": webpageURL]` (see `SceneDelegateProxy`).
|
|
112
|
+
static func parseUniversalLinkNotification(_ notification: Notification) -> URL? {
|
|
113
|
+
guard let data = notification.object as? [String: Any],
|
|
114
|
+
let url = data["url"] as? URL else {
|
|
115
|
+
return nil
|
|
116
|
+
}
|
|
117
|
+
return url
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
static func handleOpenURL(_ url: URL, options: [UIApplication.OpenURLOptionsKey: Any] = [:]) {
|
|
121
|
+
assert(Thread.isMainThread)
|
|
122
|
+
#if canImport(FBSDKCoreKit)
|
|
123
|
+
if shouldDeliverURLToFacebookSDK(url) {
|
|
124
|
+
if isFacebookIntegrationConfigured {
|
|
125
|
+
deliverFacebookOpenURL(url, options: options)
|
|
126
|
+
} else {
|
|
127
|
+
pendingFacebookOpenURLs.append((url, options))
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
#endif
|
|
131
|
+
|
|
132
|
+
#if canImport(GoogleSignIn)
|
|
133
|
+
_ = GIDSignIn.sharedInstance.handle(url)
|
|
134
|
+
#endif
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/// Universal links (`capacitorOpenUniversalLink`): Facebook App Links only. Google stays on `capacitorOpenURL`.
|
|
138
|
+
static func handleCapacitorOpenUniversalLinkNotification(_ notification: Notification) {
|
|
139
|
+
let work = {
|
|
140
|
+
guard let url = parseUniversalLinkNotification(notification) else {
|
|
141
|
+
return
|
|
142
|
+
}
|
|
143
|
+
#if canImport(FBSDKCoreKit)
|
|
144
|
+
guard shouldDeliverURLToFacebookSDK(url) else {
|
|
145
|
+
return
|
|
146
|
+
}
|
|
147
|
+
if isFacebookIntegrationConfigured {
|
|
148
|
+
deliverFacebookUniversalLinkURL(url)
|
|
149
|
+
} else {
|
|
150
|
+
pendingFacebookUniversalLinkURLs.append(url)
|
|
151
|
+
}
|
|
152
|
+
#endif
|
|
153
|
+
}
|
|
154
|
+
if Thread.isMainThread {
|
|
155
|
+
work()
|
|
156
|
+
} else {
|
|
157
|
+
DispatchQueue.main.async(execute: work)
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
static func handleCapacitorOpenURLNotification(_ notification: Notification) {
|
|
162
|
+
let work = {
|
|
163
|
+
guard let parsed = parseOpenURLNotification(notification) else {
|
|
164
|
+
return
|
|
165
|
+
}
|
|
166
|
+
handleOpenURL(parsed.url, options: parsed.options)
|
|
167
|
+
}
|
|
168
|
+
if Thread.isMainThread {
|
|
169
|
+
work()
|
|
170
|
+
} else {
|
|
171
|
+
DispatchQueue.main.async(execute: work)
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
@@ -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.
|
|
19
|
+
private let pluginVersion: String = "8.7.8"
|
|
20
20
|
public let identifier = "SocialLoginPlugin"
|
|
21
21
|
public let jsName = "SocialLogin"
|
|
22
22
|
private static let userCancelledCode = "USER_CANCELLED"
|
|
@@ -140,6 +140,30 @@ public class SocialLoginPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
140
140
|
}
|
|
141
141
|
}
|
|
142
142
|
|
|
143
|
+
private static var capacitorOpenURLObserver: NSObjectProtocol?
|
|
144
|
+
private static var capacitorOpenUniversalLinkObserver: NSObjectProtocol?
|
|
145
|
+
|
|
146
|
+
public override func load() {
|
|
147
|
+
if SocialLoginPlugin.capacitorOpenURLObserver == nil {
|
|
148
|
+
SocialLoginPlugin.capacitorOpenURLObserver = NotificationCenter.default.addObserver(
|
|
149
|
+
forName: .capacitorOpenURL,
|
|
150
|
+
object: nil,
|
|
151
|
+
queue: .main
|
|
152
|
+
) { notification in
|
|
153
|
+
SocialLoginOpenURLHandler.handleCapacitorOpenURLNotification(notification)
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
if SocialLoginPlugin.capacitorOpenUniversalLinkObserver == nil {
|
|
157
|
+
SocialLoginPlugin.capacitorOpenUniversalLinkObserver = NotificationCenter.default.addObserver(
|
|
158
|
+
forName: .capacitorOpenUniversalLink,
|
|
159
|
+
object: nil,
|
|
160
|
+
queue: .main
|
|
161
|
+
) { notification in
|
|
162
|
+
SocialLoginOpenURLHandler.handleCapacitorOpenUniversalLinkNotification(notification)
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
143
167
|
@objc func getPluginVersion(_ call: CAPPluginCall) {
|
|
144
168
|
call.resolve(["version": self.pluginVersion])
|
|
145
169
|
}
|
|
@@ -155,6 +179,9 @@ public class SocialLoginPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
155
179
|
return
|
|
156
180
|
}
|
|
157
181
|
fbProvider.initialize()
|
|
182
|
+
#if canImport(FBSDKCoreKit)
|
|
183
|
+
SocialLoginOpenURLHandler.markFacebookIntegrationConfiguredAndFlushPending()
|
|
184
|
+
#endif
|
|
158
185
|
initialized = true
|
|
159
186
|
}
|
|
160
187
|
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import XCTest
|
|
2
|
+
import UIKit
|
|
3
|
+
@testable import SocialLoginPlugin
|
|
4
|
+
|
|
5
|
+
class SocialLoginOpenURLHandlerTests: XCTestCase {
|
|
6
|
+
func testParseOpenURLNotificationReturnsURLAndOptions() {
|
|
7
|
+
let url = URL(string: "com.googleusercontent.apps.test:/oauth2callback")!
|
|
8
|
+
let options: [UIApplication.OpenURLOptionsKey: Any] = [.sourceApplication: "com.apple Safari"]
|
|
9
|
+
let notification = Notification(
|
|
10
|
+
name: .capacitorOpenURL,
|
|
11
|
+
object: [
|
|
12
|
+
"url": url,
|
|
13
|
+
"options": options
|
|
14
|
+
]
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
let parsed = SocialLoginOpenURLHandler.parseOpenURLNotification(notification)
|
|
18
|
+
|
|
19
|
+
XCTAssertEqual(parsed?.url, url)
|
|
20
|
+
XCTAssertEqual(parsed?.options[.sourceApplication] as? String, "com.apple Safari")
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
func testParseOpenURLNotificationReturnsNilWhenPayloadMissingURL() {
|
|
24
|
+
let notification = Notification(name: .capacitorOpenURL, object: ["options": [:]] as [String: Any])
|
|
25
|
+
|
|
26
|
+
XCTAssertNil(SocialLoginOpenURLHandler.parseOpenURLNotification(notification))
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
func testParseUniversalLinkNotificationReturnsURL() {
|
|
30
|
+
let url = URL(string: "https://www.facebook.com/connect/login_success.html")!
|
|
31
|
+
let notification = Notification(name: .capacitorOpenUniversalLink, object: ["url": url])
|
|
32
|
+
|
|
33
|
+
XCTAssertEqual(SocialLoginOpenURLHandler.parseUniversalLinkNotification(notification), url)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
func testParseUniversalLinkNotificationReturnsNilWhenPayloadMissingURL() {
|
|
37
|
+
let notification = Notification(name: .capacitorOpenUniversalLink, object: [:] as [String: Any])
|
|
38
|
+
|
|
39
|
+
XCTAssertNil(SocialLoginOpenURLHandler.parseUniversalLinkNotification(notification))
|
|
40
|
+
}
|
|
41
|
+
func testIsLikelyFacebookOpenURLAcceptsFacebookSchemesAndHosts() {
|
|
42
|
+
XCTAssertTrue(SocialLoginOpenURLHandler.isLikelyFacebookOpenURL(URL(string: "fb123456789://authorize")!))
|
|
43
|
+
XCTAssertTrue(SocialLoginOpenURLHandler.isLikelyFacebookOpenURL(URL(string: "https://www.facebook.com/connect/login_success.html")!))
|
|
44
|
+
XCTAssertTrue(SocialLoginOpenURLHandler.isLikelyFacebookOpenURL(URL(string: "https://fb.me/abc")!))
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
func testIsLikelyFacebookOpenURLRejectsUnrelatedURLs() {
|
|
48
|
+
XCTAssertFalse(SocialLoginOpenURLHandler.isLikelyFacebookOpenURL(URL(string: "com.googleusercontent.apps.test:/oauth2callback")!))
|
|
49
|
+
XCTAssertFalse(SocialLoginOpenURLHandler.isLikelyFacebookOpenURL(URL(string: "https://example.com/oauth")!))
|
|
50
|
+
XCTAssertFalse(SocialLoginOpenURLHandler.isLikelyFacebookOpenURL(URL(string: "myapp://callback")!))
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
func testShouldDeliverURLToFacebookSDKAcceptsFacebookSchemesAndHosts() {
|
|
54
|
+
XCTAssertTrue(SocialLoginOpenURLHandler.shouldDeliverURLToFacebookSDK(URL(string: "fb123456789://authorize")!))
|
|
55
|
+
XCTAssertTrue(
|
|
56
|
+
SocialLoginOpenURLHandler.shouldDeliverURLToFacebookSDK(
|
|
57
|
+
URL(string: "https://www.facebook.com/connect/login_success.html")!
|
|
58
|
+
)
|
|
59
|
+
)
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
func testShouldDeliverURLToFacebookSDKRejectsUnrelatedOAuthURLs() {
|
|
63
|
+
XCTAssertFalse(
|
|
64
|
+
SocialLoginOpenURLHandler.shouldDeliverURLToFacebookSDK(
|
|
65
|
+
URL(string: "com.googleusercontent.apps.test:/oauth2callback?code=secret")!
|
|
66
|
+
)
|
|
67
|
+
)
|
|
68
|
+
XCTAssertFalse(SocialLoginOpenURLHandler.shouldDeliverURLToFacebookSDK(URL(string: "https://example.com/oauth?code=secret")!))
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
func testShouldDeliverURLToFacebookSDKRejectsAppLinkMarkerOnUntrustedURL() {
|
|
72
|
+
// Regression: al_applink_data must not unlock delivery for unrelated schemes/hosts.
|
|
73
|
+
XCTAssertFalse(
|
|
74
|
+
SocialLoginOpenURLHandler.shouldDeliverURLToFacebookSDK(
|
|
75
|
+
URL(string: "myapp://callback?code=secret&al_applink_data=%7B%7D")!
|
|
76
|
+
)
|
|
77
|
+
)
|
|
78
|
+
XCTAssertFalse(
|
|
79
|
+
SocialLoginOpenURLHandler.shouldDeliverURLToFacebookSDK(
|
|
80
|
+
URL(string: "https://example.com/deeplink?al_applink_data=eyJ0ZXN0IjoidHJ1ZSJ9")!
|
|
81
|
+
)
|
|
82
|
+
)
|
|
83
|
+
XCTAssertFalse(
|
|
84
|
+
SocialLoginOpenURLHandler.shouldDeliverURLToFacebookSDK(
|
|
85
|
+
URL(string: "myapp://callback#al_applink_data=%7B%7D")!
|
|
86
|
+
)
|
|
87
|
+
)
|
|
88
|
+
}
|
|
89
|
+
}
|
|
@@ -2,14 +2,4 @@ import XCTest
|
|
|
2
2
|
@testable import SocialLoginPlugin
|
|
3
3
|
|
|
4
4
|
class SocialLoginTests: XCTestCase {
|
|
5
|
-
func testEcho() {
|
|
6
|
-
// This is an example of a functional test case for a plugin.
|
|
7
|
-
// Use XCTAssert and related functions to verify your tests produce the correct results.
|
|
8
|
-
|
|
9
|
-
let implementation = SocialLogin()
|
|
10
|
-
let value = "Hello, World!"
|
|
11
|
-
let result = implementation.echo(value)
|
|
12
|
-
|
|
13
|
-
XCTAssertEqual(value, result)
|
|
14
|
-
}
|
|
15
5
|
}
|