@capgo/capacitor-social-login 8.1.1 → 8.2.1
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 +215 -35
- package/android/src/main/AndroidManifest.xml +4 -0
- package/android/src/main/java/ee/forgr/capacitor/social/login/OAuth2LoginActivity.java +110 -0
- package/android/src/main/java/ee/forgr/capacitor/social/login/OAuth2Provider.java +848 -0
- package/android/src/main/java/ee/forgr/capacitor/social/login/SocialLoginPlugin.java +27 -1
- package/dist/docs.json +352 -22
- package/dist/esm/definitions.d.ts +167 -3
- package/dist/esm/definitions.js.map +1 -1
- package/dist/esm/oauth2-provider.d.ts +41 -0
- package/dist/esm/oauth2-provider.js +444 -0
- package/dist/esm/oauth2-provider.js.map +1 -0
- package/dist/esm/web.d.ts +3 -1
- package/dist/esm/web.js +32 -0
- package/dist/esm/web.js.map +1 -1
- package/dist/plugin.cjs.js +474 -0
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +474 -0
- package/dist/plugin.js.map +1 -1
- package/ios/Sources/SocialLoginPlugin/OAuth2Provider.swift +575 -0
- package/ios/Sources/SocialLoginPlugin/SocialLoginPlugin.swift +111 -2
- package/package.json +2 -1
|
@@ -15,7 +15,7 @@ import GoogleSignIn
|
|
|
15
15
|
*/
|
|
16
16
|
@objc(SocialLoginPlugin)
|
|
17
17
|
public class SocialLoginPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
18
|
-
private let pluginVersion: String = "8.
|
|
18
|
+
private let pluginVersion: String = "8.2.1"
|
|
19
19
|
public let identifier = "SocialLoginPlugin"
|
|
20
20
|
public let jsName = "SocialLogin"
|
|
21
21
|
public let pluginMethods: [CAPPluginMethod] = [
|
|
@@ -50,6 +50,7 @@ public class SocialLoginPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
50
50
|
#endif
|
|
51
51
|
|
|
52
52
|
private let twitter = TwitterProvider()
|
|
53
|
+
private let oauth2 = OAuth2Provider()
|
|
53
54
|
|
|
54
55
|
// Helper to get Facebook provider (returns nil if unavailable)
|
|
55
56
|
private var facebookProvider: FacebookProvider? {
|
|
@@ -214,6 +215,25 @@ public class SocialLoginPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
214
215
|
initialized = true
|
|
215
216
|
}
|
|
216
217
|
|
|
218
|
+
if let oauth2Settings = call.getObject("oauth2"), !oauth2Settings.isEmpty {
|
|
219
|
+
// oauth2Settings is now a dictionary of provider configs: { "github": {...}, "azure": {...} }
|
|
220
|
+
var oauth2Configs: [String: [String: Any]] = [:]
|
|
221
|
+
for (providerId, value) in oauth2Settings {
|
|
222
|
+
if let config = value as? [String: Any] {
|
|
223
|
+
oauth2Configs[providerId] = config
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
if !oauth2Configs.isEmpty {
|
|
228
|
+
let errors = oauth2.initializeProviders(configs: oauth2Configs)
|
|
229
|
+
if !errors.isEmpty {
|
|
230
|
+
call.reject(errors.joined(separator: ", "))
|
|
231
|
+
return
|
|
232
|
+
}
|
|
233
|
+
initialized = true
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
|
|
217
237
|
if initialized {
|
|
218
238
|
call.resolve()
|
|
219
239
|
} else {
|
|
@@ -298,6 +318,30 @@ public class SocialLoginPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
298
318
|
}
|
|
299
319
|
}
|
|
300
320
|
}
|
|
321
|
+
case "oauth2": do {
|
|
322
|
+
guard let providerId = call.getString("providerId") else {
|
|
323
|
+
call.reject("providerId is required for oauth2 getAuthorizationCode")
|
|
324
|
+
return
|
|
325
|
+
}
|
|
326
|
+
self.oauth2.getAuthorizationCode(providerId: providerId) { res in
|
|
327
|
+
do {
|
|
328
|
+
let token = try res.get()
|
|
329
|
+
var response: [String: Any] = [
|
|
330
|
+
"accessToken": token.token,
|
|
331
|
+
"tokenType": token.tokenType
|
|
332
|
+
]
|
|
333
|
+
if let expires = token.expires {
|
|
334
|
+
response["expires"] = expires
|
|
335
|
+
}
|
|
336
|
+
if let refreshToken = token.refreshToken {
|
|
337
|
+
response["refreshToken"] = refreshToken
|
|
338
|
+
}
|
|
339
|
+
call.resolve(response)
|
|
340
|
+
} catch {
|
|
341
|
+
call.reject(error.localizedDescription)
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
}
|
|
301
345
|
default:
|
|
302
346
|
call.reject("Invalid provider")
|
|
303
347
|
}
|
|
@@ -356,6 +400,20 @@ public class SocialLoginPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
356
400
|
}
|
|
357
401
|
}
|
|
358
402
|
}
|
|
403
|
+
case "oauth2": do {
|
|
404
|
+
guard let providerId = call.getString("providerId") else {
|
|
405
|
+
call.reject("providerId is required for oauth2 isLoggedIn")
|
|
406
|
+
return
|
|
407
|
+
}
|
|
408
|
+
self.oauth2.isLoggedIn(providerId: providerId) { res in
|
|
409
|
+
do {
|
|
410
|
+
let status = try res.get()
|
|
411
|
+
call.resolve([ "isLoggedIn": status ])
|
|
412
|
+
} catch {
|
|
413
|
+
call.reject(error.localizedDescription)
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
}
|
|
359
417
|
default:
|
|
360
418
|
call.reject("Invalid provider")
|
|
361
419
|
}
|
|
@@ -397,6 +455,14 @@ public class SocialLoginPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
397
455
|
twitter.login(payload: payload) { (result: Result<TwitterProfileResponse, Error>) in
|
|
398
456
|
self.handleLoginResult(result, call: call)
|
|
399
457
|
}
|
|
458
|
+
case "oauth2":
|
|
459
|
+
guard let providerId = payload["providerId"] as? String else {
|
|
460
|
+
call.reject("providerId is required for oauth2 login")
|
|
461
|
+
return
|
|
462
|
+
}
|
|
463
|
+
oauth2.login(providerId: providerId, payload: payload) { (result: Result<OAuth2LoginResponse, Error>) in
|
|
464
|
+
self.handleLoginResult(result, call: call)
|
|
465
|
+
}
|
|
400
466
|
default:
|
|
401
467
|
call.reject("Invalid provider")
|
|
402
468
|
}
|
|
@@ -483,6 +549,14 @@ public class SocialLoginPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
483
549
|
twitter.logout { result in
|
|
484
550
|
self.handleLogoutResult(result, call: call)
|
|
485
551
|
}
|
|
552
|
+
case "oauth2":
|
|
553
|
+
guard let providerId = call.getString("providerId") else {
|
|
554
|
+
call.reject("providerId is required for oauth2 logout")
|
|
555
|
+
return
|
|
556
|
+
}
|
|
557
|
+
oauth2.logout(providerId: providerId) { result in
|
|
558
|
+
self.handleLogoutResult(result, call: call)
|
|
559
|
+
}
|
|
486
560
|
default:
|
|
487
561
|
call.reject("Invalid provider")
|
|
488
562
|
}
|
|
@@ -523,7 +597,14 @@ public class SocialLoginPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
523
597
|
twitter.refresh { result in
|
|
524
598
|
self.handleRefreshResult(result, call: call)
|
|
525
599
|
}
|
|
526
|
-
|
|
600
|
+
case "oauth2":
|
|
601
|
+
guard let options = call.getObject("options"), let providerId = options["providerId"] as? String else {
|
|
602
|
+
call.reject("providerId is required for oauth2 refresh")
|
|
603
|
+
return
|
|
604
|
+
}
|
|
605
|
+
oauth2.refresh(providerId: providerId) { result in
|
|
606
|
+
self.handleRefreshResult(result, call: call)
|
|
607
|
+
}
|
|
527
608
|
default:
|
|
528
609
|
call.reject("Invalid provider")
|
|
529
610
|
}
|
|
@@ -555,6 +636,13 @@ public class SocialLoginPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
555
636
|
"refreshToken": twitterResponse.accessToken.refreshToken ?? NSNull(),
|
|
556
637
|
"expiresIn": twitterResponse.accessToken.expiresIn ?? NSNull()
|
|
557
638
|
])
|
|
639
|
+
} else if let oauth2Response = response as? OAuth2LoginResponse {
|
|
640
|
+
call.resolve([
|
|
641
|
+
"accessToken": oauth2Response.accessToken.token,
|
|
642
|
+
"idToken": oauth2Response.idToken ?? NSNull(),
|
|
643
|
+
"refreshToken": oauth2Response.refreshToken ?? NSNull(),
|
|
644
|
+
"expiresIn": oauth2Response.expiresIn ?? NSNull()
|
|
645
|
+
])
|
|
558
646
|
} else {
|
|
559
647
|
call.reject("Invalid refresh response")
|
|
560
648
|
}
|
|
@@ -684,6 +772,27 @@ public class SocialLoginPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
684
772
|
"provider": "twitter",
|
|
685
773
|
"result": twitterResult
|
|
686
774
|
])
|
|
775
|
+
} else if let oauth2Response = response as? OAuth2LoginResponse {
|
|
776
|
+
let accessToken: [String: Any] = [
|
|
777
|
+
"token": oauth2Response.accessToken.token,
|
|
778
|
+
"tokenType": oauth2Response.accessToken.tokenType,
|
|
779
|
+
"expires": oauth2Response.accessToken.expires ?? NSNull(),
|
|
780
|
+
"refreshToken": oauth2Response.accessToken.refreshToken ?? NSNull()
|
|
781
|
+
]
|
|
782
|
+
var oauth2Result: [String: Any] = [
|
|
783
|
+
"providerId": oauth2Response.providerId,
|
|
784
|
+
"accessToken": accessToken,
|
|
785
|
+
"idToken": oauth2Response.idToken ?? NSNull(),
|
|
786
|
+
"refreshToken": oauth2Response.refreshToken ?? NSNull(),
|
|
787
|
+
"resourceData": oauth2Response.resourceData ?? NSNull(),
|
|
788
|
+
"scope": oauth2Response.scope,
|
|
789
|
+
"tokenType": oauth2Response.tokenType,
|
|
790
|
+
"expiresIn": oauth2Response.expiresIn ?? NSNull()
|
|
791
|
+
]
|
|
792
|
+
call.resolve([
|
|
793
|
+
"provider": "oauth2",
|
|
794
|
+
"result": oauth2Result
|
|
795
|
+
])
|
|
687
796
|
} else {
|
|
688
797
|
call.reject("Unsupported provider response")
|
|
689
798
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@capgo/capacitor-social-login",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.2.1",
|
|
4
4
|
"description": "All social logins in one plugin",
|
|
5
5
|
"main": "dist/plugin.cjs.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
@@ -26,6 +26,7 @@
|
|
|
26
26
|
"bugs": {
|
|
27
27
|
"url": "https://github.com/Cap-go/capacitor-social-login/issues"
|
|
28
28
|
},
|
|
29
|
+
"homepage": "https://capgo.app/docs/plugins/social-login/",
|
|
29
30
|
"keywords": [
|
|
30
31
|
"capacitor",
|
|
31
32
|
"plugin",
|