Compare commits

..

No commits in common. "758e2ef7e2f5f2b4c5445c5fcbf9bc96a4bfc78a" and "108eec139d961e7549ab0572be5a56d2cd774eb8" have entirely different histories.

7 changed files with 2 additions and 77 deletions

View file

@ -1,2 +0,0 @@
DISCORD_OAUTH_CLIENTID=""
DISCORD_OAUTH_CLIENTSECRET=""

3
.gitignore vendored
View file

@ -2,5 +2,4 @@
node_modules node_modules
built built
config/config.json config/config.json
*.log *.log
.env

18
package-lock.json generated
View file

@ -422,14 +422,6 @@
"resolved": "https://registry.npmjs.org/async/-/async-3.2.0.tgz", "resolved": "https://registry.npmjs.org/async/-/async-3.2.0.tgz",
"integrity": "sha512-TR2mEZFVOj2pLStYxLht7TyfuRzaydfpxr3k9RpHIzMgw7A64dzsdqCxH1WJyQdoe8T10nDXd9wnEigmiuHIZw==" "integrity": "sha512-TR2mEZFVOj2pLStYxLht7TyfuRzaydfpxr3k9RpHIzMgw7A64dzsdqCxH1WJyQdoe8T10nDXd9wnEigmiuHIZw=="
}, },
"axios": {
"version": "0.20.0",
"resolved": "https://registry.npmjs.org/axios/-/axios-0.20.0.tgz",
"integrity": "sha512-ANA4rr2BDcmmAQLOKft2fufrtuvlqR+cXNNinUmvfeSNCOF98PZL+7M/v1zIdGo7OLjEA9J2gXJL+j4zGsl0bA==",
"requires": {
"follow-redirects": "^1.10.0"
}
},
"balanced-match": { "balanced-match": {
"version": "1.0.0", "version": "1.0.0",
"resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz",
@ -707,11 +699,6 @@
"esutils": "^2.0.2" "esutils": "^2.0.2"
} }
}, },
"dotenv": {
"version": "8.2.0",
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-8.2.0.tgz",
"integrity": "sha512-8sJ78ElpbDJBHNeBzUbUVLsqKdccaa/BXF1uPTw3GrvQTBgrQrtObr2mUrE38vzYd8cEv+m/JBfDLioYcfXoaw=="
},
"ee-first": { "ee-first": {
"version": "1.1.1", "version": "1.1.1",
"resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz", "resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz",
@ -1064,11 +1051,6 @@
"resolved": "https://registry.npmjs.org/fn.name/-/fn.name-1.1.0.tgz", "resolved": "https://registry.npmjs.org/fn.name/-/fn.name-1.1.0.tgz",
"integrity": "sha512-GRnmB5gPyJpAhTQdSZTSp9uaPSvl09KoYcMQtsB9rQoOmzs9dH6ffeccH+Z+cv6P68Hu5bC6JjRh4Ah/mHSNRw==" "integrity": "sha512-GRnmB5gPyJpAhTQdSZTSp9uaPSvl09KoYcMQtsB9rQoOmzs9dH6ffeccH+Z+cv6P68Hu5bC6JjRh4Ah/mHSNRw=="
}, },
"follow-redirects": {
"version": "1.13.0",
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.13.0.tgz",
"integrity": "sha512-aq6gF1BEKje4a9i9+5jimNFIpq4Q1WiwBToeRK5NvZBd/TRsmW8BsJfOEGkr76TbOyPVD3OVDN910EcUNtRYEA=="
},
"forwarded": { "forwarded": {
"version": "0.1.2", "version": "0.1.2",
"resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.1.2.tgz", "resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.1.2.tgz",

View file

@ -13,8 +13,6 @@
"dependencies": { "dependencies": {
"@types/express": "github:types/express", "@types/express": "github:types/express",
"@types/mongoose": "^5.7.36", "@types/mongoose": "^5.7.36",
"axios": "^0.20.0",
"dotenv": "^8.2.0",
"express": "^4.17.1", "express": "^4.17.1",
"express-fileupload": "^1.2.0", "express-fileupload": "^1.2.0",
"mongoose": "^5.10.2", "mongoose": "^5.10.2",

View file

@ -1,40 +0,0 @@
const API_ENDPOINT = 'https://discord.com/api/v6';
const axios = require('axios').default;
export function run(app) {
app.get('/discordauth', async (req, res) => {
const code = req.query.code;
if (code) {
try {
const data = new URLSearchParams({
client_id: process.env.DISCORD_OAUTH_CLIENTID,
client_secret: process.env.DISCORD_OAUTH_CLIENTSECRET,
grant_type: 'authorization_code',
code: code,
redirect_uri: 'http://localhost:8080/discordauth',
scope: 'identify'
});
const postRes = await axios.post(`${API_ENDPOINT}/oauth2/token`, data, {
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
}
});
const userInfo = await axios.get(`${API_ENDPOINT}/users/@me`, {
headers: {
authorization: `${postRes.data.token_type} ${postRes.data.access_token}`
}
});
res.send(`hi ${userInfo.data.username}#${userInfo.data.discriminator}`);
} catch(err) {
res.send(`whoooops<br>${err}`);
}
} else {
res.send('https://discord.com/api/oauth2/authorize?client_id=750952563079250012&redirect_uri=http%3A%2F%2Flocalhost%3A8080%2Fdiscordauth&response_type=code&scope=identify');
}
});
}

View file

@ -8,10 +8,6 @@ import * as format from './lib/format';
import { File } from './schema'; import { File } from './schema';
import * as upload from './upload'; import * as upload from './upload';
import * as auth from './auth';
// .env stuff
require('dotenv').config();
const config = JSON.parse(fs.readFileSync('./config/config.json', {encoding: 'utf8'})); const config = JSON.parse(fs.readFileSync('./config/config.json', {encoding: 'utf8'}));
@ -59,7 +55,6 @@ db.then(() => {
app.set('logger', logger); app.set('logger', logger);
upload.run(app); upload.run(app);
auth.run(app);
app.get('/list', async (req, res) => { // only for testing app.get('/list', async (req, res) => { // only for testing
const docs = await File.find({}); const docs = await File.find({});

View file

@ -29,11 +29,4 @@ const FileSchema = new Schema({
charts: [Chart] charts: [Chart]
}); });
export const File = mongoose.model('File', FileSchema); export const File = mongoose.model('File', FileSchema);
const UserSchema = new Schema({ // this is pretty much just a discord user lol
id: String, // cus longass number
approved: Boolean
});
export const User = mongoose.model('User', UserSchema);