Home > database >  RefreshToken not working as expecting in ktor
RefreshToken not working as expecting in ktor

Time:04-22

Hey I am working in Ktor in KMM. I tried to use enter image description here

  1. when I click 2nd time or more time on button. It call only my main api. It not calling my refresh api.

enter image description here

Can someone guide me please. How can I achieve my expected output.

CodePudding user response:

The problem is that a client (specifically the Auth plugin) tries to infinitely refresh a token. Here is the comment from the corresponding issue:

When refresh token request fails with 401 it tries to refresh token again, resulting in an infinite cycle. Since token refreshing is a users' code, users need to mark such requests, so we can have a special case.

To solve it you need to call markAsRefreshTokenRequest() inside the request builder:

val response =
    client.post("https://vivek-modi.com/api/v1/session/refresh") {
        markAsRefreshTokenRequest()
        contentType(ContentType.Application.Json)
        setBody(KtorSessionCommand(tokenProvider.refreshToken))
    }
  • Related