Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: make clientId mandatory #70

Merged
merged 8 commits into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

4 changes: 2 additions & 2 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@
"repositoryURL": "https://github.com/torusresearch/torus-utils-swift.git",
"state": {
"branch": null,
"revision": "3fb829e71caa275556a067a1ffa1ca579bafbf8e",
"version": "7.0.1"
"revision": "04c62fd5f73f21bd01b7c07e08f6135db26c5940",
"version": "8.0.0"
}
}
]
Expand Down
6 changes: 3 additions & 3 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:5.2
// swift-tools-version:5.5
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription
Expand All @@ -14,14 +14,14 @@ let package = Package(
targets: ["CustomAuth"])
],
dependencies: [
.package(name: "TorusUtils", url: "https://github.com/torusresearch/torus-utils-swift.git", from: "7.0.1"),
.package(url: "https://github.com/torusresearch/torus-utils-swift.git", from: "8.0.0"),
.package(name: "jwt-kit", url: "https://github.com/vapor/jwt-kit.git", from: "4.13.0"),
.package(name: "JWTDecode", url: "https://github.com/auth0/JWTDecode.swift.git", from: "3.1.0")
],
targets: [
.target(
name: "CustomAuth",
dependencies: ["TorusUtils", "JWTDecode"]),
dependencies: ["JWTDecode", .product(name: "TorusUtils", package: "torus-utils-swift")]),
.testTarget(
name: "CustomAuthTests",
dependencies: ["CustomAuth", .product(name: "JWTKit", package: "jwt-kit")])
Expand Down
21 changes: 13 additions & 8 deletions Sources/CustomAuth/CustomAuth.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ var tsSdkLogType = OSLogType.default
public struct TorusKeyData {
public let torusKey : TorusKey
public var userInfo : [String: Any]

public init(torusKey: TorusKey, userInfo: [String : Any]) {
self.torusKey = torusKey
self.userInfo = userInfo
}
}

/// Provides integration of an iOS app with Torus CustomAuth.
Expand All @@ -44,15 +49,15 @@ open class CustomAuth {
/// - factory: Providng mocking by implementing TDSDKFactoryProtocol.
/// - network: Etherum network to be used.
/// - loglevel: Indicates the log level of this instance. All logs lower than this level will be ignored.
public init(aggregateVerifierType: verifierTypes, aggregateVerifier: String, subVerifierDetails: [SubVerifierDetails], network: TorusNetwork = .legacy(.MAINNET), loglevel: OSLogType = .debug, urlSession: URLSession = URLSession.shared, enableOneKey: Bool = false, networkUrl: String? = nil) {
public init(web3AuthClientId: String ,aggregateVerifierType: verifierTypes, aggregateVerifier: String, subVerifierDetails: [SubVerifierDetails], network: TorusNetwork, loglevel: OSLogType = .debug, urlSession: URLSession = URLSession.shared, enableOneKey: Bool = false, networkUrl: String? = nil) {
tsSdkLogType = loglevel
self.networkUrl = networkUrl
self.enableOneKey = enableOneKey
// factory method
self.nodeDetailManager = NodeDetailManager(network: network)
self.urlSession = urlSession

self.torusUtils = TorusUtils(loglevel: loglevel, urlSession: urlSession, enableOneKey: enableOneKey, serverTimeOffset: 1000, network: network)
self.torusUtils = TorusUtils( loglevel: loglevel, urlSession: urlSession, enableOneKey: enableOneKey, serverTimeOffset: 1000, network: network, clientId: web3AuthClientId)

// verifier details
self.aggregateVerifier = aggregateVerifier
Expand All @@ -66,15 +71,15 @@ open class CustomAuth {
/// - aggregateVerifierType: Type of the verifier. Use `singleLogin` for single providers. Only `singleLogin` and `singleIdVerifier` is supported currently.
/// - aggregateVerifier: Name of the verifier to be used..
/// - subVerifierDetails: Details of each subverifiers to be used.
public convenience init(aggregateVerifierType: verifierTypes, aggregateVerifier: String, subVerifierDetails: [SubVerifierDetails], enableOneKey: Bool = false, networkUrl: String? = nil) {
public convenience init(web3AuthClientId: String ,aggregateVerifierType: verifierTypes, aggregateVerifier: String, subVerifierDetails: [SubVerifierDetails], network: TorusNetwork, enableOneKey: Bool = false, networkUrl: String? = nil) {
// let factory = CASDKFactory()
self.init(aggregateVerifierType: aggregateVerifierType, aggregateVerifier: aggregateVerifier, subVerifierDetails: subVerifierDetails, network: .legacy(.MAINNET), loglevel: .debug, enableOneKey: enableOneKey, networkUrl: networkUrl)
self.init(web3AuthClientId: web3AuthClientId, aggregateVerifierType: aggregateVerifierType, aggregateVerifier: aggregateVerifier, subVerifierDetails: subVerifierDetails, network: network, loglevel: .debug, enableOneKey: enableOneKey, networkUrl: networkUrl)
}

public convenience init(aggregateVerifierType: verifierTypes, aggregateVerifier: String, subVerifierDetails: [SubVerifierDetails], loglevel: OSLogType = .debug, enableOneKey: Bool = false, networkUrl: String? = nil) {
// let factory = CASDKFactory()
self.init(aggregateVerifierType: aggregateVerifierType, aggregateVerifier: aggregateVerifier, subVerifierDetails: subVerifierDetails, network: .legacy(.MAINNET), loglevel: loglevel, enableOneKey: enableOneKey, networkUrl: networkUrl)
}
// public convenience init(web3AuthClientId: String ,aggregateVerifierType: verifierTypes, aggregateVerifier: String, subVerifierDetails: [SubVerifierDetails], network: TorusNetwork, loglevel: OSLogType = .debug, enableOneKey: Bool = false, networkUrl: String? = nil) {
metalurgical marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should remove these commented code blocks

//// let factory = CASDKFactory()
// self.init(web3AuthClientId: web3AuthClientId, aggregateVerifierType: aggregateVerifierType, aggregateVerifier: aggregateVerifier, subVerifierDetails: subVerifierDetails, network: network, loglevel: loglevel, enableOneKey: enableOneKey, networkUrl: networkUrl)
// }

/// Retrieve information of Torus nodes from a predefined Etherum contract.
/// - Returns: An array of URLs to the nodes.
Expand Down
6 changes: 3 additions & 3 deletions Tests/CustomAuthTests/CustomAuthTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ final class MockSDKTest: XCTestCase {
let expectedVerifier = fakeData.generateVerifier()
let expectedVerfierId = fakeData.generateRandomEmail(of: 6)

let CustomAuth = CustomAuth(aggregateVerifierType: .singleLogin, aggregateVerifier: expectedVerifier, subVerifierDetails: [])
let CustomAuth = CustomAuth(web3AuthClientId:"YOUR_CLIENT_ID", aggregateVerifierType: .singleLogin, aggregateVerifier: expectedVerifier, subVerifierDetails: [], network: .legacy(.MAINNET))

var mockTorusUtils = MockTorusUtils()
let mockTorusUtils = MockTorusUtils()
CustomAuth.torusUtils = mockTorusUtils
// Set Mock data
mockTorusUtils.retrieveShares_output["privateKey"] = expectedPrivateKey
Expand Down Expand Up @@ -55,7 +55,7 @@ final class MockSDKTest: XCTestCase {

let subVerifier = [SubVerifierDetails(loginProvider: .jwt, clientId: fakeData.generateVerifier(), verifier: expectedVerifier, redirectURL: fakeData.generateVerifier())]

let CustomAuth = CustomAuth(aggregateVerifierType: .singleIdVerifier, aggregateVerifier: expectedVerifier, subVerifierDetails: subVerifier)
let CustomAuth = CustomAuth(web3AuthClientId:"YOUR_CLIENT_ID", aggregateVerifierType: .singleIdVerifier, aggregateVerifier: expectedVerifier, subVerifierDetails: subVerifier, network: .legacy(.MAINNET))
// var mockTorusUtils = CustomAuth.torusUtils as! MockAbstractTorusUtils
let mockTorusUtils = MockTorusUtils()
CustomAuth.torusUtils = mockTorusUtils
Expand Down
20 changes: 18 additions & 2 deletions Tests/CustomAuthTests/IntegrationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ final class IntegrationTests: XCTestCase {
redirectURL: "com.googleusercontent.apps.238941746713-vfap8uumijal4ump28p9jd3lbe6onqt4:/oauthredirect",
browserRedirectURL: "https://scripts.toruswallet.io/redirect.html")

IntegrationTests.sdk = CustomAuth(aggregateVerifierType: .singleLogin, aggregateVerifier: "torus-test-ios-public", subVerifierDetails: [sub], network: .legacy(.CYAN))
IntegrationTests.sdk = CustomAuth(web3AuthClientId:"YOUR_CLIENT_ID", aggregateVerifierType: .singleLogin, aggregateVerifier: "torus-test-ios-public", subVerifierDetails: [sub], network: .legacy(.CYAN))
}

func test_getTorusKey() async throws {
Expand Down Expand Up @@ -53,7 +53,23 @@ final class IntegrationTests: XCTestCase {
verifier: "google-lrc",
redirectURL: "com.googleusercontent.apps.238941746713-vfap8uumijal4ump28p9jd3lbe6onqt4:/oauthredirect",
browserRedirectURL: "https://scripts.toruswallet.io/redirect.html")
let sdk = CustomAuth(aggregateVerifierType: .singleLogin, aggregateVerifier: "torus-test-ios-public", subVerifierDetails: [sub], network: .sapphire(.SAPPHIRE_DEVNET))
let sdk = CustomAuth(web3AuthClientId:"221898609709-obfn3p63741l5333093430j3qeiinaa8.apps.googleusercontent.com", aggregateVerifierType: .singleLogin, aggregateVerifier: "torus-test-ios-public", subVerifierDetails: [sub], network: .sapphire(.SAPPHIRE_DEVNET))

let jwt = try! generateIdToken(email: TORUS_TEST_EMAIL)
let data = try await sdk.getTorusKey(verifier: TORUS_TEST_VERIFIER, verifierId: TORUS_TEST_EMAIL, idToken: jwt)
let finalKeyDataDict = data.finalKeyData!
let evmAddress = finalKeyDataDict.evmAddress
XCTAssertEqual(evmAddress, "0x81001206C06AD09b3611b593aEEd3A607d79871E")
}

func test_Sapphire_getTorusKey_gated() async throws {
let sub = SubVerifierDetails(loginType: .web,
loginProvider: .jwt,
clientId: "221898609709-obfn3p63741l5333093430j3qeiinaa8.apps.googleusercontent.com",
verifier: "torus-test-ios-public",
redirectURL: "com.googleusercontent.apps.238941746713-vfap8uumijal4ump28p9jd3lbe6onqt4:/oauthredirect",
browserRedirectURL: "https://scripts.toruswallet.io/redirect.html")
let sdk = CustomAuth(web3AuthClientId:"221898609709-obfn3p63741l5333093430j3qeiinaa8.apps.googleusercontent.com", aggregateVerifierType: .singleLogin, aggregateVerifier: "torus-test-ios-public", subVerifierDetails: [sub], network: .sapphire(.SAPPHIRE_DEVNET))

let jwt = try! generateIdToken(email: TORUS_TEST_EMAIL)
let data = try await sdk.getTorusKey(verifier: TORUS_TEST_VERIFIER, verifierId: TORUS_TEST_EMAIL, idToken: jwt)
Expand Down
2 changes: 1 addition & 1 deletion Tests/CustomAuthTests/StubURLProtocolTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class StubMockCASDKFactory: CASDKFactoryProtocol {
public func createTorusUtils(loglevel: OSLogType, urlSession: URLSession, enableOneKey: Bool, network: TorusNetwork) -> AbstractTorusUtils {
let allowHost = network.signerMap.appending("/api/allow")
let signerHost = network.signerMap.appending("/api/sign")
return StubMockTorusUtils(loglevel: loglevel, urlSession: urlSession, enableOneKey: enableOneKey, signerHost: signerHost, allowHost: allowHost)
return StubMockTorusUtils(loglevel: loglevel, urlSession: urlSession, enableOneKey: enableOneKey, signerHost: signerHost, allowHost: allowHost, clientId: "Your Client ID")
}

public init() {
Expand Down
Loading