duanbu9345 2019-02-27 02:19
浏览 79

如何使用php验证服务器中的访问令牌

I want to pass access token with curl to request download the file on server. How should I validate the access token(if access token is valid, return file. If access token is invalid, return access denied.) in server. I have one php file(download_file_from_server.php) in local and one php file(getRequest.php) in server. (getRequest.php) is use to receive the request from local and validate the access token and return response.

I am using FileZilla to connect my ftp server and using OAuth 2.0 to generate the bearer access token.

Below is the curl code:

function getZipFile($remoteData,$token){
//$token = "33a6d06d42ebfc629f3dbe8746a5cfb60c00f290";
/*$remoteData = array(
        'fileData' => $local_version_name
        //"username" => "bwuser@brightwin.com",
        //"password" => "mVYdueeEVgan",
        //"client_id" => "LIVE",
        //"client_secret" => "liveUpdate",
        //"grant_type" => "password"
    );*/

$curl = curl_init('http://company.com/companyuser/getRequest.php');

$authorization = "Authorization: Bearer ".$token; // Prepare the authorisation token
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded' , $authorization )); // Inject the token into the header
curl_setopt($curl, CURLOPT_TIMEOUT, 30);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $remoteData);
$response = curl_exec($curl);
if(!$response) {
 echo "Error :- ".curl_error($curl)."<br>";
}
curl_close($curl);
echo $response."<br/>";// set response to server.php file 
}

Expected output:

validate token successful/failure and return response to local.

Thank for those who reply me.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
    • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
    • ¥15 cmd cl 0x000007b
    • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
    • ¥500 火焰左右视图、视差(基于双目相机)
    • ¥100 set_link_state
    • ¥15 虚幻5 UE美术毛发渲染
    • ¥15 CVRP 图论 物流运输优化
    • ¥15 Tableau online 嵌入ppt失败
    • ¥100 支付宝网页转账系统不识别账号