Skip to content

Commit

Permalink
Let ParseFacebook accept expiresIn parameter (#104)
Browse files Browse the repository at this point in the history
* Let ParseFacebook accept expiresIn parameter

* Accept expiresIn as optional

* Remove expiresIn from being required in publishers.

* Fully test verifyMandatoryKeys
  • Loading branch information
cbaker6 authored Mar 28, 2021
1 parent a233682 commit f3f2244
Show file tree
Hide file tree
Showing 8 changed files with 131 additions and 118 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
# Parse-Swift Changelog

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

### 1.2.5
[Full Changelog](https://github.com/parse-community/Parse-Swift/compare/1.2.4...1.2.5)

__Fixes__
- 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).

### 1.2.4
[Full Changelog](https://github.com/parse-community/Parse-Swift/compare/1.2.3...1.2.4)

Expand Down
2 changes: 1 addition & 1 deletion ParseSwift.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "ParseSwift"
s.version = "1.2.4"
s.version = "1.2.5"
s.summary = "Parse Pure Swift SDK"
s.homepage = "https://github.com/parse-community/Parse-Swift"
s.authors = {
Expand Down
16 changes: 8 additions & 8 deletions ParseSwift.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -2321,7 +2321,7 @@
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
MARKETING_VERSION = 1.2.4;
MARKETING_VERSION = 1.2.5;
PRODUCT_BUNDLE_IDENTIFIER = com.parse.ParseSwift;
PRODUCT_NAME = ParseSwift;
SKIP_INSTALL = YES;
Expand All @@ -2345,7 +2345,7 @@
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
MARKETING_VERSION = 1.2.4;
MARKETING_VERSION = 1.2.5;
PRODUCT_BUNDLE_IDENTIFIER = com.parse.ParseSwift;
PRODUCT_NAME = ParseSwift;
SKIP_INSTALL = YES;
Expand Down Expand Up @@ -2411,7 +2411,7 @@
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks";
MACOSX_DEPLOYMENT_TARGET = 10.13;
MARKETING_VERSION = 1.2.4;
MARKETING_VERSION = 1.2.5;
PRODUCT_BUNDLE_IDENTIFIER = com.parse.ParseSwift;
PRODUCT_NAME = ParseSwift;
SDKROOT = macosx;
Expand All @@ -2437,7 +2437,7 @@
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks";
MACOSX_DEPLOYMENT_TARGET = 10.13;
MARKETING_VERSION = 1.2.4;
MARKETING_VERSION = 1.2.5;
PRODUCT_BUNDLE_IDENTIFIER = com.parse.ParseSwift;
PRODUCT_NAME = ParseSwift;
SDKROOT = macosx;
Expand Down Expand Up @@ -2584,7 +2584,7 @@
INFOPLIST_FILE = "ParseSwift-watchOS/Info.plist";
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
MARKETING_VERSION = 1.2.4;
MARKETING_VERSION = 1.2.5;
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES;
PRODUCT_BUNDLE_IDENTIFIER = "com.parse.ParseSwift-watchOS";
Expand Down Expand Up @@ -2613,7 +2613,7 @@
INFOPLIST_FILE = "ParseSwift-watchOS/Info.plist";
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
MARKETING_VERSION = 1.2.4;
MARKETING_VERSION = 1.2.5;
MTL_FAST_MATH = YES;
PRODUCT_BUNDLE_IDENTIFIER = "com.parse.ParseSwift-watchOS";
PRODUCT_NAME = ParseSwift;
Expand All @@ -2640,7 +2640,7 @@
INFOPLIST_FILE = "ParseSwift-tvOS/Info.plist";
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
MARKETING_VERSION = 1.2.4;
MARKETING_VERSION = 1.2.5;
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES;
PRODUCT_BUNDLE_IDENTIFIER = "com.parse.ParseSwift-tvOS";
Expand Down Expand Up @@ -2668,7 +2668,7 @@
INFOPLIST_FILE = "ParseSwift-tvOS/Info.plist";
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
MARKETING_VERSION = 1.2.4;
MARKETING_VERSION = 1.2.5;
MTL_FAST_MATH = YES;
PRODUCT_BUNDLE_IDENTIFIER = "com.parse.ParseSwift-tvOS";
PRODUCT_NAME = ParseSwift;
Expand Down
2 changes: 1 addition & 1 deletion Scripts/jazzy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ bundle exec jazzy \
--author_url http://parseplatform.org \
--github_url https://github.com/parse-community/Parse-Swift \
--root-url http://parseplatform.org/Parse-Swift/api/ \
--module-version 1.2.4 \
--module-version 1.2.5 \
--theme fullwidth \
--skip-undocumented \
--output ./docs/api \
Expand Down
70 changes: 37 additions & 33 deletions Sources/ParseSwift/Authentication/3rd Party/ParseFacebook.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public struct ParseFacebook<AuthenticatedUser: ParseUser>: ParseAuthentication {

enum CodingKeys: String, CodingKey { // swiftlint:disable:this nesting
case id // swiftlint:disable:this identifier_name
case token
case authenticationToken = "token"
case accessToken = "access_token"
case expirationDate = "expiration_date"
}
Expand All @@ -37,16 +37,21 @@ public struct ParseFacebook<AuthenticatedUser: ParseUser>: ParseAuthentication {
/// - parameter userId: Required id for the user.
/// - parameter authenticationToken: Required identity token for Facebook limited login.
/// - parameter accessToken: Required identity token for Facebook graph API.
/// - parameter expirationDate: Required expiration data for Facebook login.
/// - parameter expiresIn: Optional expiration in seconds for Facebook login.
/// - returns: authData dictionary.
func makeDictionary(userId: String,
accessToken: String?,
authenticationToken: String?,
expirationDate: Date) -> [String: String] {

let dateString = ParseCoding.dateFormatter.string(from: expirationDate)
var returnDictionary = [AuthenticationKeys.id.rawValue: userId,
AuthenticationKeys.expirationDate.rawValue: dateString]
expiresIn: Int? = nil) -> [String: String] {

var returnDictionary = [AuthenticationKeys.id.rawValue: userId]
if let expiresIn = expiresIn,
let expirationDate = Calendar.current.date(byAdding: .second,
value: expiresIn,
to: Date()) {
let dateString = ParseCoding.dateFormatter.string(from: expirationDate)
returnDictionary[AuthenticationKeys.expirationDate.rawValue] = dateString
}

if let accessToken = accessToken {
returnDictionary[AuthenticationKeys.accessToken.rawValue] = accessToken
Expand All @@ -60,8 +65,7 @@ public struct ParseFacebook<AuthenticatedUser: ParseUser>: ParseAuthentication {
/// - parameter authData: Dictionary containing key/values.
/// - returns: `true` if all the mandatory keys are present, `false` otherwise.
func verifyMandatoryKeys(authData: [String: String]) -> Bool {
guard authData[AuthenticationKeys.id.rawValue] != nil,
authData[AuthenticationKeys.expirationDate.rawValue] != nil else {
guard authData[AuthenticationKeys.id.rawValue] != nil else {
return false
}

Expand All @@ -87,22 +91,22 @@ public extension ParseFacebook {
Login a `ParseUser` *asynchronously* using Facebook authentication for limited login.
- parameter userId: The `Facebook userId` from `FacebookSDK`.
- parameter authenticationToken: The `authenticationToken` from `FacebookSDK`.
- parameter expirationDate: Required expiration data for Facebook login.
- parameter expiresIn: Optional expiration in seconds for Facebook login.
- parameter options: A set of header options sent to the server. Defaults to an empty set.
- parameter callbackQueue: The queue to return to after completion. Default value of .main.
- parameter completion: The block to execute.
*/
func login(userId: String,
authenticationToken: String,
expirationDate: Date,
expiresIn: Int? = nil,
options: API.Options = [],
callbackQueue: DispatchQueue = .main,
completion: @escaping (Result<AuthenticatedUser, ParseError>) -> Void) {

let facebookAuthData = AuthenticationKeys.id
.makeDictionary(userId: userId, accessToken: nil,
authenticationToken: authenticationToken,
expirationDate: expirationDate)
expiresIn: expiresIn)
login(authData: facebookAuthData,
options: options,
callbackQueue: callbackQueue,
Expand All @@ -113,14 +117,14 @@ public extension ParseFacebook {
Login a `ParseUser` *asynchronously* using Facebook authentication for graph API login.
- parameter userId: The `Facebook userId` from `FacebookSDK`.
- parameter accessToken: The `accessToken` from `FacebookSDK`.
- parameter expirationDate: Required expiration data for Facebook login.
- parameter expiresIn: Optional expiration in seconds for Facebook login.
- parameter options: A set of header options sent to the server. Defaults to an empty set.
- parameter callbackQueue: The queue to return to after completion. Default value of .main.
- parameter completion: The block to execute.
*/
func login(userId: String,
accessToken: String,
expirationDate: Date,
expiresIn: Int? = nil,
options: API.Options = [],
callbackQueue: DispatchQueue = .main,
completion: @escaping (Result<AuthenticatedUser, ParseError>) -> Void) {
Expand All @@ -129,7 +133,7 @@ public extension ParseFacebook {
.makeDictionary(userId: userId,
accessToken: accessToken,
authenticationToken: nil,
expirationDate: expirationDate)
expiresIn: expiresIn)
login(authData: facebookAuthData,
options: options,
callbackQueue: callbackQueue,
Expand Down Expand Up @@ -159,19 +163,19 @@ public extension ParseFacebook {
Login a `ParseUser` *asynchronously* using Facebook authentication for limited login. Publishes when complete.
- parameter userId: The `userId` from `FacebookSDK`.
- parameter authenticationToken: The `authenticationToken` from `FacebookSDK`.
- parameter expirationDate: Required expiration data for Facebook login.
- parameter expiresIn: Optional expiration in seconds for Facebook login.
- parameter options: A set of header options sent to the server. Defaults to an empty set.
- returns: A publisher that eventually produces a single value and then finishes or fails.
*/
@available(macOS 10.15, iOS 13.0, macCatalyst 13.0, watchOS 6.0, tvOS 13.0, *)
func loginPublisher(userId: String,
authenticationToken: String,
expirationDate: Date,
expiresIn: Int? = nil,
options: API.Options = []) -> Future<AuthenticatedUser, ParseError> {
Future { promise in
self.login(userId: userId,
authenticationToken: authenticationToken,
expirationDate: expirationDate,
expiresIn: expiresIn,
options: options,
completion: promise)
}
Expand All @@ -181,19 +185,19 @@ public extension ParseFacebook {
Login a `ParseUser` *asynchronously* using Facebook authentication for graph API login. Publishes when complete.
- parameter userId: The `userId` from `FacebookSDK`.
- parameter accessToken: The `accessToken` from `FacebookSDK`.
- parameter expirationDate: Required expiration data for Facebook login.
- parameter expiresIn: Optional expiration in seconds for Facebook login.
- parameter options: A set of header options sent to the server. Defaults to an empty set.
- returns: A publisher that eventually produces a single value and then finishes or fails.
*/
@available(macOS 10.15, iOS 13.0, macCatalyst 13.0, watchOS 6.0, tvOS 13.0, *)
func loginPublisher(userId: String,
accessToken: String,
expirationDate: Date,
expiresIn: Int? = nil,
options: API.Options = []) -> Future<AuthenticatedUser, ParseError> {
Future { promise in
self.login(userId: userId,
accessToken: accessToken,
expirationDate: expirationDate,
expiresIn: expiresIn,
options: options,
completion: promise)
}
Expand All @@ -218,22 +222,22 @@ public extension ParseFacebook {
Link the *current* `ParseUser` *asynchronously* using Facebook authentication for limited login.
- parameter userId: The `userId` from `FacebookSDK`.
- parameter authenticationToken: The `authenticationToken` from `FacebookSDK`.
- parameter expirationDate: Required expiration data for Facebook login.
- parameter expiresIn: Optional expiration in seconds for Facebook login.
- parameter options: A set of header options sent to the server. Defaults to an empty set.
- parameter callbackQueue: The queue to return to after completion. Default value of .main.
- parameter completion: The block to execute.
*/
func link(userId: String,
authenticationToken: String,
expirationDate: Date,
expiresIn: Int? = nil,
options: API.Options = [],
callbackQueue: DispatchQueue = .main,
completion: @escaping (Result<AuthenticatedUser, ParseError>) -> Void) {
let facebookAuthData = AuthenticationKeys.id
.makeDictionary(userId: userId,
accessToken: nil,
authenticationToken: authenticationToken,
expirationDate: expirationDate)
expiresIn: expiresIn)
link(authData: facebookAuthData,
options: options,
callbackQueue: callbackQueue,
Expand All @@ -244,22 +248,22 @@ public extension ParseFacebook {
Link the *current* `ParseUser` *asynchronously* using Facebook authentication for graph API login.
- parameter userId: The `userId` from `FacebookSDK`.
- parameter accessToken: The `accessToken` from `FacebookSDK`.
- parameter expirationDate: the `expirationDate` from `FacebookSDK`.
- parameter expiresIn: Optional expiration in seconds for Facebook login.
- parameter options: A set of header options sent to the server. Defaults to an empty set.
- parameter callbackQueue: The queue to return to after completion. Default value of .main.
- parameter completion: The block to execute.
*/
func link(userId: String,
accessToken: String,
expirationDate: Date,
expiresIn: Int? = nil,
options: API.Options = [],
callbackQueue: DispatchQueue = .main,
completion: @escaping (Result<AuthenticatedUser, ParseError>) -> Void) {
let facebookAuthData = AuthenticationKeys.id
.makeDictionary(userId: userId,
accessToken: accessToken,
authenticationToken: nil,
expirationDate: expirationDate)
expiresIn: expiresIn)
link(authData: facebookAuthData,
options: options,
callbackQueue: callbackQueue,
Expand Down Expand Up @@ -290,19 +294,19 @@ public extension ParseFacebook {
Link the *current* `ParseUser` *asynchronously* using Facebook authentication for limited login. Publishes when complete.
- parameter userId: The `userId` from `FacebookSDK`.
- parameter authenticationToken: The `authenticationToken` from `FacebookSDK`.
- parameter expirationDate: the `expirationDate` from `FacebookSDK`.
- parameter expiresIn: Optional expiration in seconds for Facebook login.
- parameter options: A set of header options sent to the server. Defaults to an empty set.
- returns: A publisher that eventually produces a single value and then finishes or fails.
*/
@available(macOS 10.15, iOS 13.0, macCatalyst 13.0, watchOS 6.0, tvOS 13.0, *)
func linkPublisher(userId: String,
authenticationToken: String,
expirationDate: Date,
expiresIn: Int? = nil,
options: API.Options = []) -> Future<AuthenticatedUser, ParseError> {
Future { promise in
self.link(userId: userId,
authenticationToken: authenticationToken,
expirationDate: expirationDate,
expiresIn: expiresIn,
options: options,
completion: promise)
}
Expand All @@ -312,19 +316,19 @@ public extension ParseFacebook {
Link the *current* `ParseUser` *asynchronously* using Facebook authentication for graph API login. Publishes when complete.
- parameter userId: The `userId` from `FacebookSDK`.
- parameter accessToken: The `accessToken` from `FacebookSDK`.
- parameter expirationDate: the `expirationDate` from `FacebookSDK`.
- parameter expiresIn: Optional expiration in seconds for Facebook login.
- parameter options: A set of header options sent to the server. Defaults to an empty set.
- returns: A publisher that eventually produces a single value and then finishes or fails.
*/
@available(macOS 10.15, iOS 13.0, macCatalyst 13.0, watchOS 6.0, tvOS 13.0, *)
func linkPublisher(userId: String,
accessToken: String,
expirationDate: Date,
expiresIn: Int? = nil,
options: API.Options = []) -> Future<AuthenticatedUser, ParseError> {
Future { promise in
self.link(userId: userId,
accessToken: accessToken,
expirationDate: expirationDate,
expiresIn: expiresIn,
options: options,
completion: promise)
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/ParseSwift/ParseConstants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import Foundation

enum ParseConstants {
static let parseVersion = "1.2.3"
static let parseVersion = "1.2.5"
static let hashingKey = "parseSwift"
static let fileManagementDirectory = "parse/"
static let fileManagementPrivateDocumentsDirectory = "Private Documents/"
Expand Down
Loading

0 comments on commit f3f2244

Please sign in to comment.