From 9d836ee87b3553c788fe163d378842badae80f0c Mon Sep 17 00:00:00 2001 From: Kevin Kuang Date: Wed, 14 Oct 2020 23:17:10 -0400 Subject: [PATCH] Use an empty object as default value of options for Google Sign in (#6844) * Use an empty object as default value of options for Google Sign in * add test case * Update test case to specifically for google auth --- spec/index.spec.js | 23 +++++++++++++++++++++++ src/Adapters/Auth/google.js | 2 +- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/spec/index.spec.js b/spec/index.spec.js index 8d02e372..f0f4e9e2 100644 --- a/spec/index.spec.js +++ b/spec/index.spec.js @@ -531,4 +531,27 @@ describe('server', () => { }) .catch(done.fail); }); + + it('should not fail when Google signin is introduced without the optional clientId', done => { + const jwt = require('jsonwebtoken'); + + reconfigureServer({ + auth: { google: {} } + }) + .then(() => { + const fakeClaim = { + iss: 'https://accounts.google.com', + aud: 'secret', + exp: Date.now(), + sub: 'the_user_id', + }; + const fakeDecodedToken = { header: { kid: '123', alg: 'RS256' } }; + spyOn(jwt, 'decode').and.callFake(() => fakeDecodedToken); + spyOn(jwt, 'verify').and.callFake(() => fakeClaim); + const user = new Parse.User(); + user.linkWith('google', { authData: { id: 'the_user_id', id_token: 'the_token' }}) + .then(done); + }) + .catch(done.fail); + }); }); diff --git a/src/Adapters/Auth/google.js b/src/Adapters/Auth/google.js index 0a8d67b8..75671e2c 100644 --- a/src/Adapters/Auth/google.js +++ b/src/Adapters/Auth/google.js @@ -113,7 +113,7 @@ async function verifyIdToken({ id_token: token, id }, { clientId }) { } // Returns a promise that fulfills if this user id is valid. -function validateAuthData(authData, options) { +function validateAuthData(authData, options = {}) { return verifyIdToken(authData, options); }