https://kotlinlang.org logo
Title
r

Razvan

11/23/2020, 5:40 PM
Hi, is there a way to do a Principal lookup in the
security
definition of a ContractRoute or have do be done apart ?
The answer is Yes, BearerAuthSecurity has a constructor that looks like is doing it:
constructor(key: RequestContextLens<Any>, lookup: (String) -> Any?, name: String = "bearerAuth")
But the problem I got with that is that it requires a <Any> if I try to use a lens:
val credentials = RequestContextKey.required<Credentials>(contexts)
I get a:
Type mismatch.
Required:
RequestContextLens<Any> /* = BiDiLens<Request, Any> */
Found:
RequestContextLens<Credentials> /* = BiDiLens<Request, Credentials> */
Declaring the Lens as
Any
and then doing an
as
when using the Lens works.
val credentials = RequestContextKey.required<Any>(contexts)

...
val handler: HttpHandler = { request ->
    val user = credentials(request) as? Credentials
    ...
}
...

meta {
   ...
   security = BearerAuthSecurity(key = credentials, User::fromJwtClaims)
   ...
}
d

dave

11/23/2020, 8:07 PM
Hmmm. Try writing your own Security and seeing if it works. It may require changing.
You may need to override the securotyrenderer as well to get it to render correctly in the openapidocs