【发布时间】:2017-04-25 17:13:00
【问题描述】:
我已经安装了 firebase 推荐的用于 php 自定义令牌的包,可以在此处找到,https://firebase.google.com/docs/auth/admin/create-custom-tokens 可以在 使用第三方 JWT 库创建自定义令牌标题下找到。
我已经安装了 php-jwt 建议。 然后,我创建了一个找到 here 的服务帐户,并在 /apis/credentials 中获得了与下载类似的详细信息。
"private_key": "-----BEGIN PRIVATE KEY-----veryLongKey---END PRIVATE KEY-----\n",
"client_email": "randomemail@appspot.gserviceaccount.com",
然后我使用顶部链接所示的格式生成令牌。
但是,当我将 $theCreatedToken 放入此卷曲时 ....
$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);
我收到此错误 { "error": "应为 ID 令牌,但获得了自定义令牌。" }
如果我删除 ?auth=' .$theCreatedToken; 它可以工作。
我究竟做错了什么?我对此进行了广泛的搜索,但没有答案。
我希望有人能够提供帮助。
最好的
【问题讨论】:
-
我遵循了这个解决方案,但它也不起作用,同样的错误。 link
-
你是如何获得 $theCreatedToken 的?
-
$theCreatedToken 从 JWT 库返回。
标签: php curl firebase jwt firebase-authentication