Search code examples
phpwordpressquickbooksintuit-partner-platform

oAuth login to Quickbooks API


I'm having a problem using the untuit api for quickbooks im trying to build a plugin for Wordpress that allows users to call the API. however when i try to register im getting a strange error

define('OAUTH_CONSUMER_KEY', 'qyprdCeT1XrfB2naZuXXXXXXXXXX');
define('OAUTH_CONSUMER_SECRET', 'AItwjqmICEnr9nQNzkTc8nzC24tXXXXXXXXXXX');
define('OAUTH_REQUEST_URL', 'https://oauth.intuit.com/oauth/v1/get_request_token');
define('OAUTH_ACCESS_URL', 'https://oauth.intuit.com/oauth/v1/get_access_token');
define('OAUTH_AUTHORISE_URL', 'https://appcenter.intuit.com/Connect/Begin');
$schema = (@$_SERVER["HTTPS"] == "on") ? "https://" : "http://";
define('CALLBACK_URL', $schema.$_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"]);
$oauth = new OAuth( OAUTH_CONSUMER_KEY, OAUTH_CONSUMER_SECRET, OAUTH_SIG_METHOD_HMACSHA1, OAUTH_AUTH_TYPE_URI);
$oauth->enableDebug();
try {

    if(isset($_POST['posted']) && !isset($_GET['oauth_token'])){
        $request_token = $oauth->getRequestToken( OAUTH_REQUEST_URL, CALLBACK_URL );
        $_SESSION['secret'] = $request_token['oauth_token_secret'];
        $vl->redirectUri =  OAUTH_AUTHORISE_URL .'?oauth_token='.$request_token['oauth_token'];
    }

    if( isset($_GET['oauth_token']) && isset($_GET['oauth_verifier']) ){
        $oauth->setToken($_GET['oauth_token'], $_SESSION['secret']);
        $access_token = $oauth->getAccessToken( OAUTH_ACCESS_URL );

        $vl->debug = print_r($access_token, true);
    }
}
catch(OAuthException $e) {
    $vl->debug = print_r($e, true);
}

When i try this way i just get UPDATED complete log (this is on oAuth Connection running when it errors)

So now the only problem i am getting is that the signature is invalid. so this must be something from the URL still but oAuth PCEL class is handling this so i dont know where the Error could be.

OAuthException Object
(
    [message:protected] => Invalid auth/bad request (got a 401, expected HTTP/1.1 20X or a redirect)
    [string:Exception:private] => 
    [code:protected] => 401
    [file:protected] => /home/ebers/www/wordpress/offPeakTraining/wp-content/plugins/QuickBooks/qb.php
    [line:protected] => 71
    [trace:Exception:private] => Array
        (
            [0] => Array
                (
                    [file] => /home/ebers/www/wordpress/offPeakTraining/wp-content/plugins/QuickBooks/qb.php
                    [line] => 71
                    [function] => getAccessToken
                    [class] => OAuth
                    [type] => ->
                    [args] => Array
                        (
                            [0] => https://oauth.intuit.com/oauth/v1/get_access_token
                        )

                )

            [1] => Array
                (
                    [function] => qbwp_plugin_options
                    [args] => Array
                        (
                            [0] => 
                        )

                )

            [2] => Array
                (
                    [file] => /home/ebers/www/wordpress/offPeakTraining/wp-includes/plugin.php
                    [line] => 429
                    [function] => call_user_func_array
                    [args] => Array
                        (
                            [0] => qbwp_plugin_options
                            [1] => Array
                                (
                                    [0] => 
                                )

                        )

                )

            [3] => Array
                (
                    [file] => /home/ebers/www/wordpress/offPeakTraining/wp-admin/admin.php
                    [line] => 217
                    [function] => do_action
                    [args] => Array
                        (
                            [0] => settings_page_qbwpapi
                        )

                )

            [4] => Array
                (
                    [file] => /home/ebers/www/wordpress/offPeakTraining/wp-admin/options-general.php
                    [line] => 10
                    [args] => Array
                        (
                            [0] => /home/ebers/www/wordpress/offPeakTraining/wp-admin/admin.php
                        )

                    [function] => require_once
                )

        )

    [previous:Exception:private] => 
    [lastResponse] => oauth_problem=signature_invalid
    [debugInfo] => Array
        (
            [sbs] => GET&https%3A%2F%2Foauth.intuit.com%2Foauth%2Fv1%2Fget_access_token&oauth_consumer_key%3DqyprdCeT1XrfB2naZu0o7bKSFL3MyK%26oauth_nonce%3D12533744765415534dd89b43.77283483%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1410683725%26oauth_token%3Dqyprdn36hBYpc75UmnkItTyxGBVDu09NhWlO4COKnRyq03xY%26oauth_verifier%3D63vgjdf%26oauth_version%3D1.0
            [headers_recv] => HTTP/1.1 401 Unauthorized
Date: Sun, 14 Sep 2014 08:35:08 GMT
Server: Apache
WWW-Authenticate: OAuth oauth_problem="signature_invalid"
Cache-Control: no-cache, no-store
Pragma: no-cache
Content-Length: 31
Connection: close
Content-Type: text/plain
X-Pad: avoid browser bug
            [body_recv] => oauth_problem=signature_invalid
        )

    [xdebug_message] => 
OAuthException: Invalid auth/bad request (got a 401, expected HTTP/1.1 20X or a redirect) in /home/ebers/www/wordpress/offPeakTraining/wp-content/plugins/QuickBooks/qb.php on line 71

Call Stack:
    0.0009     828960   1. {main}() /home/ebers/www/wordpress/offPeakTraining/wp-admin/options-general.php:0
    0.0015     954840   2. require_once('/home/ebers/www/wordpress/offPeakTraining/wp-admin/admin.php') /home/ebers/www/wordpress/offPeakTraining/wp-admin/options-general.php:10
    0.4527   53686792   3. do_action() /home/ebers/www/wordpress/offPeakTraining/wp-admin/admin.php:217
    0.4527   53688976   4. call_user_func_array() /home/ebers/www/wordpress/offPeakTraining/wp-includes/plugin.php:429
    0.4527   53689032   5. qbwp_plugin_options() /home/ebers/www/wordpress/offPeakTraining/wp-includes/plugin.php:429
    0.4534   53693984   6. OAuth->getAccessToken() /home/ebers/www/wordpress/offPeakTraining/wp-content/plugins/QuickBooks/qb.php:71

)

Solution

  • So after hours and hours of working on this i worked out that Intuit are matching what Keith Palmer said.

    I could be wrong on this, but I think I remember hearing the callback URLs straight up can't have query strings in them. Are you sure you NEED a query string in your URL?

    Well this is wrong the oAuth Standards state that all parameters must be URL encoded however this means there is a problem with Intuit's oAuth server so nothing i can fix. so i have had to setup a page on wordpress is on the front end /wpoAuthLogin/ and tied a short code to the options function and it works perfectly without errors so this re-assures me that this is a problem on Intuit's oAuth Server.