-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.js
32 lines (26 loc) · 886 Bytes
/
utils.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
import axios from 'axios'
async function getForgeToken (clientId, clientSecret) {
try {
const params = new URLSearchParams()
Object.entries({
client_id: clientId,
client_secret: clientSecret,
grant_type: 'client_credentials',
scope: 'code:all data:write data:read bucket:create bucket:delete bucket:read',
}).forEach(([ key, value ]) => {
params.append(key, value)
})
const response = await axios.post('https://developer.api.autodesk.com/authentication/v1/authenticate',
params,
{
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
}
})
const { access_token, expires_in } = response.data
return { token: access_token, timeInSeconds: expires_in }
} catch (error) {
throw (new Error(`Error while getting token - ${ error }`))
}
}
export default getForgeToken