# Token\_failed, Failed to get token: \[error: invalid\_grant, description: Unknown or invalid refresh toke

**URL:** <https://community.auth0.com/t/token-failed-failed-to-get-token-error-invalid-grant-description-unknown-or-invalid-refresh-toke/82564>\
**Category:** Get Help\
**Tags:** refresh-tokens, auth0\
**Created:** [April 28, 2022, 3:00pm UTC](https://community.auth0.com/t/token-failed-failed-to-get-token-error-invalid-grant-description-unknown-or-invalid-refresh-toke/82564 "2022-04-28T15:00:54Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![ahmed.khouaja](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ahmed.khouaja/32/33378_2.png) [@ahmed.khouaja](https://community.auth0.com/u/ahmed.khouaja)\
**Post date:** [April 28, 2022, 3:00pm UTC](https://community.auth0.com/t/token-failed-failed-to-get-token-error-invalid-grant-description-unknown-or-invalid-refresh-toke/82564/1 "2022-04-28T15:00:54Z")

</div>

PlatformException(token\_failed, Failed to get token: [error: invalid\_grant, description: Unknown or invalid refresh token.], null, null)

Future init() async {  
final storedRefreshToken = await secureStorage.read(key:REFRESH\_TOKEN\_KEY);

```
if (storedRefreshToken == null) {
  return false;
}

try {
  final TokenResponse? result = await appAuth.token(
    TokenRequest( // error is in this line (i debug the code ) 
      AUTH0_CLIENT_ID,
      AUTH0_REDIRECT_URI,
      issuer: AUTH0_ISSUER,
      refreshToken: storedRefreshToken,
    ),
  );
  final String setResult = await _setLocalVariables(result);
  return setResult == 'Success';
} catch (e, s) {
  print('error on Refresh Token: $e - stack: $s');
  // logOut() possibly
  return false;
}

```

}

didn’t understand why it can’t do tokenrequest and return an error.

---

<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 28, 2022, 10:51pm UTC](https://community.auth0.com/t/token-failed-failed-to-get-token-error-invalid-grant-description-unknown-or-invalid-refresh-toke/82564/3 "2022-04-28T22:51:03Z")

</div>

Hi there @ahmed.khouaja welcome to the community!

> [@ahmed.khouaja](#):
>
> didn’t understand why it can’t do tokenrequest and return an error

I think you’re always going to get an error thrown at that point if there is one.

As to why the error is occurring, I’ve seen this happen in a couple of scenarios. One possibility is if you are rotating refresh tokens, and trying to reuse them. Another being that if a refresh token is revoked, grants are also deleted and thus all subsequent tokens with the same user, client\_id, and audience are invalid. Some more on that here:

> [@Invalid Refresh Token](https://community.auth0.com/t/invalid-refresh-token/10335/2):
>
> An invalid refresh token can occur if: [The token was revoked](https://auth0.com/docs/api/authentication#refresh-token)[The grants to the client application were deleted](https://auth0.com/docs/api/management/v2#!/Grants/delete_grants_by_id) One important detail is that when you revoke a token, for security reasons the grants associated with that token are deleted. This means that all other refresh tokens issued to the same combination of application, user and audience effectively become invalid. If you are revoking refresh tokens as part of your flow, this might explain it.

Hope this helps!

---

<div class="post-metadata">

**Author:** ![ahmed.khouaja](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ahmed.khouaja/32/33378_2.png) [@ahmed.khouaja](https://community.auth0.com/u/ahmed.khouaja)\
**Post date:** [April 29, 2022, 9:10am UTC](https://community.auth0.com/t/token-failed-failed-to-get-token-error-invalid-grant-description-unknown-or-invalid-refresh-toke/82564/4 "2022-04-29T09:10:20Z")

</div>

Thanks for the reply @ty.frith

I send you my config

 ![image](https://global.discourse-cdn.com/auth0/original/3X/a/a/aa008fedb53e0f60d778d5502bfe64c459f68512.png)

maybe i should activate refresh token rotation …  
but its blocked and i can’t activate it

---

<div class="post-metadata">

**Author:** ![ahmed.khouaja](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ahmed.khouaja/32/33378_2.png) [@ahmed.khouaja](https://community.auth0.com/u/ahmed.khouaja)\
**Post date:** [April 29, 2022, 2:20pm UTC](https://community.auth0.com/t/token-failed-failed-to-get-token-error-invalid-grant-description-unknown-or-invalid-refresh-toke/82564/5 "2022-04-29T14:20:53Z")

</div>

Its solved .  
The problem is in TokenRequest function  
it need a (discoveryUrl required !! )so all i have done is activate OIDC in advanced settings.

---

<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 29, 2022, 8:16pm UTC](https://community.auth0.com/t/token-failed-failed-to-get-token-error-invalid-grant-description-unknown-or-invalid-refresh-toke/82564/6 "2022-04-29T20:16:17Z")

</div>

Awesome! Thanks for the update, glad you were able to resolve it 🤠

---

<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:** [May 14, 2022, 8:16pm UTC](https://community.auth0.com/t/token-failed-failed-to-get-token-error-invalid-grant-description-unknown-or-invalid-refresh-toke/82564/7 "2022-05-14T20:16:39Z")

</div>

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.
