@@ -28,7 +28,7 @@ Strategy.findOne({ name: 'github' }, function (aErr, aStrat) {
28
28
} ) ;
29
29
30
30
// Requests a GitHub url and returns the chunks as buffers
31
- function fetchRaw ( aHost , aPath , aCallback ) {
31
+ function fetchRaw ( aHost , aPath , aCallback , aOptions ) {
32
32
var options = {
33
33
hostname : aHost ,
34
34
port : 443 ,
@@ -39,6 +39,14 @@ function fetchRaw(aHost, aPath, aCallback) {
39
39
}
40
40
} ;
41
41
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
+
42
50
var req = https . request ( options ,
43
51
function ( aRes ) {
44
52
@@ -66,10 +74,16 @@ function fetchRaw(aHost, aPath, aCallback) {
66
74
// Use for call the GitHub JSON api
67
75
// Returns the JSON parsed object
68
76
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
+ } ;
70
84
fetchRaw ( 'api.github.com' , aPath , function ( aBufs ) {
71
85
aCallback ( JSON . parse ( Buffer . concat ( aBufs ) . toString ( ) ) ) ;
72
- } ) ;
86
+ } , opts ) ;
73
87
}
74
88
75
89
// This manages actions on the repos of a user
0 commit comments