OAuth with CData JDBC Driver for XML – Files on Google Drive – CallbackURL not Used

Tags: , , ,



I am using the CData JDBC Driver for XML to read XML files to my java application and some of those files are on google drive so OAuth is needed.

I am following the Authenticate to XML from a Web Application flow specified on CData website.

The first step is to get the OAuth Authorization URL using the GetOAuthAuthorizationURL stored procedure.

Here is my code:

try {
        Class.forName("cdata.jdbc.xml.XMLDriver");
    } catch (ClassNotFoundException e1) {
    }
    
    String url="";
    
    Properties prop = new Properties();
    prop.setProperty("InitiateOAuth", "OFF");
    prop.setProperty("OAuthClientId", "my-client-id");
    prop.setProperty("OAuthClientSecret", "my-client-secret");
    prop.setProperty("CallbackURL", redirectUri);
            
    prop.setProperty("OAuthAuthorizationUrl", "https://accounts.google.com/o/oauth2/auth?scope=https://www.googleapis.com/auth/drive.readonly");
    
    try (Connection connection = DriverManager.getConnection("jdbc:xml:", prop)) {
        CallableStatement cstmt = connection.prepareCall("GetOAuthAuthorizationURL");
        boolean ret = cstmt.execute();
        
      if (ret) {
          ResultSet rs = cstmt.getResultSet();
          while (rs.next()){
              for (int i = 1; i <= rs.getMetaData().getColumnCount(); i++) {
                  System.out.println(rs.getMetaData().getColumnName(i) + "=" + rs.getString(i));
                  if (StringUtils.equals(rs.getMetaData().getColumnName(i), "URL"))
                      url = rs.getString(i);
              }
          }
      }
        
    } catch (SQLException e) {
        e.printStackTrace();
    }

The redirect_uri parameter from the url returned is always set to the default value [127.0.0.1] instead of the callbackURL I send as a property to the JDBC.

prop.setProperty(“CallbackURL”, redirectUri);

How can this be fixed

Answer

This was the way to do it:

cstmt.setString("CallbackURL", redirectUri);


Source: stackoverflow