discord-token-generator icon indicating copy to clipboard operation
discord-token-generator copied to clipboard

token is undefined

Open Reubencfernandes opened this issue 4 years ago • 6 comments

Screenshot_1 i get token=undefined after logging in

Reubencfernandes avatar May 31 '20 07:05 Reubencfernandes

Can confirm.. same here

IeuanGol avatar May 31 '20 21:05 IeuanGol

Was shown this in the Discord API server

IeuanGol avatar Jun 01 '20 14:06 IeuanGol

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

image

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,
      })

mraaz avatar Jun 24 '20 03:06 mraaz

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

image

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"}

hateful911 avatar Sep 30 '20 17:09 hateful911

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

image

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. . .

ghost avatar Nov 11 '20 16:11 ghost

Hey all, I answered this in #11!

alaninnovates avatar Feb 24 '21 23:02 alaninnovates