getOAuthToken method
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 CarpServiceException(
message:
"CARP Service not initialized. Call 'CarpService.configure()' first.");
}
if (token == null) {
throw 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;
}