All Downloads are FREE. Search and download functionalities are using the official Maven repository.

kotlin-client.libraries.multiplatform.auth.ApiKeyAuth.kt.mustache Maven / Gradle / Ivy

There is a newer version: 7.9.0
Show newest version
package {{packageName}}.auth

{{^nonPublicApi}}{{#explicitApi}}public {{/explicitApi}}{{/nonPublicApi}}class ApiKeyAuth(private val location: String, {{^nonPublicApi}}{{#explicitApi}}public {{/explicitApi}}{{/nonPublicApi}}val paramName: String) : Authentication {
    {{^nonPublicApi}}{{#explicitApi}}public {{/explicitApi}}{{/nonPublicApi}}var apiKey: String? = null
    {{^nonPublicApi}}{{#explicitApi}}public {{/explicitApi}}{{/nonPublicApi}}var apiKeyPrefix: String? = null

    override fun apply(query: MutableMap>, headers: MutableMap) {
        val key: String = apiKey ?: return
        val prefix: String? = apiKeyPrefix
        val value: String = if (prefix != null) "$prefix $key" else key
        when (location) {
            "query" -> query[paramName] = listOf(value)
            "header" -> headers[paramName] = value
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy