Sudhanshu Singh
09/19/2024, 6:47 PMdefaultRequest {
url("url")
headers.appendIfNameAbsent("Authorization", "Bearer token")
}
and I am writing Auth
to refresh the token . But on the refresh POST call, I don't want to pass the Authorization header. How do I remove it .
Setting header to empty string or null, both don't work
install(Auth) {
bearer {
loadTokens {
... load token
}
refreshTokens {
val renewTokens = <http://client.post|client.post>("refreshtoken") {
headers.append("Authorization", "") // this doesn't work
header("Authorization", null). // this also doesn't work
markAsRefreshTokenRequest()
}.body()
}
}
}
Hristijan
09/19/2024, 7:13 PMclient.plugin(HttpSend).intercept { request -> }
You can check the request URL that matches your path and remove the headers
request.headers.remove(HttpHeaders.Authorization)
execute(request)
Aleksei Tirman [JB]
09/20/2024, 8:15 AMheaders.remove(HttpHeaders.Authorization)
?Sudhanshu Singh
09/20/2024, 8:16 AMAleksei Tirman [JB]
09/20/2024, 8:27 AMHttpRequestPipeline.Before
. Here is an example:
val client = HttpClient(CIO) {
defaultRequest {
headers.appendIfNameAbsent("Authorization", "Bearer")
}
install(Auth) {
bearer {
refreshTokens {
println("In refresh")
val r = client.get("<https://httpbin.org/get>") {
markAsRefreshTokenRequest()
}
println(r.bodyAsText())
BearerTokens("refreshed", "")
}
}
}
}
client.requestPipeline.intercept(HttpRequestPipeline.State) {
if (context.attributes.contains(AuthCircuitBreaker)) {
context.headers.remove(HttpHeaders.Authorization)
}
}
client.get("<https://httpbin.org/bearer>") {
headers.remove(HttpHeaders.Authorization)
}
Sudhanshu Singh
09/27/2024, 7:06 AM