@@ -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