Open Reubencfernandes opened 4 years ago
i get token=undefined after logging in
Can confirm.. same here
Was shown this in the Discord API server
Hi All
This issue is caused by the upgrade in Discord's OAuth API. If you look at the official documentation, it clearly outlines that you now need to use content type of x-www-form-urlencoded: https://discord.com/developers/docs/topics/oauth2
For nodejs implementation you can follow this guide: https://discordjs.guide/oauth2/#oauth2-flows
Existing code:
const creds = btoa(`${CLIENT_ID}:${CLIENT_SECRET}`);
const response = await fetch(`https://discordapp.com/api/oauth2/token?grant_type=authorization_code&code=${code}&redirect_uri=${redirect}`,
{
method: 'POST',
headers: {
Authorization: `Basic ${creds}`,
},
});
New code
const FormData = require('form-data')
const data = new FormData()
data.append('client_id', CLIENT_ID)
data.append('client_secret', CLIENT_SECRET)
data.append('grant_type', 'authorization_code')
data.append('redirect_uri', REDIRECT_URI)
data.append('scope', 'identify email')
data.append('code', code)
const response = await fetch('https://discordapp.com/api/oauth2/token', {
method: 'POST',
body: data,
})
Hi All
This issue is caused by the upgrade in Discord's OAuth API. If you look at the official documentation, it clearly outlines that you now need to use content type of x-www-form-urlencoded: https://discord.com/developers/docs/topics/oauth2
For nodejs implementation you can follow this guide: https://discordjs.guide/oauth2/#oauth2-flows
Changes
Existing code:
const creds = btoa(`${CLIENT_ID}:${CLIENT_SECRET}`); const response = await fetch(`https://discordapp.com/api/oauth2/token?grant_type=authorization_code&code=${code}&redirect_uri=${redirect}`, { method: 'POST', headers: { Authorization: `Basic ${creds}`, }, });
New code
const FormData = require('form-data') const data = new FormData() data.append('client_id', CLIENT_ID) data.append('client_secret', CLIENT_SECRET) data.append('grant_type', 'authorization_code') data.append('redirect_uri', REDIRECT_URI) data.append('scope', 'identify email') data.append('code', code) const response = await fetch('https://discordapp.com/api/oauth2/token', { method: 'POST', body: data, })
What to do? Error: {"status":"ERROR","error":"REDIRECT_URI is not defined"}
Hi All
This issue is caused by the upgrade in Discord's OAuth API. If you look at the official documentation, it clearly outlines that you now need to use content type of x-www-form-urlencoded: https://discord.com/developers/docs/topics/oauth2
For nodejs implementation you can follow this guide: https://discordjs.guide/oauth2/#oauth2-flows
Changes
Existing code:
const creds = btoa(`${CLIENT_ID}:${CLIENT_SECRET}`); const response = await fetch(`https://discordapp.com/api/oauth2/token?grant_type=authorization_code&code=${code}&redirect_uri=${redirect}`, { method: 'POST', headers: { Authorization: `Basic ${creds}`, }, });
New code
const FormData = require('form-data') const data = new FormData() data.append('client_id', CLIENT_ID) data.append('client_secret', CLIENT_SECRET) data.append('grant_type', 'authorization_code') data.append('redirect_uri', REDIRECT_URI) data.append('scope', 'identify email') data.append('code', code) const response = await fetch('https://discordapp.com/api/oauth2/token', { method: 'POST', body: data, })
It still does not work. . .
Hey all, I answered this in #11!