-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathoAuthConfig.js
More file actions
63 lines (58 loc) · 1.74 KB
/
oAuthConfig.js
File metadata and controls
63 lines (58 loc) · 1.74 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
57
58
59
60
61
62
63
var q = require('q');
var request = require('request');
var CONTEXT_URI = process.env.CONTEXT_URI;
var OAuthConfig = function () {
};
OAuthConfig.prototype.getGithubOAuthConfig = function () {
return {
clientId: process.env.GITHUB_CLIENT_ID,
clientSecret: process.env.GITHUB_CLIENT_SECRET,
callbackUrl: CONTEXT_URI + "/auth/github/callback"
};
};
OAuthConfig.prototype.getGithubEmailAddresses = function (accessToken) {
var deferred = q.defer();
var options = {
url: "https://api.github.com/user/emails?access_token=" + accessToken,
headers: {
"User-Agent": "1self"
}
};
request(options, function (err, res, body) {
if (!err) {
deferred.resolve(JSON.parse(body));
}
else {
deferred.reject(err);
}
});
return deferred.promise;
};
OAuthConfig.prototype.getFacebookOAuthConfig = function () {
return {
clientId: process.env.FACEBOOK_APP_ID,
clientSecret: process.env.FACEBOOK_APP_SECRET,
callbackUrl: CONTEXT_URI + "/auth/facebook/callback"
};
};
OAuthConfig.prototype.getFacebookProfilePictureUrl = 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 pictureData = JSON.parse(body);
deferred.resolve(pictureData.picture.data.url);
}
else {
deferred.reject(err);
}
});
return deferred.promise;
};
module.exports = new OAuthConfig();