@Override
  public AuthData generateAuthData(String callbackBaseUrl, String authCode, String id,
      AuthData initialAuthData, String extra) {
    Preconditions.checkArgument(
        Strings.isNullOrEmpty(extra), "Extra data not expected for OAuth flow");
    Preconditions.checkArgument(initialAuthData == null,
        "Initial auth data not expected for " + config.getServiceName());

    Map<String, String> params = new LinkedHashMap<>();
    params.put("client_id", clientId);
    params.put("client_secret", clientSecret);
    params.put("grant_type", "authorization_code");
    params.put("redirect_uri", callbackBaseUrl);
    params.put("code", authCode);

    HttpContent content = new UrlEncodedContent(params);

    try {
      String tokenResponse = OAuthUtils.makeRawPostRequest(
          httpTransport, config.getTokenUrl(), content);

      return config.getResponseClass(tokenResponse);
    } catch (IOException e) {
      throw new RuntimeException("Error getting token", e); // TODO
    }
  }
General implementation of an {@link AuthDataGenerator} for OAuth2.
libraries/auth/src/main/java/org/datatransferproject/auth/OAuth2DataGenerator.java