2014-09-12 75 views
0

我有一個問題,使用快速入門的untuit API即時通訊嘗試構建一個允許用戶調用API的Wordpress插件。然而,當我嘗試註冊即時得到一個奇怪的錯誤oAuth登錄到Quickbooks API

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); 
} 

當我嘗試這樣我只是得到修訂完整的日誌(這是OAuth的連接運行時錯誤)

所以現在我得到的唯一問題是簽名無效。所以這一定是來自URL的東西,但oAuth PCEL類正在處理這個,所以我不知道錯誤在哪裏。

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 

) 

回答

0

因此,經過幾小時和幾小時的工作,我發現Intuit與Keith Palmer所說的一致。

我可能是錯的,但我想我記得聽到回調 網址直上不能有查詢字符串在其中。你確定你的網址需要查詢字符串嗎?

這是錯誤的oAuth標準狀態,所有參數必須是URL編碼,但這意味着有一個Intuit的oAuth服務器的問題,所以沒有我可以修復。所以我不得不在wordpress上設置一個頁面是在前端/ wpoAuthLogin /並將一個簡短代碼綁定到選項功能,並且它完美無誤地工作,因此這再次向我保證這是Intuit的oAuth服務器上的一個問題。

0

,你要發送到Intuit的OAuth的簽名是無效的:

HTTP/1.1 401 Unauthorized 
WWW-Authenticate: OAuth oauth_problem="signature_invalid" 

這很難說清楚,爲什麼沒有看到什麼這個代碼看起來像/什麼的HTTP請求你更多的細節」重新發送看起來像。

您是否考慮過使用已經爲您完成所有這些辛苦工作的已經存在的庫之一?例如

具體如下這個快速啓動:

並使用此代碼?

+0

我正在使用他們的庫,而不是用於登錄oAuth部分。因爲那裏的路徑使用oAuth.php我不能使用這樣的文件位置,因爲它是管理端的一個wordpress插件的一部分 – 2014-09-14 08:13:04

+0

oAuth系統由pecl oAuth處理,問題恰恰在於發送帶有query_stirng的url它的結束。如果我urlencode的地址,以便不打破查詢字符串,它試圖重定向回到我的頁面。 – 2014-09-14 08:23:12

+0

我使用http://runnable.com/UtEZ4OpSEoFzAACs/quickbooks-oauth-%2B-list-customers-example-for-php-intuit-intuit-partner-platform-and-ipp此代碼工作正常,當我放棄這一切都成爲一個簡碼,所以我知道他的代碼工作。它似乎只是''' – 2014-09-15 12:27:07

0

請注意,oauth_callback應該是爲了創建簽名基本字符串編碼兩個時間百分比。

例如:oauth_callback = 「HTTP://boauth.local/get_access_token.php」

這是我加入到簽名的基串串:

HTTP%253A%252F%252Fboauth.local %252Fget_access_token.php

+0

我不建立這個PCEL oAuth類建立這個... – 2014-09-14 08:19:56