Im trying to make a login system with discord for my website that is made with express. I have made a function to get an access token so that I can use that function in the route.
Im trying to get an access token from: https://discord.com/api/oauth2/token
Here is my code:
async GetToken(code) {
let access_token;
const payload = {
'client_id': client_id,
'client_secret': client_secret,
'grant_type': 'authorization_code',
'code': code,
'redirect_uri': redirect_uri,
'scope': scope,
};
const config = {
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
};
fetch(discord_token_url, {
method: 'post',
body: payload,
headers: config.headers,
}).then(response => response.json()).then(json => console.log(json)).catch(err => console.log(err));
return access_token;
},
And here's the err I get:
{
error: 'unsupported_grant_type',
error_description: 'Grant type None is not supported'
}
As you can see I've given the correct grant type yet I get this error.