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

Commit f38cb66

Browse files
committed
Adding a method to create Apple parameters, accepting that as a parameter to connectToSocialService.
1 parent 7ff6823 commit f38cb66

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

WordPressKit/AccountServiceRemoteREST+SocialService.swift

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,14 @@ extension AccountServiceRemoteREST {
1313
/// - Parameters:
1414
/// - service The name of the social service.
1515
/// - token The OpenID Connect (JWT) ID token identifying the user on the social service.
16-
/// - appleEmail The email address associated with an Apple ID. Optional.
17-
/// - appleFullName The full name associated with an Apple ID. Optional.
16+
/// - appleConnectParameters Dictionary containing endpoint parameters specific to connecting to Apple service.
1817
/// - oAuthClientID The WPCOM REST API client ID.
1918
/// - oAuthClientSecret The WPCOM REST API client secret.
2019
/// - success The block that will be executed on success.
2120
/// - failure The block that will be executed on failure.
2221
public func connectToSocialService(_ service: SocialServiceName,
2322
serviceIDToken token: String,
24-
appleEmail: String? = nil,
25-
appleFullName: String? = nil,
23+
appleConnectParameters: [String:AnyObject]? = nil,
2624
oAuthClientID: String,
2725
oAuthClientSecret: String,
2826
success:@escaping (() -> Void),
@@ -37,9 +35,8 @@ extension AccountServiceRemoteREST {
3735
] as [String: AnyObject]
3836

3937
// Append Apple specific parameters
40-
if service == .apple {
41-
params["user_email"] = appleEmail as AnyObject
42-
params["user_name"] = appleFullName as AnyObject
38+
if service == .apple, let appleConnectParameters = appleConnectParameters {
39+
params.merge(appleConnectParameters, uniquingKeysWith: { (current, _) in current })
4340
}
4441

4542
wordPressComRestApi.POST(path, parameters: params, success: { (responseObject, httpResponse) in
@@ -49,6 +46,19 @@ extension AccountServiceRemoteREST {
4946
})
5047
}
5148

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

0 commit comments

Comments
 (0)