From 969a97593aff80d863da3f9438221e2b5086ac4c Mon Sep 17 00:00:00 2001 From: Stephenie Harris Date: Wed, 21 Aug 2019 18:02:51 -0600 Subject: [PATCH 1/5] Bumping version. --- WordPressKit.podspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WordPressKit.podspec b/WordPressKit.podspec index 1223909a..fd3fe6cd 100644 --- a/WordPressKit.podspec +++ b/WordPressKit.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "WordPressKit" - s.version = "4.5.0-beta.1" + s.version = "4.5.0-beta.2" s.summary = "WordPressKit offers a clean and simple WordPress.com and WordPress.org API." s.description = <<-DESC From 7022bdf98886ac1c64ee07aaa1fa3250174257e1 Mon Sep 17 00:00:00 2001 From: Stephenie Harris Date: Wed, 21 Aug 2019 18:03:04 -0600 Subject: [PATCH 2/5] Adding apple service name. --- WordPressKit/AccountServiceRemoteREST+SocialService.swift | 1 + 1 file changed, 1 insertion(+) diff --git a/WordPressKit/AccountServiceRemoteREST+SocialService.swift b/WordPressKit/AccountServiceRemoteREST+SocialService.swift index d8a0dcab..0ad9a2db 100644 --- a/WordPressKit/AccountServiceRemoteREST+SocialService.swift +++ b/WordPressKit/AccountServiceRemoteREST+SocialService.swift @@ -2,6 +2,7 @@ import Foundation public enum SocialServiceName: String { case google + case apple } From 7ff68231765d7ffa1cb24bf704c3babf2e818020 Mon Sep 17 00:00:00 2001 From: Stephenie Harris Date: Wed, 21 Aug 2019 18:03:54 -0600 Subject: [PATCH 3/5] Adding apple specific parameters to social service connect. --- ...countServiceRemoteREST+SocialService.swift | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/WordPressKit/AccountServiceRemoteREST+SocialService.swift b/WordPressKit/AccountServiceRemoteREST+SocialService.swift index 0ad9a2db..208987e8 100644 --- a/WordPressKit/AccountServiceRemoteREST+SocialService.swift +++ b/WordPressKit/AccountServiceRemoteREST+SocialService.swift @@ -13,19 +13,35 @@ extension AccountServiceRemoteREST { /// - Parameters: /// - service The name of the social service. /// - token The OpenID Connect (JWT) ID token identifying the user on the social service. + /// - appleEmail The email address associated with an Apple ID. Optional. + /// - appleFullName The full name associated with an Apple ID. Optional. /// - oAuthClientID The WPCOM REST API client ID. /// - oAuthClientSecret The WPCOM REST API client secret. /// - success The block that will be executed on success. /// - failure The block that will be executed on failure. - public func connectToSocialService(_ service: SocialServiceName, serviceIDToken token: String, oAuthClientID: String, oAuthClientSecret: String, success:@escaping (() -> Void), failure:@escaping ((NSError) -> Void)) { + public func connectToSocialService(_ service: SocialServiceName, + serviceIDToken token: String, + appleEmail: String? = nil, + appleFullName: String? = nil, + oAuthClientID: String, + oAuthClientSecret: String, + success:@escaping (() -> Void), + failure:@escaping ((NSError) -> Void)) { let path = self.path(forEndpoint: "me/social-login/connect", withVersion: ._1_1) - let params = [ + var params = [ "client_id": oAuthClientID, "client_secret": oAuthClientSecret, "service": service.rawValue, "id_token": token, ] as [String: AnyObject] + + // Append Apple specific parameters + if service == .apple { + params["user_email"] = appleEmail as AnyObject + params["user_name"] = appleFullName as AnyObject + } + wordPressComRestApi.POST(path, parameters: params, success: { (responseObject, httpResponse) in success() }, failure: { (error, httpResponse) in From f38cb66852fa03d5f98c14659ed37a9edd477063 Mon Sep 17 00:00:00 2001 From: Stephenie Harris Date: Thu, 22 Aug 2019 11:18:51 -0600 Subject: [PATCH 4/5] Adding a method to create Apple parameters, accepting that as a parameter to connectToSocialService. --- ...countServiceRemoteREST+SocialService.swift | 24 +++++++++++++------ 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/WordPressKit/AccountServiceRemoteREST+SocialService.swift b/WordPressKit/AccountServiceRemoteREST+SocialService.swift index 208987e8..d776c510 100644 --- a/WordPressKit/AccountServiceRemoteREST+SocialService.swift +++ b/WordPressKit/AccountServiceRemoteREST+SocialService.swift @@ -13,16 +13,14 @@ extension AccountServiceRemoteREST { /// - Parameters: /// - service The name of the social service. /// - token The OpenID Connect (JWT) ID token identifying the user on the social service. - /// - appleEmail The email address associated with an Apple ID. Optional. - /// - appleFullName The full name associated with an Apple ID. Optional. + /// - appleConnectParameters Dictionary containing endpoint parameters specific to connecting to Apple service. /// - oAuthClientID The WPCOM REST API client ID. /// - oAuthClientSecret The WPCOM REST API client secret. /// - success The block that will be executed on success. /// - failure The block that will be executed on failure. public func connectToSocialService(_ service: SocialServiceName, serviceIDToken token: String, - appleEmail: String? = nil, - appleFullName: String? = nil, + appleConnectParameters: [String:AnyObject]? = nil, oAuthClientID: String, oAuthClientSecret: String, success:@escaping (() -> Void), @@ -37,9 +35,8 @@ extension AccountServiceRemoteREST { ] as [String: AnyObject] // Append Apple specific parameters - if service == .apple { - params["user_email"] = appleEmail as AnyObject - params["user_name"] = appleFullName as AnyObject + if service == .apple, let appleConnectParameters = appleConnectParameters { + params.merge(appleConnectParameters, uniquingKeysWith: { (current, _) in current }) } wordPressComRestApi.POST(path, parameters: params, success: { (responseObject, httpResponse) in @@ -49,6 +46,19 @@ extension AccountServiceRemoteREST { }) } + /// Get Apple connect parameters from provided account information. + /// + /// - Parameters: + /// - email Email from Apple account. + /// - fullName User's full name from Apple account. + /// - Returns: Dictionary with endpoint parameters, to be used when connecting to social service. + static public func appleSignInParameters(email: String, fullName: String) -> [String:AnyObject] { + return [ + "user_email": email as AnyObject, + "user_name": fullName as AnyObject + ] + } + /// Disconnect fromm the specified social service. /// /// - Parameters: From 09674890a824042946cf15b77fdebb0197d2e1e3 Mon Sep 17 00:00:00 2001 From: Stephenie Harris Date: Thu, 22 Aug 2019 15:35:22 -0600 Subject: [PATCH 5/5] Nix references to Apple. --- .../AccountServiceRemoteREST+SocialService.swift | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/WordPressKit/AccountServiceRemoteREST+SocialService.swift b/WordPressKit/AccountServiceRemoteREST+SocialService.swift index d776c510..1434304d 100644 --- a/WordPressKit/AccountServiceRemoteREST+SocialService.swift +++ b/WordPressKit/AccountServiceRemoteREST+SocialService.swift @@ -13,14 +13,14 @@ extension AccountServiceRemoteREST { /// - Parameters: /// - service The name of the social service. /// - token The OpenID Connect (JWT) ID token identifying the user on the social service. - /// - appleConnectParameters Dictionary containing endpoint parameters specific to connecting to Apple service. + /// - connectParameters Dictionary containing additional endpoint parameters. Currently only used for the Apple service. /// - oAuthClientID The WPCOM REST API client ID. /// - oAuthClientSecret The WPCOM REST API client secret. /// - success The block that will be executed on success. /// - failure The block that will be executed on failure. public func connectToSocialService(_ service: SocialServiceName, serviceIDToken token: String, - appleConnectParameters: [String:AnyObject]? = nil, + connectParameters: [String:AnyObject]? = nil, oAuthClientID: String, oAuthClientSecret: String, success:@escaping (() -> Void), @@ -33,10 +33,9 @@ extension AccountServiceRemoteREST { "service": service.rawValue, "id_token": token, ] as [String: AnyObject] - - // Append Apple specific parameters - if service == .apple, let appleConnectParameters = appleConnectParameters { - params.merge(appleConnectParameters, uniquingKeysWith: { (current, _) in current }) + + if let connectParameters = connectParameters { + params.merge(connectParameters, uniquingKeysWith: { (current, _) in current }) } wordPressComRestApi.POST(path, parameters: params, success: { (responseObject, httpResponse) in