Skip to content
This repository was archived by the owner on Sep 15, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion WordPressKit.podspec
Original file line number Diff line number Diff line change
@@ -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
Expand Down
30 changes: 28 additions & 2 deletions WordPressKit/AccountServiceRemoteREST+SocialService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import Foundation

public enum SocialServiceName: String {
case google
case apple
}


Expand All @@ -12,26 +13,51 @@ extension AccountServiceRemoteREST {
/// - Parameters:
/// - service The name of the social service.
/// - token The OpenID Connect (JWT) ID token identifying the user on the social 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, oAuthClientID: String, oAuthClientSecret: String, success:@escaping (() -> Void), failure:@escaping ((NSError) -> Void)) {
public func connectToSocialService(_ service: SocialServiceName,
serviceIDToken token: String,
connectParameters: [String:AnyObject]? = 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]

if let connectParameters = connectParameters {
params.merge(connectParameters, uniquingKeysWith: { (current, _) in current })
}

wordPressComRestApi.POST(path, parameters: params, success: { (responseObject, httpResponse) in
success()
}, failure: { (error, httpResponse) in
failure(error)
})
}

/// 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:
Expand Down