From a4caf24a35d94a3ea72433290f2e5827767ffa81 Mon Sep 17 00:00:00 2001 From: Henrik Lepson Date: Wed, 17 Nov 2021 09:15:29 +0200 Subject: [PATCH] MOB-41 fixed some remaining issues --- TestMobileApp/README.md | 0 .../com/example/testmobileapp/MainActivity.kt | 36 ++++++++++++++----- .../app/src/main/res/layout/activity_main.xml | 11 ++---- .../app/src/main/res/values-en/strings.xml | 3 +- .../app/src/main/res/values-et/strings.xml | 3 +- .../app/src/main/res/values/strings.xml | 3 +- 6 files changed, 36 insertions(+), 20 deletions(-) create mode 100644 TestMobileApp/README.md diff --git a/TestMobileApp/README.md b/TestMobileApp/README.md new file mode 100644 index 0000000..e69de29 diff --git a/TestMobileApp/app/src/main/java/com/example/testmobileapp/MainActivity.kt b/TestMobileApp/app/src/main/java/com/example/testmobileapp/MainActivity.kt index d317f18..afc6035 100644 --- a/TestMobileApp/app/src/main/java/com/example/testmobileapp/MainActivity.kt +++ b/TestMobileApp/app/src/main/java/com/example/testmobileapp/MainActivity.kt @@ -11,6 +11,12 @@ import androidx.activity.result.contract.ActivityResultContracts import com.example.testmobileapp.databinding.ActivityMainBinding import com.google.gson.JsonObject import com.koushikdutta.ion.Ion +import org.json.JSONObject + +/** + * Base url where the requests should be made. Add yours here. It must use https. + */ +private const val BASE_URL = "https-base-url-here" /** * Test mobile app to demonstrate how other applications can use MobileAuthApp. @@ -32,6 +38,24 @@ class MainActivity : AppCompatActivity() { // Currently we are not actually checking whether we get a valid token. // For testing purposes only, to make sure that we are able to get a response at all. binding.loginTextView.text = getString(R.string.auth_success) + Log.i("getResult", response.data?.getStringExtra("token").toString()) + Log.i("getResult", response.data?.getStringExtra("result").toString()) + var user = "" + try { + val resultObject = JSONObject(response.data?.getStringExtra("result").toString()) + user = resultObject.getString("principal") + } catch (e: Exception) { + Log.i("getResult", "unable to retrieve name from principal") + } + showResult(user) + /* + binding.loginOptionNfcButton.text = "Log Out" + binding.loginOptionNfcButton.setOnClickListener { + binding.loginOptionNfcButton.text = "NFC auth" + binding.loginOptionNfcButton.setOnClickListener { getData() } + } + + */ } if (response.resultCode == Activity.RESULT_CANCELED) { binding.loginTextView.text = getString(R.string.auth_failure) @@ -64,9 +88,7 @@ class MainActivity : AppCompatActivity() { */ private fun getData() { // Enter the server endpoint address to here - //val originUrl = "enter-base-url-here" - val originUrl = "https://5d0c-85-253-195-195.ngrok.io" - val url = "$originUrl/auth/challenge" + val url = "$BASE_URL/auth/challenge" Ion.getDefault(this).conscryptMiddleware.enable(false) Ion.with(applicationContext) .load(url) @@ -76,7 +98,7 @@ class MainActivity : AppCompatActivity() { // Get data from the result and call launchAuth method val challenge = result.asJsonObject["nonce"].toString().replace("\"", "") Log.v("Challenge", challenge) - launchAuth(challenge, originUrl, "/auth/authentication") + launchAuth(challenge, BASE_URL, "/auth/authentication") } catch (e: Exception) { Log.i("GETrequest", "was unsuccessful") } @@ -87,14 +109,12 @@ class MainActivity : AppCompatActivity() { binding.loginOptions.visibility = View.VISIBLE } - private fun showResult(resultObject: String, token: String) { + private fun showResult(user: String) { binding.loginOptions.visibility = View.GONE binding.resultLayout.visibility = View.VISIBLE - binding.resultObject.text = resultObject - binding.resultToken.text = token + binding.resultObject.text = getString(R.string.hello, user) binding.buttonForget.setOnClickListener { binding.resultObject.text = "" - binding.resultToken.text = "" binding.resultLayout.visibility = View.GONE binding.loginOptions.visibility = View.VISIBLE } diff --git a/TestMobileApp/app/src/main/res/layout/activity_main.xml b/TestMobileApp/app/src/main/res/layout/activity_main.xml index 98727e4..dab6a25 100644 --- a/TestMobileApp/app/src/main/res/layout/activity_main.xml +++ b/TestMobileApp/app/src/main/res/layout/activity_main.xml @@ -52,7 +52,7 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" - app:layout_constraintTop_toTopOf="parent" + app:layout_constraintTop_toBottomOf="@id/login_text_view" app:layout_constraintStart_toStartOf="parent" app:layout_constraintEnd_toEndOf="parent" android:visibility="gone"> @@ -64,14 +64,7 @@ android:layout_margin="6dp" android:textSize="18sp"/> - - - Login Choose login method NFC auth - Successful response + Logged in Response failed Forget + Hello, %s! \ No newline at end of file diff --git a/TestMobileApp/app/src/main/res/values-et/strings.xml b/TestMobileApp/app/src/main/res/values-et/strings.xml index 09391e1..d4f3981 100644 --- a/TestMobileApp/app/src/main/res/values-et/strings.xml +++ b/TestMobileApp/app/src/main/res/values-et/strings.xml @@ -4,7 +4,8 @@ Logi sisse Vali sobiv meetod NFC auth - Vastus kätte saadud + Sisse logimine õnnestus Vastust ei õnnestunud kätte saada Unusta + Tere, %s! \ No newline at end of file diff --git a/TestMobileApp/app/src/main/res/values/strings.xml b/TestMobileApp/app/src/main/res/values/strings.xml index 6108518..b340b7e 100644 --- a/TestMobileApp/app/src/main/res/values/strings.xml +++ b/TestMobileApp/app/src/main/res/values/strings.xml @@ -3,7 +3,8 @@ Login Choose login method NFC auth - Successful response + Logged in Response failed Forget + Hello, %s! \ No newline at end of file