-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathextractAuthCode.js
More file actions
executable file
·38 lines (31 loc) · 964 Bytes
/
extractAuthCode.js
File metadata and controls
executable file
·38 lines (31 loc) · 964 Bytes
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
32
33
34
35
36
37
38
#!/usr/local/bin/node
const fs = require("fs");
const fileName = "credentials.json";
const url = process.argv[2];
const urlParamString = url.split("?")[1];
const paramsKeyValue = urlParamString.split("&");
const paramsMap = {};
paramsKeyValue.forEach(str => {
const [key, value] = str.split("=");
paramsMap[key] = value;
});
const credentials = fetch();
const updatedCredentials = {
...credentials,
code: decodeURIComponent(paramsMap["code"]),
sessionId: decodeURIComponent(paramsMap["session"])
};
update(updatedCredentials);
console.log(updatedCredentials);
function update(tdaCredential) {
fs.writeFileSync(fileName, JSON.stringify(tdaCredential, null, 2), "utf8");
}
function fetch() {
const credential = JSON.parse(fs.readFileSync(fileName, "utf8"));
if (!credential) {
throw new Error(
"You need to create the test credential file if you want to run the tests. Check out the README.md file"
);
}
return credential;
}