Support Google login

This doesn't support setting accounts up for Google login: that still
has to be manually done via the database by setting the email field to
`username@gmail.com@`, where the second `@` denotes that it's using
Gmail login.

If the email field does end in `@`, `getassertion` will note this by
sending `;;@gmail`, to convey that the server is expecting a Google
login token rather than a password.

Upon receiving `;;@gmail`, the client will replace the password box will
with a Google login button, and then send the resulting Google login
token to the server in the `password` field. The server will validate
the "password" using the Google server libraries, and otherwise handle
the login as normal.

Note that Google login requires various features that a paranoid person
might disable; most notably 3rd-party cookies.

Fixes Zarel/Pokemon-Showdown#3394
This commit is contained in:
Guangcong Luo
2017-09-06 02:25:23 -04:00
parent 92f81037ca
commit 248f4a0887
7 changed files with 766 additions and 6 deletions

View File

@@ -179,7 +179,7 @@ class NTBBSession {
}
private function passwordVerifyInner($userid, $pass, $user) {
global $psdb;
global $psdb, $psconfig;
// throttle
$ip = $this->getIp();
@@ -202,6 +202,18 @@ class NTBBSession {
}
}
if (substr(@$user['email'], -1) === '@') {
require_once dirname(__FILE__).'/../vendor/autoload.php';
$client = new Google_Client(['client_id' => $psconfig['gapi_clientid']]);
$payload = $client->verifyIdToken($pass);
if (!$payload) return false;
if (strpos($payload['aud'], $psconfig['gapi_clientid']) === false) return false;
if ($payload['email'] === substr($user['email'], 0, -1)) {
return true;
}
return false;
}
$rehash = false;
if ($user['passwordhash']) {
// new password hashes
@@ -489,6 +501,7 @@ class NTBBSession {
if ($row['password'] && $row['nonce']) {
return ';;Your username is no longer available.';
}
if (substr($row['email'], -1) === '@') return ';;@gmail';
return ';';
} else {
// Unregistered username.