andylamax
08/17/2025, 10:29 PMdarkmoon_uk
08/17/2025, 11:20 PMtoken
parameter to each 'authenticated' RPC function, even if this pollutes the API somewhat.andylamax
08/18/2025, 9:34 AMdarkmoon_uk
08/18/2025, 9:41 AMandylamax
08/18/2025, 9:51 AMandylamax
08/18/2025, 9:53 AMdarkmoon_uk
08/18/2025, 10:29 AMaccessToken
parameter; it makes the data-layer contract explicit after all, and auth concerns can be 'stripped off' as we map to/from the Domain layer.darkmoon_uk
08/18/2025, 10:35 AMDumitru Preguza
08/18/2025, 10:54 AMandylamax
08/18/2025, 11:09 AMandylamax
08/18/2025, 11:10 AMdarkmoon_uk
08/18/2025, 11:13 AMaccess
and refresh
tokens with HTTP, much of the time, is to send part of the 'indefinite authentication' less often - harder to intercept.
With a persistent websocket, we're sending the auth details even less often, doesn't this theoretically make our authentication even more secure i.e. better?
The server then acknowledges the web-socket as authenticated once.
Only if it disconnects does it need re-authenticating.
I guess I'd need to lean on a lower-level understanding of TCP/IP and WebSockets at this point - but isn't the standard pretty robust to hijacking against a continuously open socket, making 'auth once' preferable?
Maybe not! Keen to get more inputs but it strikes me there's a nuanced balance between '_keep reassuring me you're who you say you are_' vs '_don't tell me too often lest others copy how_'.darkmoon_uk
08/18/2025, 11:20 AMdarkmoon_uk
08/18/2025, 11:21 AMandylamax
08/18/2025, 12:56 PMDumitru Preguza
08/18/2025, 1:17 PMkRPC currently uses websockets and the client establishes the connection with the server on the first request
So you want to say that the only problem at the moment is that the auth takes place only on first request, when the ktor client gets created for the first time and the first kRPC call is made, and not for every kRPC call separately ?
Well, maybe this scenario suits me, with some additional changes maybe, it's interesting how people do it when dealing with plain websocketsandylamax
08/18/2025, 1:34 PMDumitru Preguza
08/18/2025, 1:38 PMandylamax
08/18/2025, 1:49 PMneworldlt
08/19/2025, 5:36 PMIf I add the auth. configs to Ktor server and client, should not it automatically cover kRPC as well @Alexander Sysoev?I am also currently developing an authentication solution for Krpc, and I have just found that the JWT token auth works just fine, at least in the tests. I have some tests that deliberately don't use a bearer token, and they fail with
IllegalStateException
because the route was not found.
Also, I am using an unproctored RPC connection for authentication, so my app is entirely RPC.
For my case, it is OK if the WebSocket connection outlives the JWT Token.andylamax
08/19/2025, 9:15 PMneworldlt
08/19/2025, 9:41 PMunauthorized
response:
private val authKtorClient = ktorClient.config {
install(Auth) {
bearer {
loadTokens {
BearerTokens(session.jwtToken.value, session.jwtRefreshToken.value)
}
refreshTokens {
val refreshToken = this.oldTokens!!.refreshToken
authentificationService.refresh(refreshToken)
}
}
}
}
But I don't have tests that test expiration behavior yet, so I am not sure.
It is sufficient for my goal: users should not feel interruptions, and I can implement any future authentication model without redoing the API.andylamax
08/19/2025, 10:09 PMneworldlt
08/19/2025, 10:24 PMandylamax
08/19/2025, 10:29 PMneworldlt
08/20/2025, 2:15 PMneworldlt
08/20/2025, 2:18 PMYes it should, but question is, how do you trigger a reconnection?I don't. And I don't expect someone will be able keep connection forever, but if they do, server still restarts time to time due to updates.
neworldlt
08/20/2025, 2:19 PMneworldlt
08/20/2025, 7:29 PMSmuggle access tokens
does not work, because the browser drops the connection if the subprotocol does not match.
Another interesting approach would be sending a token as the very first RPC call. It could also update the token periodically. With my DI setup, it would be easy to support session state across services. It looks appealing; however, it opens the possibility for DoS attacks just by keeping the socket open.