由于签名错误而无法生成令牌

时间:2018-08-02 10:07:51

标签: api oauth oauth-2.0 openx apiconnect

$base_url = "https://sso.openx.com/api/index/initiate";
$service_url = "https://sso.openx.com/api/index/initiate";

// $tie = time();
$time = time();
$signature_method= "HMAC-SHA1";
$oauth_version = "1.0";
$nonce = time();
$realm = "maxflow";
$consumer_key  = "MY SECRET KEY";
$consumer_secret  = "MY SECRET ";
$sig_base = "POST&" . rawurlencode($base_url) . "&"
    . rawurlencode("oauth_consumer_key=" . rawurlencode($consumer_key)
    . "&oauth_nonce=" . rawurlencode($nonce)
    . "&oauth_signature_method=" . rawurlencode($signature_method)
    . "&oauth_timestamp=" . $time
    . "&oauth_version=" . $oauth_version);


$signature = base64_encode(hash_hmac("sha1", $sig_base, $consumer_secret. "&" , true ));
$signature2 = base64_encode(hash_hmac("sha1","",rawurlencode($consumer_secret."&"),true));

$curl = curl_init($service_url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-Type" => "application/x-www-form-urlencoded"));
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS,  array(
    "oauth_realm" => $realm,
    "oauth_consumer_key"=>$consumer_key,
    "oauth_signature_method"=>$signature_method,
    "oauth_signature"=>$signature,
    "oauth_timestamp"=>$time,
    "oauth_nonce"=>$nonce,  
    "oauth_version"=>'1.0',
    "oauth_callback"=>"oob"
));
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
$curl_response = curl_exec($curl);
print_r($curl_response);
$tokenArray=json_decode($curl_response, true);
print_r($tokenArray);
$error = curl_error($curl);
print_r($error);

我正在尝试生成令牌,但无法生成令牌。我正在尝试从OpenX建立API连接,并且总是给我错误:

Invalid Request: Wrong Signature 

我正在使用基于浏览器的身份验证。这是链接:https://docs.openx.com/Content/developers/platform_api/api_auth_browser_based.html

0 个答案:

没有答案