簡體   English   中英

PHP中的oauth2-在curl中指定

[英]oauth2 in php - specified in curl

我正在嘗試實現此處指定的身份驗證: https : //api.thermosmart.com/apidoc/我完成了第一步,並獲取了授權碼。 我需要將其交換為acces_token。 curl中的步驟指定為:#4. Exchange訪問令牌的授權代碼(從上一個響應中讀取代碼)curl -k -u client123:client-secret -b cookie.txt -vd“ grant_type = authorization_code&code = HPOfdlCbiZ1tI4Lv&redirect_uri = ...“”令牌網址“

我在PHP中的代碼:

$curl = curl_init( 'url for token' );

curl_setopt( $curl, CURLOPT_POST, TRUE );
curl_setopt($curl, CURLOPT_COOKIEJAR, "cookie.txt");
$userpwd = $oauth2_client_id.":".$oauth2_secret; 
curl_setopt($curl, CURLOPT_USERPWD, $userpwd); 
curl_setopt( $curl, CURLOPT_POSTFIELDS, array(
    'redirect_uri' => $oauth2_redirect,
    'code' => $code, // The code from the previous request
    'grant_type' => 'authorization_code'
) ); 
curl_setopt( $curl, CURLOPT_RETURNTRANSFER, 1);
$auth = curl_exec( $curl );
}
$secret = json_decode($auth);
$access_key = $secret->access_token;

echo "OAuth2 server provided access token: " . $access_key; 

任何幫助,將不勝感激。

一直在為相同的問題而苦惱(對於Qt Quick應用程序,但也許可以為您提供幫助)...(尋求幫助導致ThermoSmart的快速響應...

我的代碼用於將訪問令牌交換為授權代碼:

req.open("POST", "https://api.thermosmart.com/oauth2/token", true, client_id, client_secret); req.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); req.send("grant_type=authorization_code"+"&code="+ authorization_code + "&redirect_uri=" + redirect_uri);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM