Louis Saglio
01/30/2019, 7:41 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.bdawg.io
01/31/2019, 3:25 AMPOST /account HTTP/1.1
Host: 0.0.0.0:8081
Content-Type: application/x-www-form-urlencoded
username=Louis&password=pass
this can be simulated in curl using $ curl -X POST -H 'Content-Type: application/x-www-form-urlencoded' -d 'username=Louis&password=pass' <http://0.0.0.0:8081/account>
Louis Saglio
01/31/2019, 8:57 AMhho
01/31/2019, 9:57 AM