在 curl "connect.stripe.com/oauth/token" 上它不会得到任何响应



https://connect.stripe.com/oauth/authorize?response_type=code&client_id=ca_XXXXXXXXXXXXXXXXXXXXXX&scope=read_write

从上面提到的 API 中,我得到了代码。

$code = $_GET['code'];

从这段代码中,我卷曲了这个 http://connect.stripe.com/oauth/token 但问题是它没有得到任何响应

     echo $code;
$token_request_body = array(
    'grant_type' => 'authorization_code',
    'client_id' => 'ca_xxxxxxxxxxxxxxxxxxxxx',
    'code' => $code,
    'client_secret' => 'XXXXXXXXXXXXXXXXXXX'
);
define("TOKEN_URI", "http://connect.stripe.com/oauth/token");
$req = curl_init(TOKEN_URI);
curl_setopt($req, CURLOPT_RETURNTRANSFER, true);
curl_setopt($req, CURLOPT_POST, true);
curl_setopt($req, CURLOPT_POSTFIELDS, http_build_query($token_request_body));
// TODO: Additional error handling
$respCode = curl_getinfo($req, CURLINFO_HTTP_CODE);
echo $respCode;
$resp = json_decode(curl_exec($req), true);
echo $resp;
curl_close($req);
echo $resp['access_token'];

您的代码通过纯 HTTP 将code发送到端点,这是规范所禁止的,服务器不应返回令牌。stripe.com 的示例代码还显示了一个 HTTPs URL。开关:

define("TOKEN_URI", "http://connect.stripe.com/oauth/token");

自:

define("TOKEN_URI", "https://connect.stripe.com/oauth/token");

FWIW:纯 HTTP URL 实际上重定向到 HTTP,这是您的客户端不处理的事情,也不应该这样做,因为它不安全并且违反了规范。

最新更新