@@ -27,7 +27,7 @@ public struct ParseLDAP<AuthenticatedUser: ParseUser>: ParseAuthentication {
27
27
/// Properly makes an authData dictionary with the required keys.
28
28
/// - parameter id: Required id.
29
29
/// - parameter password: Required password.
30
- /// - returns: Required authData dictionary.
30
+ /// - returns: authData dictionary.
31
31
func makeDictionary( id: String , // swiftlint:disable:this identifier_name
32
32
password: String ) -> [ String : String ] {
33
33
[ AuthenticationKeys . id. rawValue: id,
@@ -37,9 +37,8 @@ public struct ParseLDAP<AuthenticatedUser: ParseUser>: ParseAuthentication {
37
37
/// Verifies all mandatory keys are in authData.
38
38
/// - parameter authData: Dictionary containing key/values.
39
39
/// - 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 ,
43
42
authData [ AuthenticationKeys . password. rawValue] != nil else {
44
43
return false
45
44
}
@@ -67,22 +66,21 @@ public extension ParseLDAP {
67
66
options: API . Options = [ ] ,
68
67
callbackQueue: DispatchQueue = . main,
69
68
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)
74
74
}
75
75
76
- func login( authData: [ String : String ] ? ,
76
+ func login( authData: [ String : String ] ,
77
77
options: API . Options = [ ] ,
78
78
callbackQueue: DispatchQueue = . main,
79
79
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 {
84
81
callbackQueue. async {
85
- completion ( . failure( error) )
82
+ completion ( . failure( . init( code: . unknownError,
83
+ message: " Should have authData in consisting of keys \" id \" and \" token \" . " ) ) )
86
84
}
87
85
return
88
86
}
@@ -106,24 +104,22 @@ public extension ParseLDAP {
106
104
func loginPublisher( id: String , // swiftlint:disable:this identifier_name
107
105
password: String ,
108
106
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
+ }
111
113
}
112
114
113
115
@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 ] ,
115
117
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)
123
122
}
124
- return AuthenticatedUser . loginPublisher ( Self . __type,
125
- authData: authData,
126
- options: options)
127
123
}
128
124
129
125
#endif
@@ -151,12 +147,11 @@ public extension ParseLDAP {
151
147
completion: completion)
152
148
}
153
149
154
- func link( authData: [ String : String ] ? ,
150
+ func link( authData: [ String : String ] ,
155
151
options: API . Options = [ ] ,
156
152
callbackQueue: DispatchQueue = . main,
157
153
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 {
160
155
let error = ParseError ( code: . unknownError,
161
156
message: " Should have authData in consisting of keys \" id \" and \" token \" . " )
162
157
callbackQueue. async {
@@ -184,24 +179,22 @@ public extension ParseLDAP {
184
179
func linkPublisher( id: String , // swiftlint:disable:this identifier_name
185
180
password: String ,
186
181
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
+ }
189
188
}
190
189
191
190
@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 ] ,
193
192
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)
201
197
}
202
- return AuthenticatedUser . linkPublisher ( Self . __type,
203
- authData: authData,
204
- options: options)
205
198
}
206
199
207
200
#endif
0 commit comments