public Credential refreshCredential(Credential credential)
      throws IOException, InvalidTokenException {
    try {
      TokenResponse tokenResponse =
          new RefreshTokenRequest(
                  httpTransport,
                  jsonFactory,
                  new GenericUrl(credential.getTokenServerEncodedUrl()),
                  credential.getRefreshToken())
              .setClientAuthentication(credential.getClientAuthentication())
              .setRequestInitializer(credential.getRequestInitializer())
              .execute();

      return credential.setFromTokenResponse(tokenResponse);
    } catch (TokenResponseException e) {
      if (e.getStatusCode() == 401) {
        throw new InvalidTokenException("Unable to refresh token.", e);
      } else {
        throw e;
      }
    }
  }
Refreshes and updates the given credential
extensions/data-transfer/portability-data-transfer-koofr/src/main/java/org/datatransferproject/transfer/koofr/common/KoofrCredentialFactory.java