Skip to content
This repository was archived by the owner on Feb 5, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
fb4ac67
Updating Google to use updated authenticateWithIDToken method.
ScoutHarris Nov 27, 2019
256a561
Removing Apple from email login.
ScoutHarris Nov 27, 2019
f876b88
Catch 2FA_enabled error, return as success with flag.
ScoutHarris Nov 27, 2019
e90d501
Handle SIWA 2fa flow.
ScoutHarris Nov 27, 2019
b916f25
Updating pods.
ScoutHarris Nov 27, 2019
02c5110
Updating with WPKit changes.
ScoutHarris Nov 27, 2019
3c84b7d
LoginFacade: Check if login is google before calling Google delegate …
frosty Nov 29, 2019
e7d1d2a
Check for source when constructing tracks properties
frosty Nov 29, 2019
a7ef3dc
Bump WordPressKit pod version
frosty Nov 29, 2019
222a6ae
Merge pull request #159 from wordpress-mobile/release/1.10.3
loremattei Dec 2, 2019
cc62794
Bumped dependency versions and podspec version
frosty Dec 2, 2019
24d2d7f
Update podfile.lock
frosty Dec 2, 2019
0b00a59
Test new orb
loremattei Dec 2, 2019
0f942cb
Update cocoapods version
loremattei Dec 2, 2019
2b20552
Update circleci orb
loremattei Dec 2, 2019
d9e3280
Merge pull request #161 from wordpress-mobile/try/fix-lint-error
loremattei Dec 2, 2019
79f3024
Trig CircleCI
loremattei Dec 2, 2019
c150583
Revert
loremattei Dec 2, 2019
2aafff5
Bump version to 1.10.4
loremattei Dec 2, 2019
cb0d14b
Update CI config
loremattei Dec 2, 2019
606b2f5
Update CI config
loremattei Dec 2, 2019
20ff67c
Update CI config
loremattei Dec 2, 2019
b512cb6
Fix merge conflicts
loremattei Dec 2, 2019
2b2afa5
Merge pull request #158 from wordpress-mobile/issue/12477-siwa_2fa_login
loremattei Dec 2, 2019
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 .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: 2.1

orbs:
# Using 1.0 of our Orbs means it will use the latest 1.0.x version from https://github.com/wordpress-mobile/circleci-orbs
ios: wordpress-mobile/ios@1.0
ios: wordpress-mobile/ios@1.0

workflows:
test_and_validate:
Expand Down
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
source 'https://rubygems.org' do
gem 'cocoapods', '~> 1.8.0'
gem 'cocoapods', '~> 1.8.4'
end
14 changes: 7 additions & 7 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ GEM
json (>= 1.5.1)
atomos (0.1.3)
claide (1.0.3)
cocoapods (1.8.3)
cocoapods (1.8.4)
activesupport (>= 4.0.2, < 5)
claide (>= 1.0.2, < 2.0)
cocoapods-core (= 1.8.3)
cocoapods-core (= 1.8.4)
cocoapods-deintegrate (>= 1.0.3, < 2.0)
cocoapods-downloader (>= 1.2.2, < 2.0)
cocoapods-plugins (>= 1.0.0, < 2.0)
Expand All @@ -31,14 +31,14 @@ GEM
nap (~> 1.0)
ruby-macho (~> 1.4)
xcodeproj (>= 1.11.1, < 2.0)
cocoapods-core (1.8.3)
cocoapods-core (1.8.4)
activesupport (>= 4.0.2, < 6)
algoliasearch (~> 1.0)
concurrent-ruby (~> 1.1)
fuzzy_match (~> 2.0.4)
nap (~> 1.0)
cocoapods-deintegrate (1.0.4)
cocoapods-downloader (1.2.2)
cocoapods-downloader (1.3.0)
cocoapods-plugins (1.0.0)
nap
cocoapods-search (1.0.0)
Expand All @@ -57,7 +57,7 @@ GEM
i18n (0.9.5)
concurrent-ruby (~> 1.0)
json (2.2.0)
minitest (5.12.2)
minitest (5.13.0)
molinillo (0.6.6)
nanaimo (0.2.6)
nap (1.1.0)
Expand All @@ -66,7 +66,7 @@ GEM
thread_safe (0.3.6)
tzinfo (1.2.5)
thread_safe (~> 0.1)
xcodeproj (1.12.0)
xcodeproj (1.13.0)
CFPropertyList (>= 2.3.3, < 4.0)
atomos (~> 0.1.3)
claide (>= 1.0.2, < 2.0)
Expand All @@ -77,7 +77,7 @@ PLATFORMS
ruby

DEPENDENCIES
cocoapods (~> 1.8.0)!
cocoapods (~> 1.8.4)!

