【问题标题】:Google identity toolkit: JWT verification fails with status 500, "message": nullGoogle 身份工具包:JWT 验证失败,状态为 500,“消息”:null
【发布时间】: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


【解决方案1】:

要验证 Google Identity Toolkit JWT 令牌,您无需发出任何 HTTP 请求。建议使用Google Identity Toolkit libraries (Java/Python/Php/Ruby/Go/Nodejs) 之一在本地执行此操作。令牌已包含用户的电子邮件/姓名/照片网址。

【讨论】:

    猜你喜欢
    • 2020-08-17
    • 1970-01-01
    • 2012-08-15
    • 2022-08-16
    • 2019-08-13
    • 1970-01-01
    • 2015-05-13
    • 2017-05-05
    • 2019-03-18
    相关资源
    最近更新 更多