Skip to content

Commit f3f2244

Browse files
authored
Let ParseFacebook accept expiresIn parameter (#104)
* Let ParseFacebook accept expiresIn parameter * Accept expiresIn as optional * Remove expiresIn from being required in publishers. * Fully test verifyMandatoryKeys
1 parent a233682 commit f3f2244

File tree

8 files changed

+131
-118
lines changed

8 files changed

+131
-118
lines changed

CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
# Parse-Swift Changelog
22

33
### main
4-
[Full Changelog](https://github.com/parse-community/Parse-Swift/compare/1.2.4...main)
4+
[Full Changelog](https://github.com/parse-community/Parse-Swift/compare/1.2.5...main)
55
* _Contributing to this repo? Add info about your change here to be included in the next release_
66

7+
### 1.2.5
8+
[Full Changelog](https://github.com/parse-community/Parse-Swift/compare/1.2.4...1.2.5)
9+
10+
__Fixes__
11+
- Let ParseFacebook accept expiresIn parameter instead of converting to date ([#104](https://github.com/parse-community/Parse-Swift/pull/104)), thanks to [Corey Baker](https://github.com/cbaker6).
12+
713
### 1.2.4
814
[Full Changelog](https://github.com/parse-community/Parse-Swift/compare/1.2.3...1.2.4)
915

ParseSwift.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = "ParseSwift"
3-
s.version = "1.2.4"
3+
s.version = "1.2.5"
44
s.summary = "Parse Pure Swift SDK"
55
s.homepage = "https://github.com/parse-community/Parse-Swift"
66
s.authors = {

ParseSwift.xcodeproj/project.pbxproj

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2321,7 +2321,7 @@
23212321
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
23222322
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
23232323
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
2324-
MARKETING_VERSION = 1.2.4;
2324+
MARKETING_VERSION = 1.2.5;
23252325
PRODUCT_BUNDLE_IDENTIFIER = com.parse.ParseSwift;
23262326
PRODUCT_NAME = ParseSwift;
23272327
SKIP_INSTALL = YES;
@@ -2345,7 +2345,7 @@
23452345
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
23462346
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
23472347
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
2348-
MARKETING_VERSION = 1.2.4;
2348+
MARKETING_VERSION = 1.2.5;
23492349
PRODUCT_BUNDLE_IDENTIFIER = com.parse.ParseSwift;
23502350
PRODUCT_NAME = ParseSwift;
23512351
SKIP_INSTALL = YES;
@@ -2411,7 +2411,7 @@
24112411
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
24122412
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks";
24132413
MACOSX_DEPLOYMENT_TARGET = 10.13;
2414-
MARKETING_VERSION = 1.2.4;
2414+
MARKETING_VERSION = 1.2.5;
24152415
PRODUCT_BUNDLE_IDENTIFIER = com.parse.ParseSwift;
24162416
PRODUCT_NAME = ParseSwift;
24172417
SDKROOT = macosx;
@@ -2437,7 +2437,7 @@
24372437
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
24382438
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks";
24392439
MACOSX_DEPLOYMENT_TARGET = 10.13;
2440-
MARKETING_VERSION = 1.2.4;
2440+
MARKETING_VERSION = 1.2.5;
24412441
PRODUCT_BUNDLE_IDENTIFIER = com.parse.ParseSwift;
24422442
PRODUCT_NAME = ParseSwift;
24432443
SDKROOT = macosx;
@@ -2584,7 +2584,7 @@
25842584
INFOPLIST_FILE = "ParseSwift-watchOS/Info.plist";
25852585
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
25862586
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
2587-
MARKETING_VERSION = 1.2.4;
2587+
MARKETING_VERSION = 1.2.5;
25882588
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
25892589
MTL_FAST_MATH = YES;
25902590
PRODUCT_BUNDLE_IDENTIFIER = "com.parse.ParseSwift-watchOS";
@@ -2613,7 +2613,7 @@
26132613
INFOPLIST_FILE = "ParseSwift-watchOS/Info.plist";
26142614
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
26152615
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
2616-
MARKETING_VERSION = 1.2.4;
2616+
MARKETING_VERSION = 1.2.5;
26172617
MTL_FAST_MATH = YES;
26182618
PRODUCT_BUNDLE_IDENTIFIER = "com.parse.ParseSwift-watchOS";
26192619
PRODUCT_NAME = ParseSwift;
@@ -2640,7 +2640,7 @@
26402640
INFOPLIST_FILE = "ParseSwift-tvOS/Info.plist";
26412641
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
26422642
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
2643-
MARKETING_VERSION = 1.2.4;
2643+
MARKETING_VERSION = 1.2.5;
26442644
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
26452645
MTL_FAST_MATH = YES;
26462646
PRODUCT_BUNDLE_IDENTIFIER = "com.parse.ParseSwift-tvOS";
@@ -2668,7 +2668,7 @@
26682668
INFOPLIST_FILE = "ParseSwift-tvOS/Info.plist";
26692669
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
26702670
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
2671-
MARKETING_VERSION = 1.2.4;
2671+
MARKETING_VERSION = 1.2.5;
26722672
MTL_FAST_MATH = YES;
26732673
PRODUCT_BUNDLE_IDENTIFIER = "com.parse.ParseSwift-tvOS";
26742674
PRODUCT_NAME = ParseSwift;

Scripts/jazzy.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ bundle exec jazzy \
55
--author_url http://parseplatform.org \
66
--github_url https://github.com/parse-community/Parse-Swift \
77
--root-url http://parseplatform.org/Parse-Swift/api/ \
8-
--module-version 1.2.4 \
8+
--module-version 1.2.5 \
99
--theme fullwidth \
1010
--skip-undocumented \
1111
--output ./docs/api \

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

Lines changed: 37 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

Sources/ParseSwift/ParseConstants.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import Foundation
1010

1111
enum ParseConstants {
12-
static let parseVersion = "1.2.3"
12+
static let parseVersion = "1.2.5"
1313
static let hashingKey = "parseSwift"
1414
static let fileManagementDirectory = "parse/"
1515
static let fileManagementPrivateDocumentsDirectory = "Private Documents/"

0 commit comments

Comments
 (0)