Android: Access token not refreshing (CredentialsManagerException)

Hello Auth0 community,

I have a problem with my access tokens not getting refreshed in the Android app.

I login the user with Lock like this:

 lock = Lock.newBuilder(Auth0(this), callback)
            .withScope("offline_access openid")

I store the returned credentials (including the refresh token and id token) using the CredentialsManager like this:


Then I retrieve the access token using the credentialsManager.getCredentials() function, which as stated in the documentation

Retrieves the credentials from the storage and refresh them if they have already expired.
It will fail with [CredentialsManagerException] if the saved access_token or id_token is null,
or if the tokens have already expired and the refresh_token is null.

like this:

 override suspend fun getAccessToken(): String {
        val credentials = suspendCoroutine<Credentials> { continuation ->
            credentialsManager.getCredentials(object : Callback<Credentials, CredentialsManagerException> {
                override fun onSuccess(result: Credentials) {
                    // Use credentials

                override fun onFailure(error: CredentialsManagerException) {
                    // No credentials were previously saved or they couldn't be refreshed
        return credentials.accessToken

However, once the access token has expired, i get the following error when attempting to retrieve the access token this way: An error occurred while trying to use the Refresh Token to renew the Credentials.
at$r8$lambda$Pfq2vyLDFhY2XM__E5Uh2vtQFxk(Unknown Source:0)
at$$ Source:4)
at android.os.Handler.handleCallback(
at android.os.Handler.dispatchMessage(
at android.os.Looper.loopOnce(
at android.os.Looper.loop(
at java.lang.reflect.Method.invoke(Native Method)
Caused by: An error occurred when trying to authenticate with the server.
at$r8$lambda$uH6X7wIol62Lzts5fbwoUeRDLU4(Unknown Source:0)
at$$ Source:4)
at java.util.concurrent.ThreadPoolExecutor.runWorker(
at java.util.concurrent.ThreadPoolExecutor$

Any help would be very welcome, thanks.

Solved. It was caused by refresh token Reuse Interval being set to 0s in the Mobile App settings in Auth0 Dashboard.

Hi Minarik - I read thru your issue and your fix. Does the Reuse Interval being set to 0s affect individual user access tokens or did this result in an issue for all of your users? Seems it would affect all, but I have a single user who seems to be logged out of our app from time to time due to the access tokens not refreshing and I am not sure what to check on his side since it only affects him. I appreciate any feedback you might have.

It was only causing an issue when requesting the Access Token multiple times a second so it’s use-case dependent.