forked from 1self/api
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoAuthConfig.js
More file actions
56 lines (53 loc) · 1.69 KB
/
oAuthConfig.js
File metadata and controls
56 lines (53 loc) · 1.69 KB
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
56
var q = require('q');
var request = require('request');
var CONTEXT_URI = process.env.CONTEXT_URI;
var githubOAuth = {
clientId: process.env.GITHUB_CLIENT_ID,
clientSecret: process.env.GITHUB_CLIENT_SECRET,
callbackUrl: CONTEXT_URI + "/auth/github/callback",
getEmailAddresses: function (accessToken) {
var deferred = q.defer();
var options = {
url: "https://api.github.com/user/emails?access_token=" + accessToken,
headers: {
"User-Agent": "Quantified Dev Localhost"
}
};
request(options, function (err, res, body) {
if (!err) {
deferred.resolve(JSON.parse(body));
}
else {
deferred.reject(err);
}
});
return deferred.promise;
}
};
var facebookOAuth = {
clientId: "454452498039912",
clientSecret: "8d1ec3eb775bda7ca2f3157c5efbce75",
callbackUrl: CONTEXT_URI + "/auth/facebook/callback",
getProfilePictureUrl: function (userId, accessToken) {
var deferred = q.defer();
var options = {
url: "https://graph.facebook.com?id=" + userId
+ "&fields=picture&access_token=" + accessToken,
headers: {
"User-Agent": "1self Localhost"
}
};
request(options, function (err, res, body) {
if (!err) {
var picture = JSON.parse(body);
deferred.resolve(picture.data.url);
}
else {
deferred.reject(err);
}
});
return deferred.promise;
}
};
exports.githubOAuth = githubOAuth;
exports.facebookOAuth = facebookOAuth;