Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

token is undefined #6

Open
Reubencfernandes opened this issue May 31, 2020 · 6 comments
Open

token is undefined #6

Reubencfernandes opened this issue May 31, 2020 · 6 comments

Comments

@Reubencfernandes
Copy link

Screenshot_1
i get token=undefined after logging in

@IeuanGol
Copy link

IeuanGol commented May 31, 2020

Can confirm.. same here

@IeuanGol
Copy link

IeuanGol commented Jun 1, 2020

Was shown this in the Discord API server

@mraaz
Copy link

mraaz commented Jun 24, 2020

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
Copy link

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
Copy link

ghost commented Nov 11, 2020

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
Copy link

Hey all, I answered this in #11!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants