【发布时间】:2021-07-21 07:33:22
【问题描述】:
所以我一直在使用 Discord 开发登录系统,这是我遇到的第一个障碍。
我正在尝试 POST 到 /oauth2/token/revoke,但它不断给我返回错误“invalid_client”。
我尝试过使用客户端密码而不使用它,只发送令牌,将名称“access_token”更改为“令牌”,以及其他一些我不记得的事情。
我发送请求的代码是这样的:
session_start();
//debug thing
echo OAUTH2_CLIENT_ID;
$params = array(
"access_token" => $_SESSION["access_token"],
"client_id" => OAUTH2_CLIENT_ID
);
apiRequest("https://discordapp.com/api/oauth2/token/revoke", $params);
该 apiRequest 函数的代码改编自这里的不同线程,如下所示:
function apiRequest($url, $post=FALSE, $headers=array()) {
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$response = curl_exec($ch);
if($post) {
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post));
$headers[] = 'Content-Type: application/x-www-form-urlencoded';
}
$headers[] = 'Accept: application/json, application/x-www-form-urlencoded';
if(isset($_SESSION["access_token"]))
$headers[] = 'Authorization: Bearer ' . $_SESSION["access_token"];
// using this to see my headers
var_dump($headers);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($ch);
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ($code != 200) {
//using this to see the error
echo $response;
exit();
fatalError($code, $_SERVER[REQUEST_URI]);
}
return $response;
}
是的,访问令牌和客户端 ID 都是有效的。它们在其他请求上正常工作,我已在此页面上显示它们并确认它们是有效的。
有什么想法吗?我错过了什么愚蠢的东西吗?
【问题讨论】: