Hello Everyone, I am using below block to reauthen...
# ktor
r
Hello Everyone, I am using below block to reauthenticate if token expires. Here for the original request where I got 401, once the token is updated, I want to add one more parameter to original request.But I am not able to find a way to it. Any help will be appreciated. install(Auth) { bearer { refreshTokens { // this: RefreshTokensParams // Refresh tokens and return them as the 'BearerTokens' instance val refreshToken = CoreSDK.get("refreshToken","") val apiUrl = CoreSDK.baseUrl + "/oauth/token" val response = client.post(apiUrl) { markAsRefreshTokenRequest() basicAuth(Constants.USER_NAME, Constants.PASSWORD) setBody( FormDataContent( Parameters.build { append("refresh_token", refreshToken) append("grant_type", "refresh_token") } ) ) } var token:RefreshToken ?= null if(response.isSuccessful()){ val bodyAsText = response.bodyAsText() token = jsonParser.decodeFromString(bodyAsText) CoreSDK.save("tokenValue",token?.access_token.orEmpty()) CoreSDK.save("refreshToken",token?.refresh_token.orEmpty()) } BearerTokens( accessToken = token?.access_token.orEmpty(), refreshToken = token?.refresh_token.orEmpty() ) } } }
a
Unfortunately, that's not possible.
r
@Aleksei Tirman [JB] what is the standard approach?
a
For what?
r
Refresh token
so the above code snippet is correct for handling refresh token if any api gets 401
a
Yes. It seems correct.