Skip to content

Instantly share code, notes, and snippets.

@jrom
Created May 20, 2014 17:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jrom/0f8d978d9253e3625a76 to your computer and use it in GitHub Desktop.
Save jrom/0f8d978d9253e3625a76 to your computer and use it in GitHub Desktop.
var local_hash = window.location.hash.substr(1),
hash_value = local_hash.substr(local_hash.indexOf(key + '=')).split('&')[0].split('=')[1],
Data = {};
// Once OAuth handshake is done, we'll be redirected with a hash string in the location that we'll use to extract the token
if (hash_value) {
Data.access_token = hash_value;
call_api("organizations", {}, function (data) {
console.log(data); // Here you have your organizations
});
}
else {
// We are not in the callback page, show a link to:
// https://redbooth.com/oauth2/authorize?client_id=our_client_id&redirect_uri=our_application_url&response_type=token
}
// Helper function to call the API using json-p
// examples:
// call_api("me", {}, console.log)
// call_api("projects", {}, console.log)
// call_api("projects", { per_page: 10 }, console.log)
function call_api(endpoint, params, callback) {
params['access_token'] = Data.access_token;
$.ajax({
url: "https://redbooth.com/api/3/" + endpoint,
data: params,
jsonp: "callback",
dataType: "jsonp",
success: function(response) {
callback(response);
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment