Last active
October 15, 2015 13:47
-
-
Save bsautron/b5f5a839a4ca22aaaf8e to your computer and use it in GitHub Desktop.
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 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