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.