【发布时间】:2020-06-14 21:03:25
【问题描述】:
正如标题所述,每当我尝试从 Web 服务 API 请求任何端点时,我都会收到 401 响应(我正在运行 orocrm 4.1,并且生成了公钥 + 私钥并以正确的名称放置在 /var 中) .
1。创建了 OAuth 应用程序
Grant type = client_credentials(所选用户拥有所有管理员权限):
2。获取令牌(使用 GuzzleHttp 客户端)
$base_uri = 'https://mywebsite.com';
$generate_token_endpoint = '/oauth2-token';
$grant_type = 'client_credentials';
$client_id = '###############################';
$client_secret = '#################################';
$client = new Client(array(
'base_uri' => $base_uri,
'headers' => array(
'Content-Type' => 'application/vnd.api+json'
)
));
$response = $client->post($generate_token_endpoint, array(
'form_params' => array(
'grant_type' => $grant_type,
'client_id' => $client_id,
'client_secret' => $client_secret
)
));
$tokenJson = json_decode($response->getBody()->getContents(), true);
$token = 'Bearer '.$tokenJson['access_token'];
// The actual request to get some data
$response = $client->get('/api/users', array(
'headers' => array(
'Authorization' => $token
)
));
我确实收到了一个令牌,我什至延长了它的生命周期,但是下一个请求的结果是(不管我做什么):
Client error: 'GET https://mywebsite.com/api/users' resulted in a '401 Unauthorized' response
我也尝试过使用 POSTMAN,但结果是一样的。
帮助!
【问题讨论】: