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

Commit 2b2afa5

Browse files
authored
Merge pull request #158 from wordpress-mobile/issue/12477-siwa_2fa_login
[SIWA] Add flow for 2FA accounts
2 parents 222a6ae + b512cb6 commit 2b2afa5

17 files changed

+131
-76
lines changed

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ version: 2.1
22

33
orbs:
44
# Using 1.0 of our Orbs means it will use the latest 1.0.x version from https://github.com/wordpress-mobile/circleci-orbs
5-
ios: wordpress-mobile/[email protected]
5+
ios: wordpress-mobile/[email protected]
66

77
workflows:
88
test_and_validate:

Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
source 'https://rubygems.org' do
2-
gem 'cocoapods', '~> 1.8.0'
2+
gem 'cocoapods', '~> 1.8.4'
33
end

Gemfile.lock

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ GEM
1212
json (>= 1.5.1)
1313
atomos (0.1.3)
1414
claide (1.0.3)
15-
cocoapods (1.8.3)
15+
cocoapods (1.8.4)
1616
activesupport (>= 4.0.2, < 5)
1717
claide (>= 1.0.2, < 2.0)
18-
cocoapods-core (= 1.8.3)
18+
cocoapods-core (= 1.8.4)
1919
cocoapods-deintegrate (>= 1.0.3, < 2.0)
2020
cocoapods-downloader (>= 1.2.2, < 2.0)
2121
cocoapods-plugins (>= 1.0.0, < 2.0)
@@ -31,14 +31,14 @@ GEM
3131
nap (~> 1.0)
3232
ruby-macho (~> 1.4)
3333
xcodeproj (>= 1.11.1, < 2.0)
34-
cocoapods-core (1.8.3)
34+
cocoapods-core (1.8.4)
3535
activesupport (>= 4.0.2, < 6)
3636
algoliasearch (~> 1.0)
3737
concurrent-ruby (~> 1.1)
3838
fuzzy_match (~> 2.0.4)
3939
nap (~> 1.0)
4040
cocoapods-deintegrate (1.0.4)
41-
cocoapods-downloader (1.2.2)
41+
cocoapods-downloader (1.3.0)
4242
cocoapods-plugins (1.0.0)
4343
nap
4444
cocoapods-search (1.0.0)
@@ -57,7 +57,7 @@ GEM
5757
i18n (0.9.5)
5858
concurrent-ruby (~> 1.0)
5959
json (2.2.0)
60-
minitest (5.12.2)
60+
minitest (5.13.0)
6161
molinillo (0.6.6)
6262
nanaimo (0.2.6)
6363
nap (1.1.0)
@@ -66,7 +66,7 @@ GEM
6666
thread_safe (0.3.6)
6767
tzinfo (1.2.5)
6868
thread_safe (~> 0.1)
69-
xcodeproj (1.12.0)
69+
xcodeproj (1.13.0)
7070
CFPropertyList (>= 2.3.3, < 4.0)
7171
atomos (~> 0.1.3)
7272
claide (>= 1.0.2, < 2.0)
@@ -77,7 +77,7 @@ PLATFORMS
7777
ruby
7878

7979
DEPENDENCIES
80-
cocoapods (~> 1.8.0)!
80+
cocoapods (~> 1.8.4)!
8181

8282
BUNDLED WITH
8383
2.0.2

Podfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ def wordpress_authenticator_pods
1111
##
1212
pod 'Gridicons', '~> 0.15'
1313
pod 'WordPressUI', '~> 1.4-beta.1'
14-
pod 'WordPressKit', '~> 4.5.1'
14+
pod 'WordPressKit', '~> 4.5.4'
15+
# pod 'WordPressKit', :git => 'https://github.com/wordpress-mobile/WordPressKit-iOS.git', :branch => 'issue/apple_2fa_auth'
1516
pod 'WordPressShared', '~> 1.8'
1617

1718
## Third party libraries

Podfile.lock

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,12 @@ PODS:
4343
- OHHTTPStubs/Default
4444
- Specta (1.0.7)
4545
- SVProgressHUD (2.2.5)
46-
- UIDeviceIdentifier (1.1.4)
47-
- WordPressKit (4.5.1):
46+
- UIDeviceIdentifier (1.4.0)
47+
- WordPressKit (4.5.4):
4848
- Alamofire (~> 4.7.3)
4949
- CocoaLumberjack (~> 3.4)
5050
- NSObject-SafeExpectations (= 0.0.3)
51-
- UIDeviceIdentifier (~> 1.1.4)
51+
- UIDeviceIdentifier (~> 1)
5252
- WordPressShared (~> 1.8.0)
5353
- wpxmlrpc (= 0.8.4)
5454
- WordPressShared (1.8.7):
@@ -71,7 +71,7 @@ DEPENDENCIES:
7171
- OHHTTPStubs/Swift (= 8.0.0)
7272
- Specta (= 1.0.7)
7373
- SVProgressHUD (= 2.2.5)
74-
- WordPressKit (~> 4.5.1)
74+
- WordPressKit (~> 4.5.4)
7575
- WordPressShared (~> 1.8)
7676
- WordPressUI (~> 1.4-beta.1)
7777

@@ -116,12 +116,12 @@ SPEC CHECKSUMS:
116116
OHHTTPStubs: 9cbce6364bec557cc3439aa6bb7514670d780881
117117
Specta: 3e1bd89c3517421982dc4d1c992503e48bd5fe66
118118
SVProgressHUD: 1428aafac632c1f86f62aa4243ec12008d7a51d6
119-
UIDeviceIdentifier: 8f8a24b257a4d978c8d40ad1e7355b944ffbfa8c
120-
WordPressKit: c35230114bbd380d63250b6d9a43337c29266c9b
119+
UIDeviceIdentifier: 44f805037d21b94394821828f4fcaba34b38c2d0
120+
WordPressKit: 1d365775fac17903a76ad5723bc146ab1739ec82
121121
WordPressShared: 09cf184caa614835f5811e8609227165201e6d3e
122122
WordPressUI: 35b144885c8e5817ba6874b68accc200bda61ee1
123123
wpxmlrpc: 6ba55c773cfa27083ae4a2173e69b19f46da98e2
124124

125-
PODFILE CHECKSUM: 831117be8f1a447aaa2277d2b421a8e64fe6f02c
125+
PODFILE CHECKSUM: 6f930e58860031b74be490800e49e91a4f3cd75f
126126

127-
COCOAPODS: 1.8.3
127+
COCOAPODS: 1.8.4

WordPressAuthenticator.podspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = "WordPressAuthenticator"
3-
s.version = "1.10.3"
3+
s.version = "1.10.4"
44
s.summary = "WordPressAuthenticator implements an easy and elegant way to authenticate your WordPress Apps."
55

66
s.description = <<-DESC
@@ -39,6 +39,6 @@ Pod::Spec.new do |s|
3939
s.dependency 'Gridicons', '~> 0.15'
4040
s.dependency 'GoogleSignIn', '~> 4.4'
4141
s.dependency 'WordPressUI', '~> 1.4-beta.1'
42-
s.dependency 'WordPressKit', '~> 4.5.1'
42+
s.dependency 'WordPressKit', '~> 4.5.4'
4343
s.dependency 'WordPressShared', '~> 1.8'
4444
end

WordPressAuthenticator/Services/LoginFacade.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,12 @@ NS_ASSUME_NONNULL_BEGIN
5858
- (void)requestSocial2FACodeWithLoginFields:(LoginFields *)loginFields;
5959

6060
/**
61-
* Social login via google.
61+
* Social login.
6262
*
63-
* @param googleIDToken A Google id_token.
63+
* @param token Social id token.
6464
*/
65-
- (void)loginToWordPressDotComWithGoogleIDToken:(NSString *)googleIDToken;
65+
- (void)loginToWordPressDotComWithSocialIDToken:(NSString *)token
66+
service:(NSString *)service;
6667

