Files
Superalgos/utils/auth.js
T
mati108@gmail.com 6135d516db Container support
Changes required to accepts parameters and run the bots on the virtual machine.
2019-01-28 11:36:48 -03:00

25 lines
855 B
JavaScript

const axios = require('axios')
const appRoot = require('app-root-path')
const { logger } = require(`${appRoot}/utils/logger`)
exports.authenticate = function () {
try {
logger.debug('authenticate -> Entering Function.')
const authBody = '{"client_id":"' + process.env.AUTH_CLIENT_ID
+ '","client_secret": "' + process.env.AUTH_CLIENT_SECRET
+ '","audience":"' + process.env.AUTH_AUDIENCE
+ '","grant_type":"client_credentials"}'
return axios({
url: process.env.AUTH_URL,
method: 'post',
data: authBody,
headers: { 'content-type': 'application/json' }
})
} catch (error) {
logger.error('authenticate -> Error: ' + error.stack)
throw new Error('There has been an error on the authentication: ' + error)
}
}