<p dir="auto">I can't download glide from jcenter, and there is no glide version 4 in jcenter.<br>
Follow this link <a href="https://jcenter.bintray.com/com/github/bumptech/glide/glide/" rel="nofollow">https://jcenter.bintray.com/com/github/bumptech/glide/glide/</a></p>
<p dir="auto">I'm using Glide 3.7.0 with OkHttp3 integration library to display images in RecyclerView.<br>
Authentication is needed to access the images which is done inside OkHttpClient authenticator.<br>
But sometime i need to refresh the token first when the token expired . In this case there are many refresh token request from glide to server. What i'm using now by comparing lastRefreshTime against current time refreshToken function.<br>
Something like below:</p>
<div class="highlight highlight-source-kotlin notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="fun refreshToken(): AccessToken? {
        synchronized(lockObject) {
            if (System.currentTimeMillis() - lastSyncTime &gt; SYNC_INTERVAL) {
                val oldToken = activeToken.get()
                accountManager.invalidateAuthToken(MyAccountAuthenticator.ACCOUNT_TYPE, oldToken)
            }
            return getToken() //blocking method
        }
    }"><pre class="notranslate"><span class="pl-k">fun</span> <span class="pl-en">refreshToken</span>(): <span class="pl-en">AccessToken</span><span class="pl-k">?</span> {
        synchronized(lockObject) {
            <span class="pl-k">if</span> (<span class="pl-en">System</span>.currentTimeMillis() <span class="pl-k">-</span> lastSyncTime <span class="pl-k">&gt;</span> <span class="pl-en">SYNC_INTERVAL</span>) {
                <span class="pl-k">val</span> oldToken <span class="pl-k">=</span> activeToken.get()
                accountManager.invalidateAuthToken(<span class="pl-en">MyAccountAuthenticator</span>.<span class="pl-en">ACCOUNT_TYPE</span>, oldToken)
            }
            <span class="pl-k">return</span> getToken() <span class="pl-c"><span class="pl-c">//</span>blocking method</span>
        }
    }</pre></div>
<p dir="auto">Do you have some kind of best practices to avoid multiple refresh token calling?</p>
<div class="highlight highlight-source-kotlin notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="class MyGlideSetup : GlideModule { 
    override fun applyOptions(context: Context?, builder: GlideBuilder?) {  }  
    override fun registerComponents(context: Context?, glide: Glide?) { 
        if (context == null) { 
            return 
        }  
        val httpClientBuilder = OkHttpClient.Builder()  
        httpClientBuilder.authenticator {
             route, response -&gt;
             val originalRequest = response.request()
             val newRequest = originalRequest.newBuilder()
              val credentialManager = MyApplication.getCredentialManager(context)
             val accessToken: AccessToken?
             if (originalRequest.header(&quot;Authorization&quot;) == null) {
                 accessToken = credentialManager.getToken() 
                accessToken?.let { 
                    newRequest.header(&quot;Authorization&quot;, &quot;${it.token_type} ${it.access_token}&quot;) 
                } 
            } else { 
                accessToken = credentialManager.refreshToken() 
            }  
            accessToken?.let { 
                newRequest.header(&quot;Authorization&quot;, &quot;${it.token_type} ${it.access_token}&quot;) 
            }   
           newRequest.build() 
        }  
        glide?.register(GlideUrl::class.java, InputStream::class.java,   
                      OkHttpUrlLoader.Factory(httpClientBuilder.build())) 
    }
 }
"><pre class="notranslate"><span class="pl-k">class</span> <span class="pl-en">MyGlideSetup</span> : <span class="pl-en">GlideModule</span> { 
    <span class="pl-k">override</span> <span class="pl-k">fun</span> <span class="pl-en">applyOptions</span>(<span class="pl-smi">context</span><span class="pl-k">:</span> <span class="pl-en">Context</span><span class="pl-k">?</span>, <span class="pl-smi">builder</span><span class="pl-k">:</span> <span class="pl-en">GlideBuilder</span><span class="pl-k">?</span>) {  }  
    <span class="pl-k">override</span> <span class="pl-k">fun</span> <span class="pl-en">registerComponents</span>(<span class="pl-smi">context</span><span class="pl-k">:</span> <span class="pl-en">Context</span><span class="pl-k">?</span>, <span class="pl-smi">glide</span><span class="pl-k">:</span> <span class="pl-en">Glide</span><span class="pl-k">?</span>) { 
        <span class="pl-k">if</span> (context <span class="pl-k">==</span> <span class="pl-c1">null</span>) { 
            <span class="pl-k">return</span> 
        }  
        <span class="pl-k">val</span> httpClientBuilder <span class="pl-k">=</span> <span class="pl-en">OkHttpClient</span>.<span class="pl-en">Builder</span>()  
        httpClientBuilder.authenticator {
             route, response <span class="pl-k">-&gt;</span>
             <span class="pl-k">val</span> originalRequest <span class="pl-k">=</span> response.request()
             <span class="pl-k">val</span> newRequest <span class="pl-k">=</span> originalRequest.newBuilder()
              <span class="pl-k">val</span> credentialManager <span class="pl-k">=</span> <span class="pl-en">MyApplication</span>.getCredentialManager(context)
             <span class="pl-k">val</span> accessToken<span class="pl-k">:</span> <span class="pl-en">AccessToken</span><span class="pl-k">?</span>
             <span class="pl-k">if</span> (originalRequest.header(<span class="pl-s"><span class="pl-pds">"</span>Authorization<span class="pl-pds">"</span></span>) <span class="pl-k">==</span> <span class="pl-c1">null</span>) {
                 accessToken <span class="pl-k">=</span> credentialManager.getToken() 
                accessToken?.<span class="pl-c1">let</span> { 
                    newRequest.header(<span class="pl-s"><span class="pl-pds">"</span>Authorization<span class="pl-pds">"</span></span>, <span class="pl-s"><span class="pl-pds">"</span><span class="pl-e">${it.token_type}</span> <span class="pl-e">${it.access_token}</span><span class="pl-pds">"</span></span>) 
                } 
            } <span class="pl-k">else</span> { 
                accessToken <span class="pl-k">=</span> credentialManager.refreshToken() 
            }  
            accessToken?.<span class="pl-c1">let</span> { 
                newRequest.header(<span class="pl-s"><span class="pl-pds">"</span>Authorization<span class="pl-pds">"</span></span>, <span class="pl-s"><span class="pl-pds">"</span><span class="pl-e">${it.token_type}</span> <span class="pl-e">${it.access_token}</span><span class="pl-pds">"</span></span>) 
            }   
           newRequest.build() 
        }  
        glide?.register(<span class="pl-en">GlideUrl</span>::<span class="pl-c1">class</span>.java, <span class="pl-en">InputStream</span>::<span class="pl-c1">class</span>.java,   
                      <span class="pl-en">OkHttpUrlLoader</span>.<span class="pl-en">Factory</span>(httpClientBuilder.build())) 
    }
 }
</pre></div>