使用 paypal api 的客户端无效,使用 HTTPoison.post!/3 的客户端身份验证失败 [英] Invalid Client with paypal api, client authentication failed using HTTPoison.post!/3

查看:24
本文介绍了使用 paypal api 的客户端无效,使用 HTTPoison.post!/3 的客户端身份验证失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 HTTPoison 向 Paypal api 发送请求.这是使用其 api 登录的 paypal 文档:https://developer.paypal.com/docs/log-in-with-paypal/integrate/

I am using HTTPoison to send request to the Paypal api. Here is the paypal documentation for using its api for logging in: https://developer.paypal.com/docs/log-in-with-paypal/integrate/

当我获取代码并尝试将其交换为访问令牌时,出现此错误:"{\"error\":\"invalid_client\",\"error_description\":\"客户端身份验证失败\"}",

When I get the code, and try to exchange it for an access token, I get this error: "{\"error\":\"invalid_client\",\"error_description\":\"Client Authentication failed\"}",

HTTPoison.post!/3 发布请求的方式如下:

Here is how HTTPoison.post!/3 post request:

url = "https://api-m.sandbox.paypal.com/v1/oauth2/token"
headers = [
  Authorization: "Basic #{ClientID}:#{Secret}" 
]
body = "grant_type=authorization_code&code=#{code}"

HTTPoison.post!(url, body, headers)

这显示了 status_code: 401{\"error\":\"invalid_client\",\"error_description\":\"ClientAuthentication failed\"}", error.. 这个问题怎么解决?

This shows the a status_code: 401 and {\"error\":\"invalid_client\",\"error_description\":\"Client Authentication failed\"}", error.. How can this issue be solved?

推荐答案

HTTP 基本身份验证要求值为 base-64 编码.尝试这样做:

HTTP Basic Authentication requires the value to be base-64 encoded. Try doing that:

Authorization: "Basic " <> Base.encode64("#{ClientID}:#{Secret}")

这篇关于使用 paypal api 的客户端无效,使用 HTTPoison.post!/3 的客户端身份验证失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