程序问答   发布时间:2022-06-02  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了invalid_client 当向 Discord API 发送 OAuth2 请求时大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

如何解决invalid_client 当向 Discord API 发送 OAuth2 请求时?

开发过程中遇到invalid_client 当向 Discord API 发送 OAuth2 请求时的问题如何解决?下面主要结合日常开发的经验,给出你关于invalid_client 当向 Discord API 发送 OAuth2 请求时的解决方法建议,希望对你解决invalid_client 当向 Discord API 发送 OAuth2 请求时有所启发或帮助;

所以我一直在使用 discord 开发登录系统,这是我遇到的第一个障碍。

我正在尝试 POST 到 /oauth2/token/revoke 并且它不断给我返回错误“invalID_clIEnt”。

我试过使用客户端密钥而不使用它,只发送令牌,将名称“access_token”更改为“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 都是有效的。它们可以正常处理其他请求,我已在此页面上显示它们并确认它们有效。

有什么想法吗?我错过了一些愚蠢的东西吗?

解决方法

计算出您需要的字段并稍微调整一下 curl,此代码正在运行。

    [20:12:38] [INF] An account failed to log on.

Subject:
    Security ID:        S-1-0-0
    Account Name:       -
    Account Domain:     -
    Logon ID:       0x0

Logon Type:         3

Account For Which Logon Failed:
    Security ID:        S-1-0-0
    Account Name:       sqa_augstb
    Account Domain:     

Failure Information:
    Failure Reason:     Unknown user name or bad password.
    Status:         0xC000006D
    Sub Status:     0xC000006A

Process Information:
    Caller Process ID:  0x0
    Caller Process Name:    -

Network Information:
    Workstation Name:   VDASW2
    source Network Address: 10.10.2.127
    source Port:        60973

Detailed Authentication Information:
    Logon Process:      NtLmSsp 
    Authentication Package: NTLM
    Transited services: -
    Package Name (NTLM only):   -
    Key Length:     0

This event is generated when a logon request fails. it is generated on the computer where access was attempted.

The Subject fields inDicate the account on the local system which requested the logon. This is most commonly a service such as the Server service,or a local process such as Winlogon.exe or services.exe.

The Logon Type field inDicates the kind of logon that was requested. The most common types are 2 (interactivE) and 3 (network).

The Process Information fields inDicate which account and process on the system requested the logon.

The Network Information fields inDicate where a remote logon request originated. Workstation name is not always available and may be left blank in some cases.

The authentication information fields provide detailed information about this specific logon request.
    - Transited services inDicate which intermediate services have participated in this logon request.
    - Package name inDicates which sub-protocol was used among the NTLM protocols.
    - Key length inDicates the length of the generated session key. This will be 0 if no session key was requested. 

大佬总结

以上是大佬教程为你收集整理的invalid_client 当向 Discord API 发送 OAuth2 请求时全部内容,希望文章能够帮你解决invalid_client 当向 Discord API 发送 OAuth2 请求时所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。