refresh method

Future<void> refresh([
  1. List<String>? newScopes
])

Refreshes the currently used credentials.

newScopes can be also provided to obtain a different set of scopes after the refreshing. If left null, old scopes are used.

This method will log the LoginClient out on the authorization failure.

See also:

Implementation

Future<void> refresh([List<String>? newScopes]) async {
  if (_oAuthClient == null) {
    throw const RefreshException(
      'Cannot refresh unauthorized client. Login first.',
    );
  }

  try {
    _oAuthClient = await _oAuthClient!.refreshCredentials(newScopes);
    _logger('Refreshed credentials with success');
  } on oauth2.AuthorizationException {
    await _logOutInternal();
    _logger(
      'An error while force refreshing occured, '
      'successfully logged out and cleared credentials.',
    );
    rethrow;
  }
}