Skip to content

Commit

Permalink
Use the correct function when validating google auth tokens (#5018)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
orette authored and flovilmart committed Aug 31, 2018
1 parent 8c0a443 commit c7357ed
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
12 changes: 6 additions & 6 deletions spec/AuthenticationAdapters.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -430,35 +430,35 @@ describe('google auth adapter', () => {
const httpsRequest = require('../lib/Adapters/Auth/httpsRequest');

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

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

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

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

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

it('should fail when the access_token is invalid', async () => {
spyOn(httpsRequest, 'request').and.callFake(() => {
spyOn(httpsRequest, 'get').and.callFake(() => {
return Promise.resolve({ sub: 'badId' });
});
try {
Expand Down
2 changes: 1 addition & 1 deletion src/Adapters/Auth/google.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ function validateAppId() {

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

module.exports = {
Expand Down

0 comments on commit c7357ed

Please sign in to comment.