【发布时间】:2021-12-30 03:07:25
【问题描述】:
我正在尝试在我的网站上实现 Discord-Login。不幸的是,我收到了不和谐的错误。
有人看到我的代码有什么问题吗?
仅供参考:我已经从 discord 中取回了代码。所以我的第一个请求运行良好。
我想对数据做什么:
我想获取 user_ID,以便在我的 Discord 服务器上向用户添加组。
错误:
error: 'unsupported_grant_type',
error_description: 'Grant type None is not supported'
代码:
router.get('/account-settings/connections/discord/callback', (async (req, res) => {
const code = await req.query.code;
const creds = btoa(`${CLIENT_ID}:${CLIENT_SECRET}`);
fetch(`https://discordapp.com/api/oauth2/token`, {
method: "POST",
headers: {
Authorization: `Basic ${creds}`,
},
body: querystring.stringify({
grant_type: 'authorization_code',
code: code,
redirect_uri: dis_redirect
}),
})
.then((res) => res.json())
.then((body) => console.log(body));
})
提前非常感谢您!!!
最好的问候, 乔希
【问题讨论】:
-
您可能错过了:
Content-Type: application/x-www-form-urlencoded,但我不确定!await req.query.code也是可疑的。它和你认为的一样吗? -
我必须把它放在哪里?当用户将他的个人资料授权给我的应用程序时,req.query.code 包含我从不和谐 oauth 获得的代码。所以是的,这应该是正确的:)
标签: javascript node.js oauth discord