【问题标题】:Can't fix Paypal "invalid_client" authentication error无法修复 Paypal“invalid_client”身份验证错误
【发布时间】:2021-04-07 09:03:48
【问题描述】:

我正在尝试使用 Paypal 沙盒从 localhost 测试我的 Paypal 集成,但每当我尝试从 Paypal 获取访问令牌时,都会返回以下错误:

{
    "error": "invalid_client",
    "error_description": "Client Authentication failed"
}

我用 curl 提出请求:

curl -v https://api.sandbox.paypal.com/v1/oauth2/token \
-H "Accept: application/json" \
-H "Accept-Language: en_US" \
-u "clientId:secret" \ 
-d "grant_type=client_credentials"

显然我在请求中使用了实际的客户端 ID 和密码,并且我确定我在沙盒环境中使用了正确的客户端 ID 和密码(我仔细检查了)。

Curl 的详细日志如下所示:

curl -v https://api.sandbox.paypal.com/v1/oauth2/token \
> -H "Accept: application/json" \
> -H "Accept-Language: en_US" \
-u "clientId:secret" \ 
> -d "grant_type=client_credentials"
*   Trying 173.0.82.78...
* TCP_NODELAY set
* Connected to api.sandbox.paypal.com (173.0.82.78) port 443 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
* Cipher selection: ALL:!EXPORT:!EXPORT40:!EXPORT56:!aNULL:!LOW:!RC4:@STRENGTH
* successfully set certificate verify locations:
*   CAfile: /etc/ssl/cert.pem
  CApath: none
* TLSv1.2 (OUT), TLS handshake, Client hello (1):
* TLSv1.2 (IN), TLS handshake, Server hello (2):
* TLSv1.2 (IN), TLS handshake, Certificate (11):
* TLSv1.2 (IN), TLS handshake, Server key exchange (12):
* TLSv1.2 (IN), TLS handshake, Request CERT (13):
* TLSv1.2 (IN), TLS handshake, Server finished (14):
* TLSv1.2 (OUT), TLS handshake, Certificate (11):
* TLSv1.2 (OUT), TLS handshake, Client key exchange (16):
* TLSv1.2 (OUT), TLS change cipher, Client hello (1):
* TLSv1.2 (OUT), TLS handshake, Finished (20):
* TLSv1.2 (IN), TLS change cipher, Client hello (1):
* TLSv1.2 (IN), TLS handshake, Finished (20):
* SSL connection using TLSv1.2 / ECDHE-RSA-AES128-GCM-SHA256
* ALPN, server did not agree to a protocol
* Server certificate:
*  subject: C=US; ST=California; L=San Jose; O=PayPal, Inc.; OU=PayPal Production; CN=api.sandbox.paypal.com
*  start date: Jul 27 00:00:00 2020 GMT
*  expire date: Aug  1 12:00:00 2022 GMT
*  subjectAltName: host "api.sandbox.paypal.com" matched cert's "api.sandbox.paypal.com"
*  issuer: C=US; O=DigiCert Inc; OU=www.digicert.com; CN=DigiCert SHA2 High Assurance Server CA
*  SSL certificate verify ok.
* Server auth using Basic with user 'clientId' // The original log has the actual clientId here
> POST /v1/oauth2/token HTTP/1.1
> Host: api.sandbox.paypal.com
> Authorization: Basic QVRQZGl5TTFqeXpQZkdxMW9FQ2xnZG1uUE13VDRQM01yZEJ1MGRGWVZGLWRNVjk1X09xVjZVam1nNU5xRC0wR2ZPT1I3U1ZianYybWQzQXc6RURQSVdoREpPM0dkdndYNVlRaG45QzRCYzBlUTctaEpWZ041ZlVjUlpkbG1Ta0pMelhzZXE0TmpXeEZMV3kwcGdBNE5zTE5MZ1Qyc0pBVW0=
> User-Agent: curl/7.54.0
> Accept: application/json
> Accept-Language: en_US
> Content-Length: 29
> Content-Type: application/x-www-form-urlencoded
> 
* upload completely sent off: 29 out of 29 bytes
< HTTP/1.1 401 Unauthorized
< Cache-Control: max-age=0, no-cache, no-store, must-revalidate
< Content-Length: 77
< Content-Type: application/json
< Date: Wed, 07 Apr 2021 08:57:50 GMT
< Paypal-Debug-Id: 891f84363e502
< X-Paypal-Token-Service: IAAS
< 
* Connection #0 to host api.sandbox.paypal.com left intact
{"error":"invalid_client","error_description":"Client Authentication failed"}

问题似乎出在这里:

ALPN, server did not agree to a protocol

我不知道这意味着什么。这可能与我从 localhost 进行测试的事实有关吗?我该如何解决这个问题?

【问题讨论】:

  • 不不,我改了。原始日志中包含实际的 clientId。

标签: paypal


【解决方案1】:

在详细日志中解码base64,传递的客户端ID为ATPdiyM1jyzPfGq1oEClgdmnPMwT4P3MrdBu0dFYVF-dMV95_OqV6Ujmg5NqD-0GfOOR7SVbjv2md3Aw

这在 https://developer.paypal.com/demo/checkout/#/pattern/client 测试时不起作用,因此它不是有效的 ID。

(Link showing the error, "client-id 不能用于生产或沙箱")


创建一个新的 REST 应用,https://www.paypal.com/signin?intent=developer&returnUri=https%3A%2F%2Fdeveloper.paypal.com%2Fdeveloper%2Fapplications

【讨论】:

  • 感谢您的帮助。你怎么知道它不是一个有效的ID?我刚刚尝试在这里用我的客户 ID 替换“测试”:&lt;script src="https://www.paypal.com/sdk/js?client-id=test&amp;currency=USD"&gt;&lt;/script&gt;,当我点击 Paypal 按钮时,我确实看到了 Paypal 对话框......这不意味着 ID 有效吗?无论如何都会尝试创建一个新应用。
  • 如果它成功了,你一定是用ATPdiyM1jyzPfGq1oEClgdmnPMwT4P3MrdBu0dFYVF-dMV95_OqV6Ujmg5NqD-0GfOOR7SVbjv2md3Aw以外的东西替换了它——即一个有效的ID。
  • 不,我刚刚用ATPdiyM1jyzPfGq1oEClgdmnPMwT4P3MrdBu0dFYVF-dMV95_OqV6Ujmg5NqD-0GfOOR7SVbjv2md3Aw 再次尝试了它,它对我有用,我确实得到了 Paypal 盒子......无论如何,我已经按照你的建议创建了一个新的 REST 应用程序,现在我的集成作品。再次感谢!
  • paypal.com/sdk/… , "client-id 无法用于生产或沙箱" ... 耸耸肩
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-12-02
  • 2014-04-11
  • 2011-08-04
  • 1970-01-01
  • 1970-01-01
  • 2023-03-07
  • 1970-01-01
相关资源
最近更新 更多