Skip to content

Commit e53c4d5

Browse files
authored
Ensuring service credentials can be removed from the Keychain (#196)
Fixes #191
1 parent d2c8904 commit e53c4d5

File tree

8 files changed

+25
-20
lines changed

8 files changed

+25
-20
lines changed

Loop.xcodeproj/project.pbxproj

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -470,23 +470,18 @@
470470
43757D131C06F26C00910CB9 /* Models */ = {
471471
isa = PBXGroup;
472472
children = (
473+
43880F961D9D8052009061A8 /* ServiceAuthentication */,
473474
43DE92601C555C26001FFDE1 /* AbsorptionTimeType+CarbKit.swift */,
474-
438849EB1D29EC34003B3F23 /* AmplitudeService.swift */,
475475
4331E0791C85650D00FBE832 /* ChartAxisValueDoubleLog.swift */,
476476
43F41C321D3A17AA00C11ED6 /* ChartAxisValueDoubleUnit.swift */,
477477
43E397A21D56B9E40028E321 /* Glucose.swift */,
478478
4D5B7A4A1D457CCA00796CA9 /* GlucoseG4.swift */,
479479
436FACED1D0BA636004E2427 /* InsulinDataSource.swift */,
480480
436A0DA41D236A2A00104B24 /* LoopError.swift */,
481-
438849ED1D2A1EBB003B3F23 /* MLabService.swift */,
482481
430DA58F1D4B0E4C0097D1CA /* MySentryPumpStatusMessageBody.swift */,
483-
438849E91D297CB6003B3F23 /* NightscoutService.swift */,
484482
438D42F81D7C88BC003244B0 /* PredictionInputEffect.swift */,
485483
43EA28611D517E42001BC233 /* SensorDisplayable.swift */,
486-
437CCADF1D285C7B0075D2C3 /* ServiceAuthentication.swift */,
487-
434F54601D28859B002A9274 /* ServiceCredential.swift */,
488484
43C418B41CE0575200405B6A /* ShareGlucose+GlucoseKit.swift */,
489-
434F545E1D288345002A9274 /* ShareService.swift */,
490485
4328E0311CFC068900E199AA /* WatchContext+LoopKit.swift */,
491486
);
492487
path = Models;
@@ -536,6 +531,19 @@
536531
path = Loop;
537532
sourceTree = "<group>";
538533
};
534+
43880F961D9D8052009061A8 /* ServiceAuthentication */ = {
535+
isa = PBXGroup;
536+
children = (
537+
438849EB1D29EC34003B3F23 /* AmplitudeService.swift */,
538+
438849ED1D2A1EBB003B3F23 /* MLabService.swift */,
539+
438849E91D297CB6003B3F23 /* NightscoutService.swift */,
540+
437CCADF1D285C7B0075D2C3 /* ServiceAuthentication.swift */,
541+
434F54601D28859B002A9274 /* ServiceCredential.swift */,
542+
434F545E1D288345002A9274 /* ShareService.swift */,
543+
);
544+
path = ServiceAuthentication;
545+
sourceTree = "<group>";
546+
};
539547
43A943731B926B7B0051FA24 /* WatchApp */ = {
540548
isa = PBXGroup;
541549
children = (

Loop/Models/AmplitudeService.swift renamed to Loop/Models/ServiceAuthentication/AmplitudeService.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,11 @@ struct AmplitudeService: ServiceAuthentication {
3535
return credentials[0].value
3636
}
3737

38-
var isAuthorized: Bool = false
38+
var isAuthorized: Bool = true
3939

4040
mutating func verify(_ completion: @escaping (_ success: Bool, _ error: Error?) -> Void) {
4141
guard let APIKey = APIKey else {
42+
isAuthorized = false
4243
completion(false, nil)
4344
return
4445
}

Loop/Models/MLabService.swift renamed to Loop/Models/ServiceAuthentication/MLabService.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ struct MLabService: ServiceAuthentication {
6262
error = LoopError.connectionError
6363
}
6464

65-
completion(error == nil, error)
65+
completion(true, error)
6666
}).resume()
6767
}
6868

Loop/Models/NightscoutService.swift renamed to Loop/Models/ServiceAuthentication/NightscoutService.swift

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,21 +58,18 @@ struct NightscoutService: ServiceAuthentication {
5858
return credentials[1].value
5959
}
6060

61-
var isAuthorized: Bool = false
61+
var isAuthorized: Bool = true
6262

6363
mutating func verify(_ completion: @escaping (_ success: Bool, _ error: Error?) -> Void) {
6464
guard let siteURL = siteURL, let APISecret = APISecret else {
65+
isAuthorized = false
6566
completion(false, nil)
6667
return
6768
}
6869

6970
let uploader = NightscoutUploader(siteURL: siteURL, APISecret: APISecret)
7071
uploader.checkAuth { (error) in
71-
if let error = error {
72-
completion(false, error)
73-
} else {
74-
completion(true, nil)
75-
}
72+
completion(true, error)
7673
}
7774
self.uploader = uploader
7875
}

Loop/View Controllers/AuthenticationViewController.swift

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@ final class AuthenticationViewController<T: ServiceAuthentication>: UITableViewC
3737
self.navigationItem.hidesBackButton = false
3838
})
3939

40+
if let error = error {
41+
self.presentAlertController(with: error)
42+
}
43+
4044
if success {
4145
self.state = .authorized
4246
} else {
43-
if let error = error {
44-
self.presentAlertController(with: error)
45-
}
46-
4747
self.state = .unauthorized
4848
}
4949
}
@@ -179,14 +179,13 @@ final class AuthenticationViewController<T: ServiceAuthentication>: UITableViewC
179179
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
180180
if textField.returnKeyType == .done {
181181
textField.resignFirstResponder()
182+
validate()
182183
} else {
183184
let point = tableView.convert(textField.frame.origin, from: textField.superview)
184185
if let indexPath = tableView.indexPathForRow(at: point),
185186
let cell = tableView.cellForRow(at: IndexPath(row: indexPath.row + 1, section: indexPath.section)) as? AuthenticationTableViewCell
186187
{
187188
cell.textField.becomeFirstResponder()
188-
189-
validate()
190189
}
191190
}
192191

0 commit comments

Comments
 (0)