我正在使用pecl oAuth库,是否可以构建一个符合身体的签名oauth请求:
POST http://www.imsglobal.org/developers/BLTI/service_handle.php HTTP/1.0
Host: 127.0.0.1:80
Content-Length: 757
Authorization: OAuth realm="",oauth_version="1.0",
oauth_nonce="29f90c047a44b2ece73d00a09364d49b",
oauth_timestamp="1313350943",oauth_consumer_key="lmsng.school.edu",
oauth_body_hash="v%2BxFnmDSHV%2Fj29qhxLwkFILrtPo%3D",
oauth_signature_method="HMAC-SHA1",
oauth_signature="8auRpRdPY2KRXUrOyz3HKCs92y8%3D"
Content-type: application/xml
<?xml version = "1.0" encoding = "UTF-8"?>
... more xml data ...
我正在尝试使用IMS Global LTI标准接口与Instructure的Canvas LMS进行通信。 Outcomes Service可让您使用oauth signed xml messages
将分数发送回LMS答案 0 :(得分:3)
事实证明,pecl oAuth目前不支持oaut_body_hash。
我最终使用了来自这个谷歌代码库http://code.google.com/p/oauth/的oAuth库并计算了我自己的身体:
$bodyHash = base64_encode(sha1($body, TRUE)); // build oauth_body_hash
$consumer = new \OAuthConsumer($key, $secret);
$request = \OAuthRequest::from_consumer_and_token($consumer, '', 'POST', $endpoint, array('oauth_body_hash' => $bodyHash) );
$request->sign_request(new \OAuthSignatureMethod_HMAC_SHA1(), $consumer, '');
$header = $request->to_header() . "\r\nContent-Type: application/xml\r\n"; // add content type header
答案 1 :(得分:1)
标准OAuth::generateSignature
函数允许额外的参数作为第三个参数。这可以用来传递自定义主体哈希参数:
$oauth = new OAuth($credentials["oauthKey"], $credentials["oauthSecret"]);
$timestamp = time();
$oauth->setTimestamp($timestamp);
$nonce = mt_rand();
$oauth->setNonce($nonce);
$bodyHash = base64_encode(sha1($content, true)); // $content contains the body
$sig = $oauth->generateSignature('GET', $url, Array("oauth_body_hash" => $bodyHash));
然后我们可以使用它来构建我们的OAuth标头:
$header = array
(
'Content-Type: application/xml'
);
$header[] = 'Authorization: OAuth '.
'oauth_version="1.0",'.
'oauth_nonce="'.$nonce.'",'.
'oauth_timestamp="'.$timestamp.'",'.
'oauth_body_hash="'.$bodyHash.'",'.
'oauth_consumer_key="'.$credentials["oauthKey"].'",'.
'oauth_signature_method="HMAC-SHA1",'.
'oauth_signature="'.urlencode($sig).'"';