小编Max*_*678的帖子

OAuth“unsupported_grant_type”Discord API

我正在努力让不和谐的 OAuth 发挥作用。在文档中,需要生成代码,这一步效果很好,但之后是生成令牌。它要求使用正确的参数发出 POST 请求,但它总是给我带来错误:{"error":"unsupported_grant_type"}

我的代码:

app.get('/discord/callback', async function (req, res) {
    if (req.query.code === undefined || req.query.code == '') return next();

    const response = await fetch("https://discordapp.com/api/v6/auth2/token", {
        method: 'POST',
        headers: {
            "Content-type": "application/x-www-form-urlencoded"
        },
        data: {
            client_id: process.env.CLIENT_ID,
            client_secret: process.env.CLIENT_SECRET,
            code: req.query.code,
            redirect_uri: redirect,
            grant_type: "authorization_code",
            scope: "identify"
        }
    });
    const json = await response.json();

    debug('%O', json);
    res.send(json);
});
Run Code Online (Sandbox Code Playgroud)

文档:

def exchange_code(code):
  data = {
    'client_id': CLIENT_ID,
    'client_secret': CLIENT_SECRET,
    'grant_type': 'authorization_code',
    'code': code,
    'redirect_uri': REDIRECT_URI,
    'scope': 'identify email …
Run Code Online (Sandbox Code Playgroud)

javascript oauth node.js discord

3
推荐指数
1
解决办法
4950
查看次数

标签 统计

discord ×1

javascript ×1

node.js ×1

oauth ×1