# Cannot login/out when access token expired?

**URL:** <https://community.auth0.com/t/cannot-login-out-when-access-token-expired/80896>\
**Category:** Get Help\
**Tags:** sdk:java, auth0-sdk, android\
**Created:** [March 31, 2022, 12:30pm UTC](https://community.auth0.com/t/cannot-login-out-when-access-token-expired/80896 "2022-03-31T12:30:12Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![lizfltn](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/lizfltn/32/35480_2.png) [@lizfltn](https://community.auth0.com/u/lizfltn)\
**Post date:** [March 31, 2022, 12:30pm UTC](https://community.auth0.com/t/cannot-login-out-when-access-token-expired/80896/1 "2022-03-31T12:30:12Z")

</div>

Which SDK? - com.auth0.android:auth0:2.7.0

I am using the Android SDK to login users to my app through social connections (Fitbit). I have followed the quick-start guide, however I am having trouble with reauthenticating users when their access token is expired.

If the token is expired, and I attempt to either call the Auth0 Account object’s logout method (to try and clear cookies) and/or call the login method, it fails with “Error occurred trying to authenticate with the server” (through an Authentication Exception).

Edited to add: the more detailed description of the exception is that “the user closed the browser and the authentication was cancelled”, however the browser is not being closed.

When running the app, what this looks like is the custom browser tab being opened to run the login/out, except instead of getting to the Auth0 login page, it simply says “not found” on the page - plain text, no other information. If I open the link from the custom tab in Chrome proper, it is trying to access the following URL but getting the “not found” message: https://{MY\_APPLICATION}.eu.auth0.com/android/{ANDROID\_PACKAGE\_NAME}/callback - which I set up per the quickstart guide.

Any way of getting around this? Since it then causes my app to quietly fail in the background and not perform as expected for the end user.

---

<div class="post-metadata">

**Author:** ![ty.frith](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ty.frith/32/58484_2.png) [@ty.frith](https://community.auth0.com/u/ty.frith)\
**Post date:** [April 6, 2022, 11:49pm UTC](https://community.auth0.com/t/cannot-login-out-when-access-token-expired/80896/3 "2022-04-06T23:49:33Z")

</div>

Hi there @lizfltn welcome to the community!

> [@lizfltn](#):
>
> If the token is expired, and I attempt to either call the Auth0 Account object’s logout method (to try and clear cookies) and/or call the login method, it fails with “Error occurred trying to authenticate with the server” (through an Authentication Exception).

Have you had a chance to try out our [sample apps](https://github.com/auth0-samples/auth0-android-sample) at all? I’d be curious to know if the same behavior happens there.

> [@lizfltn](#):
>
> Any way of getting around this? Since it then causes my app to quietly fail in the background and not perform as expected for the end user.

You should be able to mitigate this behavior by using [CredentialsManager](https://github.com/auth0/Auth0.Android#credentials-manager) to save a refresh token in order to renew id/access tokens as they expire. This requires passing an additional `offline_access` scope in the authorization request. Some more on refresh tokens [here](https://auth0.com/docs/secure/tokens/refresh-tokens).

Hope this helps get you started in the right direction!

---

<div class="post-metadata">

**Author:** ![lizfltn](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/lizfltn/32/35480_2.png) [@lizfltn](https://community.auth0.com/u/lizfltn)\
**Post date:** [April 20, 2022, 10:27am UTC](https://community.auth0.com/t/cannot-login-out-when-access-token-expired/80896/4 "2022-04-20T10:27:06Z")

</div>

> Have you had a chance to try out our [sample apps](https://github.com/auth0-samples/auth0-android-sample) at all? I’d be curious to know if the same behavior happens there.

Yes, I tried the Android sample app and was getting the same issue if the token was expired.

> You should be able to mitigate this behavior by using [CredentialsManager](https://github.com/auth0/Auth0.Android#credentials-manager) to save a refresh token in order to renew id/access tokens as they expire. This requires passing an additional `offline_access` scope in the authorization request.

Thank you, this did fix my problem!

---

<div class="post-metadata">

**Author:** ![ty.frith](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ty.frith/32/58484_2.png) [@ty.frith](https://community.auth0.com/u/ty.frith)\
**Post date:** [April 20, 2022, 11:45pm UTC](https://community.auth0.com/t/cannot-login-out-when-access-token-expired/80896/5 "2022-04-20T23:45:04Z")

</div>

Wonderful! Thanks for confirming and happy to help 😃

---

<div class="post-metadata">

**Author:** ![ty.frith](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ty.frith/32/58484_2.png) [@ty.frith](https://community.auth0.com/u/ty.frith)\
**Post date:** [April 22, 2022, 11:31pm UTC](https://community.auth0.com/t/cannot-login-out-when-access-token-expired/80896/6 "2022-04-22T23:31:36Z")

</div>


