Skip to content
This repository was archived by the owner on Sep 15, 2025. It is now read-only.

Commit 161630c

Browse files
authored
Merge pull request #182 from wordpress-mobile/feature/add_apple_social_service
Add Apple specific parameters to social service connect
2 parents 96ba9cc + 0967489 commit 161630c

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

WordPressKit.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = "WordPressKit"
3-
s.version = "4.5.0-beta.1"
3+
s.version = "4.5.0-beta.2"
44
s.summary = "WordPressKit offers a clean and simple WordPress.com and WordPress.org API."
55

66
s.description = <<-DESC

WordPressKit/AccountServiceRemoteREST+SocialService.swift

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import Foundation
22

33
public enum SocialServiceName: String {
44
case google
5+
case apple
56
}
67

78

@@ -12,26 +13,51 @@ extension AccountServiceRemoteREST {
1213
/// - Parameters:
1314
/// - service The name of the social service.
1415
/// - token The OpenID Connect (JWT) ID token identifying the user on the social service.
16+
/// - connectParameters Dictionary containing additional endpoint parameters. Currently only used for the Apple service.
1517
/// - oAuthClientID The WPCOM REST API client ID.
1618
/// - oAuthClientSecret The WPCOM REST API client secret.
1719
/// - success The block that will be executed on success.
1820
/// - failure The block that will be executed on failure.
19-
public func connectToSocialService(_ service: SocialServiceName, serviceIDToken token: String, oAuthClientID: String, oAuthClientSecret: String, success:@escaping (() -> Void), failure:@escaping ((NSError) -> Void)) {
21+
public func connectToSocialService(_ service: SocialServiceName,
22+
serviceIDToken token: String,
23+
connectParameters: [String:AnyObject]? = nil,
24+
oAuthClientID: String,
25+
oAuthClientSecret: String,
26+
success:@escaping (() -> Void),
27+
failure:@escaping ((NSError) -> Void)) {
2028
let path = self.path(forEndpoint: "me/social-login/connect", withVersion: ._1_1)
2129

22-
let params = [
30+
var params = [
2331
"client_id": oAuthClientID,
2432
"client_secret": oAuthClientSecret,
2533
"service": service.rawValue,
2634
"id_token": token,
2735
] as [String: AnyObject]
36+
37+
if let connectParameters = connectParameters {
38+
params.merge(connectParameters, uniquingKeysWith: { (current, _) in current })
39+
}
40+
2841
wordPressComRestApi.POST(path, parameters: params, success: { (responseObject, httpResponse) in
2942
success()
3043
}, failure: { (error, httpResponse) in
3144
failure(error)
3245
})
3346
}
3447

48+
/// Get Apple connect parameters from provided account information.
49+
///
50+
/// - Parameters:
51+
/// - email Email from Apple account.
52+
/// - fullName User's full name from Apple account.
53+
/// - Returns: Dictionary with endpoint parameters, to be used when connecting to social service.
54+
static public func appleSignInParameters(email: String, fullName: String) -> [String:AnyObject] {
55+
return [
56+
"user_email": email as AnyObject,
57+
"user_name": fullName as AnyObject
58+
]
59+
}
60+
3561
/// Disconnect fromm the specified social service.
3662
///
3763
/// - Parameters:

0 commit comments

Comments
 (0)