Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Google Play Games Service #6147

Merged
merged 4 commits into from
Oct 28, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions spec/AuthenticationAdapters.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const defaultColumns = require('../lib/Controllers/SchemaController')
const authenticationLoader = require('../lib/Adapters/Auth');
const path = require('path');
const responses = {
gpgames: { playerId: 'userId' },
instagram: { data: { id: 'userId' } },
janrainengage: { stat: 'ok', profile: { identifier: 'userId' } },
janraincapture: { stat: 'ok', result: 'userId' },
Expand All @@ -22,6 +23,7 @@ describe('AuthenticationProviders', function() {
[
'apple',
'gcenter',
'gpgames',
'facebook',
'facebookaccountkit',
'github',
Expand Down
5 changes: 4 additions & 1 deletion src/Adapters/Auth/gcenter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
33 changes: 33 additions & 0 deletions src/Adapters/Auth/gpgames.js
Original file line number Diff line number Diff line change
@@ -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,
};
2 changes: 2 additions & 0 deletions src/Adapters/Auth/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -35,6 +36,7 @@ const anonymous = {
const providers = {
apple,
gcenter,
gpgames,
facebook,
facebookaccountkit,
instagram,
Expand Down