Added the Sheepstar API to the Archive

This commit is contained in:
2022-09-06 16:37:56 +02:00
parent d6c272cdaf
commit bb78376745
36 changed files with 5346 additions and 0 deletions

View File

@ -0,0 +1,20 @@
const axios = require('axios');
const qs = require('qs');
const Session = require("../models/Session");
async function refreshToken(token) {
try {
const session = await Session.findOne({where: {token: token}});
const {data} = await axios.post(DISCORD_TOKEN_ENDPOINT, qs.stringify({
client_id: process.env.CLIENT_ID, client_secret: process.env.CLIENT_SECRET, grant_type: "refresh_token",
refresh_token: session.refresh_token
}));
await Session.update({access_token: data.access_token, refresh_token: data.refresh_token}, {where: {token: token}});
return data.access_token;
} catch (e) {
return "could not refresh token";
}
}
module.exports.refreshToken = refreshToken;