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

Commit c43367f

Browse files
committed
Adding method to create WP account from Apple ID credentials.
1 parent 0312a60 commit c43367f

File tree

2 files changed

+55
-10
lines changed

2 files changed

+55
-10
lines changed

WordPressKit/WordPressComServiceRemote.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,25 @@ typedef void(^WordPressComServiceFailureBlock)(NSError *error);
4848
success:(WordPressComServiceSuccessBlock)success
4949
failure:(WordPressComServiceFailureBlock)failure;
5050

51+
/**
52+
* @brief Create a new WordPress.com account from Apple ID credentials.
53+
*
54+
* @param token Token provided by Apple.
55+
* @param email Apple email to use for new account.
56+
* @param userName The username for the new account. Formed from the Apple ID fullname.
57+
* @param clientID wpcom client ID.
58+
* @param clientSecret wpcom secret.
59+
* @param success success block.
60+
* @param failure failure block.
61+
*/
62+
- (void)createWPComAccountWithApple:(NSString *)token
63+
andEmail:(NSString *)email
64+
andUserName:(NSString *)userName
65+
andClientID:(NSString *)clientID
66+
andClientSecret:(NSString *)clientSecret
67+
success:(WordPressComServiceSuccessBlock)success
68+
failure:(WordPressComServiceFailureBlock)failure;
69+
5170
/**
5271
* @brief Validates a WordPress.com blog with the specified parameters.
5372
*

WordPressKit/WordPressComServiceRemote.m

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,47 @@ - (void)createWPComAccountWithEmail:(NSString *)email
6464
[self.wordPressComRestApi POST:requestUrl parameters:params success:successBlock failure:failureBlock];
6565
}
6666

67-
// API v1 POST /users/social/new
6867
- (void)createWPComAccountWithGoogle:(NSString *)token
6968
andClientID:(NSString *)clientID
7069
andClientSecret:(NSString *)clientSecret
7170
success:(WordPressComServiceSuccessBlock)success
7271
failure:(WordPressComServiceFailureBlock)failure
72+
{
73+
NSDictionary *params = @{
74+
@"client_id": clientID,
75+
@"client_secret": clientSecret,
76+
@"id_token": token,
77+
@"service": @"google",
78+
@"signup_flow_name": @"social",
79+
};
80+
81+
[self createSocialWPComAccountWithParams:params success:success failure:failure];
82+
}
83+
84+
- (void)createWPComAccountWithApple:(NSString *)token
85+
andEmail:(NSString *)email
86+
andUserName:(NSString *)userName
87+
andClientID:(NSString *)clientID
88+
andClientSecret:(NSString *)clientSecret
89+
success:(WordPressComServiceSuccessBlock)success
90+
failure:(WordPressComServiceFailureBlock)failure
91+
{
92+
NSDictionary *params = @{
93+
@"client_id": clientID,
94+
@"client_secret": clientSecret,
95+
@"id_token": token,
96+
@"service": @"apple",
97+
@"signup_flow_name": @"social",
98+
@"user_email": email,
99+
@"user_name": userName,
100+
};
101+
102+
[self createSocialWPComAccountWithParams:params success:success failure:failure];
103+
}
104+
105+
- (void)createSocialWPComAccountWithParams:(NSDictionary *)params
106+
success:(WordPressComServiceSuccessBlock)success
107+
failure:(WordPressComServiceFailureBlock)failure
73108
{
74109
void (^successBlock)(id, NSHTTPURLResponse *) = ^(id responseObject, NSHTTPURLResponse *httpResponse) {
75110
success(responseObject);
@@ -80,16 +115,7 @@ - (void)createWPComAccountWithGoogle:(NSString *)token
80115
failure(errorWithLocalizedMessage);
81116
};
82117

83-
NSDictionary *params = @{
84-
@"client_id": clientID,
85-
@"client_secret": clientSecret,
86-
@"id_token": token,
87-
@"service": @"google",
88-
@"signup_flow_name": @"social",
89-
};
90-
91118
NSString *requestUrl = [self pathForEndpoint:@"users/social/new" withVersion:ServiceRemoteWordPressComRESTApiVersion_1_0];
92-
93119
[self.wordPressComRestApi POST:requestUrl parameters:params success:successBlock failure:failureBlock];
94120
}
95121

0 commit comments

Comments
 (0)