Skip to content

Commit 10fcb49

Browse files
Merge pull request #69 from woocommerce/issue/22-authentication
Implementing WordPress.com Authentication
2 parents c6087fc + aa5bedd commit 10fcb49

File tree

10 files changed

+660
-52
lines changed

10 files changed

+660
-52
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
## Build generated
66
build/
77
DerivedData/
8+
DerivedSources/
89

910
## Various settings
1011
*.pbxuser

Podfile

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ target 'WooCommerce' do
1616
# Automattic Libraries
1717
# ====================
1818
#
19-
pod 'Automattic-Tracks-iOS', :git => 'https://github.com/Automattic/Automattic-Tracks-iOS.git', :tag => '0.2.1'
20-
pod 'Gridicons', '0.14'
19+
pod 'Automattic-Tracks-iOS', :git => 'https://github.com/Automattic/Automattic-Tracks-iOS.git', :tag => '0.2.3'
20+
pod 'Gridicons', '0.15'
21+
pod 'WordPressAuthenticator', :git => 'https://github.com/wordpress-mobile/WordPressAuthenticator-iOS.git', :commit => '58ed623'
2122

2223
# External Libraries
2324
# ==================
2425
#
25-
pod 'Alamofire', '4.6.0'
26-
pod 'Crashlytics', '3.9.3'
26+
pod 'Crashlytics', '3.10.1'
2727

2828
end
2929

@@ -37,7 +37,7 @@ target 'Networking' do
3737
# External Libraries
3838
# ==================
3939
#
40-
pod 'Alamofire', '4.6.0'
40+
pod 'Alamofire', '4.7.2'
4141

4242
target 'NetworkingTests' do
4343
inherit! :search_paths

Podfile.lock

