Token_failed, Failed to get token: [error: invalid_grant, description: Unknown or invalid refresh toke

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.

Hi there @ahmed.khouaja welcome to the community!

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:

Hope this helps!

Thanks for the reply @tyf

I send you my config

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

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

1 Like

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

1 Like

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