Support Google Play Games Service (#6147)

* Support Google Play Games Service

* clean up

* improve coverage

* more tests
This commit is contained in:
Diamond Lewis
2019-10-28 13:16:55 -05:00
committed by GitHub
parent 355663cc98
commit b44726987d
4 changed files with 72 additions and 1 deletions

View File

@@ -107,7 +107,10 @@ function verifySignature(publicKey, authData) {
// Returns a promise that fulfills if this user id is valid.
async function validateAuthData(authData) {
if (!authData.id) {
return Promise.reject('Apple Game Center - authData id missing');
throw new Parse.Error(
Parse.Error.OBJECT_NOT_FOUND,
'Apple Game Center - authData id missing'
);
}
authData.playerId = authData.id;
const publicKey = await getAppleCertificate(authData.publicKeyUrl);

View File

@@ -0,0 +1,33 @@
/* Google Play Game Services
https://developers.google.com/games/services/web/api/players/get
const authData = {
id: 'playerId',
access_token: 'token',
};
*/
const { Parse } = require('parse/node');
const httpsRequest = require('./httpsRequest');
// Returns a promise that fulfills if this user id is valid.
async function validateAuthData(authData) {
const response = await httpsRequest.get(
`https://www.googleapis.com/games/v1/players/${authData.id}?access_token=${authData.access_token}`
);
if (!(response && response.playerId === authData.id)) {
throw new Parse.Error(
Parse.Error.OBJECT_NOT_FOUND,
'Google Play Games Services - authData is invalid for this user.'
);
}
}
// Returns a promise that fulfills if this app id is valid.
function validateAppId() {
return Promise.resolve();
}
module.exports = {
validateAppId,
validateAuthData,
};

View File

@@ -2,6 +2,7 @@ import loadAdapter from '../AdapterLoader';
const apple = require('./apple');
const gcenter = require('./gcenter');
const gpgames = require('./gpgames');
const facebook = require('./facebook');
const facebookaccountkit = require('./facebookaccountkit');
const instagram = require('./instagram');
@@ -35,6 +36,7 @@ const anonymous = {
const providers = {
apple,
gcenter,
gpgames,
facebook,
facebookaccountkit,
instagram,