diff --git a/Package.resolved b/Package.resolved index a318f3c8..4d683174 100644 --- a/Package.resolved +++ b/Package.resolved @@ -3,7 +3,7 @@ "pins": [ { "package": "NWWebSocket", - "repositoryURL": "https://github.com/pusher/NWWebSocket.git", + "repositoryURL": "https://github.com/kwiadmin/NWWebSocket", "state": { "branch": null, "revision": "eed470bc3607bc4893046f461107ec463dbd1220", @@ -12,7 +12,7 @@ }, { "package": "TweetNacl", - "repositoryURL": "https://github.com/bitmark-inc/tweetnacl-swiftwrap", + "repositoryURL": "https://github.com/kwiadmin/tweetnacl-swiftwrap", "state": { "branch": null, "revision": "d1552db4d907f2c5cb3d1bf1336496b2e16c8ecf", diff --git a/Package.swift b/Package.swift index 1eabbfe2..29a8fc7d 100644 --- a/Package.swift +++ b/Package.swift @@ -9,8 +9,8 @@ let package = Package( .library(name: "PusherSwift", targets: ["PusherSwift"]) ], dependencies: [ - .package(url: "https://github.com/pusher/NWWebSocket.git", .upToNextMajor(from: "0.5.2")), - .package(url: "https://github.com/bitmark-inc/tweetnacl-swiftwrap", .upToNextMajor(from: "1.0.0")), + .package(url: "https://github.com/kwiadmin/NWWebSocket", .upToNextMajor(from: "0.5.2")), + .package(url: "https://github.com/kwiadmin/tweetnacl-swiftwrap", .upToNextMajor(from: "1.0.0")), ], targets: [ .target( diff --git a/Sources/Models/AuthError.swift b/Sources/Models/AuthError.swift index b8580d2f..d652bda0 100644 --- a/Sources/Models/AuthError.swift +++ b/Sources/Models/AuthError.swift @@ -1,19 +1,26 @@ import Foundation -struct AuthError: Error { - enum Kind { +public struct AuthError: Error { + public enum Kind { case notConnected case noMethod case couldNotBuildRequest case invalidAuthResponse case requestFailure } - - let kind: Kind - - var message: String? - - var response: URLResponse? - var data: String? - var error: NSError? + + public init(kind: Kind, message: String? = nil, response: URLResponse? = nil, data: String? = nil, error: NSError? = nil) { + self.kind = kind + self.message = message + self.response = response + self.data = data + self.error = error + } + + + public let kind: Kind + public var message: String? + public var response: URLResponse? + public var data: String? + public var error: NSError? } diff --git a/Sources/Protocols/Authorizer.swift b/Sources/Protocols/Authorizer.swift index 3e82c7f7..7ff7f325 100644 --- a/Sources/Protocols/Authorizer.swift +++ b/Sources/Protocols/Authorizer.swift @@ -1,5 +1,5 @@ import Foundation -@objc public protocol Authorizer { - @objc func fetchAuthValue(socketID: String, channelName: String, completionHandler: @escaping (PusherAuth?) -> Void) +public protocol Authorizer { + func fetchAuthValue(socketID: String, channelName: String, completionHandler: @escaping (PusherAuth?, AuthError?) -> ()) } diff --git a/Sources/Services/PusherConnection.swift b/Sources/Services/PusherConnection.swift index 87325c2b..1fe8e706 100644 --- a/Sources/Services/PusherConnection.swift +++ b/Sources/Services/PusherConnection.swift @@ -730,12 +730,7 @@ import NWWebSocket } case .authorizer(authorizer: let authorizer): - authorizer.fetchAuthValue(socketID: socketId, channelName: channel.name) { pusherAuth in - if pusherAuth == nil { - Logger.shared.debug(for: .authInfoForCompletionHandlerIsNil) - } - completionHandler(pusherAuth, nil) - } + authorizer.fetchAuthValue(socketID: socketId, channelName: channel.name, completionHandler: completionHandler) return true case .inline(secret: let secret): diff --git a/Tests/Integration/AuthenticationTests.swift b/Tests/Integration/AuthenticationTests.swift index ecd38ab0..61f6d97a 100644 --- a/Tests/Integration/AuthenticationTests.swift +++ b/Tests/Integration/AuthenticationTests.swift @@ -217,8 +217,8 @@ class AuthenticationTests: XCTestCase { func testAuthorizationUsingSomethingConformingToTheAuthorizerProtocol() { class SomeAuthorizer: Authorizer { - func fetchAuthValue(socketID: String, channelName: String, completionHandler: @escaping (PusherAuth?) -> Void) { - completionHandler(PusherAuth(auth: "testKey123:authorizerblah123")) + func fetchAuthValue(socketID: String, channelName: String, completionHandler: @escaping (PusherAuth?, AuthError?) -> ()) { + completionHandler(PusherAuth(auth: "testKey123:authorizerblah123"), nil) } } @@ -248,11 +248,11 @@ class AuthenticationTests: XCTestCase { func testAuthorizationOfPresenceChannelSubscriptionUsingSomethingConformingToTheAuthorizerProtocol() { class SomeAuthorizer: Authorizer { - func fetchAuthValue(socketID: String, channelName: String, completionHandler: @escaping (PusherAuth?) -> Void) { + func fetchAuthValue(socketID: String, channelName: String, completionHandler: @escaping (PusherAuth?, AuthError?) -> ()) { completionHandler(PusherAuth( auth: "testKey123:authorizerblah1234", channelData: "{\"\(Constants.JSONKeys.userId)\":\"777\", \"\(Constants.JSONKeys.userInfo)\":{\"twitter\":\"hamchapman\"}}" - )) + ), nil) } } diff --git a/Tests/Unit/Models/PrivateEncryptedChannelTests.swift b/Tests/Unit/Models/PrivateEncryptedChannelTests.swift index 0987e640..bca7434c 100644 --- a/Tests/Unit/Models/PrivateEncryptedChannelTests.swift +++ b/Tests/Unit/Models/PrivateEncryptedChannelTests.swift @@ -310,8 +310,8 @@ class PrivateEncryptedChannelTests: XCTestCase { init(_ authResponseSequence: [PusherAuth]) { self.authResponseSequence = authResponseSequence } - func fetchAuthValue(socketID: String, channelName: String, completionHandler: @escaping (PusherAuth?) -> Void) { - completionHandler(authResponseSequence.removeFirst()) + func fetchAuthValue(socketID: String, channelName: String, completionHandler: @escaping (PusherAuth?, AuthError?) -> ()) { + completionHandler(authResponseSequence.removeFirst(), nil) } }