@@ -28,7 +28,7 @@ public struct ParseFacebook<AuthenticatedUser: ParseUser>: ParseAuthentication {
2828
2929 enum CodingKeys : String , CodingKey { // swiftlint:disable:this nesting
3030 case id // swiftlint:disable:this identifier_name
31- case token
31+ case authenticationToken = " token "
3232 case accessToken = " access_token "
3333 case expirationDate = " expiration_date "
3434 }
@@ -37,16 +37,21 @@ public struct ParseFacebook<AuthenticatedUser: ParseUser>: ParseAuthentication {
3737 /// - parameter userId: Required id for the user.
3838 /// - parameter authenticationToken: Required identity token for Facebook limited login.
3939 /// - parameter accessToken: Required identity token for Facebook graph API.
40- /// - parameter expirationDate: Required expiration data for Facebook login.
40+ /// - parameter expiresIn: Optional expiration in seconds for Facebook login.
4141 /// - returns: authData dictionary.
4242 func makeDictionary( userId: String ,
4343 accessToken: String ? ,
4444 authenticationToken: String ? ,
45- expirationDate: Date ) -> [ String : String ] {
46-
47- let dateString = ParseCoding . dateFormatter. string ( from: expirationDate)
48- var returnDictionary = [ AuthenticationKeys . id. rawValue: userId,
49- AuthenticationKeys . expirationDate. rawValue: dateString]
45+ expiresIn: Int ? = nil ) -> [ String : String ] {
46+
47+ var returnDictionary = [ AuthenticationKeys . id. rawValue: userId]
48+ if let expiresIn = expiresIn,
49+ let expirationDate = Calendar . current. date ( byAdding: . second,
50+ value: expiresIn,
51+ to: Date ( ) ) {
52+ let dateString = ParseCoding . dateFormatter. string ( from: expirationDate)
53+ returnDictionary [ AuthenticationKeys . expirationDate. rawValue] = dateString
54+ }
5055
5156 if let accessToken = accessToken {
5257 returnDictionary [ AuthenticationKeys . accessToken. rawValue] = accessToken
@@ -60,8 +65,7 @@ public struct ParseFacebook<AuthenticatedUser: ParseUser>: ParseAuthentication {
6065 /// - parameter authData: Dictionary containing key/values.
6166 /// - returns: `true` if all the mandatory keys are present, `false` otherwise.
6267 func verifyMandatoryKeys( authData: [ String : String ] ) -> Bool {
63- guard authData [ AuthenticationKeys . id. rawValue] != nil ,
64- authData [ AuthenticationKeys . expirationDate. rawValue] != nil else {
68+ guard authData [ AuthenticationKeys . id. rawValue] != nil else {
6569 return false
6670 }
6771
@@ -87,22 +91,22 @@ public extension ParseFacebook {
8791 Login a `ParseUser` *asynchronously* using Facebook authentication for limited login.
8892 - parameter userId: The `Facebook userId` from `FacebookSDK`.
8993 - parameter authenticationToken: The `authenticationToken` from `FacebookSDK`.
90- - parameter expirationDate: Required expiration data for Facebook login.
94+ - parameter expiresIn: Optional expiration in seconds for Facebook login.
9195 - parameter options: A set of header options sent to the server. Defaults to an empty set.
9296 - parameter callbackQueue: The queue to return to after completion. Default value of .main.
9397 - parameter completion: The block to execute.
9498 */
9599 func login( userId: String ,
96100 authenticationToken: String ,
97- expirationDate : Date ,
101+ expiresIn : Int ? = nil ,
98102 options: API . Options = [ ] ,
99103 callbackQueue: DispatchQueue = . main,
100104 completion: @escaping ( Result < AuthenticatedUser , ParseError > ) -> Void ) {
101105
102106 let facebookAuthData = AuthenticationKeys . id
103107 . makeDictionary ( userId: userId, accessToken: nil ,
104108 authenticationToken: authenticationToken,
105- expirationDate : expirationDate )
109+ expiresIn : expiresIn )
106110 login ( authData: facebookAuthData,
107111 options: options,
108112 callbackQueue: callbackQueue,
@@ -113,14 +117,14 @@ public extension ParseFacebook {
113117 Login a `ParseUser` *asynchronously* using Facebook authentication for graph API login.
114118 - parameter userId: The `Facebook userId` from `FacebookSDK`.
115119 - parameter accessToken: The `accessToken` from `FacebookSDK`.
116- - parameter expirationDate: Required expiration data for Facebook login.
120+ - parameter expiresIn: Optional expiration in seconds for Facebook login.
117121 - parameter options: A set of header options sent to the server. Defaults to an empty set.
118122 - parameter callbackQueue: The queue to return to after completion. Default value of .main.
119123 - parameter completion: The block to execute.
120124 */
121125 func login( userId: String ,
122126 accessToken: String ,
123- expirationDate : Date ,
127+ expiresIn : Int ? = nil ,
124128 options: API . Options = [ ] ,
125129 callbackQueue: DispatchQueue = . main,
126130 completion: @escaping ( Result < AuthenticatedUser , ParseError > ) -> Void ) {
@@ -129,7 +133,7 @@ public extension ParseFacebook {
129133 . makeDictionary ( userId: userId,
130134 accessToken: accessToken,
131135 authenticationToken: nil ,
132- expirationDate : expirationDate )
136+ expiresIn : expiresIn )
133137 login ( authData: facebookAuthData,
134138 options: options,
135139 callbackQueue: callbackQueue,
@@ -159,19 +163,19 @@ public extension ParseFacebook {
159163 Login a `ParseUser` *asynchronously* using Facebook authentication for limited login. Publishes when complete.
160164 - parameter userId: The `userId` from `FacebookSDK`.
161165 - parameter authenticationToken: The `authenticationToken` from `FacebookSDK`.
162- - parameter expirationDate: Required expiration data for Facebook login.
166+ - parameter expiresIn: Optional expiration in seconds for Facebook login.
163167 - parameter options: A set of header options sent to the server. Defaults to an empty set.
164168 - returns: A publisher that eventually produces a single value and then finishes or fails.
165169 */
166170 @available ( macOS 10 . 15 , iOS 13 . 0 , macCatalyst 13 . 0 , watchOS 6 . 0 , tvOS 13 . 0 , * )
167171 func loginPublisher( userId: String ,
168172 authenticationToken: String ,
169- expirationDate : Date ,
173+ expiresIn : Int ? = nil ,
170174 options: API . Options = [ ] ) -> Future < AuthenticatedUser , ParseError > {
171175 Future { promise in
172176 self . login ( userId: userId,
173177 authenticationToken: authenticationToken,
174- expirationDate : expirationDate ,
178+ expiresIn : expiresIn ,
175179 options: options,
176180 completion: promise)
177181 }
@@ -181,19 +185,19 @@ public extension ParseFacebook {
181185 Login a `ParseUser` *asynchronously* using Facebook authentication for graph API login. Publishes when complete.
182186 - parameter userId: The `userId` from `FacebookSDK`.
183187 - parameter accessToken: The `accessToken` from `FacebookSDK`.
184- - parameter expirationDate: Required expiration data for Facebook login.
188+ - parameter expiresIn: Optional expiration in seconds for Facebook login.
185189 - parameter options: A set of header options sent to the server. Defaults to an empty set.
186190 - returns: A publisher that eventually produces a single value and then finishes or fails.
187191 */
188192 @available ( macOS 10 . 15 , iOS 13 . 0 , macCatalyst 13 . 0 , watchOS 6 . 0 , tvOS 13 . 0 , * )
189193 func loginPublisher( userId: String ,
190194 accessToken: String ,
191- expirationDate : Date ,
195+ expiresIn : Int ? = nil ,
192196 options: API . Options = [ ] ) -> Future < AuthenticatedUser , ParseError > {
193197 Future { promise in
194198 self . login ( userId: userId,
195199 accessToken: accessToken,
196- expirationDate : expirationDate ,
200+ expiresIn : expiresIn ,
197201 options: options,
198202 completion: promise)
199203 }
@@ -218,22 +222,22 @@ public extension ParseFacebook {
218222 Link the *current* `ParseUser` *asynchronously* using Facebook authentication for limited login.
219223 - parameter userId: The `userId` from `FacebookSDK`.
220224 - parameter authenticationToken: The `authenticationToken` from `FacebookSDK`.
221- - parameter expirationDate: Required expiration data for Facebook login.
225+ - parameter expiresIn: Optional expiration in seconds for Facebook login.
222226 - parameter options: A set of header options sent to the server. Defaults to an empty set.
223227 - parameter callbackQueue: The queue to return to after completion. Default value of .main.
224228 - parameter completion: The block to execute.
225229 */
226230 func link( userId: String ,
227231 authenticationToken: String ,
228- expirationDate : Date ,
232+ expiresIn : Int ? = nil ,
229233 options: API . Options = [ ] ,
230234 callbackQueue: DispatchQueue = . main,
231235 completion: @escaping ( Result < AuthenticatedUser , ParseError > ) -> Void ) {
232236 let facebookAuthData = AuthenticationKeys . id
233237 . makeDictionary ( userId: userId,
234238 accessToken: nil ,
235239 authenticationToken: authenticationToken,
236- expirationDate : expirationDate )
240+ expiresIn : expiresIn )
237241 link ( authData: facebookAuthData,
238242 options: options,
239243 callbackQueue: callbackQueue,
@@ -244,22 +248,22 @@ public extension ParseFacebook {
244248 Link the *current* `ParseUser` *asynchronously* using Facebook authentication for graph API login.
245249 - parameter userId: The `userId` from `FacebookSDK`.
246250 - parameter accessToken: The `accessToken` from `FacebookSDK`.
247- - parameter expirationDate: the `expirationDate` from `FacebookSDK` .
251+ - parameter expiresIn: Optional expiration in seconds for Facebook login .
248252 - parameter options: A set of header options sent to the server. Defaults to an empty set.
249253 - parameter callbackQueue: The queue to return to after completion. Default value of .main.
250254 - parameter completion: The block to execute.
251255 */
252256 func link( userId: String ,
253257 accessToken: String ,
254- expirationDate : Date ,
258+ expiresIn : Int ? = nil ,
255259 options: API . Options = [ ] ,
256260 callbackQueue: DispatchQueue = . main,
257261 completion: @escaping ( Result < AuthenticatedUser , ParseError > ) -> Void ) {
258262 let facebookAuthData = AuthenticationKeys . id
259263 . makeDictionary ( userId: userId,
260264 accessToken: accessToken,
261265 authenticationToken: nil ,
262- expirationDate : expirationDate )
266+ expiresIn : expiresIn )
263267 link ( authData: facebookAuthData,
264268 options: options,
265269 callbackQueue: callbackQueue,
@@ -290,19 +294,19 @@ public extension ParseFacebook {
290294 Link the *current* `ParseUser` *asynchronously* using Facebook authentication for limited login. Publishes when complete.
291295 - parameter userId: The `userId` from `FacebookSDK`.
292296 - parameter authenticationToken: The `authenticationToken` from `FacebookSDK`.
293- - parameter expirationDate: the `expirationDate` from `FacebookSDK` .
297+ - parameter expiresIn: Optional expiration in seconds for Facebook login .
294298 - parameter options: A set of header options sent to the server. Defaults to an empty set.
295299 - returns: A publisher that eventually produces a single value and then finishes or fails.
296300 */
297301 @available ( macOS 10 . 15 , iOS 13 . 0 , macCatalyst 13 . 0 , watchOS 6 . 0 , tvOS 13 . 0 , * )
298302 func linkPublisher( userId: String ,
299303 authenticationToken: String ,
300- expirationDate : Date ,
304+ expiresIn : Int ? = nil ,
301305 options: API . Options = [ ] ) -> Future < AuthenticatedUser , ParseError > {
302306 Future { promise in
303307 self . link ( userId: userId,
304308 authenticationToken: authenticationToken,
305- expirationDate : expirationDate ,
309+ expiresIn : expiresIn ,
306310 options: options,
307311 completion: promise)
308312 }
@@ -312,19 +316,19 @@ public extension ParseFacebook {
312316 Link the *current* `ParseUser` *asynchronously* using Facebook authentication for graph API login. Publishes when complete.
313317 - parameter userId: The `userId` from `FacebookSDK`.
314318 - parameter accessToken: The `accessToken` from `FacebookSDK`.
315- - parameter expirationDate: the `expirationDate` from `FacebookSDK` .
319+ - parameter expiresIn: Optional expiration in seconds for Facebook login .
316320 - parameter options: A set of header options sent to the server. Defaults to an empty set.
317321 - returns: A publisher that eventually produces a single value and then finishes or fails.
318322 */
319323 @available ( macOS 10 . 15 , iOS 13 . 0 , macCatalyst 13 . 0 , watchOS 6 . 0 , tvOS 13 . 0 , * )
320324 func linkPublisher( userId: String ,
321325 accessToken: String ,
322- expirationDate : Date ,
326+ expiresIn : Int ? = nil ,
323327 options: API . Options = [ ] ) -> Future < AuthenticatedUser , ParseError > {
324328 Future { promise in
325329 self . link ( userId: userId,
326330 accessToken: accessToken,
327- expirationDate : expirationDate ,
331+ expiresIn : expiresIn ,
328332 options: options,
329333 completion: promise)
330334 }
0 commit comments