I am trying to implement Discord OAuth2 in my node.js Application. As soon as I try to get the access token from the given authorization code, I always get the HTTP response Error 400 {"error": "invalid_grant"}
let xhr = new XMLHttpRequest()
xhr.open('POST', 'https://discord.com/api/oauth2/token')
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded')
let payload ={
client_id: clientID,
client_secret: clientSecret,
grant_type: 'authorization_code',
code: code,
redirect_uri: redirectUrl,
scope: 'identify'
};
console.log(payload)
xhr.send(JSON.stringify(payload))
xhr.onreadystatechange = () => {
console.log(xhr.status)
console.log(xhr.responseText)
}
xhr.onerror = () => {
console.log('Failed')
}