【发布时间】:2021-06-27 21:31:28
【问题描述】:
我目前正在尝试生成一个签名以对在线快速手册进行 API 调用,但是我不断收到身份验证错误。我确定签名部分是我出错的地方。这是不正确的吗:
//method to generate signature
//$this->method = "GET"
//QBO_SANDBOX_URL = 'https://some_url.com/'
//$this->_query = 'something=something'
public function generate_signature()
{
$base = $this->_method.'&'.rawurlencode($this->_url.QBO_SANDBOX_URL.'v3/company/'.$this->_realm_id).'&'
.rawurlencode("oauth_consumer_key=".rawurlencode($this->_consumer_key).'&'
.'&oauth_nonce='.rawurlencode('34604g54654y456546')
.'&oauth_signature_method='.rawurlencode('HMAC-SHA1')
.'&oauth_timestamp='.rawurlencode(time())
.'&oauth_token='.rawurlencode($this->_auth_token)
.'&oauth_version='.rawurlencode('1.0')
.'&'.rawurlencode($this->_query));
$key = rawurlencode($this->_consumer_secret.'&'.$this->_token_secret);
$this->_signature = base64_encode(hash_hmac("sha1", $base, $key, true));
}
现在当我去发送我的请求时,这里是标题:
$this->_headers = array(
'Authorization: '.urlencode('OAuth oauth_token="'.$this->_auth_token.'",oauth_nonce="ea9ec8429b68d6b77cd5600adbbb0456",oauth_consumer_key="'.$this->_consumer_key.'",oauth_signature_method="HMAC-SHA1", oauth_timestamp="'.time().'", oauth_version ="1.0"oauth_signature="'.$this->_signature.'"').''
);
我收到 401 授权响应。我签错了吗?
编辑:此处未包含的所有字段(即$this->_auth_token)均已设置。
【问题讨论】:
-
我正在尝试做同样的事情并且我正在尝试使用此代码,您如何获得 App Token Secret?根据documentation,我需要签名才能检索App Token Secret,但是您正在使用它来生成签名
$this->_token_secret,有什么帮助吗? -
@Josh Whitlow:您的应用令牌应该由您尝试对其进行身份验证的任何服务提供给您。通常在某处的仪表板中。顺便说一句,上述代码的工作原理是双
&结束了$base变量声明的第二行。