mirror of
https://github.com/TanelOrumaa/Estonian-ID-card-mobile-authenticator-POC.git
synced 2024-12-22 12:30:16 +02:00
MOB-23 MOB-41 small fixes related to HTTP
This commit is contained in:
parent
1b79eba4a4
commit
f0c7ab96bb
@ -55,9 +55,9 @@ class AuthFragment : Fragment() {
|
|||||||
override fun onTick(p0: Long) {
|
override fun onTick(p0: Long) {
|
||||||
timeRemaining--
|
timeRemaining--
|
||||||
if (timeRemaining == 0) {
|
if (timeRemaining == 0) {
|
||||||
binding!!.timeCounter.text = getString(R.string.no_time)
|
binding?.timeCounter?.text = getString(R.string.no_time)
|
||||||
} else {
|
} else {
|
||||||
binding!!.timeCounter.text = getString(R.string.time_left, timeRemaining)
|
binding?.timeCounter?.text = getString(R.string.time_left, timeRemaining)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,8 +57,10 @@ class HomeFragment : Fragment() {
|
|||||||
intentParams.setChallenge(requireActivity().intent.getStringExtra("challenge")!!)
|
intentParams.setChallenge(requireActivity().intent.getStringExtra("challenge")!!)
|
||||||
intentParams.setAuthUrl(requireActivity().intent.getStringExtra("authUrl")!!)
|
intentParams.setAuthUrl(requireActivity().intent.getStringExtra("authUrl")!!)
|
||||||
} else { //Website
|
} else { //Website
|
||||||
|
// Currently the test website won't send the authUrl parameter
|
||||||
|
//Log.i("intentDebugging", requireActivity().intent.data.toString())
|
||||||
intentParams.setChallenge(requireActivity().intent.data!!.getQueryParameter("challenge")!!)
|
intentParams.setChallenge(requireActivity().intent.data!!.getQueryParameter("challenge")!!)
|
||||||
intentParams.setAuthUrl(requireActivity().intent.data!!.getQueryParameter("authUrl")!!)
|
//intentParams.setAuthUrl(requireActivity().intent.data!!.getQueryParameter("authUrl")!!)
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
// There was a problem with parameters, which means that authentication is not possible.
|
// There was a problem with parameters, which means that authentication is not possible.
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package com.tarkvaraprojekt.mobileauthapp.model
|
package com.tarkvaraprojekt.mobileauthapp.model
|
||||||
|
|
||||||
import androidx.lifecycle.ViewModel
|
import androidx.lifecycle.ViewModel
|
||||||
import com.tarkvaraprojekt.mobileauthapp.network.TokenItem
|
|
||||||
|
|
||||||
class ParametersViewModel: ViewModel() {
|
class ParametersViewModel: ViewModel() {
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@ private val retrofit = Retrofit.Builder().addConverterFactory(MoshiConverterFact
|
|||||||
|
|
||||||
interface TokenApiService {
|
interface TokenApiService {
|
||||||
@Headers("Content-Type: application/json")
|
@Headers("Content-Type: application/json")
|
||||||
@POST("authentication")
|
@POST("auth/authentication")
|
||||||
suspend fun postToken(@Body data: TokenItem): Response<TokenItem>
|
suspend fun postToken(@Body data: TokenItem): Response<TokenItem>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,13 +35,14 @@ class MainActivity : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
binding.loginOptionNfcButton.setOnClickListener { launchAuth() }
|
binding.loginOptionNfcButton.setOnClickListener { launchAuth() }
|
||||||
|
//binding.loginOptionNfcButton.setOnClickListener { getData() }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method that creates an intent to launch the MobileAuthApp
|
* 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()
|
val launchIntent = Intent()
|
||||||
launchIntent.setClassName("com.tarkvaraprojekt.mobileauthapp", "com.tarkvaraprojekt.mobileauthapp.MainActivity")
|
launchIntent.setClassName("com.tarkvaraprojekt.mobileauthapp", "com.tarkvaraprojekt.mobileauthapp.MainActivity")
|
||||||
launchIntent.putExtra("action", "auth")
|
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.
|
* Ion library is used as it is very convenient for making simple GET requests.
|
||||||
*/
|
*/
|
||||||
private fun getData() {
|
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)
|
Ion.with(applicationContext)
|
||||||
.load(url)
|
.load(url)
|
||||||
.asJsonObject()
|
.asJsonObject()
|
||||||
.setCallback { _, result ->
|
.setCallback { _, result ->
|
||||||
try {
|
try {
|
||||||
// Get data from the result and call launchAuth method
|
// Get data from the result and call launchAuth method
|
||||||
launchAuth()
|
val challenge = result.asJsonObject["nonce"].toString()
|
||||||
|
launchAuth(challenge, baseUrl)
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
Log.i("GETrequest", "was unsuccessful")
|
Log.i("GETrequest", "was unsuccessful")
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user