-
Notifications
You must be signed in to change notification settings - Fork 0
/
refreshToken.js
executable file
·47 lines (38 loc) · 1.15 KB
/
refreshToken.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
require('dotenv').config()
const token_data = require('./data/tokens/current.json')
const fs = require('fs').promises
const oauth = Buffer.from(`${process.env.CLIENTID}:${process.env.OASECRET}`,'base64')
const apiKey = process.env.APIKEY
const axios = require('axios')
const url = process.env.APISERVER
const headers = {
headers: {
"X-API-Key": apiKey
}
}
let refreshed_token_data = {}
async function retrieveCurrentToken() {
let file = JSON.parse(await fs.readFile('./data/tokens/current.json'))
return file
}
async function refreshToken() {
let response
let token_data = await retrieveCurrentToken()
headers.headers.Authorization = `Bearer ${token_data.access_token}`
const params = new URLSearchParams({
"grant_type": "refresh_token",
"refresh_token": `${token_data.refresh_token}`
})
console.log(params)
// try {
// response = await axios.post(`${process.env.TOKENURL}`, params, headers)
// refreshed_token_data = {...response.data}
// console.log(response.data)
// } catch(err) {
// console.log(err)
// }
}
async function execute() {
refreshToken()
}
execute()