Google PlayIntegrity API - validate token via PHP

510 views Asked by At

I am no professional Android developer and I'm having problems to get the Google PlayIntegrity token from my app to decode via PHP through my back-end server and couldn't find much help online.

I included the Google PHP API onto my server, integrated the API into my app and activated&linked it on the Play Console. But it seems I am doing something wrong, I am getting the following PHP error messages:

Warning: Attempt to read property "appLicensingVerdict" on null

My code:

<?php
namespace foo;

use Google\Client;
use Google\Service\PlayIntegrity;
use Google\Service\PlayIntegrity\DecodeIntegrityTokenRequest;

require_once __DIR__ . '/google/vendor/autoload.php';

// Google Integrity token, as obtained from Google through my app:
$token = $_POST['IntegrityToken'];

$client = new Client();
$client->setAuthConfig('google/credentials.json');

$client->addScope(PlayIntegrity::PLAYINTEGRITY);
$service = new PlayIntegrity($client);
$tokenRequest = new DecodeIntegrityTokenRequest();
$tokenRequest->setIntegrityToken($token);
$result = $service->v1->decodeIntegrityToken('com.myapp.game', $tokenRequest);

// Read and handle the JSON response:
        
$appLicensingVerdict = $result->accountDetails->appLicensingVerdict;
// ... more fields are available in the JSON... see Google documentation

// Check/verify the obtained response values.....

?>

Any help would be much appreciated! Many thanks!

1

There are 1 answers

0
lukey2000 On BEST ANSWER

Also thanks to hakre's help, I was able to solve the problems I was facing. The code works fine with tokenPayLoadExternal included:

$appLicensingVerdict = $result->tokenPayloadExternal # <-- this
                              ->accountDetails
                              ->appLicensingVerdict
    ;