Estoy creando OAuth2 para mi aplicación mediante el cual las personas que son redirigidas al servidor al hacer clic en él obtendrán el rol verificado. ¿Alguien puede ayudarme sobre cómo puedo agregarlo en mi script? En este momento estoy usando el script que se proporciona a continuación:
const express = require('express'); const { port } = require('./config.json'); const app = express(); app.get('/', (request, response) => { console.log(`The access code is: ${request.query.code}`) ; return response.sendFile('index.html', { root: '.' }); }); app.listen(port, () => console.log(`App listening at http://localhost:${port}`));y desde el archivo de índice son redirigidos al servidor aquí está el script index.html:
<script> window.location.href = "https://discord.gg/DhsYQ3u4jj"; </script> <div id="info">Congrats! You have been successfully connected to Discord.</div> <a id="login" style="display: none;" href="https://discord.gg/jkBJarBY">Click here to Join Akudo's official Discord!</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>