diff --git a/session-manager-android/src/androidTest/java/com/web3auth/session_manager_android/SessionManagerTest.kt b/session-manager-android/src/androidTest/java/com/web3auth/session_manager_android/SessionManagerTest.kt index c941633..0931776 100644 --- a/session-manager-android/src/androidTest/java/com/web3auth/session_manager_android/SessionManagerTest.kt +++ b/session-manager-android/src/androidTest/java/com/web3auth/session_manager_android/SessionManagerTest.kt @@ -20,7 +20,7 @@ class SessionManagerTest { @Throws(ExecutionException::class, InterruptedException::class) fun test_createSession() { val context = InstrumentationRegistry.getInstrumentation().context - sessionManager = SessionManager(context) + sessionManager = SessionManager(context, 86400, context.packageName) val json = JSONObject() json.put( "privateKey", @@ -29,7 +29,6 @@ class SessionManagerTest { json.put("publicAddress", "0x93475c78dv0jt80f2b6715a5c53838eC4aC96EF7") val sessionKey = sessionManager.createSession( json.toString(), - 86400, context ).get() assert(sessionKey != null) @@ -39,7 +38,7 @@ class SessionManagerTest { @Throws(ExecutionException::class, InterruptedException::class) fun test_authorizeSession() { val context = InstrumentationRegistry.getInstrumentation().context - sessionManager = SessionManager(context) + sessionManager = SessionManager(context, 86400, context.packageName) val json = JSONObject() json.put( "privateKey", @@ -48,12 +47,11 @@ class SessionManagerTest { json.put("publicAddress", "0x93475c78dv0jt80f2b6715a5c53838eC4aC96EF7") sessionManager.createSession( json.toString(), - 86400, context, ).get() - sessionManager = SessionManager(context) + sessionManager = SessionManager(context, 86400, "*") val authResponse = sessionManager.authorizeSession( - "", + context.packageName, context ).get() val resp = JSONObject(authResponse) @@ -65,7 +63,7 @@ class SessionManagerTest { @Throws(ExecutionException::class, InterruptedException::class) fun test_invalidateSession() { val context = InstrumentationRegistry.getInstrumentation().context - sessionManager = SessionManager(context) + sessionManager = SessionManager(context, 86400, context.packageName) val json = JSONObject() json.put( "privateKey", @@ -74,10 +72,9 @@ class SessionManagerTest { json.put("publicAddress", "0x93475c78dv0jt80f2b6715a5c53838eC4aC96EF7") sessionManager.createSession( json.toString(), - 86400, context ).get() - sessionManager = SessionManager(context) + sessionManager = SessionManager(context, 86400, context.packageName) val invalidateRes = sessionManager.invalidateSession(context).get() assertEquals(invalidateRes, true) } diff --git a/session-manager-android/src/main/java/com/web3auth/session_manager_android/SessionManager.kt b/session-manager-android/src/main/java/com/web3auth/session_manager_android/SessionManager.kt index 4636310..f3f8fd6 100644 --- a/session-manager-android/src/main/java/com/web3auth/session_manager_android/SessionManager.kt +++ b/session-manager-android/src/main/java/com/web3auth/session_manager_android/SessionManager.kt @@ -23,10 +23,12 @@ import java.nio.charset.StandardCharsets import java.util.concurrent.CompletableFuture import kotlin.math.min -class SessionManager(context: Context) { +class SessionManager(context: Context, sessionTime: Long = 86400, allowedOrigin: String = "*") { private val gson = GsonBuilder().disableHtmlEscaping().create() private val web3AuthApi = ApiHelper.getInstance().create(Web3AuthApi::class.java) + private var sessionTime: Long + private var allowedOrigin: String companion object { fun generateRandomSessionKey(): String { @@ -37,6 +39,8 @@ class SessionManager(context: Context) { init { KeyStoreManager.initializePreferences(context.applicationContext) initiateKeyStoreManager() + this.sessionTime = sessionTime + this.allowedOrigin = allowedOrigin } private fun initiateKeyStoreManager() { @@ -189,9 +193,7 @@ class SessionManager(context: Context) { fun createSession( data: String, - sessionTime: Long, context: Context, - allowedOrigin: String = "*", ): CompletableFuture { return CompletableFuture.supplyAsync { val newSessionKey = generateRandomSessionKey()