Created
November 9, 2013 21:38
-
-
Save jfromaniello/7390369 to your computer and use it in GitHub Desktop.
use github from client_side only
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var auth0 = new Auth0({ | |
clientID: 'KgSjMN3OCwmrjvtjJ8bfuZyAaoKOrgH3', | |
domain: 'todos.auth0.com', | |
callbackURL: 'http://localhost:8080/' | |
}); | |
$(function () { | |
var tmpl_text = $('#item-tmpl').html(); | |
var item_tmpl = ejs.compile(tmpl_text); | |
//init login | |
$('#signin').click(function () { | |
auth0.login({ | |
connection: 'github' | |
}); | |
}); | |
//parse profile hash | |
auth0.parseHash(function (profile) { | |
$('#anonymous, #dashboard').toggle(); | |
window.location.hash = ''; | |
//github access token. | |
var token = profile.identities[0].access_token; | |
get_repositories(token, null, function (err, repos) { | |
for (var i = 0; i < repos.length; i++) { | |
$(item_tmpl(repos[i])) | |
.appendTo('#repos'); | |
} | |
}); | |
}); | |
function get_repositories(token, url, callback) { | |
$.get( url || ('https://api.github.com/user/repos?access_token=' + token) ) | |
.done(function (repos, _, response) { | |
var link_header = response.getResponseHeader('link'); | |
var links = parseLinks(link_header); | |
if (!links.next) return callback(null, repos); | |
get_repositories(null, links.next, function (err, repos2) { | |
callback(null, repos.concat(repos2)); | |
}); | |
}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment