Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for sending magic links to inexistent accounts #822

Merged
merged 1 commit into from
Nov 20, 2024
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
15 changes: 15 additions & 0 deletions Sources/WordPressKit/Services/AccountServiceRemoteREST.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,21 @@ extern MagicLinkFlow const MagicLinkFlowSignup;

@interface AccountServiceRemoteREST : ServiceRemoteWordPressComREST <AccountServiceRemote>

/**
* @brief Request an authentication link be sent to the email address provided.
*
* @param success The block that will be executed on success. Can be nil.
* @param failure The block that will be executed on failure. Can be nil.
*/
- (void)requestWPComAuthLinkForEmail:(NSString *)email
clientID:(NSString *)clientID
clientSecret:(NSString *)clientSecret
source:(MagicLinkSource)source
wpcomScheme:(NSString *)scheme
createAccountIfNotFound:(BOOL)createAccountIfNotFound
success:(void (^)(void))success
failure:(void (^)(NSError *error))failure;

/**
* @brief Request an authentication link be sent to the email address provided.
*
Expand Down
26 changes: 23 additions & 3 deletions Sources/WordPressKit/Services/AccountServiceRemoteREST.m
Original file line number Diff line number Diff line change
Expand Up @@ -245,17 +245,19 @@ - (void)requestWPComAuthLinkForEmail:(NSString *)email
clientSecret:(NSString *)clientSecret
source:(MagicLinkSource)source
wpcomScheme:(NSString *)scheme
createAccountIfNotFound:(BOOL)createAccountIfNotFound
success:(void (^)(void))success
failure:(void (^)(NSError *error))failure
{
NSString *path = [self pathForEndpoint:@"auth/send-login-email"
withVersion:WordPressComRESTAPIVersion_1_3];

NSDictionary *extraParams = @{
MagicLinkParameterFlow: MagicLinkFlowLogin,
MagicLinkParameterSource: source
MagicLinkParameterSource: source,
@"create_account": createAccountIfNotFound ? @"true" : @"false"
};

[self requestWPComMagicLinkForEmail:email
path:path
clientID:clientID
Expand All @@ -266,6 +268,24 @@ - (void)requestWPComAuthLinkForEmail:(NSString *)email
failure:failure];
}

- (void)requestWPComAuthLinkForEmail:(NSString *)email
clientID:(NSString *)clientID
clientSecret:(NSString *)clientSecret
source:(MagicLinkSource)source
wpcomScheme:(NSString *)scheme
success:(void (^)(void))success
failure:(void (^)(NSError *error))failure
{
[self requestWPComAuthLinkForEmail:email
clientID:clientID
clientSecret:clientSecret
source:source
wpcomScheme:scheme
createAccountIfNotFound:NO
success:success
failure:failure];
}

- (void)requestWPComSignupLinkForEmail:(NSString *)email
clientID:(NSString *)clientID
clientSecret:(NSString *)clientSecret
Expand Down