Can I get a quick code review on my authorization ...
# squarelibraries
c
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
How is it compressed here? Also do you need to reset the method and body?
c
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
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
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.