【发布时间】:2016-03-21 15:38:06
【问题描述】:
根据implementation guide和常识,我想验证发给通过Google身份工具包登录我网站的用户的JWT令牌,以防止伪造和..以防万一。
通过 cURL(下面的代码)到 https://www.googleapis.com/identitytoolkit/v3/relyingparty/getAccountInfo 的 POST 请求包含 idToken(字符串)、localId(列表)和电子邮件(列表)就足够了。我的应用程序使用 IDSP 发出的 tokenId 作为本地 ID。
然而,这就是我得到的:
Error: call to URL https://www.googleapis.com/identitytoolkit/v3/relyingparty/getAccountInfo?key=MyAPIKey failed with status 500, response { "error": { "code": 500, "message": null } } , curl_error , curl_errno 0
坦率地说,我完全不知所措:我的 Google-fu 只是退出并重新登录,但不出所料,它并没有解决问题。
更令人担忧的是,必须通过同一个依赖方获取用户显示名称和图像。
代码
function verifytoken($data){
$url = "https://www.googleapis.com/identitytoolkit/v3/relyingparty/getAccountInfo?key=MyAPIKey";
var_dump($data);
$content = json_encode($data);
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER,
array("Content-type: application/json"));
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $content);
$json_response = curl_exec($curl);
$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
if ( $status != 201 ) {
die("Error: call to URL $url failed with status $status, response $json_response, curl_error " . curl_error($curl) . ", curl_errno " . curl_errno($curl));
}
curl_close($curl);
$response = json_decode($json_response, true);
var_dump($response);
}
$tok=array('idToken'=>$gitkitUser->getUserId(),'localId'=>array($gitkitUser->getUserId()),'email'=>array($gitkitUser->getEmail()));
verifytoken($tok);
【问题讨论】:
-
顺便说一句,我确实尝试将数据发送为不是数组,而是简单的字符串,但它没有改变任何事情。
标签: php curl jwt google-identity-toolkit