我试图
使用从 API 控制台获取的私钥,使用 SHA256withRSA(也称为 RSASSA-PKCS1-V1_5-SIGN 和 SHA-256 哈希函数)对输入的 UTF-8 表示进行签名。输出将是一个字节数组。
所以让我们把 Header 和 Claim 设置成数组
{"alg":"RS256","typ":"JWT"}.
{
"iss":"761326798069-r5mljlln1rd4lrbhg75efgigp36m78j5@developer.gserviceaccount.com",
"scope":"https://www.googleapis.com/auth/prediction",
"aud":"https://accounts.google.com/o/oauth2/token",
"exp":1328554385,
"iat":1328550785
}
Run Code Online (Sandbox Code Playgroud)
JSON Web 签名 (JWS) 是指导为 JWT 生成签名的机制的规范。签名的输入是以下内容的字节数组:
{ Base64url 编码的标头}.{ Base64url 编码的声明集}
所以我构建数组只是为了测试
$seg0 = array(
"alg" => "RS256",
"typ" => "JWT"
);
$seg1 = array(
"iss" => "761326798069-r5mljlln1rd4lrbhg75efgigp36m78j5@developer.gserviceaccount.com",
"scope" => "https://www.googleapis.com/auth/prediction",
"aud" => "https://accounts.google.com/o/oauth2/token",
"exp" => 1328554385,
"iat" => 1328550785
);
$segs = array(
json_encode($seg0),
stripslashes(json_encode($seg1))
); …Run Code Online (Sandbox Code Playgroud)