【问题标题】:Client credentials invalid error for external API authentication, when credentials are correct in Processmaker当 Processmaker 中的凭据正确时,外部 API 身份验证的客户端凭据无效错误
【发布时间】:2021-02-24 08:09:22
【问题描述】:

我正在尝试从 Processmaker 获取身份验证令牌以使用 API。我使用了相同的 API 调用,它在测试环境中运行良好,带有生产 url 和各自的客户端 ID 和客户端密码。但是,尽管帐户的用户名和密码是正确的,但我遇到了错误。

请求:

{
    "grant_type": "password",
    "scope": "*",
    "client_id": "xxxxxx",
    "client_secret":"7777777",
    "username": "username",
    "password": "password"
}

回应:

{
    "error": "invalid_client",
    "error_description": "The client credentials are invalid"
}

我尝试了以下步骤。但还是同样的错误。

  1. 创建一个没有 AD 用户帐户的新帐户,因为在测试环境中使用的帐户不是域帐户
  2. 将帐号的角色更改为“系统管理员”,类似于测试中的帐号

**在注册客户端使用 API 时,我们没有使用回调 URL,因为它是可选的(我们也没有在测试环境中配置它)

非常感谢一些帮助,因为我不知道在环境之间还有什么可以检查来解决这个问题。

【问题讨论】:

    标签: api rpa processmaker


    【解决方案1】:

    我不确定您是尝试从 ProcessMaker 调用 API 到 RPA 还是 RPA 到 ProcessMaker。

    对于 ProcessMaker 到 RPA:

    使用脚本:我在 PHP 中构建了一个 ProcessMaker 脚本,并且通过适当的脚本配置,您将能够从 ProcessMaker 运行 RPA 机器人。

    <?php 
    
    /*  
     *  Yo. This script is developed by Abhishek Kadam.
     *  This script is sufficient to run all the Microbots. 
     *  The Script Configuration contains "release_key" which is the Process ID,
     *  "robot_id" which is to identify where to run the Bot, "orch_unit_id" which is the folder name
     *  and "orch_url" which stands for Orchestrator URL. To Run the bot, All the configurations are required. 
     */
    
    
    //******ASSIGNING VARIABLES*****
    $client_id = $config['client_id'];   // $config to get data from Script Configuration
    $refresh_token = $config['refresh_token'];
    $release_key = $config['release_key'];
    $robot_id = $config['robot_id'];
    $orch_url = $config['orch_url'];
    $orch_unit_id = $config["orch_unit_id"];
    
    
    
    
    //****** GET ACCESS TOKENS USING CLIENT ID AND REFRESH TOKENS******
    $access_token = getAccessToken($client_id,$refresh_token);
    $output_response = runBot($access_token,$release_key,$robot_id,$orch_url,$orch_unit_id);   
    //pass the Access token to runbot() and run the bot ez-pz! 
    
    
    
    
    function getAccessToken($client_id,$refresh_token){
      $curl = curl_init();
      curl_setopt_array($curl, array(
        CURLOPT_URL => "https://account.uipath.com/oauth/token",
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_ENCODING => "",
        CURLOPT_MAXREDIRS => 10,
        CURLOPT_TIMEOUT => 0,
        CURLOPT_FOLLOWLOCATION => true,
        CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
        CURLOPT_CUSTOMREQUEST => "POST",
        CURLOPT_POSTFIELDS =>"{\r\n    \"grant_type\": \"refresh_token\",\r\n    \"client_id\": \"".$client_id."\",\r\n    \"refresh_token\": \"".$refresh_token."\"\r\n}",
        CURLOPT_HTTPHEADER => array(
          "Content-Type: application/json"
        ),
      ));
      
      $response = curl_exec($curl);
    
      curl_close($curl);
    
    
      $responseDecode = json_decode($response);
      $accessToken= $responseDecode -> access_token;  //get the access token
      return $accessToken;
    }
    
    
    
    function runBot($access_token,$release_key,$robot_id,$orch_url,$orch_unit_id){
      
      $curl = curl_init();  //Not sure if it's the right way to initialize or not but meh, it works :P 
    
     
    
      curl_setopt_array($curl, array(
        CURLOPT_URL => $orch_url."/odata/Jobs/UiPath.Server.Configuration.OData.StartJobs",
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_ENCODING => "",
        CURLOPT_MAXREDIRS => 10,
        CURLOPT_TIMEOUT => 0,
        CURLOPT_FOLLOWLOCATION => true,
        CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
        CURLOPT_CUSTOMREQUEST => "POST",
        CURLOPT_POSTFIELDS =>"{ \"startInfo\":\r\n   { \"ReleaseKey\": \"".$release_key."\",\r\n     \"Strategy\": \"Specific\",\r\n     \"RobotIds\": [ ".$robot_id."],\r\n     \"JobsCount\": 0,\r\n     \"Source\": \"Manual\" \r\n   } \r\n}",
        // Release key and Robot ID can be concatenated and passed as an argument(once I figure out how to get arguments in PM 4 scripts)
        CURLOPT_HTTPHEADER => array(
          "Content-Type: application/json",
          "Authorization: Bearer ".$access_token,
          "X-UIPATH-OrganizationUnitId: ".$orch_unit_id
    
        //There's another way to use the Access token. For now, I found this more helpful.
        //As the document is TL;DR. https://www.php.net/manual/en/function.curl-setopt.php
        
        ),
      ));
    
      $response = curl_exec($curl);
      curl_close($curl);
      return $response;
    //echo $response; //Print Response cuz why not? ;) 
    }
     return [$access_token];
    
    
    ?>
    

    我为此使用了 UiPath RPA 工具,但没有提及任何回调 URL。

    使用数据连接器:在 ProcessMaker 中创建数据连接器。我更喜欢在创建 DC 之前使用 Postman 应用程序。参考:Postman to UiPath Bot

    RPA 机器人到 ProcessMaker 在 ProcessMaker 文档中,您可以看到特定实例的 Swagger Link。 ProcessMaker 的 Swagger 文档并没有真正的帮助。提供的文档中几乎没有错误。 为方便起见,我确实在 Postman 中导入了 API 集合并继续创建变量:baseURL & accessToken

    baseURL:你的 URL (https://something.processmaker.net)

    添加/api/1.0

    /api/1.0 (https://something.processmaker.net/api/1.0)

    现在 URL 是正确的。此外,在发送请求时,请确保 Params 不为空。

    注意:对于访问令牌,管理员 --> 用户 --> 编辑 --> API 令牌 --> 创建新令牌 --> 复制令牌。 在 Processmaker 4 中,API 令牌可供个人用户使用。

    我希望这对您有所帮助。谢谢!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-08-02
      • 2016-01-10
      • 2023-02-19
      • 1970-01-01
      • 2023-02-08
      • 2021-07-22
      • 2013-03-17
      • 2015-12-20
      相关资源
      最近更新 更多