Skip to content

Commit 702e1c6

Browse files
committed
Use Basic auth for GitHub (OpenUserJS#1705)
1 parent bc85876 commit 702e1c6

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

libs/repoManager.js

+17-3
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ Strategy.findOne({ name: 'github' }, function (aErr, aStrat) {
2828
});
2929

3030
// Requests a GitHub url and returns the chunks as buffers
31-
function fetchRaw(aHost, aPath, aCallback) {
31+
function fetchRaw(aHost, aPath, aCallback, aOptions) {
3232
var options = {
3333
hostname: aHost,
3434
port: 443,
@@ -39,6 +39,14 @@ function fetchRaw(aHost, aPath, aCallback) {
3939
}
4040
};
4141

42+
if (aOptions) {
43+
// Ideally do a deep merge of aOptions -> options
44+
// But for now, we just need the headers
45+
if (aOptions.headers) {
46+
Object.assign(options.headers, aOptions.headers);
47+
}
48+
}
49+
4250
var req = https.request(options,
4351
function (aRes) {
4452

@@ -66,10 +74,16 @@ function fetchRaw(aHost, aPath, aCallback) {
6674
// Use for call the GitHub JSON api
6775
// Returns the JSON parsed object
6876
function fetchJSON(aPath, aCallback) {
69-
aPath += '?client_id=' + clientId + '&client_secret=' + clientKey;
77+
//aPath += '?client_id=' + clientId + '&client_secret=' + clientKey;
78+
var encodedAuth = Buffer.from(`${clientId}:${client_secret}`).toString('base64');
79+
var opts = {
80+
headers: {
81+
authorization: `Basic ${encodedAuth}`
82+
}
83+
};
7084
fetchRaw('api.github.com', aPath, function (aBufs) {
7185
aCallback(JSON.parse(Buffer.concat(aBufs).toString()));
72-
});
86+
}, opts);
7387
}
7488

7589
// This manages actions on the repos of a user

0 commit comments

Comments
 (0)