Use Node library for Google token validation

After lots of tries, the PHP code just couldn't be made to work...
This commit is contained in:
Guangcong Luo
2017-11-17 20:21:24 -05:00
parent 090b3b67e2
commit 2dc0f28e78
3 changed files with 32 additions and 11 deletions

View File

@@ -203,15 +203,9 @@ class NTBBSession {
}
if (substr(@$user['email'], -1) === '@') {
// Timezone determined to work at 7:30 PM CDT
// Timezones known to fail at various times: America/Chicago, America/New_York
date_default_timezone_set('UTC');
require_once dirname(__FILE__).'/../vendor/autoload.php';
$client = new Google_Client(['client_id' => $psconfig['gapi_clientid']]);
$payload = '';
try {
$payload = $client->verifyIdToken($pass);
} catch (Firebase\JWT\SignatureInvalidException $e) {}
// Forgive me, gods, for I have hardcoded way more than I really should have
$valResult = shell_exec("cd /var/www/html/play.pokemonshowdown.com && node lib/validate-token.js \"$pass\"");
$payload = json_decode($valResult, true);
if (!$payload) return false;
if (strpos($payload['aud'], $psconfig['gapi_clientid']) === false) return false;
if ($payload['email'] === substr($user['email'], 0, -1)) {