@@ -30,9 +30,8 @@ import java.util.logging.Logger
3030import kotlin.random.Random
3131import kotlin.reflect.KClass
3232
33- const val API_TOKEN_PARAM_NAME = " token"
34- private const val APP_CLIENT_ID_PARAM_NAME = " appClientId"
35- const val APP_CLIENT_SECRET_PARAM_NAME = " appSecretKey"
33+ private const val APP_CLIENT_ID_HEADER_NAME = " X-Ecwid-App-Client-Id"
34+ private const val APP_CLIENT_SECRET_HEADER_NAME = " X-Ecwid-App-Secret-Key"
3635private const val RESPONSE_FIELDS_PARAM_NAME = " responseFields"
3736private const val REQUEST_ID_HEADER_NAME = " X-Ecwid-Api-Request-Id"
3837
@@ -238,7 +237,7 @@ class ApiClientHelper private constructor(
238237 return
239238 }
240239
241- val securePatterns = createSecurePatterns(loggingSettings )
240+ val securePatterns = createSecurePatterns()
242241 logEntry(
243242 prefix = " Request" ,
244243 logLevel = Level .INFO ,
@@ -259,10 +258,8 @@ class ApiClientHelper private constructor(
259258 @PublishedApi
260259 internal fun RequestInfo.toHttpRequest (requestId : String , responseFieldsOverride : ResponseFields ? ): HttpRequest {
261260 val uri = createApiEndpointUri(pathSegments)
262- val params = params
263- .withCredentialsParams(credentials)
264- .let { if (responseFieldsOverride != null ) it.withResponseFieldsParam(responseFieldsOverride) else it }
265- val headers = headers.withRequestId(requestId)
261+ val params = if (responseFieldsOverride != null ) params.withResponseFieldsParam(responseFieldsOverride) else params
262+ val headers = headers.withRequestId(requestId).withCredentials(credentials)
266263
267264 return when (method) {
268265 HttpMethod .GET -> HttpRequest .HttpGetRequest (
@@ -313,7 +310,7 @@ class ApiClientHelper private constructor(
313310 return
314311 }
315312
316- val securePatterns = createSecurePatterns(loggingSettings )
313+ val securePatterns = createSecurePatterns()
317314 logEntry(
318315 prefix = " Response" ,
319316 logLevel = Level .INFO ,
@@ -440,9 +437,9 @@ internal fun generateRequestId(): String {
440437}
441438
442439@PublishedApi
443- internal fun Map <String , String >.withCredentialsParams (credentials : ApiCredentials ) = when (credentials) {
444- is ApiStoreCredentials -> this .withApiTokenParam (credentials.apiToken)
445- is ApiAppCredentials -> withAppCredentialsParams (credentials)
440+ internal fun Map <String , String >.withCredentials (credentials : ApiCredentials ) = when (credentials) {
441+ is ApiStoreCredentials -> this .withApiTokenHeader (credentials.apiToken)
442+ is ApiAppCredentials -> withAppCredentialsHeaders (credentials)
446443}
447444
448445internal fun Map <String , String >.withResponseFieldsParam (responseFields : ResponseFields ): Map <String , String > {
@@ -454,20 +451,20 @@ internal fun Map<String, String>.withResponseFieldsParam(responseFields: Respons
454451}
455452
456453@PublishedApi
457- internal fun Map <String , String >.withApiTokenParam (apiToken : String ): Map <String , String > {
454+ internal fun Map <String , String >.withApiTokenHeader (apiToken : String ): Map <String , String > {
458455 return toMutableMap()
459456 .apply {
460- put(API_TOKEN_PARAM_NAME , apiToken)
457+ put(" Authorization " , " Bearer $ apiToken" )
461458 }
462459 .toMap()
463460}
464461
465462@PublishedApi
466- internal fun Map <String , String >.withAppCredentialsParams (appCredentials : ApiAppCredentials ): Map <String , String > {
463+ internal fun Map <String , String >.withAppCredentialsHeaders (appCredentials : ApiAppCredentials ): Map <String , String > {
467464 return toMutableMap()
468465 .apply {
469- put(APP_CLIENT_ID_PARAM_NAME , appCredentials.clientId)
470- put(APP_CLIENT_SECRET_PARAM_NAME , appCredentials.clientSecret)
466+ put(APP_CLIENT_ID_HEADER_NAME , appCredentials.clientId)
467+ put(APP_CLIENT_SECRET_HEADER_NAME , appCredentials.clientSecret)
471468 }
472469 .toMap()
473470}
0 commit comments