Marc
01/10/2025, 1:52 PMRootingContext
where i can get the headers of…
Any help is super welcome 🙏🏻Marc
01/10/2025, 1:56 PMAlexander Sysoev
01/10/2025, 2:55 PMMarc
01/10/2025, 2:56 PMAlexander Sysoev
01/10/2025, 2:58 PMAlexander Sysoev
01/10/2025, 2:59 PMAlexander Sysoev
01/10/2025, 3:00 PMktorClient.rpc("<ws://localhost:4242/services>") { // this: HttpRequestBuilder
headers["my-auth"] = "token"
}
Alexander Sysoev
01/10/2025, 3:00 PMMarc
01/10/2025, 3:01 PMMarc
01/10/2025, 4:26 PMktorClient.rpc("<ws://localhost:4242/services>") { // this: HttpRequestBuilder
headers["my-auth"] = "token"
}
Marc
01/10/2025, 4:30 PM@Rpc
interface TransactionsService : RemoteService {
suspend fun getTransactrionList(): Flow<List<Transaction>>
}
and i would like to access the userId somehow how would I? right now I’m accessing it by reading the access token (I set the id in the claim
) but as I don’t have access to the headers in the service I’m a bit lost on how can I identify the user 🤔Marc
01/12/2025, 1:51 PMJs
target. If i run jvm all looks goodarve
01/15/2025, 12:41 PMMarc
01/15/2025, 1:43 PMHttpRequestBuilder
as contextMarc
01/15/2025, 1:45 PMauthentication {
session<MySession> {
validate { session ->
session.also {
println("session for: ${session.userId}")
}
}
}
jwt {
realm = jwtRealm
verifier(
JWT
.require(Algorithm.HMAC512(secret))
.withClaimPresence("id")
.withIssuer(issuer)
.build(),
)
validate { credential ->
println("claim id: ${credential.payload.getClaim("id")}")
if (credential.payload.getClaim("id").asLong() != null) JWTPrincipal(credential.payload) else null
}
}
}
rpc("/api") {
rpcConfig {
serialization { json() }
}
val principal = call.principal<JWTPrincipal>()
val userId = principal?.payload?.getClaim("id")?.let { UserId(it.asLong()) }
print("userId is: $userId \n")
print("payload is: ${principal?.payload} \n")
userId?.run {
registerService<TransactionsService> { context ->
//UserId passed as context using context receivers
TransactionsRpcService.new(coroutineContext = context)
}
}
}