Hello everybody! I have a question as a newby.
I’d like to implement on ktor 2 endpoint: one authenticated and one not, but with the same endpoint
Something like
authenticate(“jwt”) {
get(“hello”) {
call.respond(“Authenticated”)
}
}
get(“hello”) {
call.respond(“Public”)
}
The above is of course not working. Is there a way to achieve this?
l
Luke Rohde
10/07/2019, 2:16 PM
you can do
Copy code
authenticate("jwt", optional = true) {
...
}
Per docs,
Copy code
* optional=true:
* - No credentials: route handler will be executed with a null [Principal]
* - Bad credentials: Unauthorized
* - Good credentials: route handler will be execute