From b4d6b5dd0c5dd05cb79dc97c76d0402da5f06c66 Mon Sep 17 00:00:00 2001 From: wiecktobi Date: Mon, 11 May 2020 20:59:32 +0200 Subject: [PATCH] Changed to read header --- .../java/de/hft/geotracker/GeofenceService.kt | 9 ++++----- .../src/main/java/de/hft/geotracker/Login.kt | 20 +++++++++++++------ 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/android/app/src/main/java/de/hft/geotracker/GeofenceService.kt b/android/app/src/main/java/de/hft/geotracker/GeofenceService.kt index a30c052..31320ae 100644 --- a/android/app/src/main/java/de/hft/geotracker/GeofenceService.kt +++ b/android/app/src/main/java/de/hft/geotracker/GeofenceService.kt @@ -1,14 +1,13 @@ package de.hft.geotracker +import okhttp3.Authenticator import retrofit2.Call -import retrofit2.http.GET -import retrofit2.http.Path -import retrofit2.http.Query +import retrofit2.http.* interface GeofenceService { - @GET("/login?username=user&password=pw") + @POST("/login") fun login(@Query("user") user : String, - @Query("pw") password : String) : Call + @Query("pw") password : String) : Call diff --git a/android/app/src/main/java/de/hft/geotracker/Login.kt b/android/app/src/main/java/de/hft/geotracker/Login.kt index 2904a1c..153899f 100644 --- a/android/app/src/main/java/de/hft/geotracker/Login.kt +++ b/android/app/src/main/java/de/hft/geotracker/Login.kt @@ -9,12 +9,15 @@ import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch import kotlinx.coroutines.withContext +import okhttp3.Authenticator import okhttp3.OkHttpClient import retrofit2.Call import retrofit2.Callback import retrofit2.Response import retrofit2.Retrofit import retrofit2.converter.gson.GsonConverterFactory +import retrofit2.http.Header +import retrofit2.http.Headers import java.net.HttpRetryException /** @@ -51,21 +54,26 @@ class Login : AppCompatActivity() { } private fun login() { - var call : Call = service.login("wito","tobias") - call.enqueue(object : Callback { - override fun onResponse(call: Call?, response: Response?) { + var call= service.login("wito","tobias") + + call.enqueue(object : Callback { + override fun onResponse(call: Call?, response: Response?) { if(response != null && response.isSuccessful) { - response.body() - token = JWToken(call.toString()) + + var headers = response.headers() + var authentication = headers.get("Authorization") + + token = JWToken(authentication) println("Erfolg") } else { println("Fehler1") } } - override fun onFailure(call: Call?, t: Throwable?) { + override fun onFailure(call: Call?, t: Throwable?) { println("Fehler2 ${t.toString()}") } + }) // var token = call.execute().body() // val intent = Intent(this, MainActivity::class.java)