Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Allow authorized use of github API without revealing account secrets …

…to clients.
  • Loading branch information...
commit 95b2fd6b1e865816cd68c8af33567b6ca3745563 1 parent 136335f
@jdm authored
Showing with 52 additions and 1 deletion.
  1. +46 −0 cgi-bin/githubapi.cgi
  2. +4 −0 config.sample
  3. +2 −1  magic.js
View
46 cgi-bin/githubapi.cgi
@@ -0,0 +1,46 @@
+#!/usr/bin/env python
+
+# enable debugging
+import cgitb
+import cgi
+import urllib2
+from StringIO import StringIO
+import gzip
+import ConfigParser
+import base64
+cgitb.enable()
+
+print "Content-Type: text/html;charset=utf-8"
+print
+
+form = cgi.FieldStorage()
+url = urllib2.unquote(form.getfirst('url', ''))
+
+#data = {}
+#parts = url.split('?')
+#if len(parts) > 1:
+# params = parts[1].split('&')
+# for param in params:
+# param_data = param.split('=')
+# data[param_data[0]] = param_data[1]
+
+config = ConfigParser.RawConfigParser()
+config.read('config')
+try:
+ user = config.get('github', 'username')
+ passw = config.get('github', 'password')
+except ConfigParser.NoSectionError:
+ user = None
+ passw = None
+
+req = urllib2.Request('https://api.github.com/%s' % url, None, {'Accept': 'application/vnd.github.raw',
+ 'Accept-Encoding': 'gzip'})
+if user and passw:
+ base64string = base64.standard_b64encode('%s:%s' % (user, passw)).replace('\n', '')
+ req.add_header("Authorization", "Basic %s" % base64string)
+
+f = urllib2.urlopen(req)
+if f.info().get('Content-Encoding') == 'gzip':
+ buf = StringIO(f.read())
+ f = gzip.GzipFile(fileobj=buf)
+print f.read()
View
4 config.sample
@@ -0,0 +1,4 @@
+[github]
+username = github_username
+password = github_password
+
View
3  magic.js
@@ -409,7 +409,8 @@ function retrieveResults(category) {
var curMap = ghMapping[i];
var user = curMap.repo.split('/')[0];
var name = curMap.repo.split('/')[1];
- $.getJSON('https://api.github.com/repos/' + user + '/' + name + '/issues?labels=' + curMap.tag,
+ var apiCall = 'repos/' + user + '/' + name + '/issues?labels=' + curMap.tag;
+ $.getJSON('cgi-bin/githubapi.cgi?url=' + encodeURIComponent(apiCall),
null, function(data) {
for (var d in data) {
data[d].id = data[d].number;
Please sign in to comment.
Something went wrong with that request. Please try again.