Lines changed: 118 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,153 @@
11
PODS:
2-
- Alamofire (4.6.0)
3-
- Automattic-Tracks-iOS (0.2.0):
4-
- CocoaLumberjack (~> 3.2.0)
2+
- 1PasswordExtension (1.8.5)
3+
- AFNetworking (3.2.1):
4+
- AFNetworking/NSURLSession (= 3.2.1)
5+
- AFNetworking/Reachability (= 3.2.1)
6+
- AFNetworking/Security (= 3.2.1)
7+
- AFNetworking/Serialization (= 3.2.1)
8+
- AFNetworking/UIKit (= 3.2.1)
9+
- AFNetworking/NSURLSession (3.2.1):
10+
- AFNetworking/Reachability
11+
- AFNetworking/Security
12+
- AFNetworking/Serialization
13+
- AFNetworking/Reachability (3.2.1)
14+
- AFNetworking/Security (3.2.1)
15+
- AFNetworking/Serialization (3.2.1)
16+
- AFNetworking/UIKit (3.2.1):
17+
- AFNetworking/NSURLSession
18+
- Alamofire (4.7.2)
19+
- Automattic-Tracks-iOS (0.2.3):
20+
- CocoaLumberjack (~> 3.4.1)
521
- Reachability (~> 3.1)
622
- UIDeviceIdentifier (~> 0.4)
7-
- CocoaLumberjack (3.2.1):
8-
- CocoaLumberjack/Default (= 3.2.1)
9-
- CocoaLumberjack/Extensions (= 3.2.1)
10-
- CocoaLumberjack/Default (3.2.1)
11-
- CocoaLumberjack/Extensions (3.2.1):
23+
- CocoaLumberjack (3.4.2):
24+
- CocoaLumberjack/Default (= 3.4.2)
25+
- CocoaLumberjack/Extensions (= 3.4.2)
26+
- CocoaLumberjack/Default (3.4.2)
27+
- CocoaLumberjack/Extensions (3.4.2):
1228
- CocoaLumberjack/Default
13-
- Crashlytics (3.9.3):
14-
- Fabric (~> 1.7.2)
29+
- Crashlytics (3.10.1):
30+
- Fabric (~> 1.7.5)
1531
- Fabric (1.7.6)
16-
- Gridicons (0.14)
32+
- FormatterKit/Resources (1.8.2)
33+
- FormatterKit/TimeIntervalFormatter (1.8.2):
34+
- FormatterKit/Resources
35+
- GoogleSignInRepacked (4.1.2):
36+
- "GoogleToolboxForMac/NSDictionary+URLArguments (~> 2.1)"
37+
- "GoogleToolboxForMac/NSString+URLArguments (~> 2.1)"
38+
- GoogleToolboxForMac/DebugUtils (2.1.4):
39+
- GoogleToolboxForMac/Defines (= 2.1.4)
40+
- GoogleToolboxForMac/Defines (2.1.4)
41+
- "GoogleToolboxForMac/NSDictionary+URLArguments (2.1.4)":
42+
- GoogleToolboxForMac/DebugUtils (= 2.1.4)
43+
- GoogleToolboxForMac/Defines (= 2.1.4)
44+
- "GoogleToolboxForMac/NSString+URLArguments (= 2.1.4)"
45+
- "GoogleToolboxForMac/NSString+URLArguments (2.1.4)"
46+
- Gridicons (0.15)
47+
- lottie-ios (2.5.0)
48+
- NSObject-SafeExpectations (0.0.3)
49+
- "NSURL+IDN (0.3)"
1750
- Reachability (3.2)
51+
- SVProgressHUD (2.2.5)
1852
- UIDeviceIdentifier (0.5.0)
53+
- WordPressAuthenticator (1.0.0):
54+
- 1PasswordExtension (= 1.8.5)
55+
- Alamofire (= 4.7.2)
56+
- CocoaLumberjack (= 3.4.2)
57+
- GoogleSignInRepacked (= 4.1.2)
58+
- Gridicons (~> 0.15)
59+
- lottie-ios (= 2.5.0)
60+
- "NSURL+IDN (= 0.3)"
61+
- SVProgressHUD (= 2.2.5)
62+
- UIDeviceIdentifier (~> 0.4)
63+
- WordPressKit (~> 1.0)
64+
- WordPressShared (~> 1.0)
65+
- WordPressUI (~> 1.0)
66+
- wpxmlrpc (~> 0.8)
67+
- WordPressKit (1.0.5):
68+
- AFNetworking (= 3.2.1)
69+
- Alamofire (= 4.7.2)
70+
- CocoaLumberjack (= 3.4.2)
71+
- NSObject-SafeExpectations (= 0.0.3)
72+
- UIDeviceIdentifier (~> 0.4)
73+
- WordPressShared (= 1.0.3)
74+
- wpxmlrpc (= 0.8.3)
75+
- WordPressShared (1.0.3):
76+
- CocoaLumberjack (~> 3.4)
77+
- FormatterKit/TimeIntervalFormatter (= 1.8.2)
78+
- WordPressUI (1.0.2)
79+
- wpxmlrpc (0.8.3)
1980

2081
DEPENDENCIES:
21-
- Alamofire (= 4.6.0)
22-
- Automattic-Tracks-iOS (from `https://github.com/Automattic/Automattic-Tracks-iOS.git`, tag `0.2.1`)
23-
- Crashlytics (= 3.9.3)
24-
- Gridicons (= 0.14)
82+
- Alamofire (= 4.7.2)
83+
- Automattic-Tracks-iOS (from `https://github.com/Automattic/Automattic-Tracks-iOS.git`, tag `0.2.3`)
84+
- Crashlytics (= 3.10.1)
85+
- Gridicons (= 0.15)
86+
- WordPressAuthenticator (from `https://github.com/wordpress-mobile/WordPressAuthenticator-iOS.git`, commit `58ed623`)
2587

2688
SPEC REPOS:
2789
https://github.com/cocoapods/specs.git:
90+
- 1PasswordExtension
91+
- AFNetworking
2892
- Alamofire
2993
- CocoaLumberjack
3094
- Crashlytics
3195
- Fabric
96+
- FormatterKit
97+
- GoogleSignInRepacked
98+
- GoogleToolboxForMac
3299
- Gridicons
100+
- lottie-ios
101+
- NSObject-SafeExpectations
102+
- "NSURL+IDN"
33103
- Reachability
104+
- SVProgressHUD
34105
- UIDeviceIdentifier
106+
- WordPressKit
107+
- WordPressShared
108+
- WordPressUI
109+
- wpxmlrpc
35110

