使用 CURL 设置承载令牌的正确方法 [英] Correct way to set Bearer token with CURL
本文介绍了使用 CURL 设置承载令牌的正确方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我从 API 端点获取我的不记名令牌并设置以下内容:
I get my bearer token from an API end point and set the following:
$authorization = "Bearer 080042cad6356ad5dc0a720c18b53b8e53d4c274"
接下来我想使用 CURL 访问安全端点,但是我不确定如何或在哪里设置承载令牌.
Next I want to use CURL to access the secure endpoint however I am unsure on how or where to set the Bearer token.
我已经试过了,但是没有用:
I have tried this but but it does not work:
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json' , $authorization ));
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS,$post);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
$result = curl_exec($ch);
curl_close($ch);
return json_decode($result);
根据文档,我应该使用不记名令牌:https://apigility.org/文档/身份验证/身份验证-oauth2
According to the documentation, I am supposed to be using the bearer token as such: https://apigility.org/documentation/auth/authentication-oauth2
GET /oauth/resource HTTP/1.1
Accept: application/json
Authorization: Bearer 907c762e069589c2cd2a229cdae7b8778caa9f07
推荐答案
替换:
$authorization = "Bearer 080042cad6356ad5dc0a720c18b53b8e53d4c274"
与:
$authorization = "Authorization: Bearer 080042cad6356ad5dc0a720c18b53b8e53d4c274";
使其成为有效且有效的授权标头.
to make it a valid and working Authorization header.
这篇关于使用 CURL 设置承载令牌的正确方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文