orels1 / discord-token-generator

An example discord oauth2 token generator
116 stars 75 forks source link

token is undefined #6

Open Reubencfernandes opened 4 years ago

Reubencfernandes commented 4 years ago

Screenshot_1 i get token=undefined after logging in

IeuanGol commented 4 years ago

Can confirm.. same here

IeuanGol commented 4 years ago

Was shown this in the Discord API server

mraaz commented 4 years ago

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,
      })
hateful911 commented 3 years ago

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

ghost commented 3 years ago

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

alaninnovates commented 3 years ago

Hey all, I answered this in #11!