Skip to content

Instantly share code, notes, and snippets.

@jfromaniello
Created November 9, 2013 21:38
Show Gist options
  • Save jfromaniello/7390369 to your computer and use it in GitHub Desktop.
Save jfromaniello/7390369 to your computer and use it in GitHub Desktop.
use github from client_side only
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