From d573eb26441885afdd06f7a151a67bee3f934b35 Mon Sep 17 00:00:00 2001 From: this-Aditya Date: Tue, 22 Oct 2024 20:52:21 +0530 Subject: [PATCH] Refactored ManagementPortalClient to working state --- .../auth/portal/ManagementPortalClient.kt | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/radar-commons-android/src/main/java/org/radarbase/android/auth/portal/ManagementPortalClient.kt b/radar-commons-android/src/main/java/org/radarbase/android/auth/portal/ManagementPortalClient.kt index ad0559159..52ac6abfa 100644 --- a/radar-commons-android/src/main/java/org/radarbase/android/auth/portal/ManagementPortalClient.kt +++ b/radar-commons-android/src/main/java/org/radarbase/android/auth/portal/ManagementPortalClient.kt @@ -29,7 +29,7 @@ import java.io.IOException import java.lang.RuntimeException import java.net.MalformedURLException -class ManagementPortalClient constructor( +class ManagementPortalClient( managementPortal: ServerConfig, private val clientId: String, private val clientSecret: String, @@ -76,15 +76,15 @@ class ManagementPortalClient constructor( if (state.userId == null) { throw IOException("Authentication state does not contain user ID") } - val request = client.request("api/subjects/${state.userId}") { - + val request = client.prepareRequest("api/subjects/${state.userId}") { + headers { + appendAll(state.ktorHeaders) + append(HttpHeaders.Accept, APPLICATION_JSON) + } } - .headers(state.okHttpHeaders) - .header("Accept", APPLICATION_JSON) - .build() logger.info("Requesting subject {} with parseHeaders {}", state.userId, - state.okHttpHeaders) + state.ktorHeaders) return handleRequest(request, parser) } @@ -168,7 +168,7 @@ class ManagementPortalClient constructor( @Throws(IOException::class) private suspend fun handleRequest(request: HttpStatement, parser: Parser): T { return request.execute { response -> - val body: OAuthAccess = response.body() + val body: JSONObject = response.body() if (response.status == HttpStatusCode.Unauthorized) { throw AuthenticationException("QR code is invalid: $body")