Skip to content

Commit

Permalink
feat: OAuth2 try
Browse files Browse the repository at this point in the history
  • Loading branch information
DavDeDev committed Jun 11, 2023
1 parent c3c75c4 commit 6e696fd
Show file tree
Hide file tree
Showing 7 changed files with 702 additions and 33 deletions.
1 change: 0 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
"curly": ["error", "multi-line", "consistent"],
"dot-location": ["error", "property"],
"handle-callback-err": "off",
"indent": ["error", "space"],
"keyword-spacing": "error",
"max-nested-callbacks": ["error", { "max": 4 }],
"max-statements-per-line": ["error", { "max": 2 }],
Expand Down
34 changes: 34 additions & 0 deletions OAuth2/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<!DOCTYPE html>
<html>
<head>
<title>My Discord OAuth2 App</title>
</head>
<body>
<div id="info">Hoi!</div>
<div id="info">Hoi!</div>
<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>
<script>
window.onload = () => {
const fragment = new URLSearchParams(window.location.hash.slice(1));
const [accessToken, tokenType] = [fragment.get('access_token'), fragment.get('token_type')];

if (!accessToken) {
return (document.getElementById('login').style.display = 'block');
}

fetch('https://discord.com/api/users/@me', {
headers: {
authorization: `${tokenType} ${accessToken}`,
},
})
.then(result => result.json())
.then(response => {
const { username, discriminator } = response;
document.getElementById('info').innerText += ` ${username}#${discriminator}`;
})
.catch(console.error);
};
</script>

</body>
</html>
10 changes: 10 additions & 0 deletions OAuth2/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const express = require('express');
const { port } = require('./config.json');

const app = express();

app.get('/', (request, response) => {
return response.sendFile('index.html', { root: '.' });
});

app.listen(port, () => console.log(`App listening at http://localhost:${port}`));
Loading

0 comments on commit 6e696fd

Please sign in to comment.