Mr.Boon Mr.Boon - 1 month ago 13
PHP Question

Decode JWT encoded string from Google in PHP

I am upgrading my Google based login system, which requires me to decode

strings supplied by Google. The strings are valid, and I can decode them via:

But I want my server to do this on the fly in PHP.

I found both: and

But I cannot figure out how to work with PEAR packages. Simple PHP scripts to copy to my server I can do, but I find the documentation given with these 2 packages very limited. 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? If so maybe the following PHP code (taken from can help you using the script from 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'];