https://kotlinlang.org logo
Title
d

Dario Pellegrini

10/07/2019, 12:42 PM
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
authenticate("jwt", optional = true) {
...
}
Per docs,
* optional=true:
 *   - No credentials: route handler will be executed with a null [Principal]
 *   - Bad credentials: Unauthorized
 *   - Good credentials: route handler will be execute
👆 3
d

Dario Pellegrini

10/08/2019, 8:24 AM
Thank you very much!