[英]When I use Discord OAuth2 I am getting error 400. How can I make this return the access_token correctly?
I am unable to get the clients identiy through discords oauth2.我无法通过不和谐 oauth2 获取客户身份。 First we do this:
首先我们这样做:
https://discord.com/api/oauth2/authorize?client_id=9999999999999&redirect_uri=http%3A%2F%2Fxxxx.xyz%2F&response_type=code&scope=identify https://discord.com/api/oauth2/authorize?client_id=9999999999999&redirect_uri=http%3A%2F%2Fxxxx.xyz%2F&response_type=code&scope=identify
to get their code.获取他们的代码。 Which seems to work fine.
这似乎工作正常。
let options = {
url: 'https://discord.com/api/oauth2/token',
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
body: new URLSearchParams({
'client_id': '9999999999999',
'client_secret': 'MYSECRETHERE',
'grant_type': 'authorization_code',
'code': code,
'redirect_uri': 'https://xxxx.xyz/callback',
'scope': 'identify'
}).toString()
};
await fetch("https://discord.com/api/oauth2/token", options)
.then(handleErrors)
.then(response => response.json())
.then(response => {
access_token = response.access_token;
}).catch(function(error) {
console.log(error);
});
What happens here is I get a error 400 instead of the access token.这里发生的是我收到错误 400 而不是访问令牌。 Originally the 'grant_type' was set as client_credientals but I realized that this only grabs the identity of the application owner itself, not others.
最初,“grant_type”被设置为 client_credientals,但我意识到这只会获取应用程序所有者本身的身份,而不是其他人。 This worked however.
然而,这奏效了。 Changing it to authorization_code however does not.
但是,将其更改为 authorization_code 不会。
Any suggestions?有什么建议么?
Compared to the token exchange example , you are passing scope
in the request – that shouldn't be there.与令牌交换示例相比,您在请求中传递了
scope
——这不应该存在。 Scope is passed only in the initial authorization URL.范围仅在初始授权 URL 中传递。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.