Skip to content

Instantly share code, notes, and snippets.

@bsautron
Last active October 15, 2015 13:47
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 bsautron/b5f5a839a4ca22aaaf8e to your computer and use it in GitHub Desktop.
Save bsautron/b5f5a839a4ca22aaaf8e to your computer and use it in GitHub Desktop.
var request = require('request');
var qs = require('querystring');
var username = '...',
password = '...',
client_id = '...',
client_secret = '...';
var data = qs.stringify({
'username' : username,
'password' : password,
'client_id' : client_id,
'client_secret' : client_secret,
'grant_type' : 'password',
});
var options = {
json: true,
headers: {'Content-length': data.length, 'Content-type':'application/x-www-form-urlencoded'},
url: 'https://apiflowerpower.parrot.com/user/v1/authenticate',
body: data,
};
/* Request to get your first token */
request.post(options, function(err, res, body) {
console.log(err || body);
/*{ access_token: '...',
expires_in: 2678400,
refresh_token: '...' }
*/
var data = qs.stringify({
'client_id' : client_id,
'client_secret' : client_secret,
'refresh_token' : body.refresh_token,
'grant_type' : 'refresh_token',
});
var options = {
json: true,
headers: {'Content-length': data.length, 'Content-type':'application/x-www-form-urlencoded'},
url: 'https://apiflowerpower.parrot.com/user/v1/authenticate',
body: data,
};
/* request to get a new token from the refresh token */
request.post(options, function(err, res, body) {
console.log(err || body);
/*{ access_token: '...',
expires_in: 2678400,
refresh_token: '...' }
*/
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment