From 576139ce446e397bce4f2b68b9b7d28ab5b0082f Mon Sep 17 00:00:00 2001 From: metalurgical <97008724+metalurgical@users.noreply.github.com> Date: Thu, 12 Sep 2024 06:38:16 +0200 Subject: [PATCH] update cocoapods demo --- .../CustomAuthDemo/ContentView.swift | 105 +++++---- cocoapods/cptest/LoginView.swift | 32 +-- cocoapods/cptest/ViewModel.swift | 212 +++++------------- 3 files changed, 107 insertions(+), 242 deletions(-) diff --git a/CustomAuthDemo/CustomAuthDemo/ContentView.swift b/CustomAuthDemo/CustomAuthDemo/ContentView.swift index bc5c1a4..28bd4d7 100644 --- a/CustomAuthDemo/CustomAuthDemo/ContentView.swift +++ b/CustomAuthDemo/CustomAuthDemo/ContentView.swift @@ -2,14 +2,13 @@ import CustomAuth import SwiftUI struct ContentView: View { - var body: some View { VStack { Button(action: { Task { do { let sub = SingleLoginParams(typeOfLogin: .google, verifier: "w3a-google-demo", clientId: "519228911939-cri01h55lsjbsia1k7ll6qpalrus75ps.apps.googleusercontent.com") - + let customAuthArgs = CustomAuthArgs(urlScheme: "tdsdk://tdsdk/oauthCallback", network: .sapphire(.SAPPHIRE_MAINNET), enableOneKey: true, web3AuthClientId: "BPi5PB_UiIZ-cPz1GtV5i1I2iOSOHuimiXBI0e-Oe_u6X3oVAbCiAZOTEBtTXw4tsluTITPqA8zMsfxIKMjiqNQ") let customAuth = try CustomAuth(config: customAuthArgs) let torusLoginResponse = try await customAuth.triggerLogin(args: sub) @@ -18,19 +17,18 @@ struct ContentView: View { } catch { print(error) } - } }, label: { Text("Google Login") }) - + Button(action: { Task { do { let sub = SingleLoginParams(typeOfLogin: .discord, verifier: "w3a-discord-demo", clientId: "1151006428610433095") - + let customAuthArgs = CustomAuthArgs(urlScheme: "tdsdk://tdsdk/oauthCallback", network: .sapphire(.SAPPHIRE_MAINNET), enableOneKey: true, web3AuthClientId: "BPi5PB_UiIZ-cPz1GtV5i1I2iOSOHuimiXBI0e-Oe_u6X3oVAbCiAZOTEBtTXw4tsluTITPqA8zMsfxIKMjiqNQ") - + let customAuth = try CustomAuth(config: customAuthArgs) let torusLoginResponse = try await customAuth.triggerLogin(args: sub) let encoded = try JSONEncoder().encode(torusLoginResponse) @@ -42,32 +40,31 @@ struct ContentView: View { }, label: { Text("Discord Login") }) - - - Button(action: { - Task { - do { - let sub = SingleLoginParams(typeOfLogin: .facebook, verifier: "w3a-facebook-demo", clientId: "342380202252650") - - let customAuthArgs = CustomAuthArgs(urlScheme: "tdsdk://tdsdk/oauthCallback", network: .sapphire(.SAPPHIRE_MAINNET), enableOneKey: true, web3AuthClientId: "BPi5PB_UiIZ-cPz1GtV5i1I2iOSOHuimiXBI0e-Oe_u6X3oVAbCiAZOTEBtTXw4tsluTITPqA8zMsfxIKMjiqNQ") - - let customAuth = try CustomAuth(config: customAuthArgs) - let torusLoginResponse = try await customAuth.triggerLogin(args: sub) - let encoded = try JSONEncoder().encode(torusLoginResponse) - print(String(data: encoded, encoding: .utf8)!) - } catch { - print(error) - } - } - }, label: { - Text("Facebook Login") - }) - + + Button(action: { + Task { + do { + let sub = SingleLoginParams(typeOfLogin: .facebook, verifier: "w3a-facebook-demo", clientId: "342380202252650") + + let customAuthArgs = CustomAuthArgs(urlScheme: "tdsdk://tdsdk/oauthCallback", network: .sapphire(.SAPPHIRE_MAINNET), enableOneKey: true, web3AuthClientId: "BPi5PB_UiIZ-cPz1GtV5i1I2iOSOHuimiXBI0e-Oe_u6X3oVAbCiAZOTEBtTXw4tsluTITPqA8zMsfxIKMjiqNQ") + + let customAuth = try CustomAuth(config: customAuthArgs) + let torusLoginResponse = try await customAuth.triggerLogin(args: sub) + let encoded = try JSONEncoder().encode(torusLoginResponse) + print(String(data: encoded, encoding: .utf8)!) + } catch { + print(error) + } + } + }, label: { + Text("Facebook Login") + }) + Button(action: { - let sub = SingleLoginParams(typeOfLogin: .twitch, verifier: "w3a-twitch-demo", clientId: "3k7e70gowvxjaxg71hjnc8h8ih3bpf") - let customAuthArgs = CustomAuthArgs(urlScheme: "tdsdk://tdsdk/oauthCallback", network: .sapphire(.SAPPHIRE_MAINNET), enableOneKey: true, web3AuthClientId: "BPi5PB_UiIZ-cPz1GtV5i1I2iOSOHuimiXBI0e-Oe_u6X3oVAbCiAZOTEBtTXw4tsluTITPqA8zMsfxIKMjiqNQ") Task { do { + let sub = SingleLoginParams(typeOfLogin: .twitch, verifier: "w3a-twitch-demo", clientId: "3k7e70gowvxjaxg71hjnc8h8ih3bpf") + let customAuthArgs = CustomAuthArgs(urlScheme: "tdsdk://tdsdk/oauthCallback", network: .sapphire(.SAPPHIRE_MAINNET), enableOneKey: true, web3AuthClientId: "BPi5PB_UiIZ-cPz1GtV5i1I2iOSOHuimiXBI0e-Oe_u6X3oVAbCiAZOTEBtTXw4tsluTITPqA8zMsfxIKMjiqNQ") let customAuth = try CustomAuth(config: customAuthArgs) let torusLoginResponse = try await customAuth.triggerLogin(args: sub) let encoded = try JSONEncoder().encode(torusLoginResponse) @@ -79,12 +76,13 @@ struct ContentView: View { }, label: { Text("Twitch Login") }) - + Button(action: { - let sub = SingleLoginParams(typeOfLogin: .apple, verifier: "w3a-auth0-demo", clientId: "hUVVf4SEsZT7syOiL0gLU9hFEtm2gQ6O", jwtParams: Auth0ClientOptions(connection: "apple", domain: "web3auth.au.auth0.com")) - let customAuthArgs = CustomAuthArgs(urlScheme: "tdsdk://tdsdk/oauthCallback", network: .sapphire(.SAPPHIRE_MAINNET), enableOneKey: true, web3AuthClientId: "BPi5PB_UiIZ-cPz1GtV5i1I2iOSOHuimiXBI0e-Oe_u6X3oVAbCiAZOTEBtTXw4tsluTITPqA8zMsfxIKMjiqNQ") Task { do { + let sub = SingleLoginParams(typeOfLogin: .apple, verifier: "w3a-auth0-demo", clientId: "hUVVf4SEsZT7syOiL0gLU9hFEtm2gQ6O", jwtParams: Auth0ClientOptions(connection: "apple", domain: "web3auth.au.auth0.com")) + let customAuthArgs = CustomAuthArgs(urlScheme: "tdsdk://tdsdk/oauthCallback", network: .sapphire(.SAPPHIRE_MAINNET), enableOneKey: true, web3AuthClientId: "BPi5PB_UiIZ-cPz1GtV5i1I2iOSOHuimiXBI0e-Oe_u6X3oVAbCiAZOTEBtTXw4tsluTITPqA8zMsfxIKMjiqNQ") + let customAuth = try CustomAuth(config: customAuthArgs) let torusLoginResponse = try await customAuth.triggerLogin(args: sub) let encoded = try JSONEncoder().encode(torusLoginResponse) @@ -96,12 +94,12 @@ struct ContentView: View { }, label: { Text("Apple Login") }) - + Button(action: { - let sub = SingleLoginParams(typeOfLogin: .github, verifier: "w3a-auth0-demo", clientId: "hUVVf4SEsZT7syOiL0gLU9hFEtm2gQ6O", jwtParams: Auth0ClientOptions(connection: "github", domain: "web3auth.au.auth0.com", verifierIdField: "sub")) - let customAuthArgs = CustomAuthArgs(urlScheme: "tdsdk://tdsdk/oauthCallback", network: .sapphire(.SAPPHIRE_MAINNET), enableOneKey: true, web3AuthClientId: "BPi5PB_UiIZ-cPz1GtV5i1I2iOSOHuimiXBI0e-Oe_u6X3oVAbCiAZOTEBtTXw4tsluTITPqA8zMsfxIKMjiqNQ") Task { do { + let sub = SingleLoginParams(typeOfLogin: .github, verifier: "w3a-auth0-demo", clientId: "hUVVf4SEsZT7syOiL0gLU9hFEtm2gQ6O", jwtParams: Auth0ClientOptions(connection: "github", domain: "web3auth.au.auth0.com", verifierIdField: "sub")) + let customAuthArgs = CustomAuthArgs(urlScheme: "tdsdk://tdsdk/oauthCallback", network: .sapphire(.SAPPHIRE_MAINNET), enableOneKey: true, web3AuthClientId: "BPi5PB_UiIZ-cPz1GtV5i1I2iOSOHuimiXBI0e-Oe_u6X3oVAbCiAZOTEBtTXw4tsluTITPqA8zMsfxIKMjiqNQ") let customAuth = try CustomAuth(config: customAuthArgs) let torusLoginResponse = try await customAuth.triggerLogin(args: sub) let encoded = try JSONEncoder().encode(torusLoginResponse) @@ -113,17 +111,17 @@ struct ContentView: View { }, label: { Text("GitHub Login") }) - + Button(action: { - let sub = SingleLoginParams(typeOfLogin: .email_password, - verifier: "torus-auth0-email-password", clientId: "sqKRBVSdwa4WLkaq419U7Bamlh5vK1H7", - jwtParams: Auth0ClientOptions( - connection: "Username-Password-Authentication", - domain: "torus-test.auth0.com", - verifierIdField: "name")) - let customAuthArgs = CustomAuthArgs(urlScheme: "tdsdk://tdsdk/oauthCallback", network: .legacy(.TESTNET), enableOneKey: true, web3AuthClientId: "BPi5PB_UiIZ-cPz1GtV5i1I2iOSOHuimiXBI0e-Oe_u6X3oVAbCiAZOTEBtTXw4tsluTITPqA8zMsfxIKMjiqNQ") Task { do { + let sub = SingleLoginParams(typeOfLogin: .email_password, + verifier: "torus-auth0-email-password", clientId: "sqKRBVSdwa4WLkaq419U7Bamlh5vK1H7", + jwtParams: Auth0ClientOptions( + connection: "Username-Password-Authentication", + domain: "torus-test.auth0.com", + verifierIdField: "name")) + let customAuthArgs = CustomAuthArgs(urlScheme: "tdsdk://tdsdk/oauthCallback", network: .legacy(.TESTNET), enableOneKey: true, web3AuthClientId: "BPi5PB_UiIZ-cPz1GtV5i1I2iOSOHuimiXBI0e-Oe_u6X3oVAbCiAZOTEBtTXw4tsluTITPqA8zMsfxIKMjiqNQ") let customAuth = try CustomAuth(config: customAuthArgs) let torusLoginResponse = try await customAuth.triggerLogin(args: sub) let encoded = try JSONEncoder().encode(torusLoginResponse) @@ -135,18 +133,18 @@ struct ContentView: View { }, label: { Text("Email Password") }) - + Label( title: { Text("Aggregate Verifiers") }, icon: { Image(systemName: "circle") } ) - + Button(action: { - let aggregateLoginParams = AggregateLoginParams(aggregateVerifierType: AggregateVerifierType.single_id_verifier, verifierIdentifier: "aggregate-sapphire", subVerifierDetailsArray: [SingleLoginParams(typeOfLogin: .google, verifier: "w3a-google", clientId: "519228911939-cri01h55lsjbsia1k7ll6qpalrus75ps.apps.googleusercontent.com")]) - - let customAuthArgs = CustomAuthArgs(urlScheme: "tdsdk://tdsdk/oauthCallback", network: .sapphire(.SAPPHIRE_MAINNET), enableOneKey: true, web3AuthClientId: "BPi5PB_UiIZ-cPz1GtV5i1I2iOSOHuimiXBI0e-Oe_u6X3oVAbCiAZOTEBtTXw4tsluTITPqA8zMsfxIKMjiqNQ") Task { do { + let aggregateLoginParams = AggregateLoginParams(aggregateVerifierType: AggregateVerifierType.single_id_verifier, verifierIdentifier: "aggregate-sapphire", subVerifierDetailsArray: [SingleLoginParams(typeOfLogin: .google, verifier: "w3a-google", clientId: "519228911939-cri01h55lsjbsia1k7ll6qpalrus75ps.apps.googleusercontent.com")]) + + let customAuthArgs = CustomAuthArgs(urlScheme: "tdsdk://tdsdk/oauthCallback", network: .sapphire(.SAPPHIRE_MAINNET), enableOneKey: true, web3AuthClientId: "BPi5PB_UiIZ-cPz1GtV5i1I2iOSOHuimiXBI0e-Oe_u6X3oVAbCiAZOTEBtTXw4tsluTITPqA8zMsfxIKMjiqNQ") let customAuth = try CustomAuth(config: customAuthArgs) let torusLoginResponse = try await customAuth.triggerAggregateLogin(args: aggregateLoginParams) let encoded = try JSONEncoder().encode(torusLoginResponse) @@ -158,14 +156,14 @@ struct ContentView: View { }, label: { Text("Aggregate Gmail") }) - + Button(action: { - let subVerifierDetailsArray = SingleLoginParams(typeOfLogin: .github, verifier: "w3a-a0-github", clientId: "hiLqaop0amgzCC0AXo4w0rrG9abuJTdu", jwtParams: OAuthClientOptions(domain: "web3auth.au.auth0.com", verifierIdField: "email")) - let aggregateLoginParams = AggregateLoginParams(aggregateVerifierType: AggregateVerifierType.single_id_verifier, verifierIdentifier: "aggregate-sapphire", subVerifierDetailsArray: [subVerifierDetailsArray]) - - let customAuthArgs = CustomAuthArgs(urlScheme: "tdsdk://tdsdk/oauthCallback", network: .sapphire(.SAPPHIRE_MAINNET), enableOneKey: true, web3AuthClientId: "BPi5PB_UiIZ-cPz1GtV5i1I2iOSOHuimiXBI0e-Oe_u6X3oVAbCiAZOTEBtTXw4tsluTITPqA8zMsfxIKMjiqNQ") Task { do { + let subVerifierDetailsArray = SingleLoginParams(typeOfLogin: .github, verifier: "w3a-a0-github", clientId: "hiLqaop0amgzCC0AXo4w0rrG9abuJTdu", jwtParams: OAuthClientOptions(domain: "web3auth.au.auth0.com", verifierIdField: "email")) + let aggregateLoginParams = AggregateLoginParams(aggregateVerifierType: AggregateVerifierType.single_id_verifier, verifierIdentifier: "aggregate-sapphire", subVerifierDetailsArray: [subVerifierDetailsArray]) + + let customAuthArgs = CustomAuthArgs(urlScheme: "tdsdk://tdsdk/oauthCallback", network: .sapphire(.SAPPHIRE_MAINNET), enableOneKey: true, web3AuthClientId: "BPi5PB_UiIZ-cPz1GtV5i1I2iOSOHuimiXBI0e-Oe_u6X3oVAbCiAZOTEBtTXw4tsluTITPqA8zMsfxIKMjiqNQ") let customAuth = try CustomAuth(config: customAuthArgs) let torusLoginResponse = try await customAuth.triggerAggregateLogin(args: aggregateLoginParams) let encoded = try JSONEncoder().encode(torusLoginResponse) @@ -177,7 +175,6 @@ struct ContentView: View { }, label: { Text("Aggregate GitHub") }) - } } } diff --git a/cocoapods/cptest/LoginView.swift b/cocoapods/cptest/LoginView.swift index ea34161..d21f43c 100644 --- a/cocoapods/cptest/LoginView.swift +++ b/cocoapods/cptest/LoginView.swift @@ -6,12 +6,6 @@ struct LoginView: View { List { Section(header: Text("Single Logins")) { Group { - Button(action: { - vm.googlePolygonLogin() - }, label: { - Text("Google Polygon") - }) - Button(action: { vm.googleLogin() }, label: { @@ -19,12 +13,6 @@ struct LoginView: View { }) } - Button(action: { - vm.redditLogin() - }, label: { - Text("Reddit Login") - }) - Button(action: { vm.discordLogin() }, label: { @@ -43,36 +31,18 @@ struct LoginView: View { Text("Twitch Login") }) - Button(action: { - vm.twitterLogin() - }, label: { - Text("Twitter Login") - }) - Button(action: { vm.githubLogin() }, label: { Text("Github Login") }) - Button(action: { - vm.linkedinLogin() - }, label: { - Text("Linkedin Login") - }) - Button(action: { vm.appleLogin() }, label: { Text("Apple Login") }) - - Button(action: { - vm.weiboLogin() - }, label: { - Text("Weibo Login") - }) - + Button(action: { vm.emailPasswordLogin() }, label: { diff --git a/cocoapods/cptest/ViewModel.swift b/cocoapods/cptest/ViewModel.swift index 8dcf819..c7665d6 100644 --- a/cocoapods/cptest/ViewModel.swift +++ b/cocoapods/cptest/ViewModel.swift @@ -18,54 +18,18 @@ class ViewModel: ObservableObject { } extension ViewModel { - func googlePolygonLogin() { - let sub = SubVerifierDetails(typeOfLogin: .google, verifier: "polygon-ios-test", clientId: "908137525998-fs00a3go5r7fpbntmui4lb8nhuqqtmaa.apps.googleusercontent.com", redirectURL: "https://scripts.toruswallet.io/redirect.html") - - let options = CustomAuthArgs(urlScheme: "torus://org.torusresearch.sample/redirect", network: .legacy(.CYAN), enableOneKey: true, web3AuthClientId: "CLIENT ID") - - Task { - do { - let customAuth = try CustomAuth(config: options) - - let keyDetails = try await customAuth.triggerLogin(args: sub) - - user = User(publicAddress: keyDetails.torusKey.finalKeyData.evmAddress, privateKey: keyDetails.torusKey.finalKeyData.privKey, userInfo: keyDetails.singleVerifierResponse.userInfo) - } catch { - print(error) - } - } - } - func googleLogin() { - let sub = SubVerifierDetails(typeOfLogin: .google, verifier: "google-lrc", clientId: "221898609709-obfn3p63741l5333093430j3qeiinaa8.apps.googleusercontent.com", redirectURL: "https://scripts.toruswallet.io/redirect.html") - - let options = CustomAuthArgs(urlScheme: "tdsdk://tdsdk/oauthCallback", network: .legacy(.TESTNET), enableOneKey: true, web3AuthClientId: "CLIENT ID") - - Task { - do { - let customAuth = try CustomAuth(config: options) - - let keyDetails = try await customAuth.triggerLogin(args: sub) - - user = User(publicAddress: keyDetails.torusKey.finalKeyData.evmAddress, privateKey: keyDetails.torusKey.finalKeyData.privKey, userInfo: keyDetails.singleVerifierResponse.userInfo) - } catch { - print(error) - } - } - } - - func redditLogin() { - let sub = SubVerifierDetails(typeOfLogin: .reddit, verifier: "reddit-shubs", clientId: "rXIp6g2y3h1wqg", redirectURL: "https://scripts.toruswallet.io/redirect.html") - - let options = CustomAuthArgs(urlScheme: "tdsdk://tdsdk/oauthCallback", network: .legacy(.TESTNET), enableOneKey: true, web3AuthClientId: "CLIENT ID") - Task { do { - let customAuth = try CustomAuth(config: options) + let sub = SingleLoginParams(typeOfLogin: .google, verifier: "w3a-google-demo", clientId: "519228911939-cri01h55lsjbsia1k7ll6qpalrus75ps.apps.googleusercontent.com") - let keyDetails = try await customAuth.triggerLogin(args: sub) + let customAuthArgs = CustomAuthArgs(urlScheme: "tdsdk://tdsdk/oauthCallback", network: .sapphire(.SAPPHIRE_MAINNET), enableOneKey: true, web3AuthClientId: "BPi5PB_UiIZ-cPz1GtV5i1I2iOSOHuimiXBI0e-Oe_u6X3oVAbCiAZOTEBtTXw4tsluTITPqA8zMsfxIKMjiqNQ") + let customAuth = try CustomAuth(config: customAuthArgs) + let torusLoginResponse = try await customAuth.triggerLogin(args: sub) - user = User(publicAddress: keyDetails.torusKey.finalKeyData.evmAddress, privateKey: keyDetails.torusKey.finalKeyData.privKey, userInfo: keyDetails.singleVerifierResponse.userInfo) + DispatchQueue.main.async { + self.user = User(publicAddress: torusLoginResponse.torusKey.finalKeyData.evmAddress, privateKey: torusLoginResponse.torusKey.finalKeyData.privKey, userInfo: torusLoginResponse.singleVerifierResponse.userInfo) + } } catch { print(error) } @@ -73,17 +37,18 @@ extension ViewModel { } func discordLogin() { - let sub = SubVerifierDetails(typeOfLogin: .discord, verifier: "dhruv-discord", clientId: "1034724991972954172", redirectURL: "https://scripts.toruswallet.io/redirect.html") - - let options = CustomAuthArgs(urlScheme: "tdsdk://tdsdk/oauthCallback", network: .legacy(.TESTNET), enableOneKey: true, web3AuthClientId: "CLIENT ID") - Task { do { - let customAuth = try CustomAuth(config: options) + let sub = SingleLoginParams(typeOfLogin: .discord, verifier: "w3a-discord-demo", clientId: "1151006428610433095") - let keyDetails = try await customAuth.triggerLogin(args: sub) + let customAuthArgs = CustomAuthArgs(urlScheme: "tdsdk://tdsdk/oauthCallback", network: .sapphire(.SAPPHIRE_MAINNET), enableOneKey: true, web3AuthClientId: "BPi5PB_UiIZ-cPz1GtV5i1I2iOSOHuimiXBI0e-Oe_u6X3oVAbCiAZOTEBtTXw4tsluTITPqA8zMsfxIKMjiqNQ") - user = User(publicAddress: keyDetails.torusKey.finalKeyData.evmAddress, privateKey: keyDetails.torusKey.finalKeyData.privKey, userInfo: keyDetails.singleVerifierResponse.userInfo) + let customAuth = try CustomAuth(config: customAuthArgs) + let torusLoginResponse = try await customAuth.triggerLogin(args: sub) + + DispatchQueue.main.async { + self.user = User(publicAddress: torusLoginResponse.torusKey.finalKeyData.evmAddress, privateKey: torusLoginResponse.torusKey.finalKeyData.privKey, userInfo: torusLoginResponse.singleVerifierResponse.userInfo) + } } catch { print(error) } @@ -91,17 +56,17 @@ extension ViewModel { } func facebookLogin() { - let sub = SubVerifierDetails(typeOfLogin: .facebook, verifier: "facebook-shubs", clientId: "659561074900150", redirectURL: "https://scripts.toruswallet.io/redirect.html") - - let options = CustomAuthArgs(urlScheme: "tdsdk://tdsdk/oauthCallback", network: .legacy(.TESTNET), enableOneKey: true, web3AuthClientId: "CLIENT ID") - Task { do { - let customAuth = try CustomAuth(config: options) + let sub = SingleLoginParams(typeOfLogin: .facebook, verifier: "w3a-facebook-demo", clientId: "342380202252650") - let keyDetails = try await customAuth.triggerLogin(args: sub) + let customAuthArgs = CustomAuthArgs(urlScheme: "tdsdk://tdsdk/oauthCallback", network: .sapphire(.SAPPHIRE_MAINNET), enableOneKey: true, web3AuthClientId: "BPi5PB_UiIZ-cPz1GtV5i1I2iOSOHuimiXBI0e-Oe_u6X3oVAbCiAZOTEBtTXw4tsluTITPqA8zMsfxIKMjiqNQ") - user = User(publicAddress: keyDetails.torusKey.finalKeyData.evmAddress, privateKey: keyDetails.torusKey.finalKeyData.privKey, userInfo: keyDetails.singleVerifierResponse.userInfo) + let customAuth = try CustomAuth(config: customAuthArgs) + let torusLoginResponse = try await customAuth.triggerLogin(args: sub) + DispatchQueue.main.async { + self.user = User(publicAddress: torusLoginResponse.torusKey.finalKeyData.evmAddress, privateKey: torusLoginResponse.torusKey.finalKeyData.privKey, userInfo: torusLoginResponse.singleVerifierResponse.userInfo) + } } catch { print(error) } @@ -109,35 +74,15 @@ extension ViewModel { } func twitchLogin() { - let sub = SubVerifierDetails(typeOfLogin: .twitch, verifier: "twitch-shubs", clientId: "p560duf74b2bidzqu6uo0b3ot7qaao", redirectURL: "https://scripts.toruswallet.io/redirect.html") - - let options = CustomAuthArgs(urlScheme: "tdsdk://tdsdk/oauthCallback", network: .legacy(.TESTNET), enableOneKey: true, web3AuthClientId: "CLIENT ID") - Task { do { - let customAuth = try CustomAuth(config: options) - - let keyDetails = try await customAuth.triggerLogin(args: sub) - - user = User(publicAddress: keyDetails.torusKey.finalKeyData.evmAddress, privateKey: keyDetails.torusKey.finalKeyData.privKey, userInfo: keyDetails.singleVerifierResponse.userInfo) - } catch { - print(error) - } - } - } - - func twitterLogin() { - let sub = SubVerifierDetails(typeOfLogin: .twitter, verifier: "torus-auth0-twitter-lrc", clientId: "A7H8kkcmyFRlusJQ9dZiqBLraG2yWIsO", redirectURL: "https://scripts.toruswallet.io/redirect.html") - - let options = CustomAuthArgs(urlScheme: "tdsdk://tdsdk/oauthCallback", network: .legacy(.TESTNET), enableOneKey: true, web3AuthClientId: "CLIENT ID") - - Task { - do { - let customAuth = try CustomAuth(config: options) - - let keyDetails = try await customAuth.triggerLogin(args: sub) - - user = User(publicAddress: keyDetails.torusKey.finalKeyData.evmAddress, privateKey: keyDetails.torusKey.finalKeyData.privKey, userInfo: keyDetails.singleVerifierResponse.userInfo) + let sub = SingleLoginParams(typeOfLogin: .twitch, verifier: "w3a-twitch-demo", clientId: "3k7e70gowvxjaxg71hjnc8h8ih3bpf") + let customAuthArgs = CustomAuthArgs(urlScheme: "tdsdk://tdsdk/oauthCallback", network: .sapphire(.SAPPHIRE_MAINNET), enableOneKey: true, web3AuthClientId: "BPi5PB_UiIZ-cPz1GtV5i1I2iOSOHuimiXBI0e-Oe_u6X3oVAbCiAZOTEBtTXw4tsluTITPqA8zMsfxIKMjiqNQ") + let customAuth = try CustomAuth(config: customAuthArgs) + let torusLoginResponse = try await customAuth.triggerLogin(args: sub) + DispatchQueue.main.async { + self.user = User(publicAddress: torusLoginResponse.torusKey.finalKeyData.evmAddress, privateKey: torusLoginResponse.torusKey.finalKeyData.privKey, userInfo: torusLoginResponse.singleVerifierResponse.userInfo) + } } catch { print(error) } @@ -145,35 +90,15 @@ extension ViewModel { } func githubLogin() { - let sub = SubVerifierDetails(typeOfLogin: .github, verifier: "torus-auth0-github-lrc", clientId: "PC2a4tfNRvXbT48t89J5am0oFM21Nxff", redirectURL: "https://scripts.toruswallet.io/redirect.html") - - let options = CustomAuthArgs(urlScheme: "tdsdk://tdsdk/oauthCallback", network: .legacy(.TESTNET), enableOneKey: true, web3AuthClientId: "CLIENT ID") - Task { do { - let customAuth = try CustomAuth(config: options) - - let keyDetails = try await customAuth.triggerLogin(args: sub) - - user = User(publicAddress: keyDetails.torusKey.finalKeyData.evmAddress, privateKey: keyDetails.torusKey.finalKeyData.privKey, userInfo: keyDetails.singleVerifierResponse.userInfo) - } catch { - print(error) - } - } - } - - func linkedinLogin() { - let sub = SubVerifierDetails(typeOfLogin: .linkedin, verifier: "torus-auth0-linkedin-lrc", clientId: "59YxSgx79Vl3Wi7tQUBqQTRTxWroTuoc", redirectURL: "https://scripts.toruswallet.io/redirect.html") - - let options = CustomAuthArgs(urlScheme: "tdsdk://tdsdk/oauthCallback", network: .legacy(.TESTNET), enableOneKey: true, web3AuthClientId: "CLIENT ID") - - Task { - do { - let customAuth = try CustomAuth(config: options) - - let keyDetails = try await customAuth.triggerLogin(args: sub) - - user = User(publicAddress: keyDetails.torusKey.finalKeyData.evmAddress, privateKey: keyDetails.torusKey.finalKeyData.privKey, userInfo: keyDetails.singleVerifierResponse.userInfo) + let sub = SingleLoginParams(typeOfLogin: .github, verifier: "w3a-auth0-demo", clientId: "hUVVf4SEsZT7syOiL0gLU9hFEtm2gQ6O", jwtParams: Auth0ClientOptions(connection: "github", domain: "web3auth.au.auth0.com", verifierIdField: "sub")) + let customAuthArgs = CustomAuthArgs(urlScheme: "tdsdk://tdsdk/oauthCallback", network: .sapphire(.SAPPHIRE_MAINNET), enableOneKey: true, web3AuthClientId: "BPi5PB_UiIZ-cPz1GtV5i1I2iOSOHuimiXBI0e-Oe_u6X3oVAbCiAZOTEBtTXw4tsluTITPqA8zMsfxIKMjiqNQ") + let customAuth = try CustomAuth(config: customAuthArgs) + let torusLoginResponse = try await customAuth.triggerLogin(args: sub) + DispatchQueue.main.async { + self.user = User(publicAddress: torusLoginResponse.torusKey.finalKeyData.evmAddress, privateKey: torusLoginResponse.torusKey.finalKeyData.privKey, userInfo: torusLoginResponse.singleVerifierResponse.userInfo) + } } catch { print(error) } @@ -181,65 +106,38 @@ extension ViewModel { } func appleLogin() { - let sub = SubVerifierDetails(typeOfLogin: .apple, verifier: "torus-auth0-apple-lrc", clientId: "m1Q0gvDfOyZsJCZ3cucSQEe9XMvl9d9L", redirectURL: "https://scripts.toruswallet.io/redirect.html") - - let options = CustomAuthArgs(urlScheme: "tdsdk://tdsdk/oauthCallback", network: .legacy(.TESTNET), enableOneKey: true, web3AuthClientId: "CLIENT ID") - Task { do { - let customAuth = try CustomAuth(config: options) + let sub = SingleLoginParams(typeOfLogin: .apple, verifier: "w3a-auth0-demo", clientId: "hUVVf4SEsZT7syOiL0gLU9hFEtm2gQ6O", jwtParams: Auth0ClientOptions(connection: "apple", domain: "web3auth.au.auth0.com")) + let customAuthArgs = CustomAuthArgs(urlScheme: "tdsdk://tdsdk/oauthCallback", network: .sapphire(.SAPPHIRE_MAINNET), enableOneKey: true, web3AuthClientId: "BPi5PB_UiIZ-cPz1GtV5i1I2iOSOHuimiXBI0e-Oe_u6X3oVAbCiAZOTEBtTXw4tsluTITPqA8zMsfxIKMjiqNQ") - let keyDetails = try await customAuth.triggerLogin(args: sub) + let customAuth = try CustomAuth(config: customAuthArgs) + let torusLoginResponse = try await customAuth.triggerLogin(args: sub) - user = User(publicAddress: keyDetails.torusKey.finalKeyData.evmAddress, privateKey: keyDetails.torusKey.finalKeyData.privKey, userInfo: keyDetails.singleVerifierResponse.userInfo) + DispatchQueue.main.async { + self.user = User(publicAddress: torusLoginResponse.torusKey.finalKeyData.evmAddress, privateKey: torusLoginResponse.torusKey.finalKeyData.privKey, userInfo: torusLoginResponse.singleVerifierResponse.userInfo) + } } catch { print(error) } } } - func weiboLogin() { - let sub = SubVerifierDetails( - typeOfLogin: .weibo, - verifier: "torus-auth0-weibo-lrc", - clientId: "dhFGlWQMoACOI5oS5A1jFglp772OAWr1", - redirectURL: "tdsdk://tdsdk/oauthCallback") - - let options = CustomAuthArgs(urlScheme: "tdsdk://tdsdk/oauthCallback", network: .legacy(.TESTNET), enableOneKey: true, web3AuthClientId: "CLIENT ID") - - Task { - do { - let customAuth = try CustomAuth(config: options) - - let keyDetails = try await customAuth.triggerLogin(args: sub) - - user = User(publicAddress: keyDetails.torusKey.finalKeyData.evmAddress, privateKey: keyDetails.torusKey.finalKeyData.privKey, userInfo: keyDetails.singleVerifierResponse.userInfo) - } catch { - print(error) - } - } - } - func emailPasswordLogin() { - let sub = SubVerifierDetails( - typeOfLogin: .email_password, - verifier: "torus-auth0-email-password", - clientId: "sqKRBVSdwa4WLkaq419U7Bamlh5vK1H7", - redirectURL: "tdsdk://tdsdk/oauthCallback", - jwtParams: Auth0ClientOptions( - connection: "Username-Password-Authentication", - domain: "torus-test.auth0.com", - verifierIdField: "name")) - - let options = CustomAuthArgs(urlScheme: "tdsdk://tdsdk/oauthCallback", network: .legacy(.TESTNET), enableOneKey: true, web3AuthClientId: "BPi5PB_UiIZ-cPz1GtV5i1I2iOSOHuimiXBI0e-Oe_u6X3oVAbCiAZOTEBtTXw4tsluTITPqA8zMsfxIKMjiqNQ") - Task { do { - let customAuth = try CustomAuth(config: options) - - let keyDetails = try await customAuth.triggerLogin(args: sub) - - user = User(publicAddress: keyDetails.torusKey.finalKeyData.evmAddress, privateKey: keyDetails.torusKey.finalKeyData.privKey, userInfo: keyDetails.singleVerifierResponse.userInfo) + let sub = SingleLoginParams(typeOfLogin: .email_password, + verifier: "torus-auth0-email-password", clientId: "sqKRBVSdwa4WLkaq419U7Bamlh5vK1H7", + jwtParams: Auth0ClientOptions( + connection: "Username-Password-Authentication", + domain: "torus-test.auth0.com", + verifierIdField: "name")) + let customAuthArgs = CustomAuthArgs(urlScheme: "tdsdk://tdsdk/oauthCallback", network: .legacy(.TESTNET), enableOneKey: true, web3AuthClientId: "BPi5PB_UiIZ-cPz1GtV5i1I2iOSOHuimiXBI0e-Oe_u6X3oVAbCiAZOTEBtTXw4tsluTITPqA8zMsfxIKMjiqNQ") + let customAuth = try CustomAuth(config: customAuthArgs) + let torusLoginResponse = try await customAuth.triggerLogin(args: sub) + DispatchQueue.main.async { + self.user = User(publicAddress: torusLoginResponse.torusKey.finalKeyData.evmAddress, privateKey: torusLoginResponse.torusKey.finalKeyData.privKey, userInfo: torusLoginResponse.singleVerifierResponse.userInfo) + } } catch { print(error) }