From 5791130e1267e7732111581ee72a5a9efc7a7198 Mon Sep 17 00:00:00 2001 From: manar Date: Wed, 10 Feb 2021 15:45:32 +0100 Subject: [PATCH 1/3] Fix for authenticating with instagram --- src/Adapters/Auth/instagram.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Adapters/Auth/instagram.js b/src/Adapters/Auth/instagram.js index 6d61413bf0..f14b76bf61 100644 --- a/src/Adapters/Auth/instagram.js +++ b/src/Adapters/Auth/instagram.js @@ -8,7 +8,7 @@ function validateAuthData(authData) { const apiURL = authData.apiURL || defaultURL; const path = `${apiURL}me?fields=id&access_token=${authData.access_token}`; return httpsRequest.get(path).then(response => { - if (response && response.data && response.data.id == authData.id) { + if (response && response.id == authData.id) { return; } throw new Parse.Error(Parse.Error.OBJECT_NOT_FOUND, 'Instagram auth is invalid for this user.'); From 8a4915b1735e1b26257b8f97a53e1cc12724e118 Mon Sep 17 00:00:00 2001 From: manar Date: Fri, 19 Feb 2021 19:25:37 +0100 Subject: [PATCH 2/3] Change tests for instagram authentication --- spec/AuthenticationAdapters.spec.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/spec/AuthenticationAdapters.spec.js b/spec/AuthenticationAdapters.spec.js index 87679d02a4..ddeafa3668 100644 --- a/spec/AuthenticationAdapters.spec.js +++ b/spec/AuthenticationAdapters.spec.js @@ -5,7 +5,7 @@ const authenticationLoader = require('../lib/Adapters/Auth'); const path = require('path'); const responses = { gpgames: { playerId: 'userId' }, - instagram: { data: { id: 'userId' } }, + instagram: { id: 'userId' }, janrainengage: { stat: 'ok', profile: { identifier: 'userId' } }, janraincapture: { stat: 'ok', result: 'userId' }, line: { userId: 'userId' }, @@ -492,7 +492,15 @@ describe('instagram auth adapter', () => { 'https://graph.instagram.com/me?fields=id&access_token=the_token' ); }); - + it('response object without data child', async () => { + spyOn(httpsRequest, 'get').and.callFake(() => { + return Promise.resolve({ id: 'userId' }); + }); + await instagram.validateAuthData({ id: 'userId', access_token: 'the_token' }, {}); + expect(httpsRequest.get).toHaveBeenCalledWith( + 'https://graph.instagram.com/me?fields=id&access_token=the_token' + ); + }); it('should pass in api url', async () => { spyOn(httpsRequest, 'get').and.callFake(() => { return Promise.resolve({ data: { id: 'userId' } }); From 35fe088d677691c2b1d06c65426b1df167ea8dd9 Mon Sep 17 00:00:00 2001 From: manar Date: Fri, 19 Feb 2021 19:33:56 +0100 Subject: [PATCH 3/3] Instagram authentication for the case when data child object is presented in the response --- src/Adapters/Auth/instagram.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Adapters/Auth/instagram.js b/src/Adapters/Auth/instagram.js index f14b76bf61..0b493a6945 100644 --- a/src/Adapters/Auth/instagram.js +++ b/src/Adapters/Auth/instagram.js @@ -8,7 +8,8 @@ function validateAuthData(authData) { const apiURL = authData.apiURL || defaultURL; const path = `${apiURL}me?fields=id&access_token=${authData.access_token}`; return httpsRequest.get(path).then(response => { - if (response && response.id == authData.id) { + const user = response.data ? response.data : response + if (user && user.id == authData.id) { return; } throw new Parse.Error(Parse.Error.OBJECT_NOT_FOUND, 'Instagram auth is invalid for this user.');