Skip to content

Instantly share code, notes, and snippets.

@heridev
Created February 13, 2014 22: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 heridev/8985406 to your computer and use it in GitHub Desktop.
Save heridev/8985406 to your computer and use it in GitHub Desktop.
Probar funcionalidad de api en rails con ajax
Para generar un nuevo token desde la api usamos lo siguiente:
var server = 'http://localhost:3000';
var userAuthUrl = server + '/api/sessions/create?access_token=';
$.ajax({
url: userAuthUrl + access_token,
success: function(resp) {
console.log(resp);
}
});
Para poder validar nuestro token desde la api de google tenemos el siguiente codigo de ejemplo:
var google_url = 'https://www.googleapis.com/oauth2/v1/userinfo?access_token=';
var token = ''
$.ajax({
url: google_url + token,
data: null,
success: function(resp) {
user = resp;
console.log(user);
},
dataType: "jsonp"
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment