mirror of
https://github.com/TanelOrumaa/Estonian-ID-card-mobile-authenticator-POC.git
synced 2024-12-22 20:40:16 +02:00
MOB-41 small changes to the test app
This commit is contained in:
parent
cc3a3c10d6
commit
eca3f92468
@ -70,40 +70,44 @@ class AuthFragment : Fragment() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun getInfoFromIdCard(adapter: NfcAdapter) {
|
private fun getInfoFromIdCard(adapter: NfcAdapter) {
|
||||||
adapter.enableReaderMode(activity, { tag ->
|
if (args.reading) {
|
||||||
timer.cancel()
|
adapter.enableReaderMode(activity, { tag ->
|
||||||
requireActivity().runOnUiThread {
|
timer.cancel()
|
||||||
binding!!.timeCounter.text = getString(R.string.card_detected)
|
requireActivity().runOnUiThread {
|
||||||
}
|
binding!!.timeCounter.text = getString(R.string.card_detected)
|
||||||
val card = IsoDep.get(tag)
|
|
||||||
card.timeout = 32768
|
|
||||||
card.use {
|
|
||||||
try {
|
|
||||||
val comms = Comms(it, viewModel.userCan)
|
|
||||||
val response = comms.readPersonalData(byteArrayOf(1, 2, 6, 3, 4, 8))
|
|
||||||
viewModel.setUserFirstName(response[1])
|
|
||||||
viewModel.setUserLastName(response[0])
|
|
||||||
viewModel.setUserIdentificationNumber(response[2])
|
|
||||||
viewModel.setGender(response[3])
|
|
||||||
viewModel.setCitizenship(response[4])
|
|
||||||
viewModel.setExpiration(response[5])
|
|
||||||
requireActivity().runOnUiThread{
|
|
||||||
binding!!.timeCounter.text = getString(R.string.data_read)
|
|
||||||
}
|
|
||||||
} catch (e: Exception) {
|
|
||||||
requireActivity().runOnUiThread {
|
|
||||||
binding!!.timeCounter.text = getString(R.string.no_success)
|
|
||||||
}
|
|
||||||
// If the CAN is wrong we will also delete the saved CAN so that the user won't use it again.
|
|
||||||
viewModel.deleteCan(requireContext())
|
|
||||||
// Gives user some time to read the error message
|
|
||||||
Thread.sleep(1000)
|
|
||||||
goToTheStart()
|
|
||||||
} finally {
|
|
||||||
adapter.disableReaderMode(activity)
|
|
||||||
}
|
}
|
||||||
}
|
val card = IsoDep.get(tag)
|
||||||
}, NfcAdapter.FLAG_READER_NFC_A, null)
|
card.timeout = 32768
|
||||||
|
card.use {
|
||||||
|
try {
|
||||||
|
val comms = Comms(it, viewModel.userCan)
|
||||||
|
val response = comms.readPersonalData(byteArrayOf(1, 2, 6, 3, 4, 8))
|
||||||
|
viewModel.setUserFirstName(response[1])
|
||||||
|
viewModel.setUserLastName(response[0])
|
||||||
|
viewModel.setUserIdentificationNumber(response[2])
|
||||||
|
viewModel.setGender(response[3])
|
||||||
|
viewModel.setCitizenship(response[4])
|
||||||
|
viewModel.setExpiration(response[5])
|
||||||
|
requireActivity().runOnUiThread {
|
||||||
|
binding!!.timeCounter.text = getString(R.string.data_read)
|
||||||
|
}
|
||||||
|
} catch (e: Exception) {
|
||||||
|
requireActivity().runOnUiThread {
|
||||||
|
binding!!.timeCounter.text = getString(R.string.no_success)
|
||||||
|
}
|
||||||
|
// If the CAN is wrong we will also delete the saved CAN so that the user won't use it again.
|
||||||
|
viewModel.deleteCan(requireContext())
|
||||||
|
// Gives user some time to read the error message
|
||||||
|
Thread.sleep(1000)
|
||||||
|
goToTheStart()
|
||||||
|
} finally {
|
||||||
|
adapter.disableReaderMode(activity)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, NfcAdapter.FLAG_READER_NFC_A, null)
|
||||||
|
} else { //We want to create a JWT instead of reading the info from the card.
|
||||||
|
goToNextFragment()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun goToNextFragment() {
|
private fun goToNextFragment() {
|
||||||
|
@ -38,7 +38,9 @@ class ResultFragment : Fragment() {
|
|||||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
super.onViewCreated(view, savedInstanceState)
|
super.onViewCreated(view, savedInstanceState)
|
||||||
binding!!.resultBackButton.setOnClickListener {
|
binding!!.resultBackButton.setOnClickListener {
|
||||||
createResponse()
|
if (!args.mobile) {
|
||||||
|
createResponse()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,7 +35,7 @@ android {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
|
implementation 'com.koushikdutta.ion:ion:3.1.0'
|
||||||
implementation 'androidx.core:core-ktx:1.6.0'
|
implementation 'androidx.core:core-ktx:1.6.0'
|
||||||
implementation 'androidx.appcompat:appcompat:1.3.1'
|
implementation 'androidx.appcompat:appcompat:1.3.1'
|
||||||
implementation 'com.google.android.material:material:1.4.0'
|
implementation 'com.google.android.material:material:1.4.0'
|
||||||
|
@ -4,10 +4,16 @@ import android.app.Activity
|
|||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
import android.util.Log
|
||||||
import androidx.activity.result.ActivityResultLauncher
|
import androidx.activity.result.ActivityResultLauncher
|
||||||
import androidx.activity.result.contract.ActivityResultContracts
|
import androidx.activity.result.contract.ActivityResultContracts
|
||||||
import com.example.testmobileapp.databinding.ActivityMainBinding
|
import com.example.testmobileapp.databinding.ActivityMainBinding
|
||||||
|
import com.koushikdutta.ion.Ion
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test mobile app to demonstrate how other applications can use MobileAuthApp.
|
||||||
|
* Single purpose app that launches the MobileAuthApp and gets the response back (JWT).
|
||||||
|
*/
|
||||||
class MainActivity : AppCompatActivity() {
|
class MainActivity : AppCompatActivity() {
|
||||||
|
|
||||||
private lateinit var authLauncher: ActivityResultLauncher<Intent>
|
private lateinit var authLauncher: ActivityResultLauncher<Intent>
|
||||||
@ -32,10 +38,33 @@ class MainActivity : AppCompatActivity() {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun launchAuth() {
|
/**
|
||||||
|
* Method that creates an intent to launch the MobileAuthApp
|
||||||
|
*/
|
||||||
|
private fun launchAuth(arg: String = "nothing") {
|
||||||
val launchIntent = Intent()
|
val launchIntent = Intent()
|
||||||
launchIntent.setClassName("com.tarkvaraprojekt.mobileauthapp", "com.tarkvaraprojekt.mobileauthapp.MainActivity")
|
launchIntent.setClassName("com.tarkvaraprojekt.mobileauthapp", "com.tarkvaraprojekt.mobileauthapp.MainActivity")
|
||||||
launchIntent.putExtra("auth", true)
|
launchIntent.putExtra("auth", true)
|
||||||
|
launchIntent.putExtra("nonce", arg) // Currently nothing
|
||||||
authLauncher.launch(launchIntent)
|
authLauncher.launch(launchIntent)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method for retrieving data from an endpoint.
|
||||||
|
* Ion library is used as it is very convenient for making simple GET requests.
|
||||||
|
*/
|
||||||
|
private fun getData() {
|
||||||
|
val url = "real-address-here"
|
||||||
|
Ion.with(applicationContext)
|
||||||
|
.load(url)
|
||||||
|
.asJsonObject()
|
||||||
|
.setCallback { _, result ->
|
||||||
|
try {
|
||||||
|
// Get data from the result and call launchAuth method
|
||||||
|
launchAuth()
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Log.i("GETrequest", "was unsuccessful")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
9
TestMobileApp/app/src/main/res/values-en/strings.xml
Normal file
9
TestMobileApp/app/src/main/res/values-en/strings.xml
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<resources>
|
||||||
|
<string name="app_name">TestMobileApp</string>
|
||||||
|
<string name="login_text">Login</string>
|
||||||
|
<string name="choose_login_method">Choose login method</string>
|
||||||
|
<string name="method_nfc">NFC auth</string>
|
||||||
|
<string name="auth_success">Successful response</string>
|
||||||
|
<string name="auth_failure">Response failed</string>
|
||||||
|
</resources>
|
9
TestMobileApp/app/src/main/res/values-et/strings.xml
Normal file
9
TestMobileApp/app/src/main/res/values-et/strings.xml
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<resources>
|
||||||
|
<string name="app_name">TestMobileApp</string>
|
||||||
|
<string name="login_text">Logi sisse</string>
|
||||||
|
<string name="choose_login_method">Vali sobiv meetod</string>
|
||||||
|
<string name="method_nfc">NFC auth</string>
|
||||||
|
<string name="auth_success">Vastus kätte saadud</string>
|
||||||
|
<string name="auth_failure">Vastust ei õnnestunud kätte saada</string>
|
||||||
|
</resources>
|
@ -1,8 +1,8 @@
|
|||||||
<resources>
|
<resources>
|
||||||
<string name="app_name">TestMobileApp</string>
|
<string name="app_name">TestMobileApp</string>
|
||||||
<string name="login_text">Logi sisse</string>
|
<string name="login_text">Login</string>
|
||||||
<string name="choose_login_method">Vali sobiv meetod</string>
|
<string name="choose_login_method">Choose login method</string>
|
||||||
<string name="method_nfc">NFC auth</string>
|
<string name="method_nfc">NFC auth</string>
|
||||||
<string name="auth_success">Autentimine õnnestus</string>
|
<string name="auth_success">Successful response</string>
|
||||||
<string name="auth_failure">Autentimine ebaõnnestus</string>
|
<string name="auth_failure">Response failed</string>
|
||||||
</resources>
|
</resources>
|
Loading…
Reference in New Issue
Block a user