getOAuthToken method

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

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

Implementation

Future<OAuthToken> getOAuthToken({bool refresh = false}) async {
  if (CarpService() == null)
    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) {
    this.token = await CarpService().refresh();
  }

  return token;
}