-
Notifications
You must be signed in to change notification settings - Fork 27
/
instagram_server.js
55 lines (45 loc) · 1.57 KB
/
instagram_server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
Instagram = {};
Oauth.registerService('instagram', 2, null, function(query) {
var response = getTokenResponse(query);
var accessToken = response.access_token;
var identity = response.user;
var serviceData = _.extend(identity, {accessToken: response.access_token});
return {
serviceData: serviceData,
options: {
profile: { name: identity.full_name },
services: { instagram: identity }
}
};
});
var getTokenResponse = function (query) {
var config = ServiceConfiguration.configurations.findOne({service: 'instagram'});
if (!config)
throw new ServiceConfiguration.ConfigError();
var response;
try {
response = HTTP.post(
"https://api.instagram.com/oauth/access_token", {
params: {
code: query.code,
client_id: config.clientId,
redirect_uri: OAuth._redirectUri("instagram", config),
client_secret: OAuth.openSecret(config.secret),
grant_type: 'authorization_code'
}
});
if (response.error) // if the http response was an error
throw response.error;
if (typeof response.content === "string")
response.content = JSON.parse(response.content);
if (response.content.error)
throw response.content;
} catch (err) {
throw _.extend(new Error("Failed to complete OAuth handshake with Instagram. " + err.message),
{response: err.response});
}
return response.content;
};
Instagram.retrieveCredential = function(credentialToken, credentialSecret) {
return Oauth.retrieveCredential(credentialToken, credentialSecret);
};