Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Basic auth for GitHub (#1705) #1729

Merged
merged 1 commit into from
Aug 16, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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