Skip to content

Commit 597b854

Browse files
oretteflovilmart
authored andcommitted
Use the correct function when validating google auth tokens (parse-community#5018)
* Use the correct function when validating google auth tokens httpsRequest.request expects the param postData and has no default value or validation to check if it is missing before using it. As a result, an error `TypeError: First argument must be a string or Buffer` is thrown when an attempt is made to authenticate with Google. A quick check on the LinkedIn, FB, and twitter authentication adapters shows they are using httpsRequest.get for their validation calls. * Correct google auth adapter tests
1 parent 768c28e commit 597b854

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

spec/AuthenticationAdapters.spec.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -430,35 +430,35 @@ describe('google auth adapter', () => {
430430
const httpsRequest = require('../lib/Adapters/Auth/httpsRequest');
431431

432432
it('should use id_token for validation is passed', async () => {
433-
spyOn(httpsRequest, 'request').and.callFake(() => {
433+
spyOn(httpsRequest, 'get').and.callFake(() => {
434434
return Promise.resolve({ sub: 'userId' });
435435
});
436436
await google.validateAuthData({ id: 'userId', id_token: 'the_token' }, {});
437437
});
438438

439439
it('should use id_token for validation is passed and responds with user_id', async () => {
440-
spyOn(httpsRequest, 'request').and.callFake(() => {
440+
spyOn(httpsRequest, 'get').and.callFake(() => {
441441
return Promise.resolve({ user_id: 'userId' });
442442
});
443443
await google.validateAuthData({ id: 'userId', id_token: 'the_token' }, {});
444444
});
445445

446446
it('should use access_token for validation is passed and responds with user_id', async () => {
447-
spyOn(httpsRequest, 'request').and.callFake(() => {
447+
spyOn(httpsRequest, 'get').and.callFake(() => {
448448
return Promise.resolve({ user_id: 'userId' });
449449
});
450450
await google.validateAuthData({ id: 'userId', access_token: 'the_token' }, {});
451451
});
452452

453453
it('should use access_token for validation is passed with sub', async () => {
454-
spyOn(httpsRequest, 'request').and.callFake(() => {
454+
spyOn(httpsRequest, 'get').and.callFake(() => {
455455
return Promise.resolve({ sub: 'userId' });
456456
});
457457
await google.validateAuthData({ id: 'userId', id_token: 'the_token' }, {});
458458
});
459459

460460
it('should fail when the id_token is invalid', async () => {
461-
spyOn(httpsRequest, 'request').and.callFake(() => {
461+
spyOn(httpsRequest, 'get').and.callFake(() => {
462462
return Promise.resolve({ sub: 'badId' });
463463
});
464464
try {
@@ -470,7 +470,7 @@ describe('google auth adapter', () => {
470470
});
471471

472472
it('should fail when the access_token is invalid', async () => {
473-
spyOn(httpsRequest, 'request').and.callFake(() => {
473+
spyOn(httpsRequest, 'get').and.callFake(() => {
474474
return Promise.resolve({ sub: 'badId' });
475475
});
476476
try {

src/Adapters/Auth/google.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ function validateAppId() {
4848

4949
// A promisey wrapper for api requests
5050
function googleRequest(path) {
51-
return httpsRequest.request("https://www.googleapis.com/oauth2/v3/" + path);
51+
return httpsRequest.get("https://www.googleapis.com/oauth2/v3/" + path);
5252
}
5353

5454
module.exports = {

0 commit comments

Comments
 (0)