BUNDLED WITH
2.0.2
3 changes: 2 additions & 1 deletion Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ def wordpress_authenticator_pods
##
pod 'Gridicons', '~> 0.15'
pod 'WordPressUI', '~> 1.4-beta.1'
pod 'WordPressKit', '~> 4.5.1'
pod 'WordPressKit', '~> 4.5.4'
# pod 'WordPressKit', :git => 'https://github.com/wordpress-mobile/WordPressKit-iOS.git', :branch => 'issue/apple_2fa_auth'
pod 'WordPressShared', '~> 1.8'

## Third party libraries
Expand Down
16 changes: 8 additions & 8 deletions Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ PODS:
- OHHTTPStubs/Default
- Specta (1.0.7)
- SVProgressHUD (2.2.5)
- UIDeviceIdentifier (1.1.4)
- WordPressKit (4.5.1):
- UIDeviceIdentifier (1.4.0)
- WordPressKit (4.5.4):
- Alamofire (~> 4.7.3)
- CocoaLumberjack (~> 3.4)
- NSObject-SafeExpectations (= 0.0.3)
- UIDeviceIdentifier (~> 1.1.4)
- UIDeviceIdentifier (~> 1)
- WordPressShared (~> 1.8.0)
- wpxmlrpc (= 0.8.4)
- WordPressShared (1.8.7):
Expand All @@ -71,7 +71,7 @@ DEPENDENCIES:
- OHHTTPStubs/Swift (= 8.0.0)
- Specta (= 1.0.7)
- SVProgressHUD (= 2.2.5)
- WordPressKit (~> 4.5.1)
- WordPressKit (~> 4.5.4)
- WordPressShared (~> 1.8)
- WordPressUI (~> 1.4-beta.1)

Expand Down Expand Up @@ -116,12 +116,12 @@ SPEC CHECKSUMS:
OHHTTPStubs: 9cbce6364bec557cc3439aa6bb7514670d780881
Specta: 3e1bd89c3517421982dc4d1c992503e48bd5fe66
SVProgressHUD: 1428aafac632c1f86f62aa4243ec12008d7a51d6
UIDeviceIdentifier: 8f8a24b257a4d978c8d40ad1e7355b944ffbfa8c
WordPressKit: c35230114bbd380d63250b6d9a43337c29266c9b
UIDeviceIdentifier: 44f805037d21b94394821828f4fcaba34b38c2d0
WordPressKit: 1d365775fac17903a76ad5723bc146ab1739ec82
WordPressShared: 09cf184caa614835f5811e8609227165201e6d3e
WordPressUI: 35b144885c8e5817ba6874b68accc200bda61ee1
wpxmlrpc: 6ba55c773cfa27083ae4a2173e69b19f46da98e2

PODFILE CHECKSUM: 831117be8f1a447aaa2277d2b421a8e64fe6f02c
PODFILE CHECKSUM: 6f930e58860031b74be490800e49e91a4f3cd75f

COCOAPODS: 1.8.3
COCOAPODS: 1.8.4
4 changes: 2 additions & 2 deletions WordPressAuthenticator.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "WordPressAuthenticator"
s.version = "1.10.3"
s.version = "1.10.4"
s.summary = "WordPressAuthenticator implements an easy and elegant way to authenticate your WordPress Apps."

s.description = <<-DESC
Expand Down Expand Up @@ -39,6 +39,6 @@ Pod::Spec.new do |s|
s.dependency 'Gridicons', '~> 0.15'
s.dependency 'GoogleSignIn', '~> 4.4'
s.dependency 'WordPressUI', '~> 1.4-beta.1'
s.dependency 'WordPressKit', '~> 4.5.1'
s.dependency 'WordPressKit', '~> 4.5.4'
s.dependency 'WordPressShared', '~> 1.8'
end
7 changes: 4 additions & 3 deletions WordPressAuthenticator/Services/LoginFacade.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,12 @@ NS_ASSUME_NONNULL_BEGIN
- (void)requestSocial2FACodeWithLoginFields:(LoginFields *)loginFields;

/**
* Social login via google.
* Social login.
*
* @param googleIDToken A Google id_token.
* @param token Social id token.
*/
- (void)loginToWordPressDotComWithGoogleIDToken:(NSString *)googleIDToken;
- (void)loginToWordPressDotComWithSocialIDToken:(NSString *)token
service:(NSString *)service;

