小编pro*_*007的帖子

Discord Ouath2 访问令牌“不支持授予类型无”

我正在尝试为我的用 Express 制作的网站制作一个不和谐的登录系统。我创建了一个函数来获取访问令牌,以便我可以在路由中使用该函数。

我试图从以下位置获取访问令牌:https://discord.com/api/oauth2/token

这是我的代码:

    async GetToken(code) {
        let access_token;
        const payload = {
            'client_id': client_id,
            'client_secret': client_secret,
            'grant_type': 'authorization_code',
            'code': code,
            'redirect_uri': redirect_uri,
            'scope': scope,
        };
        const config = {
            headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
        };
        fetch(discord_token_url, {
            method: 'post',
            body: payload,
            headers: config.headers,
        }).then(response => response.json()).then(json => console.log(json)).catch(err => console.log(err));
        return access_token;
    },
Run Code Online (Sandbox Code Playgroud)

这是我得到的错误:

{
  error: 'unsupported_grant_type',
  error_description: 'Grant type None is not supported'
}
Run Code Online (Sandbox Code Playgroud)

正如您所看到的,我已经给出了正确的授权类型,但我收到了此错误。

node.js oauth-2.0 express discord

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

标签 统计

discord ×1

express ×1

node.js ×1

oauth-2.0 ×1