Skip to content
This repository was archived by the owner on Jan 23, 2019. It is now read-only.

Commit 95b2fd6

Browse files
committed
Allow authorized use of github API without revealing account secrets to clients.
1 parent 136335f commit 95b2fd6

File tree

3 files changed

+52
-1
lines changed

3 files changed

+52
-1
lines changed

cgi-bin/githubapi.cgi

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/usr/bin/env python
2+
3+
# enable debugging
4+
import cgitb
5+
import cgi
6+
import urllib2
7+
from StringIO import StringIO
8+
import gzip
9+
import ConfigParser
10+
import base64
11+
cgitb.enable()
12+
13+
print "Content-Type: text/html;charset=utf-8"
14+
print
15+
16+
form = cgi.FieldStorage()
17+
url = urllib2.unquote(form.getfirst('url', ''))
18+
19+
#data = {}
20+
#parts = url.split('?')
21+
#if len(parts) > 1:
22+
# params = parts[1].split('&')
23+
# for param in params:
24+
# param_data = param.split('=')
25+
# data[param_data[0]] = param_data[1]
26+
27+
config = ConfigParser.RawConfigParser()
28+
config.read('config')
29+
try:
30+
user = config.get('github', 'username')
31+
passw = config.get('github', 'password')
32+
except ConfigParser.NoSectionError:
33+
user = None
34+
passw = None
35+
36+
req = urllib2.Request('https://api.github.com/%s' % url, None, {'Accept': 'application/vnd.github.raw',
37+
'Accept-Encoding': 'gzip'})
38+
if user and passw:
39+
base64string = base64.standard_b64encode('%s:%s' % (user, passw)).replace('\n', '')
40+
req.add_header("Authorization", "Basic %s" % base64string)
41+
42+
f = urllib2.urlopen(req)
43+
if f.info().get('Content-Encoding') == 'gzip':
44+
buf = StringIO(f.read())
45+
f = gzip.GzipFile(fileobj=buf)
46+
print f.read()

config.sample

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[github]
2+
username = github_username
3+
password = github_password
4+

magic.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,8 @@ function retrieveResults(category) {
409409
var curMap = ghMapping[i];
410410
var user = curMap.repo.split('/')[0];
411411
var name = curMap.repo.split('/')[1];
412-
$.getJSON('https://api.github.com/repos/' + user + '/' + name + '/issues?labels=' + curMap.tag,
412+
var apiCall = 'repos/' + user + '/' + name + '/issues?labels=' + curMap.tag;
413+
$.getJSON('cgi-bin/githubapi.cgi?url=' + encodeURIComponent(apiCall),
413414
null, function(data) {
414415
for (var d in data) {
415416
data[d].id = data[d].number;

0 commit comments

Comments
 (0)