I wrote a js widget for listing one’s github repos on any website with a single line of js:
http://gitview.logicalcognition.com
Currently gitview.js hits gitview.php (which i host remotely) which in turn hits api.github.com to pull user / repo info. Originally, I just did the XHR GET directly to api.github.com rather than through the proxy, but I hit the same origin policy.
I tried using CORS or JSONP, but according to http://developer.github.com/v3/ this only works if the originating domain “is registered as an OAuth Application”. I didn’t want to make developers do this just to use the widget.
Any suggestions? Am I missing something?
The documentation linked indicates a registered domain is needed for CORS (used if you wanted to do a direct XHR), but not JSON-P. With JSON-P, you’d insert a script tag like this programatically (using
document.writeor DOM manipulation):This will then invoke the global function
foowith the returned data as an argument. Since this is a script tag and not an XHR request, the same-origin policy does not apply and CORS authorization is not required.