Can I get a quick code review on my authorization interceptor for retrofit? It's not a network interceptor, but an application interceptor
Copy code
class RollerToasterAuthInterceptor @Inject constructor(val userManager: UserManagerService) :
Interceptor {
override fun intercept(chain: Interceptor.Chain): Response {
val originalRequest: Request = chain.request()
val compressedRequest: Request =
originalRequest
.newBuilder()
.header("authorization", "Bearer " + userManager.authToken)
.method(originalRequest.method, originalRequest.body)
.build()
return chain.proceed(compressedRequest)
}
}
y
yschimke
09/27/2021, 8:21 AM
How is it compressed here? Also do you need to reset the method and body?
c
Colton Idle
09/27/2021, 4:09 PM
Whoops. I copied the variable name from the okhttp docs!
I don't need to reset anything. I just need to add the header onto my network calls.
n
nitrog42
09/28/2021, 8:00 AM
Hey, I wanted to make some comments : how do you refresh the token ? I usually make another class to handle the token like firebase : with a suspend/blocking method that is responsible for checking the token validity (expiration) and refreshing it if needed, before providing it to the interceptor to use
c
Colton Idle
09/29/2021, 2:15 PM
Yes, I do that. It works in my app code, but not in my test. SO I think something is just wrong with my testing setup.