Louis Saglio
01/30/2019, 10:11 PMfun Application.bank() {
install(Authentication) {
form("form") {
challenge = FormAuthChallenge.Unauthorized
passwordParamName = "password"
userParamName = "username"
validate { credentials ->
println("Credentials : ${credentials.name}, ${credentials.password}")
when {
credentials.name == "John" && credentials.password == "pa$$w0rd" -> UserIdPrincipal("John")
else -> null
}
}
}
}
routing {
authenticate("form") {
route("account") {
post {
call.respond(HttpStatusCode.OK, "connected")
}
}
}
}
}
To access the route /account I send this HTTP request :
POST <http://0.0.0.0:8081/account?username=Louis&password=pass>
But this raises an exception : io.ktor.features.CannotTransformContentToTypeException: Cannot transform this request's content to class io.ktor.http.Parameters
So I guess I should not give credentials to the server via POST body.
I have tried sending credentials in JSON with ContentNegocition installed but I get a similar error.
If someone could help me ...
I will update the documentation once I know how it works.
Posted in #servercy
01/31/2019, 3:07 PMcy
01/31/2019, 3:13 PMLouis Saglio
01/31/2019, 3:23 PM