23 lines
603 B
Kotlin
23 lines
603 B
Kotlin
package svitan.dev
|
|
|
|
import io.github.cdimascio.dotenv.Dotenv
|
|
import io.ktor.server.application.*
|
|
import io.ktor.server.auth.*
|
|
|
|
fun Application.configureSecurity(dotenv: Dotenv) {
|
|
val apiKey = dotenv["API_KEY"] ?: throw Exception("API_KEY not found")
|
|
|
|
authentication {
|
|
basic {
|
|
realm = "Ktor Server"
|
|
validate { credentials ->
|
|
if (credentials.name == "admin" && credentials.password == apiKey) {
|
|
UserIdPrincipal(credentials.name)
|
|
} else {
|
|
null
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|