diff --git a/app/src/main/java/com/web3auth/sfaexample/MainActivity.kt b/app/src/main/java/com/web3auth/sfaexample/MainActivity.kt index f529ecd..d22823f 100644 --- a/app/src/main/java/com/web3auth/sfaexample/MainActivity.kt +++ b/app/src/main/java/com/web3auth/sfaexample/MainActivity.kt @@ -37,7 +37,7 @@ class MainActivity : AppCompatActivity() { val res = singleFactorAuth.isSessionIdExists(this) res.whenComplete { res, err -> - if (err == null) { + if (res) { val sfakey = singleFactorAuth.initialize(this.applicationContext) sfakey.whenComplete { response, error -> if (error == null) { diff --git a/singlefactorauth/build.gradle b/singlefactorauth/build.gradle index 0c75d2c..d4d1967 100644 --- a/singlefactorauth/build.gradle +++ b/singlefactorauth/build.gradle @@ -44,7 +44,7 @@ dependencies { implementation 'com.google.code.gson:gson:2.10.1' implementation 'org.slf4j:slf4j-simple:2.0.3' //session-manager-sdk - implementation 'com.github.grvgoel81:session-manager-android:7.1.0' + implementation 'com.github.grvgoel81:session-manager-android:7.2.0' testImplementation 'junit:junit:4.13.2' testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.2' diff --git a/singlefactorauth/src/androidTest/java/com/web3auth/singlefactorauth/AquaTest.kt b/singlefactorauth/src/androidTest/java/com/web3auth/singlefactorauth/AquaTest.kt index 66a395f..8ad2a5a 100644 --- a/singlefactorauth/src/androidTest/java/com/web3auth/singlefactorauth/AquaTest.kt +++ b/singlefactorauth/src/androidTest/java/com/web3auth/singlefactorauth/AquaTest.kt @@ -135,34 +135,4 @@ class AquaTest { fail() } } - - @Test - @Throws(ExecutionException::class, InterruptedException::class) - fun testisSessionIdExistsWithLogoutApiNotCalled() { - val context = getInstrumentation().context - sfaParams = SFAParams(Web3AuthNetwork.AQUA, "YOUR_CLIENT_ID", 86400, null, 0) - singleFactorAuth = SingleFactorAuth(sfaParams, context) - val privateKey = readPrivateKeyFromReader( - WellKnownSecret.pem(), - "EC" - ) as ECPrivateKey - val publicKey = KeyFactory.getInstance("EC").generatePublic( - ECPublicKeySpec( - privateKey.params.generator, - privateKey.params - ) - ) as ECPublicKey - algorithmRs = Algorithm.ECDSA256(publicKey, privateKey) - val idToken: String = generateIdToken(TORUS_TEST_EMAIL, algorithmRs) - loginParams = LoginParams(TEST_VERIFIER, TORUS_TEST_EMAIL, idToken) - singleFactorAuth.connect(loginParams, context) - val res = singleFactorAuth.isSessionIdExists(context) - res.whenComplete { res, err -> - if (err != null) { - fail() - } else { - assertEquals(res, true) - } - } - } } \ No newline at end of file diff --git a/singlefactorauth/src/main/java/com/web3auth/singlefactorauth/SingleFactorAuth.kt b/singlefactorauth/src/main/java/com/web3auth/singlefactorauth/SingleFactorAuth.kt index 893c67b..9bd0bad 100644 --- a/singlefactorauth/src/main/java/com/web3auth/singlefactorauth/SingleFactorAuth.kt +++ b/singlefactorauth/src/main/java/com/web3auth/singlefactorauth/SingleFactorAuth.kt @@ -51,8 +51,8 @@ class SingleFactorAuth( data.whenComplete { response, error -> val mainHandler = Handler(Looper.getMainLooper()) mainHandler.post { - if (error != null) { - sfaCF.completeExceptionally(error) + if (response.startsWith("Error")) { + sfaCF.completeExceptionally(Exception(response)) } else { sfaCF.complete( gson.fromJson( @@ -73,8 +73,8 @@ class SingleFactorAuth( fun isSessionIdExists(ctx: Context): CompletableFuture { val authorizeCF = CompletableFuture() val data = sessionManager.authorizeSession(ctx.packageName, ctx) - data.whenComplete { response, error -> - if (error != null) { + data.whenComplete { res, error -> + if (res.startsWith("Error")) { authorizeCF.complete(false) } else { authorizeCF.complete(true) @@ -147,7 +147,13 @@ class SingleFactorAuth( json.put("publicAddress", torusSFAKey.getPublicAddress()) } - sessionManager.createSession(json.toString(), ctx, true).get() + sessionManager.createSession(json.toString(), ctx).thenAccept { result -> + if (result.startsWith("Error:")) { + // do nothing + } else { + sessionManager.saveSessionId(result) + } + } return torusSFAKey }