I get my bearer token from an API end point and set the following:
$authorization = "Bearer 080042cad6356ad5dc0a720c18b53b8e53d4c274"
Next I want to use CURL to access the secure endpoint however I am unsure on how or where to set the Bearer token.
I have tried this but but it does not work:
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json' , $authorization ));
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS,$post);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
$result = curl_exec($ch);
curl_close($ch);
return json_decode($result);
EDIT:
According to the documentation, I am supposed to be using the bearer token as such: https://apigility.org/documentation/auth/authentication-oauth2
GET /oauth/resource HTTP/1.1
Accept: application/json
Authorization: Bearer 907c762e069589c2cd2a229cdae7b8778caa9f07
If you are working with a private token instead (like Gitlab API), you should replace:
$authorization = "Authorization: Bearer 080042cad6356ad5dc0a720c18b53b8e53d4c274"
with:
$authorization = "PRIVATE-TOKEN 080042cad6356ad5dc0a720c18b53b8e53d4c274";
This should works
This is a cURL function that can send or retrieve data. It should work with any PHP app that supports OAuth:
Use it within one-way or two-way requests:
Replace:
with:
to make it a valid and working Authorization header.