@@ -28,7 +28,7 @@ public struct ParseFacebook<AuthenticatedUser: ParseUser>: ParseAuthentication {
28
28
29
29
enum CodingKeys : String , CodingKey { // swiftlint:disable:this nesting
30
30
case id // swiftlint:disable:this identifier_name
31
- case token
31
+ case authenticationToken = " token "
32
32
case accessToken = " access_token "
33
33
case expirationDate = " expiration_date "
34
34
}
@@ -37,16 +37,21 @@ public struct ParseFacebook<AuthenticatedUser: ParseUser>: ParseAuthentication {
37
37
/// - parameter userId: Required id for the user.
38
38
/// - parameter authenticationToken: Required identity token for Facebook limited login.
39
39
/// - 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.
41
41
/// - returns: authData dictionary.
42
42
func makeDictionary( userId: String ,
43
43
accessToken: String ? ,
44
44
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
+ }
50
55
51
56
if let accessToken = accessToken {
52
57
returnDictionary [ AuthenticationKeys . accessToken. rawValue] = accessToken
@@ -60,8 +65,7 @@ public struct ParseFacebook<AuthenticatedUser: ParseUser>: ParseAuthentication {
60
65
/// - parameter authData: Dictionary containing key/values.
61
66
/// - returns: `true` if all the mandatory keys are present, `false` otherwise.
62
67
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 {
65
69
return false
66
70
}
67
71
@@ -87,22 +91,22 @@ public extension ParseFacebook {
87
91
Login a `ParseUser` *asynchronously* using Facebook authentication for limited login.
88
92
- parameter userId: The `Facebook userId` from `FacebookSDK`.
89
93
- 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.
91
95
- parameter options: A set of header options sent to the server. Defaults to an empty set.
92
96
- parameter callbackQueue: The queue to return to after completion. Default value of .main.
93
97
- parameter completion: The block to execute.
94
98
*/
95
99
func login( userId: String ,
96
100
authenticationToken: String ,
97
- expirationDate : Date ,
101
+ expiresIn : Int ? = nil ,
98
102
options: API . Options = [ ] ,
99
103
callbackQueue: DispatchQueue = . main,
100
104
completion: @escaping ( Result < AuthenticatedUser , ParseError > ) -> Void ) {
101
105
102
106
let facebookAuthData = AuthenticationKeys . id
103
107
. makeDictionary ( userId: userId, accessToken: nil ,
104
108
authenticationToken: authenticationToken,
105
- expirationDate : expirationDate )
109
+ expiresIn : expiresIn )
106
110
login ( authData: facebookAuthData,
107
111
options: options,
108
112
callbackQueue: callbackQueue,
@@ -113,14 +117,14 @@ public extension ParseFacebook {
113
117
Login a `ParseUser` *asynchronously* using Facebook authentication for graph API login.
114
118
- parameter userId: The `Facebook userId` from `FacebookSDK`.
115
119
- 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.
117
121
- parameter options: A set of header options sent to the server. Defaults to an empty set.
118
122
- parameter callbackQueue: The queue to return to after completion. Default value of .main.
119
123
- parameter completion: The block to execute.
120
124
*/
121
125
func login( userId: String ,
122
126
accessToken: String ,
123
- expirationDate : Date ,
127
+ expiresIn : Int ? = nil ,
124
128
options: API . Options = [ ] ,
125
129
callbackQueue: DispatchQueue = . main,
126
130
completion: @escaping ( Result < AuthenticatedUser , ParseError > ) -> Void ) {
@@ -129,7 +133,7 @@ public extension ParseFacebook {
129
133
. makeDictionary ( userId: userId,
130
134
accessToken: accessToken,
131
135
authenticationToken: nil ,
132
- expirationDate : expirationDate )
136
+ expiresIn : expiresIn )
133
137
login ( authData: facebookAuthData,
134
138
options: options,
135
139
callbackQueue: callbackQueue,
@@ -159,19 +163,19 @@ public extension ParseFacebook {
159
163
Login a `ParseUser` *asynchronously* using Facebook authentication for limited login. Publishes when complete.
160
164
- parameter userId: The `userId` from `FacebookSDK`.
161
165
- 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.
163
167
- parameter options: A set of header options sent to the server. Defaults to an empty set.
164
168
- returns: A publisher that eventually produces a single value and then finishes or fails.
165
169
*/
166
170
@available ( macOS 10 . 15 , iOS 13 . 0 , macCatalyst 13 . 0 , watchOS 6 . 0 , tvOS 13 . 0 , * )
167
171
func loginPublisher( userId: String ,
168
172
authenticationToken: String ,
169
- expirationDate : Date ,
173
+ expiresIn : Int ? = nil ,
170
174
options: API . Options = [ ] ) -> Future < AuthenticatedUser , ParseError > {
171
175
Future { promise in
172
176
self . login ( userId: userId,
173
177
authenticationToken: authenticationToken,
174
- expirationDate : expirationDate ,
178
+ expiresIn : expiresIn ,
175
179
options: options,
176
180
completion: promise)
177
181
}
@@ -181,19 +185,19 @@ public extension ParseFacebook {
181
185
Login a `ParseUser` *asynchronously* using Facebook authentication for graph API login. Publishes when complete.
182
186
- parameter userId: The `userId` from `FacebookSDK`.
183
187
- 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.
185
189
- parameter options: A set of header options sent to the server. Defaults to an empty set.
186
190
- returns: A publisher that eventually produces a single value and then finishes or fails.
187
191
*/
188
192
@available ( macOS 10 . 15 , iOS 13 . 0 , macCatalyst 13 . 0 , watchOS 6 . 0 , tvOS 13 . 0 , * )
189
193
func loginPublisher( userId: String ,
190
194
accessToken: String ,
191
- expirationDate : Date ,
195
+ expiresIn : Int ? = nil ,
192
196
options: API . Options = [ ] ) -> Future < AuthenticatedUser , ParseError > {
193
197
Future { promise in
194
198
self . login ( userId: userId,
195
199
accessToken: accessToken,
196
- expirationDate : expirationDate ,
200
+ expiresIn : expiresIn ,
197
201
options: options,
198
202
completion: promise)
199
203
}
@@ -218,22 +222,22 @@ public extension ParseFacebook {
218
222
Link the *current* `ParseUser` *asynchronously* using Facebook authentication for limited login.
219
223
- parameter userId: The `userId` from `FacebookSDK`.
220
224
- 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.
222
226
- parameter options: A set of header options sent to the server. Defaults to an empty set.
223
227
- parameter callbackQueue: The queue to return to after completion. Default value of .main.
224
228
- parameter completion: The block to execute.
225
229
*/
226
230
func link( userId: String ,
227
231
authenticationToken: String ,
228
- expirationDate : Date ,
232
+ expiresIn : Int ? = nil ,
229
233
options: API . Options = [ ] ,
230
234
callbackQueue: DispatchQueue = . main,
231
235
completion: @escaping ( Result < AuthenticatedUser , ParseError > ) -> Void ) {
232
236
let facebookAuthData = AuthenticationKeys . id
233
237
. makeDictionary ( userId: userId,
234
238
accessToken: nil ,
235
239
authenticationToken: authenticationToken,
236
- expirationDate : expirationDate )
240
+ expiresIn : expiresIn )
237
241
link ( authData: facebookAuthData,
238
242
options: options,
239
243
callbackQueue: callbackQueue,
@@ -244,22 +248,22 @@ public extension ParseFacebook {
244
248
Link the *current* `ParseUser` *asynchronously* using Facebook authentication for graph API login.
245
249
- parameter userId: The `userId` from `FacebookSDK`.
246
250
- parameter accessToken: The `accessToken` from `FacebookSDK`.
247
- - parameter expirationDate: the `expirationDate` from `FacebookSDK` .
251
+ - parameter expiresIn: Optional expiration in seconds for Facebook login .
248
252
- parameter options: A set of header options sent to the server. Defaults to an empty set.
249
253
- parameter callbackQueue: The queue to return to after completion. Default value of .main.
250
254
- parameter completion: The block to execute.
251
255
*/
252
256
func link( userId: String ,
253
257
accessToken: String ,
254
- expirationDate : Date ,
258
+ expiresIn : Int ? = nil ,
255
259
options: API . Options = [ ] ,
256
260
callbackQueue: DispatchQueue = . main,
257
261
completion: @escaping ( Result < AuthenticatedUser , ParseError > ) -> Void ) {
258
262
let facebookAuthData = AuthenticationKeys . id
259
263
. makeDictionary ( userId: userId,
260
264
accessToken: accessToken,
261
265
authenticationToken: nil ,
262
- expirationDate : expirationDate )
266
+ expiresIn : expiresIn )
263
267
link ( authData: facebookAuthData,
264
268
options: options,
265
269
callbackQueue: callbackQueue,
@@ -290,19 +294,19 @@ public extension ParseFacebook {
290
294
Link the *current* `ParseUser` *asynchronously* using Facebook authentication for limited login. Publishes when complete.
291
295
- parameter userId: The `userId` from `FacebookSDK`.
292
296
- parameter authenticationToken: The `authenticationToken` from `FacebookSDK`.
293
- - parameter expirationDate: the `expirationDate` from `FacebookSDK` .
297
+ - parameter expiresIn: Optional expiration in seconds for Facebook login .
294
298
- parameter options: A set of header options sent to the server. Defaults to an empty set.
295
299
- returns: A publisher that eventually produces a single value and then finishes or fails.
296
300
*/
297
301
@available ( macOS 10 . 15 , iOS 13 . 0 , macCatalyst 13 . 0 , watchOS 6 . 0 , tvOS 13 . 0 , * )
298
302
func linkPublisher( userId: String ,
299
303
authenticationToken: String ,
300
- expirationDate : Date ,
304
+ expiresIn : Int ? = nil ,
301
305
options: API . Options = [ ] ) -> Future < AuthenticatedUser , ParseError > {
302
306
Future { promise in
303
307
self . link ( userId: userId,
304
308
authenticationToken: authenticationToken,
305
- expirationDate : expirationDate ,
309
+ expiresIn : expiresIn ,
306
310
options: options,
307
311
completion: promise)
308
312
}
@@ -312,19 +316,19 @@ public extension ParseFacebook {
312
316
Link the *current* `ParseUser` *asynchronously* using Facebook authentication for graph API login. Publishes when complete.
313
317
- parameter userId: The `userId` from `FacebookSDK`.
314
318
- parameter accessToken: The `accessToken` from `FacebookSDK`.
315
- - parameter expirationDate: the `expirationDate` from `FacebookSDK` .
319
+ - parameter expiresIn: Optional expiration in seconds for Facebook login .
316
320
- parameter options: A set of header options sent to the server. Defaults to an empty set.
317
321
- returns: A publisher that eventually produces a single value and then finishes or fails.
318
322
*/
319
323
@available ( macOS 10 . 15 , iOS 13 . 0 , macCatalyst 13 . 0 , watchOS 6 . 0 , tvOS 13 . 0 , * )
320
324
func linkPublisher( userId: String ,
321
325
accessToken: String ,
322
- expirationDate : Date ,
326
+ expiresIn : Int ? = nil ,
323
327
options: API . Options = [ ] ) -> Future < AuthenticatedUser , ParseError > {
324
328
Future { promise in
325
329
self . link ( userId: userId,
326
330
accessToken: accessToken,
327
- expirationDate : expirationDate ,
331
+ expiresIn : expiresIn ,
328
332
options: options,
329
333
completion: promise)
330
334
}
0 commit comments