Added the Sheepstar API to the Archive
This commit is contained in:
9
SheepstarAPIV1/lib/api.js
Normal file
9
SheepstarAPIV1/lib/api.js
Normal file
@ -0,0 +1,9 @@
|
||||
global.DISCORD_API_BASE = "https://discord.com/api";
|
||||
|
||||
// oAuth2 Endpoints
|
||||
global.DISCORD_OAUTH2_BASE = DISCORD_API_BASE+"/oauth2";
|
||||
global.DISCORD_TOKEN_ENDPOINT = DISCORD_OAUTH2_BASE+"/token";
|
||||
|
||||
// User Endpoints
|
||||
global.DISCORD_USER_ENDPOINT = DISCORD_API_BASE+"/users/@me";
|
||||
global.DISCORD_USER_GUILDS_ENDPOINT = DISCORD_USER_ENDPOINT+"/guilds";
|
20
SheepstarAPIV1/lib/discord.js
Normal file
20
SheepstarAPIV1/lib/discord.js
Normal 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;
|
Reference in New Issue
Block a user