Php oAuth登录到Quickbooks API
我在使用quickbooks的untuit api时遇到问题,我正在尝试为Wordpress构建一个插件,允许用户调用api。然而,当我试图注册时,我得到了一个奇怪的错误Php oAuth登录到Quickbooks API,php,wordpress,quickbooks,intuit-partner-platform,intuit,Php,Wordpress,Quickbooks,Intuit Partner Platform,Intuit,我在使用quickbooks的untuit api时遇到问题,我正在尝试为Wordpress构建一个插件,允许用户调用api。然而,当我试图注册时,我得到了一个奇怪的错误 define('OAUTH_CONSUMER_KEY', 'qyprdCeT1XrfB2naZuXXXXXXXXXX'); define('OAUTH_CONSUMER_SECRET', 'AItwjqmICEnr9nQNzkTc8nzC24tXXXXXXXXXXX'); define('OAUTH_REQUEST_URL',
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连接出错时,这是在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
)
您发送给Intuit的OAuth签名无效:
HTTP/1.1 401 Unauthorized
WWW-Authenticate: OAuth oauth_problem="signature_invalid"
如果看不到有关此代码的详细信息/您发送的HTTP请求的详细信息,很难说清楚原因
您是否考虑过使用已经为您完成所有这些艰苦工作的现有库之一?e、 g
http%253A%252F%252fBouth.local%252Fget_access_token.php因此,经过数小时的研究,我发现Intuit符合Keith Palmer所说的 我可能错了,但我想我记得听到过电话回电 URL不能直接包含查询字符串。你确定你 在URL中需要查询字符串吗
这是错误的,oAuth标准规定所有参数必须是URL编码的,但是这意味着Intuit的oAuth服务器存在问题,因此我无法修复任何问题。因此,我不得不在wordpress的前端/wpoAuthLogin/上设置一个页面,并将一个短代码绑定到选项函数,它可以完美地工作,没有错误,因此这再次向我保证,这是Intuit的oAuth服务器上的一个问题。我使用他们的库只是不用于登录oAuth部分。由于there path使用oAuth.php,我不能使用这样的文件位置,因为它是管理端wordpress插件的一部分。oAuth系统由pecl oAuth处理,问题恰恰在于发送一个url并在其末尾添加一个查询。如果我对地址进行URL编码,这样就不会破坏查询字符串,在试图重定向回我的页面时,它会破坏。我使用的代码很好,当我将其全部放入一个短代码中时,我知道他的代码可以工作。这似乎是
?
的一个问题,特别是为什么链接到代码的链接不适合您?您对它有什么错误消息/具体问题?问题是,当我传递使用查询字符串的回调url时,它可能由于以下原因而破坏签名?在地址中,但如果我对其进行URL编码,oAuth远程站点将在重定向回我的网站时生成500错误。