Commit 8369de38 authored by Anton's avatar Anton
Browse files

Remove unused modules

parent c31950cc
This diff is collapsed.
......@@ -40,12 +40,10 @@
},
"dependencies": {
"auth0-js": "9.8.2",
"auth0-lock": "^11.16.3",
"axios": "^0.18.0",
"bluebird": "3.5.3",
"cote": "^0.20.0",
"ffprobe-static": "^3.0.0",
"he": "1.2.0",
"jwt-decode": "^2.2.0",
"keytar": "^4.10.0",
"luxon": "1.8.2",
......@@ -59,7 +57,6 @@
"nedb": "^1.8.0",
"qs": "^6.6.0",
"raven-js": "3.27.0",
"request": "^2.88.0",
"sanitize-html": "1.19.2",
"sift": "^7.0.1",
"socket.io-client": "^2.2.0",
......
const
pkg = require('../../package.json'),
jwtDecode = require('jwt-decode'),
request = require('request'),
axios = require('axios'),
url = require('url'),
keytar = require('keytar'),
os = require('os')
......@@ -21,74 +21,44 @@ function getAuthenticationURL () {
'redirect_uri=' + redirectUri
}
function refreshTokens () {
return new Promise(async (resolve, reject) => {
const refreshToken = await keytar.getPassword(keytarService, keytarAccount)
if (!refreshToken) return reject(new Error('No refresh token found'))
async function refreshTokens () {
const refreshToken = await keytar.getPassword(keytarService, keytarAccount)
if (!refreshToken) return throw new Error('No refresh token found')
const refreshOptions = {
method: 'POST',
url: `https://${process.env.AUTH0_DOMAIN}/oauth/token`,
headers: {'content-type': 'application/json'},
body: {
grant_type: 'refresh_token',
client_id: process.env.AUTH0_CLIENT_ID,
refresh_token: refreshToken
},
json: true
}
request(refreshOptions, async function (error, response, body) {
if (error || body.error) {
await logout()
return reject(error || body.error)
}
global.accessToken = body.access_token
global.profile = jwtDecode(body.id_token)
resolve()
})
const result = await axios.post(`https://${process.env.AUTH0_DOMAIN}/oauth/token`, {
grant_type: 'refresh_token',
client_id: process.env.AUTH0_CLIENT_ID,
refresh_token: refreshToken
}, {
headers: {'Content-Type': 'application/json'}
})
global.accessToken = result.data.access_token
global.profile = jwtDecode(result.data.id_token)
}
function loadTokens (callbackURL) {
return new Promise((resolve, reject) => {
const urlParts = url.parse(callbackURL, true)
const query = urlParts.query
async function loadTokens (callbackURL) {
const urlParts = url.parse(callbackURL, true)
const query = urlParts.query
const exchangeOptions = {
'grant_type': 'authorization_code',
'client_id': process.env.AUTH0_CLIENT_ID,
'code': query.code,
'redirect_uri': redirectUri
}
const exchangeOptions = {
'grant_type': 'authorization_code',
'client_id': process.env.AUTH0_CLIENT_ID,
'code': query.code,
'redirect_uri': redirectUri
}
const options = {
method: 'POST',
url: `https://${process.env.AUTH0_DOMAIN}/oauth/token`,
headers: {
'content-type': 'application/json'
},
body: JSON.stringify(exchangeOptions)
const result = await axios.post(`https://${process.env.AUTH0_DOMAIN}/oauth/token`, exchangeOptions, {
headers: {
'Content-Type': 'application/json'
}
})
request(options, async (error, resp, body) => {
if (error || body.error) {
await logout()
return reject(error || body.error)
}
const responseBody = JSON.parse(body)
global.accessToken = responseBody.access_token
global.profile = jwtDecode(responseBody.id_token)
const refreshToken = responseBody.refresh_token
keytar.setPassword(keytarService, keytarAccount, refreshToken)
global.accessToken = result.data.access_token
global.profile = jwtDecode(result.data.id_token)
const refreshToken = result.data.refresh_token
resolve()
})
})
keytar.setPassword(keytarService, keytarAccount, refreshToken)
}
async function logout () {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment