By Gueu PACOME
Hello i have the following credential I would like to use them for authentification and fetch the token from header using PHP.
GRAND TYPE: client_redential (json) TOKEN URL: http://localhost/?access-token CLIENT ID: 5646545-4654651-45645465-554 CLIENT SECRET: 874561-565156-5646551
Can someone helps me ?
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
To receive an access token, the client POSTs an API call to Edge with the values for client ID and client secret obtained from a registered developer app. In addition, the parameter grant_type=client_credentials must be passed as a query parameter.
@pistle2020 Hello, thank you for your answer: The Body to send is a jSon format:
{
"grant_type": "client_credentials"
}
I use Insomnia to generate this PHP cURL Script Here is my PHP cURL script:
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://localhost/access-token",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "{\n\t\"grant_type\": \"client_credentials\"\n}",
CURLOPT_COOKIE => "dtCookie=v_4_srv_2_sn_6BC691EA47E4B3612884E99AB3D8EB3B_perc_100000_ol_0_mul_1",
CURLOPT_HTTPHEADER => [
"authorization: Bearer 55d4f5s5-dff4-56dsf54-dsdfsdf",
"content-type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
###########################
The result of this sccript is:
{
"message": "Invalid Authorization header"
}
But i can see in the Insomnia GUI the generates Token. My Problem is, how to get the token in variable a use it.
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.