vTiger REST login error: "INVALID_AUTH_TOKEN" (php and/or python)

vTiger REST login error: "INVALID_AUTH_TOKEN" (php and/or python)

我正在尝试使用 vTiger REST API 但我一直碰壁 - 我无法通过登录身份验证 (!)。

我已经按照指南和说明完成了所有操作,但是本应该是一个相当简单的过程却无法正常工作,总是给我提供相同的错误。

我已经通过 python 和 php 在两个不同的服务器上使用过它,但结果是一样的。

我做错了什么?

PHP代码:

<?php

$usercode = 'x5pox9oihbjp1pna';

$service_url = '<VTIGER ROOT>/webservice.php';
                
$curl = curl_init($service_url);
$curl_post_data = array(
    'operation'=> 'getchallenge',
    'username' => 'admin',
    );

   curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
   curl_setopt($curl, CURLOPT_POST, true);
   curl_setopt($curl, CURLOPT_POSTFIELDS, $curl_post_data);
   curl_setopt($curl ,CURLOPT_SSL_VERIFYPEER, false); //one server is ssl so i use this, the other isn't so i discard this when i try that one.

   $curl_response = curl_exec($curl);
   curl_close($curl);

   echo "<p> First response: $curl_response<p>";
   $x = json_decode($curl_response);
   $token =  var_export($x->result->token, true);
   $token = substr($token, 1, -1); //getting rid of excess quote marks
   echo "<p> token: $token  </p>";
   
   echo "<p> finished part 1 of php script</p>";
   
    $combined = $token.$usercode;
    
    echo "<p> token: $token  </p>";
    echo "<p> userAccessKey: $usercode  </p>";
    echo "<p> token + userAccessKey: $combined  </p>";
    
    $accessKeyHash= md5($combined);
    echo "<p>Full Acces Key Hash: $accessKeyHash</p>";
    
    $curl = curl_init($service_url);
    $curl_post_data = array(
    'operation'=> 'login',
    'username' => 'admin',
    'accessKey' => $accessKeyHash
    );

   curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
   curl_setopt($curl, CURLOPT_POST, true);
   curl_setopt($curl, CURLOPT_POSTFIELDS, $curl_post_data);
   curl_setopt($curl ,CURLOPT_SSL_VERIFYPEER, false); 
  
  $curl_response = curl_exec($curl);
   curl_close($curl);
   
   echo "<p> Second response: $curl_response<p>";
   echo "<p> finished part 2 of php script</p>";

输出为:

First response: {"success":true,"result":{"token":"591432eb404da","serverTime":1494495979,"expireTime":1494496279}}

token: 591432eb404da

finished part 1 of php script

token: 591432eb404da

userAccessKey: x5pox9oihbjp1pna

token + userAccessKey: 591432eb404dax5pox9oihbjp1pna

Full Acces Key Hash: 07700eafa6aea78c2602d84fc83b3f73

Second response: {"success":false,"error":{"code":"INVALID_AUTH_TOKEN","message":"Specified token is invalid or expired"}}

finished part 2 of php script

尝试替换这个:

$token =  var_export($x->result->token, true);
$token = substr($token, 1, -1); //getting rid of excess quote marks

通过这个:

$token = $x->{'result'}->{'token'};

您正在执行 POST getchallenge 操作请求。应该是GET请求。

更改您的第一个 POST 请求:

$curl = curl_init($service_url);
$curl_post_data = array(
    'operation'=> 'getchallenge',
    'username' => 'admin',
);

curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $curl_post_data);
curl_setopt($curl ,CURLOPT_SSL_VERIFYPEER, false);

对于此 GET 请求:

$vtiger_user = 'admin';
$curl = curl_init($service_url . '?operation=getchallenge&username=' . $vtiger_user);
//$curl_post_data = array(
    //'operation'=> 'getchallenge',
    //'username' => 'admin',
//);

curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
//curl_setopt($curl, CURLOPT_POST, true);
//curl_setopt($curl, CURLOPT_POSTFIELDS, $curl_post_data);
curl_setopt($curl ,CURLOPT_SSL_VERIFYPEER, false);

你的第二个请求没问题,应该是POST请求。只需更改上面的部分即可。

源码: 我一直调试到成功