Skip to content

Commit b60502d

Browse files
Instagram: Support passing in API url (#6398)
* Update instagram.js Instagram API was updated. * Update instagram.js Instagram API was updated and is not allowing anymore to setup new projects to use the old style but it is still working for the ones that have it already setup. New docs are listed here: https://developers.facebook.com/docs/instagram-basic-display-api/ I've added support for both old and new API To use new API just add new field "api_type" = "new_api" in client side. For old API just no changes needed. * support api url Co-authored-by: Diamond Lewis <[email protected]>
1 parent beecedb commit b60502d

File tree

2 files changed

+48
-17
lines changed

2 files changed

+48
-17
lines changed

spec/AuthenticationAdapters.spec.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,41 @@ describe('AuthenticationProviders', function() {
590590
});
591591
});
592592

593+
describe('instagram auth adapter', () => {
594+
const instagram = require('../lib/Adapters/Auth/instagram');
595+
const httpsRequest = require('../lib/Adapters/Auth/httpsRequest');
596+
597+
it('should use default api', async () => {
598+
spyOn(httpsRequest, 'get').and.callFake(() => {
599+
return Promise.resolve({ data: { id: 'userId' } });
600+
});
601+
await instagram.validateAuthData(
602+
{ id: 'userId', access_token: 'the_token' },
603+
{}
604+
);
605+
expect(httpsRequest.get).toHaveBeenCalledWith(
606+
'https://api.instagram.com/v1/users/self/?access_token=the_token'
607+
);
608+
});
609+
610+
it('should pass in api url', async () => {
611+
spyOn(httpsRequest, 'get').and.callFake(() => {
612+
return Promise.resolve({ data: { id: 'userId' } });
613+
});
614+
await instagram.validateAuthData(
615+
{
616+
id: 'userId',
617+
access_token: 'the_token',
618+
apiURL: 'https://new-api.instagram.com/v1/',
619+
},
620+
{}
621+
);
622+
expect(httpsRequest.get).toHaveBeenCalledWith(
623+
'https://new-api.instagram.com/v1/users/self/?access_token=the_token'
624+
);
625+
});
626+
});
627+
593628
describe('google auth adapter', () => {
594629
const google = require('../lib/Adapters/Auth/google');
595630
const httpsRequest = require('../lib/Adapters/Auth/httpsRequest');

src/Adapters/Auth/instagram.js

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,29 @@
11
// Helper functions for accessing the instagram API.
22
var Parse = require('parse/node').Parse;
33
const httpsRequest = require('./httpsRequest');
4+
const defaultURL = 'https://api.instagram.com/v1/';
45

56
// Returns a promise that fulfills iff this user id is valid.
67
function validateAuthData(authData) {
7-
return request('users/self/?access_token=' + authData.access_token).then(
8-
response => {
9-
if (response && response.data && response.data.id == authData.id) {
10-
return;
11-
}
12-
throw new Parse.Error(
13-
Parse.Error.OBJECT_NOT_FOUND,
14-
'Instagram auth is invalid for this user.'
15-
);
8+
const apiURL = authData.apiURL || defaultURL;
9+
const path = `${apiURL}users/self/?access_token=${authData.access_token}`;
10+
return httpsRequest.get(path).then(response => {
11+
if (response && response.data && response.data.id == authData.id) {
12+
return;
1613
}
17-
);
14+
throw new Parse.Error(
15+
Parse.Error.OBJECT_NOT_FOUND,
16+
'Instagram auth is invalid for this user.'
17+
);
18+
});
1819
}
1920

2021
// Returns a promise that fulfills iff this app id is valid.
2122
function validateAppId() {
2223
return Promise.resolve();
2324
}
2425

25-
// A promisey wrapper for api requests
26-
function request(path) {
27-
return httpsRequest.get('https://api.instagram.com/v1/' + path);
28-
}
29-
3026
module.exports = {
31-
validateAppId: validateAppId,
32-
validateAuthData: validateAuthData,
27+
validateAppId,
28+
validateAuthData,
3329
};

0 commit comments

Comments
 (0)