Skip to content

Commit

Permalink
feat(AppIntegrity): Add mobile_token to the call header
Browse files Browse the repository at this point in the history
  • Loading branch information
FabianDevel committed Dec 5, 2024
1 parent 487a0ce commit 8ac4bdb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -138,5 +138,6 @@ class AppIntegrityManager(private val appContext: Context) {

companion object {
const val APP_INTEGRITY_MANAGER_TAG = "App integrity manager"
const val MOBILE_TOKEN_HEADER = "Ik-mobile-token"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,19 @@
*/
package com.infomaniak.core2.appintegrity

import com.infomaniak.core2.appintegrity.AppIntegrityManager.Companion.MOBILE_TOKEN_HEADER
import com.infomaniak.core2.appintegrity.exceptions.ApiException
import com.infomaniak.core2.appintegrity.exceptions.NetworkException
import com.infomaniak.core2.appintegrity.exceptions.UnexpectedApiErrorFormatException
import com.infomaniak.core2.appintegrity.exceptions.UnknownException
import com.infomaniak.core2.appintegrity.models.ApiResponse
import io.ktor.client.call.body
import io.ktor.client.request.headers
import io.ktor.client.request.post
import io.ktor.client.request.setBody
import io.ktor.client.statement.HttpResponse
import io.ktor.http.ContentType
import io.ktor.http.HeadersBuilder
import io.ktor.http.Url
import io.ktor.http.contentType

Expand Down Expand Up @@ -57,13 +60,21 @@ internal class AppIntegrityRepository {
}

suspend fun demo(mobileToken: String): ApiResponse<String> {
val body = mapOf("mobile_token" to mobileToken)
return post<ApiResponse<String>>(url = Url(AppIntegrityRoutes.demo), data = body)
return post<ApiResponse<String>>(
url = Url(AppIntegrityRoutes.demo),
data = mapOf<String, String>(),
appendHeaders = { append(MOBILE_TOKEN_HEADER, mobileToken) }
)
}

private suspend inline fun <reified R> post(url: Url, data: Any?): R {
private suspend inline fun <reified R> post(
url: Url,
data: Any?,
crossinline appendHeaders: HeadersBuilder.() -> Unit = {},
): R {
return apiClientProvider.httpClient.post(url) {
contentType(ContentType.Application.Json)
headers { appendHeaders() }
setBody(data)
}.decode<R>()
}
Expand Down

0 comments on commit 8ac4bdb

Please sign in to comment.