6768
/**
6869
* Social login via a social account with 2FA using a nonce.

WordPressAuthenticator/Services/LoginFacade.m

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,21 +63,26 @@ - (void)requestSocial2FACodeWithLoginFields:(LoginFields *)loginFields
6363
}];
6464
}
6565

66-
- (void)loginToWordPressDotComWithGoogleIDToken:(NSString *)googleIDToken
66+
- (void)loginToWordPressDotComWithSocialIDToken:(NSString *)token
67+
service:(NSString *)service
6768
{
6869
if ([self.delegate respondsToSelector:@selector(displayLoginMessage:)]) {
6970
[self.delegate displayLoginMessage:NSLocalizedString(@"Connecting to WordPress.com", nil)];
7071
}
7172

72-
[self.wordpressComOAuthClientFacade authenticateWithGoogleIDToken:googleIDToken success:^(NSString *authToken) {
73-
if ([self.delegate respondsToSelector:@selector(finishedLoginWithGoogleIDToken:authToken:)]) {
74-
[self.delegate finishedLoginWithGoogleIDToken:googleIDToken authToken:authToken];
73+
[self.wordpressComOAuthClientFacade authenticateWithSocialIDToken:token
74+
service:service
75+
success:^(NSString *authToken) {
76+
if ([service isEqualToString:@"google"] && [self.delegate respondsToSelector:@selector(finishedLoginWithGoogleIDToken:authToken:)]) {
77+
// Apple is handled in AppleAuthenticator
78+
[self.delegate finishedLoginWithGoogleIDToken:token authToken:authToken];
7579
}
7680
} needsMultiFactor:^(NSInteger userID, SocialLogin2FANonceInfo *nonceInfo){
7781
if ([self.delegate respondsToSelector:@selector(needsMultifactorCodeForUserID:andNonceInfo:)]) {
7882
[self.delegate needsMultifactorCodeForUserID:userID andNonceInfo:nonceInfo];
7983
}
8084
} existingUserNeedsConnection: ^(NSString *email) {
85+
// Apple is handled in AppleAuthenticator
8186
if ([self.delegate respondsToSelector:@selector(existingUserNeedsConnection:)]) {
8287
[self.delegate existingUserNeedsConnection: email];
8388
}

WordPressAuthenticator/Services/SignupService.swift

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,11 @@ class SignupService {
5151
func createWPComUserWithApple(token: String,
5252
email: String,
5353
fullName: String?,
54-
success: @escaping (_ newAccount: Bool, _ existingNonSocialAccount: Bool, _ username: String, _ wpcomToken: String) -> Void,
54+
success: @escaping (_ newAccount: Bool,
55+
_ existingNonSocialAccount: Bool,
56+
_ existing2faAccount: Bool,
57+
_ username: String,
58+
_ wpcomToken: String) -> Void,
5559
failure: @escaping (_ error: Error) -> Void) {
5660
let remote = WordPressComServiceRemote(wordPressComRestApi: anonymousAPI)
5761

@@ -68,22 +72,27 @@ class SignupService {
6872
}
6973

7074
let createdAccount = (response?[ResponseKeys.createdAccount] as? Int ?? 0) == 1
71-
success(createdAccount, false, username, bearer_token)
75+
success(createdAccount, false, false, username, bearer_token)
7276
}, failure: { error in
7377
if let error = (error as NSError?) {
7478

75-
// If an account already exists, the account email should be returned in the Error response.
76-
// Extract it and return it.
77-
var existingEmail = ""
78-
if let errorData = error.userInfo[WordPressComRestApi.ErrorKeyErrorData] as? [String: String] {
79-
let emailDict = errorData.first { $0.key == WordPressComRestApi.ErrorKeyErrorDataEmail }
80-
let email = emailDict?.value ?? ""
81-
existingEmail = email
79+
if (error.userInfo[ErrorKeys.errorCode] as? String ?? "") == ErrorKeys.twoFactorEnabled {
80+
success(false, true, true, "", "")
81+
return
8282
}
8383

84-
let existingNonSocialAccount = (error.userInfo[ErrorKeys.errorCode] as? String ?? "") == ErrorKeys.existingNonSocialUser
85-
if existingNonSocialAccount {
86-
success(false, true, existingEmail, "")
84+
if (error.userInfo[ErrorKeys.errorCode] as? String ?? "") == ErrorKeys.existingNonSocialUser {
85+
86+
// If an account already exists, the account email should be returned in the Error response.
87+
// Extract it and return it.
88+
var existingEmail = ""
89+
if let errorData = error.userInfo[WordPressComRestApi.ErrorKeyErrorData] as? [String: String] {
90+
let emailDict = errorData.first { $0.key == WordPressComRestApi.ErrorKeyErrorDataEmail }
91+
let email = emailDict?.value ?? ""
92+
existingEmail = email
93+
}
94+
95+
success(false, true, false, existingEmail, "")
8796
return
8897
}
8998
}
@@ -118,6 +127,7 @@ private extension SignupService {
118127
struct ErrorKeys {
119128
static let errorCode = "WordPressComRestApiErrorCodeKey"
120129
static let existingNonSocialUser = "user_exists"
130+
static let twoFactorEnabled = "2FA_enabled"
121131
}
122132
}
123133

WordPressAuthenticator/Services/WordPressComOAuthClientFacade.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
success:(void (^)(NSString *newNonce))success
2323
failure:(void (^)(NSError *error, NSString *newNonce))failure;
2424

25-
- (void)authenticateWithGoogleIDToken:(NSString *)token
25+
- (void)authenticateWithSocialIDToken:(NSString *)token
26+
service:(NSString *)service
2627
success:(void (^)(NSString *authToken))success
2728
needsMultiFactor:(void (^)(NSInteger userID, SocialLogin2FANonceInfo *nonceInfo))needsMultifactor
2829
existingUserNeedsConnection:(void (^)(NSString *email))existingUserNeedsConnection

0 commit comments

Comments
 (0)