Flutter refreshing the tokens

Hello, I’m using the auth0_flutter package, and I’m having trouble with the credentials manager. In the documentation it clearly states that the credentials() method “Retrieves the credentials from the storage and refreshes them if they have already expired.” (docs), but I can’t seem to get it working. I’m receiving the refresh_token after authenticating and I have set token duration to 30s. Also, I have set the token rotation. But when I invoke the credentials() I get the same tokens back.

So, am I misunderstanding the credentials() method? Is it supposed to renew the tokens using the refresh_token or not?

My code:

Future<void> login() async {
    await auth0.webAuthentication(scheme: dotenv.env["AUTH0_SCOPE"]!).login();
    _isLoggedIn = true;
    notifyListeners();
  }

  Future<void> logout() async {
    await auth0.webAuthentication(scheme: dotenv.env["AUTH0_SCOPE"]!).logout();
    _isLoggedIn = false;
    notifyListeners();
  }

  Future<bool> isUserLoggedIn() async {
    final loggedIn = await auth0.credentialsManager.hasValidCredentials();
    if (loggedIn) {
      final credentials = await auth0.credentialsManager.credentials();
      print(credentials.expiresAt);
      print(credentials.idToken);
      print(credentials.accessToken);
      print(credentials.refreshToken);
    }
    if (loggedIn) {
      _isLoggedIn = true;

      return true;
    }

    return false;
  }

The isUserLoggedIn() is used only when the app starts to check if the user is already logged in.

Hey there!

In order to handle that most effectively can I ask you to raise it as a GitHub issue here in the repo:

so we can work on that directly with the repo maintainers. Once you have a link to it you can share it here so we can ping them. Thank you!

1 Like

Thanks for the answer. Here’s the issue link: Issue with refreshing the token using credentials manager · Issue #234 · auth0/auth0-flutter · GitHub

1 Like

Perfect! I’ll ping the repo maintainers in a few minutes!

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