getOAuthToken method

Future<OAuthToken?> getOAuthToken({
  1. bool refresh = false,
})

Obtains the OAuth token for the current user, forcing a refresh if desired.

Implementation

Future<OAuthToken?> getOAuthToken({bool refresh = false}) async {
  if (!CarpService().isConfigured)
    throw new CarpServiceException(
        message:
            "CARP Service not initialized. Call 'CarpService.configure()' first.");
  if (token == null)
    throw new CarpServiceException(
        message:
            "OAuth token is null. Call 'CarpService.authenticate()' first.");

  // check if we need to refresh the token.
  if (token!.hasExpired || refresh) {
    token = await CarpService().refresh();
  }

  return token;
}