refresh method
Tries to refresh the available credentials and returns a new OAuthToken
instance.
Throws an exception when refreshing fails. If the exception is a
oauth2.AuthorizationException it clears the storage.
See oauth2.Credentials.refresh
Implementation
Future<OAuthToken?> refresh() async {
final credentialsJson = await _storage.fetchCredentials();
if (credentialsJson == null) return null;
final credentials = oauth2.Credentials.fromJson(credentialsJson);
try {
final newCredentials = await credentials.refresh(
identifier: identifier,
secret: secret,
httpClient: httpClient,
);
await _storage.saveCredentials(newCredentials.toJson());
return OAuthToken.fromCredentials(newCredentials);
} on oauth2.AuthorizationException {
_storage.clear();
rethrow;
}
}