From c8ab6dfd2f0c66505bcc1a08bbb78dd9ed5b1df4 Mon Sep 17 00:00:00 2001 From: ieow Date: Thu, 31 Aug 2023 12:29:58 +0800 Subject: [PATCH 1/3] fix: add back verifier verifierId --- Sources/CustomAuth/CustomAuth.swift | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/Sources/CustomAuth/CustomAuth.swift b/Sources/CustomAuth/CustomAuth.swift index 480a409..3f21997 100644 --- a/Sources/CustomAuth/CustomAuth.swift +++ b/Sources/CustomAuth/CustomAuth.swift @@ -15,6 +15,12 @@ import CommonSources // Global variable var tsSdkLogType = OSLogType.default +public struct TorusKeyData { + public let torusKey : TorusKey + public let verifier : String + public let verifierId : String +} + /// Provides integration of an iOS app with Torus CustomAuth. open class CustomAuth { var nodeDetailManager: NodeDetailManager @@ -84,7 +90,7 @@ open class CustomAuth { /// - browserType: Indicates the way to open the browser for login flow. Use `.external` for opening system safari, or `.asWebAuthSession` for opening an in-app ASwebAuthenticationSession. /// - modalPresentationStyle: Indicates the UIModalPresentationStyle for the popup. /// - Returns: A promise that resolve with a Dictionary that contain at least `privateKey` and `publicAddress` field.. - open func triggerLogin(controller: UIViewController? = nil, browserType: URLOpenerTypes = .asWebAuthSession, modalPresentationStyle: UIModalPresentationStyle = .fullScreen) async throws -> TorusKey { + open func triggerLogin(controller: UIViewController? = nil, browserType: URLOpenerTypes = .asWebAuthSession, modalPresentationStyle: UIModalPresentationStyle = .fullScreen) async throws -> TorusKeyData { os_log("triggerLogin called with %@ %@", log: getTorusLogger(log: CASDKLogger.core, type: .info), type: .info, browserType.rawValue, modalPresentationStyle.rawValue) // Set browser authorizeURLHandler = browserType @@ -103,7 +109,7 @@ open class CustomAuth { } } - open func handleSingleLogins(controller: UIViewController?, modalPresentationStyle: UIModalPresentationStyle = .fullScreen) async throws -> TorusKey { + open func handleSingleLogins(controller: UIViewController?, modalPresentationStyle: UIModalPresentationStyle = .fullScreen) async throws -> TorusKeyData { if let subVerifier = subVerifierDetails.first { let loginURL = subVerifier.getLoginURL() await openURL(url: loginURL, view: controller, modalPresentationStyle: modalPresentationStyle) @@ -133,7 +139,7 @@ open class CustomAuth { data.removeValue(forKey: "tokenForKeys") data.removeValue(forKey: "verifierId") let torusKey = try await getTorusKey(verifier: self.aggregateVerifier, verifierId: verifierId, idToken: idToken, userData: data) - return torusKey + return TorusKeyData(torusKey: torusKey, verifier: aggregateVerifier, verifierId: verifierId) } catch { os_log("handleSingleLogin: err: %s", log: getTorusLogger(log: CASDKLogger.core, type: .error), type: .error, error.localizedDescription) throw error @@ -144,7 +150,7 @@ open class CustomAuth { throw CASDKError.unknownError } - open func handleSingleIdVerifier(controller: UIViewController?, modalPresentationStyle: UIModalPresentationStyle = .fullScreen) async throws -> TorusKey { + open func handleSingleIdVerifier(controller: UIViewController?, modalPresentationStyle: UIModalPresentationStyle = .fullScreen) async throws -> TorusKeyData { if let subVerifier = subVerifierDetails.first { let loginURL = subVerifier.getLoginURL() await MainActor.run(body: { @@ -175,7 +181,7 @@ open class CustomAuth { data.removeValue(forKey: "tokenForKeys") data.removeValue(forKey: "verifierId") let aggTorusKey = try await getAggregateTorusKey(verifier: self.aggregateVerifier, verifierId: verifierId, idToken: idToken, subVerifierDetails: subVerifier, userData: newData) - return aggTorusKey + return TorusKeyData(torusKey: aggTorusKey, verifier: self.aggregateVerifier, verifierId: verifierId) } catch { os_log("handleSingleIdVerifier err: %s", log: getTorusLogger(log: CASDKLogger.core, type: .error), type: .error, error.localizedDescription) throw error @@ -186,12 +192,12 @@ open class CustomAuth { } - func handleAndAggregateVerifier(controller: UIViewController?) async throws -> TorusKey { + func handleAndAggregateVerifier(controller: UIViewController?) async throws -> TorusKeyData { // TODO: implement verifier throw CASDKError.methodUnavailable } - func handleOrAggregateVerifier(controller: UIViewController?) async throws -> TorusKey { + func handleOrAggregateVerifier(controller: UIViewController?) async throws -> TorusKeyData { // TODO: implement verifier throw CASDKError.methodUnavailable } From 92dfe1fdbdb39391bb5807c392f0c127a92cac31 Mon Sep 17 00:00:00 2001 From: ieow Date: Thu, 31 Aug 2023 12:32:09 +0800 Subject: [PATCH 2/3] fix: formatting --- Sources/CustomAuth/CustomAuth.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/CustomAuth/CustomAuth.swift b/Sources/CustomAuth/CustomAuth.swift index 3f21997..f71dd53 100644 --- a/Sources/CustomAuth/CustomAuth.swift +++ b/Sources/CustomAuth/CustomAuth.swift @@ -139,7 +139,7 @@ open class CustomAuth { data.removeValue(forKey: "tokenForKeys") data.removeValue(forKey: "verifierId") let torusKey = try await getTorusKey(verifier: self.aggregateVerifier, verifierId: verifierId, idToken: idToken, userData: data) - return TorusKeyData(torusKey: torusKey, verifier: aggregateVerifier, verifierId: verifierId) + return TorusKeyData(torusKey: torusKey, verifier: self.aggregateVerifier, verifierId: verifierId) } catch { os_log("handleSingleLogin: err: %s", log: getTorusLogger(log: CASDKLogger.core, type: .error), type: .error, error.localizedDescription) throw error From ff5114daeac60a8473048c10db05938eaa7badf9 Mon Sep 17 00:00:00 2001 From: ieow Date: Thu, 31 Aug 2023 13:11:07 +0800 Subject: [PATCH 3/3] fix: add userInfo --- Sources/CustomAuth/CustomAuth.swift | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/Sources/CustomAuth/CustomAuth.swift b/Sources/CustomAuth/CustomAuth.swift index f71dd53..7921939 100644 --- a/Sources/CustomAuth/CustomAuth.swift +++ b/Sources/CustomAuth/CustomAuth.swift @@ -17,8 +17,7 @@ var tsSdkLogType = OSLogType.default public struct TorusKeyData { public let torusKey : TorusKey - public let verifier : String - public let verifierId : String + public var userInfo : [String: Any] } /// Provides integration of an iOS app with Torus CustomAuth. @@ -139,7 +138,9 @@ open class CustomAuth { data.removeValue(forKey: "tokenForKeys") data.removeValue(forKey: "verifierId") let torusKey = try await getTorusKey(verifier: self.aggregateVerifier, verifierId: verifierId, idToken: idToken, userData: data) - return TorusKeyData(torusKey: torusKey, verifier: self.aggregateVerifier, verifierId: verifierId) + var result = TorusKeyData(torusKey: torusKey, userInfo: newData) + result.userInfo["verifier"] = self.aggregateVerifier + return result } catch { os_log("handleSingleLogin: err: %s", log: getTorusLogger(log: CASDKLogger.core, type: .error), type: .error, error.localizedDescription) throw error @@ -181,7 +182,9 @@ open class CustomAuth { data.removeValue(forKey: "tokenForKeys") data.removeValue(forKey: "verifierId") let aggTorusKey = try await getAggregateTorusKey(verifier: self.aggregateVerifier, verifierId: verifierId, idToken: idToken, subVerifierDetails: subVerifier, userData: newData) - return TorusKeyData(torusKey: aggTorusKey, verifier: self.aggregateVerifier, verifierId: verifierId) + var result = TorusKeyData(torusKey: aggTorusKey, userInfo: newData) + result.userInfo["verifier"] = self.aggregateVerifier + return result } catch { os_log("handleSingleIdVerifier err: %s", log: getTorusLogger(log: CASDKLogger.core, type: .error), type: .error, error.localizedDescription) throw error