Skip to content

Commit e1137fc

Browse files
authored
Add more documentation (#96)
* Add more documentation * Debug docs are inherited * Update .codecov.yml * use value types in docs * Centralize internal deleteKeychain method * minor internal updates to anonymous login and authentication * nits * Further simplify ParseAnonymous. Fixed a bug in ParseACLTests where the url mocker wasn't being removed and can cause issues with tests that run after. * Improve codecov or authentication tests * More codecov for Authentication
1 parent a99bf31 commit e1137fc

18 files changed

+696
-212
lines changed

.codecov.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ coverage:
55
status:
66
patch:
77
default:
8-
target: 77
8+
target: auto
99
changes: false
1010
project:
1111
default:

Sources/ParseSwift/Authentication/3rd Party/ParseApple.swift

Lines changed: 29 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public struct ParseApple<AuthenticatedUser: ParseUser>: ParseAuthentication {
2828
/// Properly makes an authData dictionary with the required keys.
2929
/// - parameter user: Required id for the user.
3030
/// - parameter identityToken: Required identity token for the user.
31-
/// - returns: Required authData dictionary.
31+
/// - returns: authData dictionary.
3232
/// - throws: `ParseError` if the `identityToken` can't be converted
3333
/// to a string.
3434
func makeDictionary(user: String,
@@ -43,9 +43,8 @@ public struct ParseApple<AuthenticatedUser: ParseUser>: ParseAuthentication {
4343
/// Verifies all mandatory keys are in authData.
4444
/// - parameter authData: Dictionary containing key/values.
4545
/// - returns: `true` if all the mandatory keys are present, `false` otherwise.
46-
func verifyMandatoryKeys(authData: [String: String]?) -> Bool {
47-
guard let authData = authData,
48-
authData[AuthenticationKeys.id.rawValue] != nil,
46+
func verifyMandatoryKeys(authData: [String: String]) -> Bool {
47+
guard authData[AuthenticationKeys.id.rawValue] != nil,
4948
authData[AuthenticationKeys.token.rawValue] != nil else {
5049
return false
5150
}
@@ -87,16 +86,14 @@ public extension ParseApple {
8786
completion: completion)
8887
}
8988

90-
func login(authData: [String: String]?,
89+
func login(authData: [String: String],
9190
options: API.Options = [],
9291
callbackQueue: DispatchQueue = .main,
9392
completion: @escaping (Result<AuthenticatedUser, ParseError>) -> Void) {
94-
guard AuthenticationKeys.id.verifyMandatoryKeys(authData: authData),
95-
let authData = authData else {
96-
let error = ParseError(code: .unknownError,
97-
message: "Should have authData in consisting of keys \"id\" and \"token\".")
93+
guard AuthenticationKeys.id.verifyMandatoryKeys(authData: authData) else {
9894
callbackQueue.async {
99-
completion(.failure(error))
95+
completion(.failure(.init(code: .unknownError,
96+
message: "Should have authData in consisting of keys \"id\" and \"token\".")))
10097
}
10198
return
10299
}
@@ -120,30 +117,22 @@ public extension ParseApple {
120117
func loginPublisher(user: String,
121118
identityToken: Data,
122119
options: API.Options = []) -> Future<AuthenticatedUser, ParseError> {
123-
guard let appleAuthData = try? AuthenticationKeys.id.makeDictionary(user: user, identityToken: identityToken) else {
124-
return Future { promise in
125-
promise(.failure(.init(code: .unknownError,
126-
message: "Couldn't create authData.")))
127-
}
120+
Future { promise in
121+
self.login(user: user,
122+
identityToken: identityToken,
123+
options: options,
124+
completion: promise)
128125
}
129-
return loginPublisher(authData: appleAuthData,
130-
options: options)
131126
}
132127

133128
@available(macOS 10.15, iOS 13.0, macCatalyst 13.0, watchOS 6.0, tvOS 13.0, *)
134-
func loginPublisher(authData: [String: String]?,
129+
func loginPublisher(authData: [String: String],
135130
options: API.Options = []) -> Future<AuthenticatedUser, ParseError> {
136-
guard AuthenticationKeys.id.verifyMandatoryKeys(authData: authData),
137-
let authData = authData else {
138-
let error = ParseError(code: .unknownError,
139-
message: "Should have authData in consisting of keys \"id\" and \"token\".")
140-
return Future { promise in
141-
promise(.failure(error))
142-
}
131+
Future { promise in
132+
self.login(authData: authData,
133+
options: options,
134+
completion: promise)
143135
}
144-
return AuthenticatedUser.loginPublisher(Self.__type,
145-
authData: authData,
146-
options: options)
147136
}
148137

149138
#endif
@@ -178,12 +167,11 @@ public extension ParseApple {
178167
completion: completion)
179168
}
180169

181-
func link(authData: [String: String]?,
170+
func link(authData: [String: String],
182171
options: API.Options = [],
183172
callbackQueue: DispatchQueue = .main,
184173
completion: @escaping (Result<AuthenticatedUser, ParseError>) -> Void) {
185-
guard AuthenticationKeys.id.verifyMandatoryKeys(authData: authData),
186-
let authData = authData else {
174+
guard AuthenticationKeys.id.verifyMandatoryKeys(authData: authData) else {
187175
let error = ParseError(code: .unknownError,
188176
message: "Should have authData in consisting of keys \"id\" and \"token\".")
189177
callbackQueue.async {
@@ -211,30 +199,22 @@ public extension ParseApple {
211199
func linkPublisher(user: String,
212200
identityToken: Data,
213201
options: API.Options = []) -> Future<AuthenticatedUser, ParseError> {
214-
guard let appleAuthData = try? AuthenticationKeys.id.makeDictionary(user: user, identityToken: identityToken) else {
215-
return Future { promise in
216-
promise(.failure(.init(code: .unknownError,
217-
message: "Couldn't create authData.")))
218-
}
202+
Future { promise in
203+
self.link(user: user,
204+
identityToken: identityToken,
205+
options: options,
206+
completion: promise)
219207
}
220-
return linkPublisher(authData: appleAuthData,
221-
options: options)
222208
}
223209

224210
@available(macOS 10.15, iOS 13.0, macCatalyst 13.0, watchOS 6.0, tvOS 13.0, *)
225-
func linkPublisher(authData: [String: String]?,
211+
func linkPublisher(authData: [String: String],
226212
options: API.Options = []) -> Future<AuthenticatedUser, ParseError> {
227-
guard AuthenticationKeys.id.verifyMandatoryKeys(authData: authData),
228-
let authData = authData else {
229-
let error = ParseError(code: .unknownError,
230-
message: "Should have authData in consisting of keys \"id\" and \"token\".")
231-
return Future { promise in
232-
promise(.failure(error))
233-
}
213+
Future { promise in
214+
self.link(authData: authData,
215+
options: options,
216+
completion: promise)
234217
}
235-
return AuthenticatedUser.linkPublisher(Self.__type,
236-
authData: authData,
237-
options: options)
238218
}
239219

240220
#endif

Sources/ParseSwift/Authentication/3rd Party/ParseLDAP.swift

Lines changed: 36 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public struct ParseLDAP<AuthenticatedUser: ParseUser>: ParseAuthentication {
2727
/// Properly makes an authData dictionary with the required keys.
2828
/// - parameter id: Required id.
2929
/// - parameter password: Required password.
30-
/// - returns: Required authData dictionary.
30+
/// - returns: authData dictionary.
3131
func makeDictionary(id: String, // swiftlint:disable:this identifier_name
3232
password: String) -> [String: String] {
3333
[AuthenticationKeys.id.rawValue: id,
@@ -37,9 +37,8 @@ public struct ParseLDAP<AuthenticatedUser: ParseUser>: ParseAuthentication {
3737
/// Verifies all mandatory keys are in authData.
3838
/// - parameter authData: Dictionary containing key/values.
3939
/// - returns: `true` if all the mandatory keys are present, `false` otherwise.
40-
func verifyMandatoryKeys(authData: [String: String]?) -> Bool {
41-
guard let authData = authData,
42-
authData[AuthenticationKeys.id.rawValue] != nil,
40+
func verifyMandatoryKeys(authData: [String: String]) -> Bool {
41+
guard authData[AuthenticationKeys.id.rawValue] != nil,
4342
authData[AuthenticationKeys.password.rawValue] != nil else {
4443
return false
4544
}
@@ -67,22 +66,21 @@ public extension ParseLDAP {
6766
options: API.Options = [],
6867
callbackQueue: DispatchQueue = .main,
6968
completion: @escaping (Result<AuthenticatedUser, ParseError>) -> Void) {
70-
login(authData: AuthenticationKeys.id.makeDictionary(id: id, password: password),
71-
options: options,
72-
callbackQueue: callbackQueue,
73-
completion: completion)
69+
login(authData: AuthenticationKeys.id.makeDictionary(id: id,
70+
password: password),
71+
options: options,
72+
callbackQueue: callbackQueue,
73+
completion: completion)
7474
}
7575

76-
func login(authData: [String: String]?,
76+
func login(authData: [String: String],
7777
options: API.Options = [],
7878
callbackQueue: DispatchQueue = .main,
7979
completion: @escaping (Result<AuthenticatedUser, ParseError>) -> Void) {
80-
guard AuthenticationKeys.id.verifyMandatoryKeys(authData: authData),
81-
let authData = authData else {
82-
let error = ParseError(code: .unknownError,
83-
message: "Should have authData in consisting of keys \"id\" and \"token\".")
80+
guard AuthenticationKeys.id.verifyMandatoryKeys(authData: authData) else {
8481
callbackQueue.async {
85-
completion(.failure(error))
82+
completion(.failure(.init(code: .unknownError,
83+
message: "Should have authData in consisting of keys \"id\" and \"token\".")))
8684
}
8785
return
8886
}
@@ -106,24 +104,22 @@ public extension ParseLDAP {
106104
func loginPublisher(id: String, // swiftlint:disable:this identifier_name
107105
password: String,
108106
options: API.Options = []) -> Future<AuthenticatedUser, ParseError> {
109-
loginPublisher(authData: AuthenticationKeys.id.makeDictionary(id: id, password: password),
110-
options: options)
107+
Future { promise in
108+
self.login(id: id,
109+
password: password,
110+
options: options,
111+
completion: promise)
112+
}
111113
}
112114

113115
@available(macOS 10.15, iOS 13.0, macCatalyst 13.0, watchOS 6.0, tvOS 13.0, *)
114-
func loginPublisher(authData: [String: String]?,
116+
func loginPublisher(authData: [String: String],
115117
options: API.Options = []) -> Future<AuthenticatedUser, ParseError> {
116-
guard AuthenticationKeys.id.verifyMandatoryKeys(authData: authData),
117-
let authData = authData else {
118-
let error = ParseError(code: .unknownError,
119-
message: "Should have authData in consisting of keys \"id\" and \"token\".")
120-
return Future { promise in
121-
promise(.failure(error))
122-
}
118+
Future { promise in
119+
self.login(authData: authData,
120+
options: options,
121+
completion: promise)
123122
}
124-
return AuthenticatedUser.loginPublisher(Self.__type,
125-
authData: authData,
126-
options: options)
127123
}
128124

129125
#endif
@@ -151,12 +147,11 @@ public extension ParseLDAP {
151147
completion: completion)
152148
}
153149

154-
func link(authData: [String: String]?,
150+
func link(authData: [String: String],
155151
options: API.Options = [],
156152
callbackQueue: DispatchQueue = .main,
157153
completion: @escaping (Result<AuthenticatedUser, ParseError>) -> Void) {
158-
guard AuthenticationKeys.id.verifyMandatoryKeys(authData: authData),
159-
let authData = authData else {
154+
guard AuthenticationKeys.id.verifyMandatoryKeys(authData: authData) else {
160155
let error = ParseError(code: .unknownError,
161156
message: "Should have authData in consisting of keys \"id\" and \"token\".")
162157
callbackQueue.async {
@@ -184,24 +179,22 @@ public extension ParseLDAP {
184179
func linkPublisher(id: String, // swiftlint:disable:this identifier_name
185180
password: String,
186181
options: API.Options = []) -> Future<AuthenticatedUser, ParseError> {
187-
linkPublisher(authData: AuthenticationKeys.id.makeDictionary(id: id, password: password),
188-
options: options)
182+
Future { promise in
183+
self.link(id: id,
184+
password: password,
185+
options: options,
186+
completion: promise)
187+
}
189188
}
190189

191190
@available(macOS 10.15, iOS 13.0, macCatalyst 13.0, watchOS 6.0, tvOS 13.0, *)
192-
func linkPublisher(authData: [String: String]?,
191+
func linkPublisher(authData: [String: String],
193192
options: API.Options = []) -> Future<AuthenticatedUser, ParseError> {
194-
guard AuthenticationKeys.id.verifyMandatoryKeys(authData: authData),
195-
let authData = authData else {
196-
let error = ParseError(code: .unknownError,
197-
message: "Should have authData in consisting of keys \"id\" and \"token\".")
198-
return Future { promise in
199-
promise(.failure(error))
200-
}
193+
Future { promise in
194+
self.link(authData: authData,
195+
options: options,
196+
completion: promise)
201197
}
202-
return AuthenticatedUser.linkPublisher(Self.__type,
203-
authData: authData,
204-
options: options)
205198
}
206199

207200
#endif

0 commit comments

Comments
 (0)