I have installed the package recommended by firebase for php custom tokens which can be found here, https://firebase.google.com/docs/auth/admin/create-custom-tokens found under the heading Create custom tokens using the third-party JWT library.
I have installed the php-jwt advised. I then created a service account found here and in the /apis/credentials I get similar details as below which I downloaded.
"private_key": "-----BEGIN PRIVATE KEY-----veryLongKey---END PRIVATE KEY-----\n",
"client_email": "randomemail@appspot.gserviceaccount.com",
I then generate a token using the format illustrated by the link at the top.
However when I put that $theCreatedToken
in this curl ....
$url = 'https://localhost-42d67.firebaseio.com/Devices.json?auth=' .$theCreatedToken;
$arr = array("success" =>array("iPhone"=>500));
$data_string = json_encode($arr);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PATCH");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data_string))
);
echo $result = curl_exec($ch);
I get this error { "error": "Expected an ID token, but was given a custom token." }
If I remove the ?auth=' .$theCreatedToken;
it works.
What am I doing wrong? I have searched this extensively but there is no answer.
I hope someone is able to help.
Best