0
我在OA授權方面遇到問題,我有一個Flash Player應用程序請求PHP腳本。 的PHP總是返回:OAuth無效簽名
{"status":false,"message":"Invalid Signature"}
我嘗試了兩種型動物庫:
https://github.com/yahoo/yos-social-as3
https://github.com/iotashan/oauth-as3
我不知道該怎麼做努力了,可能有人幫助我?
所產生錯誤的URL AS3的腳本:
import com.yahoo.oauth.OAuthRequest;
import com.yahoo.oauth.OAuthConsumer;
import com.yahoo.oauth.OAuthSignatureMethod_HMAC_SHA1;
import com.yahoo.oauth.IOAuthSignatureMethod;
import com.yahoo.oauth.OAuthToken;
import com.yahoo.oauth.OAuthUtil;
var signature:IOAuthSignatureMethod = new OAuthSignatureMethod_HMAC_SHA1();
var consumer:OAuthConsumer = new OAuthConsumer("myKey", "mySecret");
var oauthRequest:OAuthRequest =
new OAuthRequest(
"GET",
"http://mySite.com/index.php",
null,
consumer,
null
);
var request:URLRequest = new URLRequest(oauthRequest.buildRequest(signature));
var loader:URLLoader = new URLLoader;
loader.addEventListener(Event.COMPLETE, getComplete);
loader.load(request);
function getComplete(event:Event):void
{
trace("data", URLLoader(event.currentTarget).data);
}
我有一個例子是產生一個正確的URL的PHP腳本做:
<?php
// include oath
require_once('OAuth/OAuth.php');
if ($mode == 'generate')
{
$consumer = new OAuthConsumer(OAUTHKEY, OAUTHSECRET);
$sig_method = new OAuthSignatureMethod_HMAC_SHA1;
// call this file
$api_endpoint = $_GET['url'];
//use oauth lib to sign request
$req = OAuthRequest::from_consumer_and_token($consumer, null, 'GET', $api_endpoint, $parameters);
$sig_method = new OAuthSignatureMethod_HMAC_SHA1();
$req->sign_request($sig_method, $consumer, null); //note: double entry of token
echo $req->to_url();
exit;
}
這是由PHP生成的URL腳本,這項工作:
http://mySite.com/index.php?
oauth_consumer_key=myKey&
oauth_nonce=20de438daf761115018b3d6f26456a6e&
oauth_signature=JpWrfU77Pl%2FfFoa%2BhVy8agq9I5Q%3D&
oauth_signature_method=HMAC-SHA1&
oauth_timestamp=1347583047&
oauth_version=1.0
這是由AS3腳本生成的url,這不工作:
http://mySite.com/index.php?
oauth_consumer_key=myKey&
oauth_nonce=b8808c76e9aaa264964aefabb22bdc55&
oauth_signature=jZ31R4C0Ybj1dluIjy6wKCtN7D4%3D&
oauth_signature_method=HMAC-SHA1&
oauth_timestamp=1348705359&
oauth_version=1.0
GitHub使用不需要簽名的oAuth v2。 – PeeHaa
如果您有興趣,我爲GitHub工作的PHP創建了[oAuth lib](https://github.com/PeeHaa/PHPoAuthLib)。 – PeeHaa
謝謝PeeHaa,我會建議團隊執行一個v2。同時我會嘗試找到一個v1 lib。謝謝! –