Skip to content

Commit 13b8e6c

Browse files
Merge pull request #37 from Web3Auth/feature/PD-1440-session_management
PD-1440 session management
2 parents 79d9fed + af609cf commit 13b8e6c

33 files changed

+2903
-116
lines changed

.idea/deploymentTargetDropDown.xml

Lines changed: 0 additions & 17 deletions
This file was deleted.

app/build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ android {
1212
keyPassword 'torus123'
1313
}
1414
}
15-
compileSdkVersion 31
15+
compileSdkVersion 32
1616

1717
defaultConfig {
1818
applicationId "com.web3auth.app"
19-
minSdkVersion 21
20-
targetSdkVersion 31
19+
minSdkVersion 24
20+
targetSdkVersion 32
2121
versionCode 1
2222
versionName "1.0"
2323
manifestPlaceholders = [

app/src/main/AndroidManifest.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
<data android:scheme="web3auth" />
4343
</intent-filter>
4444
</activity>
45-
4645
</application>
4746

4847
</manifest>

app/src/main/java/com/web3auth/app/LoginVerifier.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package com.web3auth.app
22

33
import com.web3auth.core.types.Provider
44

5-
data class LoginVerifier (
6-
val name : String,
7-
val loginProvider : Provider
8-
)
5+
data class LoginVerifier(
6+
val name: String,
7+
val loginProvider: Provider
8+
)

app/src/main/java/com/web3auth/app/MainActivity.kt

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,18 @@ package com.web3auth.app
33
import android.content.Intent
44
import android.net.Uri
55
import android.os.Bundle
6+
import android.text.method.ScrollingMovementMethod
67
import android.util.Log
78
import android.view.View
89
import android.widget.*
910
import androidx.appcompat.app.AppCompatActivity
1011
import com.google.android.material.textfield.TextInputLayout
1112
import com.google.gson.Gson
12-
import com.web3auth.core.types.WhiteLabelData
13-
import com.web3auth.core.types.Provider
1413
import com.web3auth.core.Web3Auth
1514
import com.web3auth.core.isEmailValid
16-
import com.web3auth.core.types.ExtraLoginOptions
17-
import com.web3auth.core.types.LoginParams
18-
import com.web3auth.core.types.Web3AuthOptions
19-
import com.web3auth.core.types.Web3AuthResponse
15+
import com.web3auth.core.types.*
2016
import java8.util.concurrent.CompletableFuture
17+
import org.json.JSONObject
2118

2219
class MainActivity : AppCompatActivity(), AdapterView.OnItemClickListener {
2320
private lateinit var web3Auth: Web3Auth
@@ -59,19 +56,18 @@ class MainActivity : AppCompatActivity(), AdapterView.OnItemClickListener {
5956
if (error == null) {
6057
reRender(loginResponse)
6158
} else {
62-
Log.d("MainActivity_Web3Auth", error.message ?: "Something went wrong" )
59+
Log.d("MainActivity_Web3Auth", error.message ?: "Something went wrong")
6360
}
64-
6561
}
6662
}
6763

6864
private fun signOut() {
69-
val logoutCompletableFuture = web3Auth.logout()
65+
val logoutCompletableFuture = web3Auth.logout()
7066
logoutCompletableFuture.whenComplete { _, error ->
7167
if (error == null) {
7268
reRender(Web3AuthResponse())
7369
} else {
74-
Log.d("MainActivity_Web3Auth", error.message ?: "Something went wrong" )
70+
Log.d("MainActivity_Web3Auth", error.message ?: "Something went wrong")
7571
}
7672
}
7773
}
@@ -86,7 +82,9 @@ class MainActivity : AppCompatActivity(), AdapterView.OnItemClickListener {
8682
val key = web3AuthResponse.privKey
8783
val userInfo = web3AuthResponse.userInfo
8884
if (key is String && key.isNotEmpty()) {
89-
contentTextView.text = gson.toJson(web3AuthResponse)
85+
val jsonObject = JSONObject(gson.toJson(web3AuthResponse))
86+
contentTextView.text = jsonObject.toString(4)
87+
contentTextView.movementMethod = ScrollingMovementMethod()
9088
contentTextView.visibility = View.VISIBLE
9189
signInButton.visibility = View.GONE
9290
signOutButton.visibility = View.VISIBLE
@@ -107,21 +105,39 @@ class MainActivity : AppCompatActivity(), AdapterView.OnItemClickListener {
107105

108106
// Configure Web3Auth
109107
web3Auth = Web3Auth(
110-
Web3AuthOptions(context = this,
111-
clientId = getString(R.string.web3auth_project_id),
112-
network = Web3Auth.Network.MAINNET,
113-
redirectUrl = Uri.parse("torusapp://org.torusresearch.web3authexample/redirect"),
108+
Web3AuthOptions(
109+
context = this,
110+
clientId = getString(R.string.web3auth_project_id),
111+
network = Web3Auth.Network.MAINNET,
112+
redirectUrl = Uri.parse("torusapp://org.torusresearch.web3authexample/redirect"),
114113
whiteLabel = WhiteLabelData(
115114
"Web3Auth Sample App", null, null, "en", true,
116115
hashMapOf(
117116
"primary" to "#123456"
118117
)
118+
),
119+
loginConfig = hashMapOf(
120+
"loginConfig" to LoginConfigItem(
121+
"torus",
122+
typeOfLogin = TypeOfLogin.GOOGLE,
123+
name = ""
124+
)
119125
)
120126
)
121127
)
122128

123129
web3Auth.setResultUrl(intent.data)
124130

131+
// for session response
132+
val sessionResponse: CompletableFuture<Web3AuthResponse> = web3Auth.sessionResponse()
133+
sessionResponse.whenComplete { loginResponse, error ->
134+
if (error == null) {
135+
reRender(loginResponse)
136+
} else {
137+
Log.d("MainActivity_Web3Auth", error.message ?: "Something went wrong")
138+
}
139+
}
140+
125141
// Setup UI and event handlers
126142
val signInButton = findViewById<Button>(R.id.signInButton)
127143
signInButton.setOnClickListener { signIn() }

app/src/main/res/layout/activity_main.xml

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,31 +47,36 @@
4747
android:layout_width="wrap_content"
4848
android:layout_height="wrap_content"
4949
android:text="@string/not_logged_in"
50+
android:textStyle="bold"
5051
android:visibility="gone"
51-
app:layout_constraintBottom_toBottomOf="parent"
52-
app:layout_constraintLeft_toLeftOf="parent"
53-
app:layout_constraintRight_toRightOf="parent"
54-
app:layout_constraintTop_toTopOf="parent" />
52+
android:scrollbars="vertical"
53+
app:layout_constraintTop_toTopOf="parent"
54+
app:layout_constraintStart_toStartOf="parent"
55+
app:layout_constraintEnd_toEndOf="parent"/>
5556

5657
<Button
5758
android:id="@+id/signInButton"
58-
android:layout_width="wrap_content"
59+
android:layout_width="match_parent"
5960
android:layout_height="wrap_content"
6061
android:layout_marginBottom="8dp"
62+
android:layout_marginStart="40dp"
63+
android:layout_marginEnd="40dp"
6164
android:text="@string/sign_in"
65+
android:textAllCaps="false"
6266
app:layout_constraintEnd_toEndOf="parent"
6367
app:layout_constraintStart_toStartOf="parent"
64-
app:layout_constraintTop_toBottomOf="@id/contentTextView" />
68+
app:layout_constraintTop_toTopOf="parent"
69+
app:layout_constraintBottom_toBottomOf="parent"/>
6570

6671
<Button
6772
android:id="@+id/signOutButton"
6873
android:layout_width="wrap_content"
6974
android:layout_height="wrap_content"
70-
android:layout_marginTop="8dp"
7175
android:text="@string/sign_out"
76+
android:textAllCaps="false"
7277
android:visibility="gone"
78+
android:layout_marginEnd="10dp"
7379
app:layout_constraintEnd_toEndOf="parent"
74-
app:layout_constraintStart_toStartOf="parent"
75-
app:layout_constraintTop_toBottomOf="@id/contentTextView" />
80+
app:layout_constraintBottom_toBottomOf="parent" />
7681

7782
</androidx.constraintlayout.widget.ConstraintLayout>

app/src/main/res/values/colors.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<resources>
33
<color name="purple_200">#FFBB86FC</color>
4-
<color name="purple_500">#FF6200EE</color>
5-
<color name="purple_700">#FF3700B3</color>
4+
<color name="purple_500">#0364FF</color>
5+
<color name="purple_700">#0364FF</color>
66
<color name="teal_200">#FF03DAC5</color>
77
<color name="teal_700">#FF018786</color>
88
<color name="black">#FF000000</color>

build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ buildscript {
33
repositories {
44
google()
55
mavenCentral()
6+
maven { url "https://jitpack.io" }
67
}
78
dependencies {
89
classpath 'com.android.tools.build:gradle:7.2.2'

core/build.gradle

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ android {
88
compileSdkVersion 31
99

1010
defaultConfig {
11-
minSdkVersion 21
11+
minSdkVersion 24
1212
targetSdkVersion 31
1313

1414
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
@@ -46,6 +46,21 @@ dependencies {
4646
// Encoding
4747
implementation 'com.google.code.gson:gson:2.9.0'
4848

49+
// retrofit
50+
implementation 'com.squareup.retrofit2:retrofit:2.9.0'
51+
implementation 'com.squareup.okhttp3:logging-interceptor:3.9.0'
52+
53+
// Gson
54+
implementation 'com.squareup.retrofit2:converter-gson:2.9.0'
55+
56+
// coroutine
57+
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.2'
58+
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.2'
59+
60+
// android security
61+
implementation 'androidx.security:security-crypto:1.0.0-alpha02'
62+
implementation 'org.web3j:core:4.8.8-android'
63+
4964
// Test
5065
testImplementation 'junit:junit:4.+'
5166
androidTestImplementation 'androidx.test.ext:junit:1.1.3'

core/src/main/AndroidManifest.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
33
package="com.web3auth.core">
44

5+
<uses-permission android:name="android.permission.INTERNET" />
6+
7+
<application
8+
android:name=".Web3AuthApp"/>
9+
510
<queries>
611
<intent>
712
<action android:name="android.support.customtabs.action.CustomTabsService" />

0 commit comments

Comments
 (0)