/**
* Social login via a social account with 2FA using a nonce.
Expand Down
13 changes: 9 additions & 4 deletions WordPressAuthenticator/Services/LoginFacade.m
Original file line number Diff line number Diff line change
Expand Up @@ -63,21 +63,26 @@ - (void)requestSocial2FACodeWithLoginFields:(LoginFields *)loginFields
}];
}

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

[self.wordpressComOAuthClientFacade authenticateWithGoogleIDToken:googleIDToken success:^(NSString *authToken) {
if ([self.delegate respondsToSelector:@selector(finishedLoginWithGoogleIDToken:authToken:)]) {
[self.delegate finishedLoginWithGoogleIDToken:googleIDToken authToken:authToken];
[self.wordpressComOAuthClientFacade authenticateWithSocialIDToken:token
service:service
success:^(NSString *authToken) {
if ([service isEqualToString:@"google"] && [self.delegate respondsToSelector:@selector(finishedLoginWithGoogleIDToken:authToken:)]) {
// Apple is handled in AppleAuthenticator
[self.delegate finishedLoginWithGoogleIDToken:token authToken:authToken];
}
} needsMultiFactor:^(NSInteger userID, SocialLogin2FANonceInfo *nonceInfo){
if ([self.delegate respondsToSelector:@selector(needsMultifactorCodeForUserID:andNonceInfo:)]) {
[self.delegate needsMultifactorCodeForUserID:userID andNonceInfo:nonceInfo];
}
} existingUserNeedsConnection: ^(NSString *email) {
// Apple is handled in AppleAuthenticator
if ([self.delegate respondsToSelector:@selector(existingUserNeedsConnection:)]) {
[self.delegate existingUserNeedsConnection: email];
}
Expand Down
34 changes: 22 additions & 12 deletions WordPressAuthenticator/Services/SignupService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,11 @@ class SignupService {
func createWPComUserWithApple(token: String,
email: String,
fullName: String?,
success: @escaping (_ newAccount: Bool, _ existingNonSocialAccount: Bool, _ username: String, _ wpcomToken: String) -> Void,
success: @escaping (_ newAccount: Bool,
_ existingNonSocialAccount: Bool,
_ existing2faAccount: Bool,
_ username: String,
_ wpcomToken: String) -> Void,
failure: @escaping (_ error: Error) -> Void) {
let remote = WordPressComServiceRemote(wordPressComRestApi: anonymousAPI)

Expand All @@ -68,22 +72,27 @@ class SignupService {
}

let createdAccount = (response?[ResponseKeys.createdAccount] as? Int ?? 0) == 1
success(createdAccount, false, username, bearer_token)
success(createdAccount, false, false, username, bearer_token)
}, failure: { error in
if let error = (error as NSError?) {

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

let existingNonSocialAccount = (error.userInfo[ErrorKeys.errorCode] as? String ?? "") == ErrorKeys.existingNonSocialUser
if existingNonSocialAccount {
success(false, true, existingEmail, "")
if (error.userInfo[ErrorKeys.errorCode] as? String ?? "") == ErrorKeys.existingNonSocialUser {

// If an account already exists, the account email should be returned in the Error response.
// Extract it and return it.
var existingEmail = ""
if let errorData = error.userInfo[WordPressComRestApi.ErrorKeyErrorData] as? [String: String] {
let emailDict = errorData.first { $0.key == WordPressComRestApi.ErrorKeyErrorDataEmail }
let email = emailDict?.value ?? ""
existingEmail = email
}

success(false, true, false, existingEmail, "")
return
}
}
Expand Down Expand Up @@ -118,6 +127,7 @@ private extension SignupService {
struct ErrorKeys {
static let errorCode = "WordPressComRestApiErrorCodeKey"
static let existingNonSocialUser = "user_exists"
static let twoFactorEnabled = "2FA_enabled"
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
success:(void (^)(NSString *newNonce))success
failure:(void (^)(NSError *error, NSString *newNonce))failure;

- (void)authenticateWithGoogleIDToken:(NSString *)token
- (void)authenticateWithSocialIDToken:(NSString *)token
service:(NSString *)service
success:(void (^)(NSString *authToken))success
needsMultiFactor:(void (^)(NSInteger userID, SocialLogin2FANonceInfo *nonceInfo))needsMultifactor
existingUserNeedsConnection:(void (^)(NSString *email))existingUserNeedsConnection
Expand Down
10 changes: 8 additions & 2 deletions WordPressAuthenticator/Services/WordPressComOAuthClientFacade.m
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,19 @@ - (void)requestSocial2FACodeWithUserID:(NSInteger)userID
[self.client requestSocial2FACodeWithUserID:userID nonce:nonce success:success failure:failure];
}

- (void)authenticateWithGoogleIDToken:(NSString *)token
- (void)authenticateWithSocialIDToken:(NSString *)token
service:(NSString *)service
success:(void (^)(NSString *authToken))success
needsMultiFactor:(void (^)(NSInteger userID, SocialLogin2FANonceInfo *nonceInfo))needsMultifactor
existingUserNeedsConnection:(void (^)(NSString *email))existingUserNeedsConnection
failure:(void (^)(NSError *error))failure
{
[self.client authenticateWithIDToken:token success:success needsMultifactor:needsMultifactor existingUserNeedsConnection:existingUserNeedsConnection failure:failure];
[self.client authenticateWithIDToken:token
service:service
success:success
needsMultifactor:needsMultifactor
existingUserNeedsConnection:existingUserNeedsConnection
failure:failure];
}

- (void)authenticateSocialLoginUser:(NSInteger)userID
Expand Down
18 changes: 17 additions & 1 deletion WordPressAuthenticator/Signin/AppleAuthenticator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import SVProgressHUD

@objc protocol AppleAuthenticatorDelegate {
func showWPComLogin(loginFields: LoginFields)
func showApple2FA(loginFields: LoginFields)
func authFailedWithError(message: String)
}

Expand Down Expand Up @@ -75,13 +76,23 @@ private extension AppleAuthenticator {

let service = SignupService()
service.createWPComUserWithApple(token: token, email: email, fullName: name,
success: { [weak self] accountCreated, existingNonSocialAccount, wpcomUsername, wpcomToken in
success: { [weak self] accountCreated,
existingNonSocialAccount,
existing2faAccount,
wpcomUsername,
wpcomToken in
SVProgressHUD.dismiss()

// Notify host app of successful Apple authentication
self?.authenticationDelegate.userAuthenticatedWithAppleUserID(appleCredentials.user)

guard !existingNonSocialAccount else {

if existing2faAccount {
self?.show2FA()
return
}

self?.updateLoginEmail(wpcomUsername)
self?.logInInstead()
return
Expand Down Expand Up @@ -154,6 +165,11 @@ private extension AppleAuthenticator {
delegate?.showWPComLogin(loginFields: loginFields)
}

func show2FA() {
WordPressAuthenticator.track(.signupSocialToLogin, properties: ["source": "apple"])
delegate?.showApple2FA(loginFields: loginFields)
}

// MARK: - Helpers

func fullName(from components: PersonNameComponents?) -> String {
Expand Down
8 changes: 7 additions & 1 deletion WordPressAuthenticator/Signin/Login2FAViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,13 @@ class Login2FAViewController: LoginViewController, NUXKeyboardResponder, UITextF
GIDSignIn.sharedInstance().disconnect()

WordPressAuthenticator.track(.signedIn)
WordPressAuthenticator.track(.loginSocialSuccess)

var properties = [AnyHashable:Any]()
if let service = loginFields.meta.socialService?.rawValue {
properties["source"] = service
}

WordPressAuthenticator.track(.loginSocialSuccess, properties: properties)
}

/// Only allow digits in the 2FA text field
Expand Down
28 changes: 3 additions & 25 deletions WordPressAuthenticator/Signin/LoginEmailViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -394,13 +394,10 @@ open class LoginEmailViewController: LoginViewController, NUXKeyboardResponder {
if let vc = segue.destination as? LoginPrologueSignupMethodViewController {
vc.transitioningDelegate = self
vc.emailTapped = { [weak self] in
self?.performSegue(withIdentifier: NUXViewController.SegueIdentifier.showSigninV2.rawValue, sender: self)
self?.performSegue(withIdentifier: .showSigninV2, sender: self)
}
vc.googleTapped = { [weak self] in
self?.performSegue(withIdentifier: NUXViewController.SegueIdentifier.showGoogle.rawValue, sender: self)
}
vc.appleTapped = { [weak self] in
self?.appleTapped()
self?.performSegue(withIdentifier: .showGoogle, sender: self)
}
vc.modalPresentationStyle = .custom
}
Expand Down Expand Up @@ -493,25 +490,6 @@ open class LoginEmailViewController: LoginViewController, NUXKeyboardResponder {
}
}

private func appleTapped() {
AppleAuthenticator.sharedInstance.delegate = self
AppleAuthenticator.sharedInstance.showFrom(viewController: self)
}
}

// MARK: - AppleAuthenticatorDelegate

extension LoginEmailViewController: AppleAuthenticatorDelegate {

func showWPComLogin(loginFields: LoginFields) {
self.loginFields = loginFields
performSegue(withIdentifier: .showWPComLogin, sender: self)
}

func authFailedWithError(message: String) {
displayErrorAlert(message, sourceTag: .wpComSignupApple)
}

}

// MARK: - Google Sign In
Expand All @@ -529,7 +507,7 @@ extension LoginEmailViewController {

func needsMultifactorCode(forUserID userID: Int, andNonceInfo nonceInfo: SocialLogin2FANonceInfo) {
configureViewLoading(false)
googleNeedsMultifactorCode(forUserID: userID, andNonceInfo: nonceInfo)
socialNeedsMultifactorCode(forUserID: userID, andNonceInfo: nonceInfo)
}
}

Expand Down
Loading