小编luk*_*lyz的帖子

OAuth2:Discord API 始终响应 {"error": "invalid_grant"}

我正在尝试在我的node.js 应用程序中实现Discord OAuth2。一旦我尝试从给定的授权代码获取访问令牌,我总是会收到 HTTP 响应错误 400 {"error": "invalid_grant"}

let xhr = new XMLHttpRequest()
xhr.open('POST', 'https://discord.com/api/oauth2/token')

xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded')

let payload ={
    client_id: clientID,
    client_secret: clientSecret,
    grant_type: 'authorization_code',
    code: code,
    redirect_uri: redirectUrl,
    scope: 'identify'
};

console.log(payload)
xhr.send(JSON.stringify(payload))

xhr.onreadystatechange = () => {
    console.log(xhr.status)
    console.log(xhr.responseText)
}

xhr.onerror = () => {
    console.log('Failed')
}
Run Code Online (Sandbox Code Playgroud)

javascript http oauth node.js discord

5
推荐指数
1
解决办法
7446
查看次数

标签 统计

discord ×1

http ×1

javascript ×1

node.js ×1

oauth ×1