36111
EXTERNAL SOURCES:
37112
Automattic-Tracks-iOS:
38113
:git: https://github.com/Automattic/Automattic-Tracks-iOS.git
39-
:tag: 0.2.1
114+
:tag: 0.2.3
115+
WordPressAuthenticator:
116+
:commit: 58ed623
117+
:git: https://github.com/wordpress-mobile/WordPressAuthenticator-iOS.git
40118

41119
CHECKOUT OPTIONS:
42120
Automattic-Tracks-iOS:
43121
:git: https://github.com/Automattic/Automattic-Tracks-iOS.git
44-
:tag: 0.2.1
122+
:tag: 0.2.3
123+
WordPressAuthenticator:
124+
:commit: 58ed623
125+
:git: https://github.com/wordpress-mobile/WordPressAuthenticator-iOS.git
45126

46127
SPEC CHECKSUMS:
47-
Alamofire: f41a599bd63041760b26d393ec1069d9d7b917f4
48-
Automattic-Tracks-iOS: edc4365d31602490af88dbed181b0b666cbdcf75
49-
CocoaLumberjack: 2800c03334042fe80589423c8d80e582dcaec482
50-
Crashlytics: dbb07d01876c171c5ccbdf7826410380189e452c
128+
1PasswordExtension: 0e95bdea64ec8ff2f4f693be5467a09fac42a83d
129+
AFNetworking: b6f891fdfaed196b46c7a83cf209e09697b94057
130+
Alamofire: e4fa87002c137ba2d8d634d2c51fabcda0d5c223
131+
Automattic-Tracks-iOS: d8c6c6c1351b1905a73e45f431b15598d71963b5
132+
CocoaLumberjack: db7cc9e464771f12054c22ff6947c5a58d43a0fd
133+
Crashlytics: aee1a064cbbf99b32efa3f056a5f458d846bc8ff
51134
Fabric: f8d42c893bb187326a7968b62abe55c36a987a46
52-
Gridicons: 558073b1ff34092a49336ee0955ad97d2ef799f0
135+
FormatterKit: 4b8f29acc9b872d5d12a63efb560661e8f2e1b98
136+
GoogleSignInRepacked: d357702618c555f38923576924661325eb1ef22b
137+
GoogleToolboxForMac: 91c824d21e85b31c2aae9bb011c5027c9b4e738f
138+
Gridicons: 0e5e76ad9fc6f7cbc3da137a9751ef516c5aef73
139+
lottie-ios: d699fdee68d7b63e721d949388b015fef1aaa4ac
140+
NSObject-SafeExpectations: b989b68a8a9b7b9f2b264a8b52ba9d7aab8f3129
141+
"NSURL+IDN": 82355a0afd532fe1de08f6417c134b49b1a1c4b3
53142
Reachability: 33e18b67625424e47b6cde6d202dce689ad7af96
143+
SVProgressHUD: 1428aafac632c1f86f62aa4243ec12008d7a51d6
54144
UIDeviceIdentifier: a959a6d4f51036b4180dd31fb26483a820f1cc46
145+
WordPressAuthenticator: 4c802aa18781858253daf984f873e3efe0dac7ef
146+
WordPressKit: afe6d2c23db6d4f110638c25e86b029e899ffc34
147+
WordPressShared: b8e910d8133a54e9452ab7bd9d8e27e78dc2f5ba
148+
WordPressUI: 70bceaff582bdd6fd8f3ed67aaa200e72fce245d
149+
wpxmlrpc: bfc572f62ce7ee897f6f38b098d2ba08732ecef4
55150

56-
PODFILE CHECKSUM: 08010c97100223abdf7a351cb2a8b1bdfd158453
151+
PODFILE CHECKSUM: 9049dbd0cd98e7a655f9dafc27c3eb744ac72fc5
57152

58153
COCOAPODS: 1.5.2

WooCommerce/Classes/AppDelegate.swift

