-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
99 lines (97 loc) · 4.11 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/*
⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿
⣿⣿⣿⡟⠁⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠈⢹⣿⣿⣿
⣿⣿⣿⡇⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⢸⣿⣿⣿
⣿⣿⣿⡇⠄⠄⠄⢠⣴⣾⣵⣶⣶⣾⣿⣦⡄⠄⠄⠄⢸⣿⣿⣿ ___ _ _ _ ____
⣿⣿⣿⡇⠄⠄⢀⣾⣿⣿⢿⣿⣿⣿⣿⣿⣿⡄⠄⠄⢸⣿⣿⣿ / _ \ / \ _ _ | |_ | |__ |___ \
⣿⣿⣿⡇⠄⠄⢸⣿⣿⣧⣀⣼⣿⣄⣠⣿⣿⣿⠄⠄⢸⣿⣿⣿ | | | | / _ \ | | | | | __| | '_ \ __) |
⣿⣿⣿⡇⠄⠄⠘⠻⢷⡯⠛⠛⠛⠛⢫⣿⠟⠛⠄⠄⢸⣿⣿⣿ | |_| | / ___ \ | |_| | | |_ | | | | / __/
⣿⣿⣿⡇⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⢸⣿⣿⣿ \___/ /_/ \_\ \__,_| \__| |_| |_| |_____|
⣿⣿⣿⣧⡀⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⢡⣀⠄⠄⢸⣿⣿⣿
⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣶⣆⣸⣿⣿⣿
⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿
- discord-auth.js
- Discord OAuth2 Made Simple.
-
- Dependencies:
- \ node-fetch@2.6.1
-
- Made by:
- \ NeutronX
*/
const fetch = require('node-fetch');
module.exports = class {
constructor(client_id, client_secret, callback_url) {
this.config = {
client_id: client_id,
client_secret: client_secret,
callback_url: callback_url
};
}
getUser(code) {
return new Promise(async (resolve, reject) => {
console.clear();
const options = {
method: 'POST'
};
let params = new URLSearchParams();
params.append('client_id', this.config.client_id);
params.append('client_secret', this.config.client_secret);
params.append('code', code);
params.append('grant_type', 'authorization_code');
params.append('scope', 'identify');
params.append('redirect_uri', this.config.callback_url);
options.body = params;
await fetch('https://discordapp.com/api/oauth2/token', options)
.then(async response => {
let x = await response.json();
await fetch('https://discordapp.com/api/v7/users/@me', {
headers: {
'Authorization': `Bearer ${x.access_token}`
}
}).then(async res => {
let user = await res.json();
resolve(user);
}).catch(err => {
reject(err);
});
})
.catch(error => {
reject(error);
});
});
}
getGuilds(code) {
return new Promise(async (resolve, reject) => {
console.clear();
const options = {
method: 'POST'
};
let params = new URLSearchParams();
params.append('client_id', this.config.client_id);
params.append('client_secret', this.config.client_secret);
params.append('code', code);
params.append('grant_type', 'authorization_code');
params.append('scope', 'identify');
params.append('redirect_uri', this.config.callback_url);
options.body = params;
await fetch('https://discordapp.com/api/oauth2/token', options)
.then(async response => {
let x = await response.json();
await fetch('https://discordapp.com/api/v7/users/@me/guilds', {
headers: {
'Authorization': `Bearer ${x.access_token}`
}
}).then(async res => {
let user = await res.json();
resolve(user);
}).catch(err => {
reject(err);
});
})
.catch(error => {
reject(error);
});
});
}
};