Skip to content

Commit

Permalink
Use Basic auth for GitHub (#1705) (#1729)
Browse files Browse the repository at this point in the history
I don't know if this will work, since I don't have a full test setup.

However this is how we did Basic authentication in our app's fetch requests. So fingers crossed it will work for GitHub too!

Addresses issue #1705

Auto-merge and THANKS!
  • Loading branch information
joeytwiddle authored Aug 16, 2020
1 parent 0c5e3e5 commit 557e66d
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions libs/repoManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Strategy.findOne({ name: 'github' }, function (aErr, aStrat) {
});

// Requests a GitHub url and returns the chunks as buffers
function fetchRaw(aHost, aPath, aCallback) {
function fetchRaw(aHost, aPath, aCallback, aOptions) {
var options = {
hostname: aHost,
port: 443,
Expand All @@ -39,6 +39,14 @@ function fetchRaw(aHost, aPath, aCallback) {
}
};

if (aOptions) {
// Ideally do a deep merge of aOptions -> options
// But for now, we just need the headers
if (aOptions.headers) {
Object.assign(options.headers, aOptions.headers);
}
}

var req = https.request(options,
function (aRes) {

Expand Down Expand Up @@ -66,10 +74,18 @@ function fetchRaw(aHost, aPath, aCallback) {
// Use for call the GitHub JSON api
// Returns the JSON parsed object
function fetchJSON(aPath, aCallback) {
aPath += '?client_id=' + clientId + '&client_secret=' + clientKey;
// The old authentication method, which GitHub deprecated
//aPath += '?client_id=' + clientId + '&client_secret=' + clientKey;
// We must now use OAuth Basic (user+key) or Bearer (token)
var encodedAuth = Buffer.from(`${clientId}:${clientKey}`).toString('base64');
var opts = {
headers: {
Authorization: `Basic ${encodedAuth}`
}
};
fetchRaw('api.github.com', aPath, function (aBufs) {
aCallback(JSON.parse(Buffer.concat(aBufs).toString()));
});
}, opts);
}

// This manages actions on the repos of a user
Expand Down

0 comments on commit 557e66d

Please sign in to comment.