Hi, dows anyone has a sample of a ktor server with...
# ktor
m
Hi, dows anyone has a sample of a ktor server with JWT with a ktor client connecting to it? The documentation on JWT server is quite ok (at least I managed to make it work). However I don't see how to connect the client using the bearer auth. Thanks,
m
That is the official docs, but don't resolve how to connect to a ktor server using jwt. The docs on how to use jwt on ktor server and ktor client don't match in any way. Using the description on server-swt I have a login route that retuns the jwt token. But the client needs two tokens, to start. There is the renew process also, not defined on the server,...
k
Are you trying to implement OAuth or just simply JWT auth?
m
Simply JWT
k
The example in the docs just uses regular username/password credentials to obtain a JWT
And afaik it does not implement refresh tokens unless you use OAuth, meaning you have to refresh your tokens manually when they expire/before they expire
m
Ok, so only use the loadTokens, and the BearerTokens("your_jwt_token, "")
k
I have not actually used the Auth plugin in the Client, but looking at the docs you should be able to just define some logic in the refreshToken {} block to get new tokens when you get a 401. How I have solved it in the client is to store the current viable token, implemented a function that validates the token internally before sending a new request, this is basically just checking if the TTL is expired. If the token is invalid I get a new token before I send my request. This is a bit more logic on the client side, but it stops me from having a bunch of 401s in my logs because of expired tokens.