[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[taler-taler-android] 02/02: [pos] Change ApiKey Authorization to Bearer
From: |
gnunet |
Subject: |
[taler-taler-android] 02/02: [pos] Change ApiKey Authorization to Bearer |
Date: |
Tue, 17 Jan 2023 18:57:45 +0100 |
This is an automated email from the git hooks/post-receive script.
torsten-grote pushed a commit to branch master
in repository taler-android.
commit de209564ed4dd6494774f9b4a26982f89637facb
Author: Torsten Grote <t@grobox.de>
AuthorDate: Tue Jan 17 14:56:08 2023 -0300
[pos] Change ApiKey Authorization to Bearer
---
.../main/java/net/taler/merchantlib/MerchantApi.kt | 20 ++++++++++++--------
1 file changed, 12 insertions(+), 8 deletions(-)
diff --git a/merchant-lib/src/main/java/net/taler/merchantlib/MerchantApi.kt
b/merchant-lib/src/main/java/net/taler/merchantlib/MerchantApi.kt
index c02907b..950cea6 100644
--- a/merchant-lib/src/main/java/net/taler/merchantlib/MerchantApi.kt
+++ b/merchant-lib/src/main/java/net/taler/merchantlib/MerchantApi.kt
@@ -20,6 +20,7 @@ import io.ktor.client.HttpClient
import io.ktor.client.call.body
import io.ktor.client.engine.okhttp.OkHttp
import io.ktor.client.plugins.contentnegotiation.ContentNegotiation
+import io.ktor.client.request.HttpRequestBuilder
import io.ktor.client.request.delete
import io.ktor.client.request.get
import io.ktor.client.request.header
@@ -28,13 +29,12 @@ import io.ktor.client.request.setBody
import io.ktor.http.ContentType.Application.Json
import io.ktor.http.HttpHeaders.Authorization
import io.ktor.http.contentType
+import io.ktor.serialization.kotlinx.json.json
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
-import net.taler.merchantlib.Response.Companion.response
-import io.ktor.serialization.kotlinx.json.*
-import kotlinx.serialization.ExperimentalSerializationApi
import kotlinx.serialization.json.Json
+import net.taler.merchantlib.Response.Companion.response
class MerchantApi(
private val httpClient: HttpClient = getDefaultHttpClient(),
@@ -53,7 +53,7 @@ class MerchantApi(
): Response<PostOrderResponse> = withContext(ioDispatcher) {
response {
httpClient.post(merchantConfig.urlFor("private/orders")) {
- header(Authorization, "ApiKey ${merchantConfig.apiKey}")
+ auth(merchantConfig)
contentType(Json)
setBody(orderRequest)
}.body()
@@ -66,7 +66,7 @@ class MerchantApi(
): Response<CheckPaymentResponse> = withContext(ioDispatcher) {
response {
httpClient.get(merchantConfig.urlFor("private/orders/$orderId")) {
- header(Authorization, "ApiKey ${merchantConfig.apiKey}")
+ auth(merchantConfig)
}.body()
}
}
@@ -77,7 +77,7 @@ class MerchantApi(
): Response<Unit> = withContext(ioDispatcher) {
response {
httpClient.delete(merchantConfig.urlFor("private/orders/$orderId")) {
- header(Authorization, "ApiKey ${merchantConfig.apiKey}")
+ auth(merchantConfig)
}.body()
}
}
@@ -86,7 +86,7 @@ class MerchantApi(
withContext(ioDispatcher) {
response {
httpClient.get(merchantConfig.urlFor("private/orders")) {
- header(Authorization, "ApiKey ${merchantConfig.apiKey}")
+ auth(merchantConfig)
}.body()
}
}
@@ -98,12 +98,16 @@ class MerchantApi(
): Response<RefundResponse> = withContext(ioDispatcher) {
response {
httpClient.post(merchantConfig.urlFor("private/orders/$orderId/refund")) {
- header(Authorization, "ApiKey ${merchantConfig.apiKey}")
+ auth(merchantConfig)
contentType(Json)
setBody(request)
}.body()
}
}
+
+ private fun HttpRequestBuilder.auth(merchantConfig: MerchantConfig) {
+ header(Authorization, "Bearer ${merchantConfig.apiKey}")
+ }
}
fun getDefaultHttpClient(): HttpClient = HttpClient(OkHttp) {
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.