forked from tommy509/mocks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.js
59 lines (41 loc) · 1.08 KB
/
config.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
48
49
50
51
52
53
54
55
56
57
58
var axios = require('axios');
const https = require('https');
const express = require('express')
require('dotenv').config();
var qs = require('qs');
var auth_url= process.env.AUTH_URL;
var endpoint= process.env.API_URL;
var data = qs.stringify({
'grant_type': process.env.GRANT_TYPE,
'client_id': process.env.CLIENT_ID,
'client_secret': process.env.CLIENT_SECRET
});
var dataUserPassword = qs.stringify({
'grant_type': process.env.GRANT_TYPE,
'username': process.env.USERNAME,
'password': process.env.PASSWORD,
'client_id': process.env.CLIENT_ID,
});
const headers = {
'Content-Type': 'application/x-www-form-urlencoded',
}
// At instance level
const instance = axios.create({
httpsAgent: new https.Agent({
rejectUnauthorized: false
})
});
function getToken() {
const promise =instance.post(auth_url, dataUserPassword, {
headers: headers
});
const dataPromise = promise
.then((res) => {
return res.data.access_token;
})
.catch((err) => {
console.log("AXIOS ERROR: ", err);
});
return dataPromise
}
module.exports = {getToken,endpoint};