Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
230 views
in Technique[技术] by (71.8m points)

node.js - Discord OAuth2 always returns the data of the applications owner?

I'm trying to make a basic Discord OAuth2 app, just with the identify scope, in node.js/express. My code is:

const express = require('express');
const app = express();
const axios = require('axios');

app.get('/oauth-callback', async (req, res) => {
  const code = req.query.code;
  if(!code) return;
  axios.post("https://discordapp.com/api/oauth2/token", `client_id=${client_id}&client_secret=${client_secret}&grant_type=client_credentials&code=${code}&redirect_uri=${redirect}&scope=identify`)
  .then(async (response) => {
    const access_token = response.data.access_token;
    console.log(access_token);
    
    
    const data = await axios.get("https://discordapp.com/api/users/@me", { headers: { "authorization":`Bearer ${access_token}` } })
    res.send(data.data);
    
  }).catch(e => console.log(`Error: ${e}`));
});

I added in the console.log(access_token); and it logs an access token to the console perfectly fine. My problem is extremely bazarre, I am working on this project with a friend and he set up the application on the developer portal, so I login with my account, and when it does res.send(data.data);, rather than my account's details, I see my friends accounts details. I'm guessing its because he created the discord application and set everything up, but I don't know how to fix it. Thanks!

question from:https://stackoverflow.com/questions/65944053/discord-oauth2-always-returns-the-data-of-the-applications-owner

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...