【问题标题】:Orocrm - Web API OAuth, request returns 401Orocrm - Web API OAuth,请求返回 401
【发布时间】: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,但结果是一样的。

帮助!

【问题讨论】:

    标签: oauth-2.0 guzzle orocrm


    【解决方案1】:

    请确保您正确生成了加密密钥并将它们放置到具有适当名称的 var 文件夹中:https://doc.oroinc.com/user/back-office/system/user-management/oauth-app/#starting-conditions 当密钥配置不正确时,在带有 oAuth 应用程序的页面上,您将看到警告

    OAuth 授权不可用作加密密钥配置 不完整。请联系您的管理员。

    如果密钥在那里,您必须在身份验证后检查应用程序日志是否有错误。另外,检查来自服务器的响应。通常,它会提示一些问题。

    【讨论】:

      【解决方案2】:

      请生成 public.key 或 private.key 并存储到 var 文件夹,如:

      app folder / var / oauth_private.key
      app folder / var / oauth_public.key
      

      您可以按照以下步骤操作:

      1. openssl genrsa -out oauth_private.key 2048
      2. openssl rsa -in private.key -pubout -out oauth_public.key
      3. 然后移动到 var 文件夹

      参考链接

      https://oauth2.thephpleague.com/installation/#generating-public-and-private-keys
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-03-14
        • 2021-08-08
        • 1970-01-01
        • 2019-01-05
        • 1970-01-01
        • 1970-01-01
        • 2011-12-10
        • 1970-01-01
        相关资源
        最近更新 更多