almeydajuan
09/10/2025, 7:03 AMBearerAuthSecurity.
I have 2 example implementations:
class Lookup(lookup: (String) -> String?) : Security by BearerAuthSecurity({ lookup(it) != null }), TokenSecurity
class WithKey(lookup: (String) -> String?) :
Security by BearerAuthSecurity(key = Header.required("Authorization"), lookup = { lookup(it) }), TokenSecurity
Then if I do:
val http1: HttpHandler = newBackend(tokenSecurity = WithKey { "hello" })
val http2: HttpHandler = newBackend(tokenSecurity = Lookup { "hello" })
Request(GET, "/hello").header("Authorization", "Bearer 123").use(http1)
Request(GET, "/hello").header("Authorization", "Bearer 123").use(http2)
The backend which uses security in with only lookup receives the bearer header, but the in the call to the 2nd backend (with the required header) Authorization headers is overriden and I get Authorization hello instead of Authorization Bearer 123
For me it is unintuitive because we are using the same BearerAuthSecurity but depending on which parameter we pass, the request that arrives to our system comes already modified.
Is this how this should behave? If so, what is the rational behind it?
cc: @Michal Wachowskidave
09/10/2025, 1:58 PMdave
09/10/2025, 1:58 PMalmeydajuan
09/11/2025, 7:05 AMMichal Wachowski
09/19/2025, 5:04 PM