Can I check permissions for a call? I've written l...
# kotlinx-rpc
a
Can I check permissions for a call? I've written like this:
Copy code
val myService = MyService(....., emptyList())
routing {
    rpc("/rpc") {
        registerService<MyService> {
            myService.copy(userRoles = authenticateAndGetRoles(call.request.cookies[authCookieName]))
        }
    }
}
Is it OK? PS: I'm using cookie instead of header because I don't know how I can fill header in kotlin-js code
d
a
Now I've done more:
Copy code
rpc(Routes.KRPC) {
            val roles = authProvider.authenticateAndGetRoles(call.request.cookies)
            registerService<LocationDaoService> { DynamicInvocationHandler.make(locationDaoService, roles) }
DynamicInvocationHandler.make
checks user roles and configuration in my annotations and create simple proxy or "Required permissions are missing" stub.
But I can't fill the header in JavaScript KRPC client, so I use cookies. Does it work?
d
correct is to say: "Does it work?" What is DynamicInvocationHandler? - looks like a fancy constructor In my case simply to propagate the permissions was not enough, I needed to know to who these permissions belong, the name or email of the principal, so I propagated the principal to the kRPC service constructor and I do what ever I want later inside the service
a
DynamicInvocationHandler is an InvocationHandler implementation
d
never used this, can't say anything about it
I just call the constructor