nebula
nebula

Reputation: 3972

Oauth Authorization issue while integrating web app with Quickbooks

I am trying to integrate my web app with QuickBooks I implemented Connect to QuickBooks button and the intuit also grants the permission to the application.

enter image description here

However, I get We encountered a problem processing your request issue. enter image description here

What might be the issue? I don't get any response in my call_back url too.

I used the code from Intuit Sample app.

public static String REQUEST_TOKEN_URL = "https://oauth.intuit.com/oauth/v1/get_request_token";
public static String ACCESS_TOKEN_URL = "https://oauth.intuit.com/oauth/v1/get_access_token";
public static String AUTHORIZE_URL = "https://appcenter.intuit.com/Connect/Begin";
public static String OAUTH_CONSUMER_KEY = "qyprdFHGmJjBj1jDH05Jen95Tu3PyW";
public static String OAUTH_CONSUMER_SECRET = "OMFkKCPRBQKrMoyaLg9mFYTM26kpJg8LPthbNzTB";
public static String OAUTH_CALLBACK_URL = "http://office.technology.com:8081/delegate/intuit/";

public Map<String, String> getRequestTokenSignPost() {

    String authURL = null;

    OAuthProvider provider = createProvider();

    String consumerkey = OAUTH_CONSUMER_KEY;
    String consumersecret = OAUTH_CONSUMER_SECRET;

    LOG.info("Inside getRequestToken, Consumer Key and Secret: " + consumerkey + " " + consumersecret);
    String callback_url = OAUTH_CALLBACK_URL;
    LOG.info("callback URL: " + callback_url);

    OAuthConsumer ouathconsumer = new DefaultOAuthConsumer(consumerkey, consumersecret);

    try {
        HttpParameters additionalParams = new HttpParameters();
        additionalParams.put("oauth_callback", URLEncoder.encode(callback_url, "UTF-8"));
        ouathconsumer.setAdditionalParameters(additionalParams);
    } catch (UnsupportedEncodingException e) {
        LOG.error(e.getLocalizedMessage());
    }

    String requestret = "";
    String requestToken = "";
    String requestTokenSecret = "";

    try {
        String signedRequestTokenUrl = ouathconsumer.sign(REQUEST_TOKEN_URL);
        LOG.info("signedRequestTokenUrl: " + signedRequestTokenUrl);

        URL url;

        url = new URL(signedRequestTokenUrl);

        HttpURLConnection httpconnection = (HttpURLConnection) url.openConnection();
        httpconnection.setRequestMethod("GET");
        httpconnection.setRequestProperty("Content-type", "application/xml");
        httpconnection.setRequestProperty("Content-Length", "0");
        if (httpconnection != null) {
            BufferedReader rd = new BufferedReader(new InputStreamReader(httpconnection.getInputStream()));
            StringBuffer sb = new StringBuffer();
            String line;
            while ((line = rd.readLine()) != null) {
                sb.append(line);

            }
            rd.close();
            requestret = sb.toString();
        }
        String[] requestTokenSections = requestret.split("&");

        for (int i = 0; i < requestTokenSections.length; i++) {
            String[] currentElements = requestTokenSections[i].split("=");

            if (currentElements[0].equalsIgnoreCase("oauth_token")) {
                requestToken = currentElements[1];
            } else if (currentElements[0].equalsIgnoreCase("oauth_token_secret")) {
                requestTokenSecret = currentElements[1];
            }
        }

        Map<String, String> requesttokenmap = new HashMap<String, String>();

        try {
            authURL = provider.retrieveRequestToken(ouathconsumer, callback_url);
        } catch (OAuthNotAuthorizedException e) {
            LOG.error(e.getLocalizedMessage());
        }
        ouathconsumer.setTokenWithSecret(ouathconsumer.getToken(), ouathconsumer.getTokenSecret());

        requesttokenmap.put("requestToken", requestToken);
        requesttokenmap.put("requestTokenSecret", requestTokenSecret);
        requesttokenmap.put("authURL", authURL);
        return requesttokenmap;

    } catch (OAuthMessageSignerException e) {
        LOG.error(e.getLocalizedMessage());
    } catch (OAuthExpectationFailedException e) {
        LOG.error(e.getLocalizedMessage());
    } catch (OAuthCommunicationException e) {
        LOG.error(e.getLocalizedMessage());
    } catch (MalformedURLException e) {
        LOG.error(e.getLocalizedMessage());
    } catch (IOException e) {
        LOG.error(e.getLocalizedMessage());
    }
    LOG.info("Error: Failed to get request token.");
    return null;

}

public static OAuthProvider createProvider() {
    OAuthProvider provider =
            new DefaultOAuthProvider(OauthHelper.REQUEST_TOKEN_URL, OauthHelper.ACCESS_TOKEN_URL, OauthHelper.AUTHORIZE_URL);

    return provider;
}

public String getAuthorizeURL(String requestToken, String requestTokenSecret) {

    String authorizeURL = "";
    try {
        authorizeURL = AUTHORIZE_URL + "?oauth_token=" + requestToken;
    } catch (Exception e) {
        LOG.error(e.getLocalizedMessage());
    }
    LOG.info("Authorize URL: " + authorizeURL);
    return authorizeURL;
}

I even get the Request token:

signedRequestTokenUrl: https://oauth.intuit.com/oauth/v1/get_request_token?oauth_signature=EHKmrR%2BV%2ByF4WRcBmpkdBeYEfuE%3D&oauth_callback=http%253Aoffice.technology.com%253A8081%252Fdelegate%252Fintuit&oauth_consumer_key=qyprdFHGaJjBj1jDH05Jen95Tu3PyW&oauth_version=1.0&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1390538706&oauth_nonce=-4612911034475731539
requestret: oauth_token_secret=XkXjGlS6bnFvOWYthCoew54W4ILcdMWQ3jaOMCQQ&oauth_callback_confirmed=true&oauth_token=qyprdRyUiXzU0QLLavn3L3TtdqvYts5CZyomkSk8miZDfB8Y

Upvotes: 1

Views: 1086

Answers (2)

joshleecreates
joshleecreates

Reputation: 85

I was able to fix the issue using an incognito window without any cookies for my quickbooks developer account.

Upvotes: 0

Keith Palmer Jr.
Keith Palmer Jr.

Reputation: 27952

This:

public static String OAUTH_CALLBACK_URL = "http:office.technology.com:8081/delegate/intuit/";

Is not a valid URL, and it needs to be. Fix your URL.

Upvotes: 2

Related Questions