MOB-23 MOB-41 small fixes related to HTTP

This commit is contained in:
Henrik Lepson
2021-11-08 20:22:33 +02:00
parent 1b79eba4a4
commit f0c7ab96bb
5 changed files with 13 additions and 8 deletions

View File

@@ -35,13 +35,14 @@ class MainActivity : AppCompatActivity() {
}
binding.loginOptionNfcButton.setOnClickListener { launchAuth() }
//binding.loginOptionNfcButton.setOnClickListener { getData() }
}
/**
* Method that creates an intent to launch the MobileAuthApp
*/
private fun launchAuth(arg: String = "nothing") {
private fun launchAuth(challenge: String = "challenge", authUrl: String = "authUrl") {
val launchIntent = Intent()
launchIntent.setClassName("com.tarkvaraprojekt.mobileauthapp", "com.tarkvaraprojekt.mobileauthapp.MainActivity")
launchIntent.putExtra("action", "auth")
@@ -56,14 +57,17 @@ class MainActivity : AppCompatActivity() {
* Ion library is used as it is very convenient for making simple GET requests.
*/
private fun getData() {
val url = "real-address-here"
// Enter the server endpoint address to here
val baseUrl = "enter-base-url-here"
val url = "$baseUrl/auth/challenge"
Ion.with(applicationContext)
.load(url)
.asJsonObject()
.setCallback { _, result ->
try {
// Get data from the result and call launchAuth method
launchAuth()
val challenge = result.asJsonObject["nonce"].toString()
launchAuth(challenge, baseUrl)
} catch (e: Exception) {
Log.i("GETrequest", "was unsuccessful")
}