commonMain.com.apadmi.mockzilla.lib.internal.plugin.SimpleAuthPlugin.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of mockzilla-jvm Show documentation
Show all versions of mockzilla-jvm Show documentation
Solution for running and configuring a local HTTP server on mobile.
The newest version!
@file:Suppress("FILE_NAME_MATCH_CLASS")
package com.apadmi.mockzilla.lib.internal.plugin
import io.ktor.http.*
import io.ktor.server.application.*
import io.ktor.server.response.*
@Suppress("VARIABLE_NAME_INCORRECT_FORMAT")
internal val SimpleAuthPlugin = createApplicationPlugin(name = "SimpleAuthPlugin", ::SimpleAuthConfiguration) {
onCall { call ->
val header = call.request.headers[pluginConfig.headerKey]
if (header == null || !pluginConfig.headerValueIsValid(header)) {
call.respond(
HttpStatusCode.Forbidden,
"Forbidden - Mockzilla is in release mode and your token is missing or invalid"
)
}
}
}
@Suppress("USE_DATA_CLASS")
internal class SimpleAuthConfiguration {
var headerKey: String = ""
var headerValueIsValid: suspend (String) -> Boolean = { true }
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy