@capgo/capacitor-social-login 8.5.18 → 8.6.0
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 +105 -0
- package/android/src/main/java/ee/forgr/capacitor/social/login/OAuth2Provider.java +36 -14
- package/android/src/main/java/ee/forgr/capacitor/social/login/SocialLoginPlugin.java +231 -4
- package/dist/docs.json +92 -0
- package/dist/esm/definitions.d.ts +45 -0
- package/dist/esm/definitions.js.map +1 -1
- package/dist/esm/social-login.d.ts +2 -1
- package/dist/esm/social-login.js +3 -0
- package/dist/esm/social-login.js.map +1 -1
- package/dist/esm/web-auth-popup-close.d.ts +9 -0
- package/dist/esm/web-auth-popup-close.js +15 -0
- package/dist/esm/web-auth-popup-close.js.map +1 -0
- package/dist/esm/web.d.ts +4 -1
- package/dist/esm/web.js +139 -25
- package/dist/esm/web.js.map +1 -1
- package/dist/plugin.cjs.js +155 -24
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +155 -24
- package/dist/plugin.js.map +1 -1
- package/ios/Sources/SocialLoginPlugin/OAuth2Provider.swift +1 -1
- package/ios/Sources/SocialLoginPlugin/PresentationWindowResolver.swift +1 -1
- package/ios/Sources/SocialLoginPlugin/SocialLoginPlugin.swift +88 -18
- package/package.json +3 -3
|
@@ -390,7 +390,7 @@ class OAuth2Provider: NSObject {
|
|
|
390
390
|
let storedIdToken = loadTokens(for: providerId)?.idToken
|
|
391
391
|
UserDefaults.standard.removeObject(forKey: tokenStorageKey(for: providerId))
|
|
392
392
|
ensureDiscovered(providerId: providerId) { [weak self] res in
|
|
393
|
-
guard
|
|
393
|
+
guard self != nil else {
|
|
394
394
|
completion(.success(()))
|
|
395
395
|
return
|
|
396
396
|
}
|
|
@@ -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.
|
|
19
|
+
private let pluginVersion: String = "8.6.0"
|
|
20
20
|
public let identifier = "SocialLoginPlugin"
|
|
21
21
|
public let jsName = "SocialLogin"
|
|
22
22
|
private static let userCancelledCode = "USER_CANCELLED"
|
|
@@ -40,7 +40,8 @@ public class SocialLoginPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
40
40
|
CAPPluginMethod(name: "isRefreshTokenAvailable", returnType: CAPPluginReturnPromise),
|
|
41
41
|
CAPPluginMethod(name: "providerSpecificCall", returnType: CAPPluginReturnPromise),
|
|
42
42
|
CAPPluginMethod(name: "getPluginVersion", returnType: CAPPluginReturnPromise),
|
|
43
|
-
CAPPluginMethod(name: "openSecureWindow", returnType: CAPPluginReturnPromise)
|
|
43
|
+
CAPPluginMethod(name: "openSecureWindow", returnType: CAPPluginReturnPromise),
|
|
44
|
+
CAPPluginMethod(name: "openAuthSession", returnType: CAPPluginReturnPromise)
|
|
44
45
|
]
|
|
45
46
|
|
|
46
47
|
// Providers - conditionally initialized based on available dependencies
|
|
@@ -62,7 +63,9 @@ public class SocialLoginPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
62
63
|
private let twitter = TwitterProvider()
|
|
63
64
|
private let oauth2 = OAuth2Provider()
|
|
64
65
|
private let telegram = TelegramProvider()
|
|
65
|
-
private var
|
|
66
|
+
private var webAuthSessionCall: CAPPluginCall?
|
|
67
|
+
private var webAuthSessionRedirectPrefix: String?
|
|
68
|
+
private var webAuthSessionResultKey: String = "callbackURL"
|
|
66
69
|
|
|
67
70
|
// Helper to get Facebook provider (returns nil if unavailable)
|
|
68
71
|
private var facebookProvider: FacebookProvider? {
|
|
@@ -777,43 +780,110 @@ public class SocialLoginPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
777
780
|
return
|
|
778
781
|
}
|
|
779
782
|
|
|
780
|
-
|
|
781
|
-
|
|
783
|
+
guard let callbackScheme = URL(string: redirectUri)?.scheme, !callbackScheme.isEmpty else {
|
|
784
|
+
call.reject("redirectUri must include a URL scheme")
|
|
785
|
+
return
|
|
786
|
+
}
|
|
787
|
+
|
|
788
|
+
startWebAuthSession(
|
|
789
|
+
call: call,
|
|
790
|
+
url: url,
|
|
791
|
+
callbackURLScheme: callbackScheme,
|
|
792
|
+
redirectPrefix: redirectUri,
|
|
793
|
+
prefersEphemeral: false,
|
|
794
|
+
resultKey: "redirectedUri"
|
|
795
|
+
)
|
|
796
|
+
}
|
|
797
|
+
|
|
798
|
+
@objc func openAuthSession(_ call: CAPPluginCall) {
|
|
799
|
+
guard let urlString = call.getString("url") else {
|
|
800
|
+
call.reject("url is required")
|
|
801
|
+
return
|
|
802
|
+
}
|
|
803
|
+
|
|
804
|
+
guard let url = URL(string: urlString) else {
|
|
805
|
+
call.reject("Invalid URL")
|
|
806
|
+
return
|
|
807
|
+
}
|
|
808
|
+
|
|
809
|
+
guard let callbackURLScheme = call.getString("callbackURLScheme"), !callbackURLScheme.isEmpty else {
|
|
810
|
+
call.reject("callbackURLScheme is required")
|
|
811
|
+
return
|
|
812
|
+
}
|
|
813
|
+
|
|
814
|
+
let prefersEphemeral = call.getBool("prefersEphemeralSession") ?? false
|
|
815
|
+
|
|
816
|
+
startWebAuthSession(
|
|
817
|
+
call: call,
|
|
818
|
+
url: url,
|
|
819
|
+
callbackURLScheme: callbackURLScheme,
|
|
820
|
+
redirectPrefix: nil,
|
|
821
|
+
prefersEphemeral: prefersEphemeral,
|
|
822
|
+
resultKey: "callbackURL"
|
|
823
|
+
)
|
|
824
|
+
}
|
|
825
|
+
|
|
826
|
+
private func startWebAuthSession(
|
|
827
|
+
call: CAPPluginCall,
|
|
828
|
+
url: URL,
|
|
829
|
+
callbackURLScheme: String,
|
|
830
|
+
redirectPrefix: String?,
|
|
831
|
+
prefersEphemeral: Bool,
|
|
832
|
+
resultKey: String
|
|
833
|
+
) {
|
|
834
|
+
if webAuthSessionCall != nil {
|
|
835
|
+
call.reject("Another auth session is already in progress")
|
|
836
|
+
return
|
|
837
|
+
}
|
|
838
|
+
|
|
839
|
+
webAuthSessionCall = call
|
|
840
|
+
webAuthSessionRedirectPrefix = redirectPrefix
|
|
841
|
+
webAuthSessionResultKey = resultKey
|
|
782
842
|
|
|
783
|
-
// Open the URL in a secure browser window
|
|
784
843
|
DispatchQueue.main.async {
|
|
785
|
-
let session = ASWebAuthenticationSession(url: url, callbackURLScheme:
|
|
786
|
-
|
|
844
|
+
let session = ASWebAuthenticationSession(url: url, callbackURLScheme: callbackURLScheme) { callbackURL, error in
|
|
845
|
+
let activeCall = self.webAuthSessionCall
|
|
846
|
+
let expectedPrefix = self.webAuthSessionRedirectPrefix
|
|
847
|
+
let resolveKey = self.webAuthSessionResultKey
|
|
787
848
|
|
|
788
|
-
|
|
789
|
-
self.
|
|
849
|
+
self.webAuthSessionCall = nil
|
|
850
|
+
self.webAuthSessionRedirectPrefix = nil
|
|
851
|
+
|
|
852
|
+
guard let activeCall = activeCall else {
|
|
853
|
+
return
|
|
854
|
+
}
|
|
790
855
|
|
|
791
856
|
if let error = error {
|
|
792
|
-
|
|
793
|
-
call.reject(error.localizedDescription)
|
|
857
|
+
self.rejectWebAuthSessionCall(activeCall, error: error)
|
|
794
858
|
return
|
|
795
859
|
}
|
|
796
860
|
|
|
797
861
|
guard let callbackURL = callbackURL else {
|
|
798
|
-
|
|
862
|
+
activeCall.reject("No callback URL received")
|
|
799
863
|
return
|
|
800
864
|
}
|
|
801
865
|
|
|
802
|
-
if !callbackURL.absoluteString.hasPrefix(
|
|
803
|
-
|
|
866
|
+
if let expectedPrefix = expectedPrefix, !callbackURL.absoluteString.hasPrefix(expectedPrefix) {
|
|
867
|
+
activeCall.reject(
|
|
868
|
+
"Redirect URI does not match, expected " + expectedPrefix + " but got " + callbackURL.absoluteString
|
|
869
|
+
)
|
|
804
870
|
return
|
|
805
871
|
}
|
|
806
872
|
|
|
807
|
-
|
|
808
|
-
call.resolve(["redirectedUri": callbackURL.absoluteString])
|
|
873
|
+
activeCall.resolve([resolveKey: callbackURL.absoluteString])
|
|
809
874
|
}
|
|
810
875
|
|
|
811
|
-
// Present the session
|
|
812
876
|
session.presentationContextProvider = self
|
|
877
|
+
session.prefersEphemeralWebBrowserSession = prefersEphemeral
|
|
813
878
|
session.start()
|
|
814
879
|
}
|
|
815
880
|
}
|
|
816
881
|
|
|
882
|
+
private func rejectWebAuthSessionCall(_ call: CAPPluginCall, error: Error) {
|
|
883
|
+
let cancelled = isUserCancelledError(error)
|
|
884
|
+
call.reject(error.localizedDescription, cancelled ? SocialLoginPlugin.userCancelledCode : nil, error)
|
|
885
|
+
}
|
|
886
|
+
|
|
817
887
|
private func decodeJwtClaims(idToken: String) throws -> [String: Any] {
|
|
818
888
|
let parts = idToken.split(separator: ".")
|
|
819
889
|
if parts.count < 2 {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@capgo/capacitor-social-login",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.6.0",
|
|
4
4
|
"description": "All social logins in one plugin",
|
|
5
5
|
"main": "dist/plugin.cjs.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
@@ -46,9 +46,9 @@
|
|
|
46
46
|
"scripts": {
|
|
47
47
|
"capacitor:sync:before": "node scripts/configure-dependencies.js",
|
|
48
48
|
"verify": "bun run verify:ios && bun run verify:android && bun run verify:web",
|
|
49
|
-
"verify:ios": "
|
|
49
|
+
"verify:ios": "bash .github/scripts/verify-ios-plugin-build.sh",
|
|
50
50
|
"verify:android": "cd android && ./gradlew clean build test && cd ..",
|
|
51
|
-
"verify:web": "bun run build",
|
|
51
|
+
"verify:web": "bun run build && bun test",
|
|
52
52
|
"lint": "bun run eslint && bun run prettier -- --check && bun run swiftlint -- lint",
|
|
53
53
|
"fmt": "bun run eslint -- --fix && bun run prettier -- --write && bun run swiftlint -- --fix --format",
|
|
54
54
|
"eslint": "eslint",
|