Skip to content

Commit 6e696fd

Browse files
committed
feat: OAuth2 try
1 parent c3c75c4 commit 6e696fd

7 files changed

+702
-33
lines changed

.eslintrc.json

-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
"curly": ["error", "multi-line", "consistent"],
1717
"dot-location": ["error", "property"],
1818
"handle-callback-err": "off",
19-
"indent": ["error", "space"],
2019
"keyword-spacing": "error",
2120
"max-nested-callbacks": ["error", { "max": 4 }],
2221
"max-statements-per-line": ["error", { "max": 2 }],

OAuth2/index.html

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>My Discord OAuth2 App</title>
5+
</head>
6+
<body>
7+
<div id="info">Hoi!</div>
8+
<div id="info">Hoi!</div>
9+
<a id="login" style="display: none;" href="https://discord.com/api/oauth2/authorize?client_id=1116208685945987113&redirect_uri=http%3A%2F%2Flocalhost%3A53134%2F&response_type=code&scope=identify">Identify Yourself</a>
10+
<script>
11+
window.onload = () => {
12+
const fragment = new URLSearchParams(window.location.hash.slice(1));
13+
const [accessToken, tokenType] = [fragment.get('access_token'), fragment.get('token_type')];
14+
15+
if (!accessToken) {
16+
return (document.getElementById('login').style.display = 'block');
17+
}
18+
19+
fetch('https://discord.com/api/users/@me', {
20+
headers: {
21+
authorization: `${tokenType} ${accessToken}`,
22+
},
23+
})
24+
.then(result => result.json())
25+
.then(response => {
26+
const { username, discriminator } = response;
27+
document.getElementById('info').innerText += ` ${username}#${discriminator}`;
28+
})
29+
.catch(console.error);
30+
};
31+
</script>
32+
33+
</body>
34+
</html>

OAuth2/index.js

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
const express = require('express');
2+
const { port } = require('./config.json');
3+
4+
const app = express();
5+
6+
app.get('/', (request, response) => {
7+
return response.sendFile('index.html', { root: '.' });
8+
});
9+
10+
app.listen(port, () => console.log(`App listening at http://localhost:${port}`));

0 commit comments

Comments
 (0)