Code Monkey home page Code Monkey logo

Comments (6)

mraaz avatar mraaz commented on July 22, 2024 4

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

from discord-token-generator.

IeuanGol avatar IeuanGol commented on July 22, 2024

Can confirm.. same here

from discord-token-generator.

IeuanGol avatar IeuanGol commented on July 22, 2024

Was shown this in the Discord API server

from discord-token-generator.

hateful911 avatar hateful911 commented on July 22, 2024

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

from discord-token-generator.

 avatar commented on July 22, 2024

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

from discord-token-generator.

alaninnovates avatar alaninnovates commented on July 22, 2024

Hey all, I answered this in #11!

from discord-token-generator.

Related Issues (14)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.