-
Notifications
You must be signed in to change notification settings - Fork 0
/
tesla.js
32 lines (30 loc) · 917 Bytes
/
tesla.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
const rp = require('request-promise');
exports.initiateAuth = function (username, password) {
return new Promise(function(resolve, reject) {
var url = process.env.TESLA_URI + "/oauth/token";
var body = {
grant_type: "password",
client_id: process.env.TESLA_CLIENT_ID,
client_secret: process.env.TESLA_CLIENT_SECRET,
email: username,
password: password
};
var headers = {
'User-Agent': 'NP Software Fleet Management/1.0'
};
var options = {
method: 'POST',
uri: url,
body: body,
headers: headers,
json: true
};
console.log("options: "+JSON.stringify(options));
rp(options).then(function(resp){
resolve(resp);
})
.catch(function(err){
reject(err);
});
});
}