Tech
01/09/2023, 9:36 PMAleksei Tirman [JB]
01/11/2023, 8:47 AMembeddedServer(CIO, port = 4444) {
install(Authentication) {
basic {
validate { creds ->
if (creds.name == "John") UserIdPrincipal(creds.name) else null
}
}
}
install(RateLimit) {
register(RateLimitName("protected")) {
rateLimiter(limit = 5, refillPeriod = 60.seconds)
requestKey { call ->
val user = call.principal<UserIdPrincipal>()
user?.name ?: "default"
}
}
}
routing {
authenticate {
rateLimit(RateLimitName("protected")) {
get("/secret") {
call.respondText { "secret" }
}
}
}
}
}.start(wait = true)
Please provide more details about your problem.Ron S
01/11/2023, 10:50 AMcall.principal<Principal>()
in requestKey
always returns null.Ron S
01/11/2023, 10:56 AMAleksei Tirman [JB]
01/11/2023, 12:21 PMRon S
01/11/2023, 12:23 PMRustam Siniukov
01/13/2023, 3:04 PMApplication
pipeline, but auth works or Route
. And phase where RateLimit
plugin works is executed before route matches.Tech
01/13/2023, 4:18 PMTech
01/13/2023, 4:21 PMRustam Siniukov
01/13/2023, 5:02 PM