Skip to content
2 changes: 1 addition & 1 deletion .codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ coverage:
status:
patch:
default:
target: 77
target: auto
changes: false
project:
default:
Expand Down
78 changes: 29 additions & 49 deletions Sources/ParseSwift/Authentication/3rd Party/ParseApple.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public struct ParseApple<AuthenticatedUser: ParseUser>: ParseAuthentication {
/// Properly makes an authData dictionary with the required keys.
/// - parameter user: Required id for the user.
/// - parameter identityToken: Required identity token for the user.
/// - returns: Required authData dictionary.
/// - returns: authData dictionary.
/// - throws: `ParseError` if the `identityToken` can't be converted
/// to a string.
func makeDictionary(user: String,
Expand All @@ -43,9 +43,8 @@ public struct ParseApple<AuthenticatedUser: ParseUser>: ParseAuthentication {
/// Verifies all mandatory keys are in authData.
/// - parameter authData: Dictionary containing key/values.
/// - returns: `true` if all the mandatory keys are present, `false` otherwise.
func verifyMandatoryKeys(authData: [String: String]?) -> Bool {
guard let authData = authData,
authData[AuthenticationKeys.id.rawValue] != nil,
func verifyMandatoryKeys(authData: [String: String]) -> Bool {
guard authData[AuthenticationKeys.id.rawValue] != nil,
authData[AuthenticationKeys.token.rawValue] != nil else {
return false
}
Expand Down Expand Up @@ -87,16 +86,14 @@ public extension ParseApple {
completion: completion)
}

func login(authData: [String: String]?,
func login(authData: [String: String],
options: API.Options = [],
callbackQueue: DispatchQueue = .main,
completion: @escaping (Result<AuthenticatedUser, ParseError>) -> Void) {
guard AuthenticationKeys.id.verifyMandatoryKeys(authData: authData),
let authData = authData else {
let error = ParseError(code: .unknownError,
message: "Should have authData in consisting of keys \"id\" and \"token\".")
guard AuthenticationKeys.id.verifyMandatoryKeys(authData: authData) else {
callbackQueue.async {
completion(.failure(error))
completion(.failure(.init(code: .unknownError,
message: "Should have authData in consisting of keys \"id\" and \"token\".")))
}
return
}
Expand All @@ -120,30 +117,22 @@ public extension ParseApple {
func loginPublisher(user: String,
identityToken: Data,
options: API.Options = []) -> Future<AuthenticatedUser, ParseError> {
guard let appleAuthData = try? AuthenticationKeys.id.makeDictionary(user: user, identityToken: identityToken) else {
return Future { promise in
promise(.failure(.init(code: .unknownError,
message: "Couldn't create authData.")))
}
Future { promise in
self.login(user: user,
identityToken: identityToken,
options: options,
completion: promise)
}
return loginPublisher(authData: appleAuthData,
options: options)
}

@available(macOS 10.15, iOS 13.0, macCatalyst 13.0, watchOS 6.0, tvOS 13.0, *)
func loginPublisher(authData: [String: String]?,
func loginPublisher(authData: [String: String],
options: API.Options = []) -> Future<AuthenticatedUser, ParseError> {
guard AuthenticationKeys.id.verifyMandatoryKeys(authData: authData),
let authData = authData else {
let error = ParseError(code: .unknownError,
message: "Should have authData in consisting of keys \"id\" and \"token\".")
return Future { promise in
promise(.failure(error))
}
Future { promise in
self.login(authData: authData,
options: options,
completion: promise)
}
return AuthenticatedUser.loginPublisher(Self.__type,
authData: authData,
options: options)
}

#endif
Expand Down Expand Up @@ -178,12 +167,11 @@ public extension ParseApple {
completion: completion)
}

func link(authData: [String: String]?,
func link(authData: [String: String],
options: API.Options = [],
callbackQueue: DispatchQueue = .main,
completion: @escaping (Result<AuthenticatedUser, ParseError>) -> Void) {
guard AuthenticationKeys.id.verifyMandatoryKeys(authData: authData),
let authData = authData else {
guard AuthenticationKeys.id.verifyMandatoryKeys(authData: authData) else {
let error = ParseError(code: .unknownError,
message: "Should have authData in consisting of keys \"id\" and \"token\".")
callbackQueue.async {
Expand Down Expand Up @@ -211,30 +199,22 @@ public extension ParseApple {
func linkPublisher(user: String,
identityToken: Data,
options: API.Options = []) -> Future<AuthenticatedUser, ParseError> {
guard let appleAuthData = try? AuthenticationKeys.id.makeDictionary(user: user, identityToken: identityToken) else {
return Future { promise in
promise(.failure(.init(code: .unknownError,
message: "Couldn't create authData.")))
}
Future { promise in
self.link(user: user,
identityToken: identityToken,
options: options,
completion: promise)
}
return linkPublisher(authData: appleAuthData,
options: options)
}

@available(macOS 10.15, iOS 13.0, macCatalyst 13.0, watchOS 6.0, tvOS 13.0, *)
func linkPublisher(authData: [String: String]?,
func linkPublisher(authData: [String: String],
options: API.Options = []) -> Future<AuthenticatedUser, ParseError> {
guard AuthenticationKeys.id.verifyMandatoryKeys(authData: authData),
let authData = authData else {
let error = ParseError(code: .unknownError,
message: "Should have authData in consisting of keys \"id\" and \"token\".")
return Future { promise in
promise(.failure(error))
}
Future { promise in
self.link(authData: authData,
options: options,
completion: promise)
}
return AuthenticatedUser.linkPublisher(Self.__type,
authData: authData,
options: options)
}

#endif
Expand Down
79 changes: 36 additions & 43 deletions Sources/ParseSwift/Authentication/3rd Party/ParseLDAP.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public struct ParseLDAP<AuthenticatedUser: ParseUser>: ParseAuthentication {
/// Properly makes an authData dictionary with the required keys.
/// - parameter id: Required id.
/// - parameter password: Required password.
/// - returns: Required authData dictionary.
/// - returns: authData dictionary.
func makeDictionary(id: String, // swiftlint:disable:this identifier_name
password: String) -> [String: String] {
[AuthenticationKeys.id.rawValue: id,
Expand All @@ -37,9 +37,8 @@ public struct ParseLDAP<AuthenticatedUser: ParseUser>: ParseAuthentication {
/// Verifies all mandatory keys are in authData.
/// - parameter authData: Dictionary containing key/values.
/// - returns: `true` if all the mandatory keys are present, `false` otherwise.
func verifyMandatoryKeys(authData: [String: String]?) -> Bool {
guard let authData = authData,
authData[AuthenticationKeys.id.rawValue] != nil,
func verifyMandatoryKeys(authData: [String: String]) -> Bool {
guard authData[AuthenticationKeys.id.rawValue] != nil,
authData[AuthenticationKeys.password.rawValue] != nil else {
return false
}
Expand Down Expand Up @@ -67,22 +66,21 @@ public extension ParseLDAP {
options: API.Options = [],
callbackQueue: DispatchQueue = .main,
completion: @escaping (Result<AuthenticatedUser, ParseError>) -> Void) {
login(authData: AuthenticationKeys.id.makeDictionary(id: id, password: password),
options: options,
callbackQueue: callbackQueue,
completion: completion)
login(authData: AuthenticationKeys.id.makeDictionary(id: id,
password: password),
options: options,
callbackQueue: callbackQueue,
completion: completion)
}

func login(authData: [String: String]?,
func login(authData: [String: String],
options: API.Options = [],
callbackQueue: DispatchQueue = .main,
completion: @escaping (Result<AuthenticatedUser, ParseError>) -> Void) {
guard AuthenticationKeys.id.verifyMandatoryKeys(authData: authData),
let authData = authData else {
let error = ParseError(code: .unknownError,
message: "Should have authData in consisting of keys \"id\" and \"token\".")
guard AuthenticationKeys.id.verifyMandatoryKeys(authData: authData) else {
callbackQueue.async {
completion(.failure(error))
completion(.failure(.init(code: .unknownError,
message: "Should have authData in consisting of keys \"id\" and \"token\".")))
}
return
}
Expand All @@ -106,24 +104,22 @@ public extension ParseLDAP {
func loginPublisher(id: String, // swiftlint:disable:this identifier_name
password: String,
options: API.Options = []) -> Future<AuthenticatedUser, ParseError> {
loginPublisher(authData: AuthenticationKeys.id.makeDictionary(id: id, password: password),
options: options)
Future { promise in
self.login(id: id,
password: password,
options: options,
completion: promise)
}
}

@available(macOS 10.15, iOS 13.0, macCatalyst 13.0, watchOS 6.0, tvOS 13.0, *)
func loginPublisher(authData: [String: String]?,
func loginPublisher(authData: [String: String],
options: API.Options = []) -> Future<AuthenticatedUser, ParseError> {
guard AuthenticationKeys.id.verifyMandatoryKeys(authData: authData),
let authData = authData else {
let error = ParseError(code: .unknownError,
message: "Should have authData in consisting of keys \"id\" and \"token\".")
return Future { promise in
promise(.failure(error))
}
Future { promise in
self.login(authData: authData,
options: options,
completion: promise)
}
return AuthenticatedUser.loginPublisher(Self.__type,
authData: authData,
options: options)
}

#endif
Expand Down Expand Up @@ -151,12 +147,11 @@ public extension ParseLDAP {
completion: completion)
}

func link(authData: [String: String]?,
func link(authData: [String: String],
options: API.Options = [],
callbackQueue: DispatchQueue = .main,
completion: @escaping (Result<AuthenticatedUser, ParseError>) -> Void) {
guard AuthenticationKeys.id.verifyMandatoryKeys(authData: authData),
let authData = authData else {
guard AuthenticationKeys.id.verifyMandatoryKeys(authData: authData) else {
let error = ParseError(code: .unknownError,
message: "Should have authData in consisting of keys \"id\" and \"token\".")
callbackQueue.async {
Expand Down Expand Up @@ -184,24 +179,22 @@ public extension ParseLDAP {
func linkPublisher(id: String, // swiftlint:disable:this identifier_name
password: String,
options: API.Options = []) -> Future<AuthenticatedUser, ParseError> {
linkPublisher(authData: AuthenticationKeys.id.makeDictionary(id: id, password: password),
options: options)
Future { promise in
self.link(id: id,
password: password,
options: options,
completion: promise)
}
}

@available(macOS 10.15, iOS 13.0, macCatalyst 13.0, watchOS 6.0, tvOS 13.0, *)
func linkPublisher(authData: [String: String]?,
func linkPublisher(authData: [String: String],
options: API.Options = []) -> Future<AuthenticatedUser, ParseError> {
guard AuthenticationKeys.id.verifyMandatoryKeys(authData: authData),
let authData = authData else {
let error = ParseError(code: .unknownError,
message: "Should have authData in consisting of keys \"id\" and \"token\".")
return Future { promise in
promise(.failure(error))
}
Future { promise in
self.link(authData: authData,
options: options,
completion: promise)
}
return AuthenticatedUser.linkPublisher(Self.__type,
authData: authData,
options: options)
}

#endif
Expand Down
Loading