kotlin-client.libraries.jvm-ktor.auth.HttpBasicAuth.kt.mustache Maven / Gradle / Ivy
package {{packageName}}.auth
import io.ktor.util.InternalAPI
import io.ktor.util.encodeBase64
class HttpBasicAuth : Authentication {
var username: String? = null
var password: String? = null
@OptIn(InternalAPI::class)
override fun apply(query: MutableMap>, headers: MutableMap) {
if (username == null && password == null) return
val str = (username ?: "") + ":" + (password ?: "")
val auth = str.encodeBase64()
headers["Authorization"] = "Basic $auth"
}
}