kotlin-client.libraries.multiplatform.auth.HttpBearerAuth.kt.mustache Maven / Gradle / Ivy
package {{packageName}}.auth
{{^nonPublicApi}}{{#explicitApi}}public {{/explicitApi}}{{/nonPublicApi}}class HttpBearerAuth(private val scheme: String?) : Authentication {
{{^nonPublicApi}}{{#explicitApi}}public {{/explicitApi}}{{/nonPublicApi}}var bearerToken: String? = null
override fun apply(query: MutableMap>, headers: MutableMap) {
val token: String = bearerToken ?: return
headers["Authorization"] = (if (scheme != null) upperCaseBearer(scheme)!! + " " else "") + token
}
private fun upperCaseBearer(scheme: String): String? {
return if ("bearer".equals(scheme, ignoreCase = true)) "Bearer" else scheme
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy