简体   繁体   English

如何包含sope数据以生成访问令牌Oauth2.0?

[英]How to include the sope datas to generate an access token Oauth2.0?

I need to generate an access token Oauth2.0 to call a webservice. 我需要生成访问令牌Oauth2.0才能调用Web服务。

My PHP script return an access token but when i call the webservice with this token i have an error code 115 (OAuth access token is not valid). 我的PHP脚本返回访问令牌,但是当我使用此令牌调用We​​b服务时,我收到错误代码115(OAuth访问令牌无效)。

$client_id = 'XXXXX';
$client_secret = 'XXXXX';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,'XXXXX/auth/oauth/v2/token' );
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt($ch, CURLOPT_POST, 1 );
curl_setopt($ch, CURLOPT_POSTFIELDS, 'grant_type=client_credentials');
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: Basic '.base64_encode($client_id.':'.$client_secret)));
$res = curl_exec($ch);

I tried with postman to generate an access token with the same datas such as my PHP script i have the same error code (115) but when i add the scope datas, the access token generate is now valid to call the webservice. 我尝试与邮递员生成具有相同数据的访问令牌,例如我的PHP脚本,我具有相同的错误代码(115),但是当我添加范围数据时,生成的访问令牌现在可以调用Web服务了。

Do you know how to include the scope datas on my PHP script ? 您知道如何在我的PHP脚本中包含范围数据吗?

Provide a scope request parameter whose value is set a form-encoded list of requested scopes separated by spaces. 提供一个范围请求参数,其值设置为一个用空格分隔的请求范围的形式编码列表。 Eg to request read and write scopes you'd use: 例如要求readwrite你使用范围:

curl_setopt($ch, CURLOPT_POSTFIELDS, 'scope=read%20write');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将 curl 转换为 php OAuth2.0 令牌生成错误 - convert curl to php OAuth2.0 Token Generate Error 在Oauth2.0中刷新令牌 - Refresh token in Oauth2.0 Google OAuth2.0 php客户端使用刷新令牌交换访问令牌 - Google OAuth2.0 php client exchange access token with refresh token 如何仅通过服务器获取OAuth2.0访问令牌?(我有用户名/密码) - How can I get a OAuth2.0 access token only by my server?(I have my username/passward) PHP cURL在标头和POST JSON数据中发送oauth2.0 access_token - PHP cURL send oauth2.0 access_token in header and POST json data 使用PHP cURL获取access_token时,Google OAuth2.0返回“ invalid_request” - Google OAuth2.0 returns 'invalid_request' when getting access_token with PHP cURL PHPleague oauth2.0 客户端在 access_token 中使用 post 请求访问时出错 - PHPleague oauth2.0 Client Error when accessing with post request in access_token Linkedin REST API:使用CRON作业中的php更新OAuth2.0访问令牌吗? - Linkedin REST API: Update OAuth2.0 Access token using php from a CRON job? PHP中的Oauth2.0服务器非常简单的实现-在POST中使用access_token - Oauth2.0 server in php very simple implementation - use access_token with POST 如何解决OAuth 2.0中的access_token - how to solve access_token in OAuth 2.0
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM