为JWT Auth BigQuery API生成令牌

时间:2015-12-10 03:49:22

标签: php oauth-2.0 google-bigquery jwt google-oauth2

我阅读了Google OAuth2.0 for server to server application的文档,并尝试在线搜索,但找不到创建和续订OAuth2.0令牌的参考资料 Bigquery API 我尝试使用文档自行生成但仍然是徒劳的

请帮帮我

以下是我用来获取Json Web令牌的代码

<?php
    $header = '{"alg":"RS256","typ":"JWT"}';

    $header = base64_encode($header);

    $claims = '{"iss":"account-1@euphoric-quanta-114611.iam.gserviceaccount.com","scope":"https://www.googleapis.com/auth/cloud-platform.read-only https://www.googleapis.com/auth/bigquery https://www.googleapis.com/auth/cloud-platform","aud":"https://www.googleapis.com/oauth2/v4/token","exp":"'.(time()+3000).'","iat":"'.time().'"}';

    $claims = base64_encode($claims);

    $encodedContent = $header . "." . $claims;

    $signature = hash_hmac("SHA256",$encodedContent, '{my private key}');


    $signature = base64_encode($signature);

    $data = $header.".".$claims.".".$signature;

    echo $data;
?>

稍后我将帖子请求发送到https://www.googleapis.com/oauth2/v4/tokenassertion作为代码和grant_type=urn%3Aietf%3Aparams%3Aoauth%3Agrant-type%3Ajwt-bearer生成的值,我得到了以下回复

    {
      "error": "invalid_grant",
      "error_description": "Bad Request"
    }

我犯了什么错误,在哪里可以找到有关Big Query API的JWT身份验证令牌的完整文档

提前致谢...

0 个答案:

没有答案