Lines changed: 93 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,59 @@
11
import UIKit
22
import CoreData
3+
import CocoaLumberjack
4+
import WordPressKit
5+
import WordPressAuthenticator
36

47

58
// MARK: - Woo's App Delegate!
69
//
710
@UIApplicationMain
811
class AppDelegate: UIResponder, UIApplicationDelegate {
912

10-
///
13+
/// AppDelegate's Instance
1114
///
1215
static var shared: AppDelegate {
1316
return UIApplication.shared.delegate as! AppDelegate
1417
}
1518

16-
///
19+
/// Main Window
1720
///
1821
var window: UIWindow?
1922

23+
/// WordPressAuthenticator Wrapper
24+
///
25+
let authenticationManager = AuthenticationManager()
26+
27+
28+
2029
func application(_ application: UIApplication, willFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey : Any]? = nil) -> Bool {
21-
customizeAppearance()
30+
31+
// Setup the Interface!
32+
setupMainWindow()
33+
setupInterfaceAppearance()
34+
35+
// Setup Components
36+
setupAuthenticationManager()
37+
setupLogLevel(.verbose)
38+
39+
// Display the Authentication UI
40+
displayAuthenticatorIfNeeded()
41+
2242
return true
2343
}
2444

2545
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
26-
// Override point for customization after application launch.
2746
return true
2847
}
2948

49+
func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey: Any] = [:]) -> Bool {
50+
guard let rootViewController = window?.rootViewController else {
51+
fatalError()
52+
}
53+
54+
return authenticationManager.handleAuthenticationUrl(url, options: options, rootViewController: rootViewController)
55+
}
56+
3057
func applicationWillResignActive(_ application: UIApplication) {
3158
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
3259
// Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
@@ -48,12 +75,73 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
4875
func applicationWillTerminate(_ application: UIApplication) {
4976

5077
}
78+
}
79+
80+
81+
// MARK: - Initialization Methods
82+
//
83+
private extension AppDelegate {
5184

52-
private func customizeAppearance() {
85+
/// Sets up the main UIWindow instance.
86+
///
87+
func setupMainWindow() {
88+
window?.makeKeyAndVisible()
89+
}
90+
91+
/// Sets up WooCommerce's UIAppearance.
92+
///
93+
func setupInterfaceAppearance() {
5394
UINavigationBar.appearance().barTintColor = StyleManager.wooCommerceBrandColor
5495
UINavigationBar.appearance().titleTextAttributes = [.foregroundColor: UIColor.white]
5596
UINavigationBar.appearance().isTranslucent = false
5697
UINavigationBar.appearance().tintColor = .white
5798
UIApplication.shared.statusBarStyle = .lightContent
5899
}
100+
101+
/// Sets up the WordPress Authenticator.
102+
///
103+
func setupAuthenticationManager() {
104+
authenticationManager.initialize()
105+
}
106+
107+
func setupLogLevel(_ level: DDLogLevel) {
108+
let rawLevel = Int32(level.rawValue)
109+
110+
WPSharedSetLoggingLevel(rawLevel)
111+
WPAuthenticatorSetLoggingLevel(rawLevel)
112+
WPKitSetLoggingLevel(rawLevel)
113+
}
114+
}
115+
116+
117+
// MARK: - Authentication Methods
118+
//
119+
private extension AppDelegate {
120+
121+
/// Whenever there is no default WordPress.com Account, let's display the Authentication UI.
122+
///
123+
func displayAuthenticatorIfNeeded() {
124+
guard needsAuthentication else {
125+
return
126+
}
127+
128+
displayAuthenticator()
129+
}
130+
131+
/// Displays the WordPress.com Authentication UI.
132+
///
133+
func displayAuthenticator() {
134+
guard let rootViewController = window?.rootViewController else {
135+
fatalError()
136+
}
137+
138+
authenticationManager.showLogin(from: rootViewController)
139+
}
140+
141+
/// Indicates if there's a default WordPress.com account.
142+
///
143+
var needsAuthentication: Bool {
144+
// TODO: Wire Me! >> AccountStore!
145+
return true
146+
}
59147
}

0 commit comments

Comments
 (0)