So I have been actively been trying to create a discord oauth2 reader so I can make a kind of verification system on ROBLOX using my own api, but I have been consistently on glitch been getting a “Socket Hangup” error. I also searched up glitch projects with discord oauth2 in the name, they ask me to accept discord permission but they end up not loading.
Is it possible that anyone could provide me a glitch project working example of discord oauth2 in effect. (Displays username)
Thanks!
Check on the ROBLOX API Discord Asking there would be the best option as ROBLOX has been very weird lately.
No, the problems I am having here are discord related, the information about making a ROBLOX discord verifier is irrelevant in this topic.
Oh, if that is the case, can you DM me an access link to your project?
Ill submit the parts of code that im having problems with. Due to the fact how much this bot is used in my group:
The main problem is that the first time, it gives my username, but when I reauthorize it, it gives the Socket Hangup error I talked about.
The project testing link: noricerm-bot.glitch.me/oauth
Server:
app.get('/', function(request, response) {
response.sendFile(__dirname + "/index.html")
});
app.get('/oauth', function(request, response) {
response.sendFile(__dirname + "/oauth.html")
});
app.use(bodyParser.text());
app.post('/oauth', function (req, res) {
console.log(req.body)
data.append('client_id', process.env.CLIENT_ID);
data.append('client_secret', process.env.CLIENT_SECRET);
data.append('grant_type', 'authorization_code');
data.append('redirect_uri', "https://noricerm-bot.glitch.me/oauth");
data.append('scope', 'identify');
data.append('code', req.body);
console.log(req.body)
fetch('https://discordapp.com/api/oauth2/token', {
method: 'POST',
body: data,
})
.then(response => response.json())
.then(data=>{
console.log(data)
const config = {
headers:{
"authorization":`Bearer ${data.access_token}`
}
}
axios
.get("https://discordapp.com/api/users/@me",config)
.then(response=>{
console.log(response.data.username)
res.send(response.data.username)
})
.catch(error=>{
//console.log(error)
})
})
})
Client:
window.onload = () => {
const fragment = new URLSearchParams(window.location.hash.slice(1));
if (fragment.has('access_token')) {
const urlState = fragment.get('state');
const stateParameter = localStorage.getItem('stateParameter');
if (stateParameter !== atob(decodeURIComponent(urlState))) {
return console.log('You may have been clickjacked!');
}
}
const code = location.href.substring(location.href.indexOf("code")+5, location.href.length)
if (location.href.indexOf("code") > -1) {
const req = new XMLHttpRequest()
req.open("POST", "https://noricerm-bot.glitch.me/oauth")
req.send(code)
req.onload = () => {
console.log(req.responseText)
document.getElementById("login").innerText = `your username is ${req.responseText}`
}
}
}
I see you are using the one from https://discordjs.guide. I would use this.
I followed the instructions but I got this… 
Can you share the full error? I suspect it may have something to do with no token being added.
Found the error, I recompleted the guide that @chessebuilderman gave me and readded my console.log to check for errors, and I get this.

Based off what I know about the error, its claiming that I do not supply the code, but I do.
Any help is appreciated,
I have found the problem, the sources about discord oauth are mostly outdated now days, and can only be found peacing together stack overflow pages
WARNING TO ANYONE WHO SEES THIS POST
In built url parameters (?variable=value) do not work with discord API any more, and they have to be encoded using x-www-urlencoding.
It took me hours of searching to finally fix this problem. Thanks for everyones help.