简体   繁体   English

用PHP从Google解码JWT编码的字符串

[英]Decode JWT encoded string from Google in PHP

I am upgrading my Google based login system, which requires me to decode id_token strings supplied by Google. 我正在升级基于Google的登录系统,这需要我解码Google提供的id_token字符串。 The strings are valid, and I can decode them via: https://developers.google.com/wallet/digital/docs/jwtdecoder 字符串有效,我可以通过以下网址对其进行解码: https : //developers.google.com/wallet/digital/docs/jwtdecoder

But I want my server to do this on the fly in PHP. 但是我希望我的服务器在PHP中即时执行此操作。

I found both: https://github.com/firebase/php-jwt/tree/master and https://github.com/luciferous/jwt 我都找到了: https : //github.com/firebase/php-jwt/tree/masterhttps://github.com/luciferous/jwt

But I cannot figure out how to work with PEAR packages. 但是我不知道如何使用PEAR包。 Simple PHP scripts to copy to my server I can do, but I find the documentation given with these 2 packages very limited. 我可以将简单的PHP脚本复制到我的服务器上,但是我发现这2个软件包提供的文档非常有限。 Does anybody have sample code on how to decode such a string? 有人有示例代码说明如何解码这样的字符串吗?

Any help would be much appreciated. 任何帮助将非常感激。

If I understood you correctly, you're trying to decode JWT's with a PHP script? 如果我对您的理解正确,那么您正在尝试使用PHP脚本解码JWT吗? If so maybe the following PHP code (taken from https://developers.google.com/wallet/instant-buy/about-jwts#jwt_decoding ) can help you using the script from luciferous. 如果是这样,下面的PHP代码(取自https://developers.google.com/wallet/instant-buy/about-jwts#jwt_decoding )也许可以帮助您使用Luciferous的脚本。

$mwr = array(
  'iat' => $now,
  'exp' => $now + 3600,
  'typ' => 'google/wallet/online/masked/v2/request',
  'aud' => 'Google',
  'iss' => MERCHANT_ID,
  'request'=> array(
    'clientId' =>  CLIENT_ID,
    'merchantName'=> MERCHANT_NAME,
    'origin'=> ORIGIN,
     'pay'=> array (
       'estimatedTotalPrice'=> $estimated_total_price,
       'currencyCode'=> $input['currencyCode'],
      ),
      'ship'=> new stdClass(),
  ),
);
if (isset($input['googleTransactionId'])) {
  $mwr['request']['googleTransactionId'] = $input['googleTransactionId'];
}
WalletUtil::encode_send_jwt($mwr);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM