@@ -2,6 +2,7 @@ import Foundation
22
33public 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