SuiteCRM API完全身份验证和登录 [英] SuiteCRM API full authentication and login
问题描述
是否可以通过后台API登录获得对SuiteCRM的完全访问权限?
Is there a away to gain full access to SuiteCRM through background API login?
例如,我们在单独的站点上使用LDAP,我想将经过身份验证的用户传递给后台的suitecrm,然后让suitecrm将访问权限授予该用户,而无需他们第二次登录.
For example, we use LDAP on a separate site and I want to pass authenticated users to suitecrm in the background then have suitecrm grant access to said user without them having to log in for a second time.
我已经能够使用该API并登录"用户并返回session_id,但是它仍然将我定向到登录页面.如果我尝试强制重定向,则会得到err_to_many_redirects.
I have been able to get the API to work and 'login' a user and return a session_id, however it still directs me to the login page. If I attempt to force a redirect I get an err_to_many_redirects.
我不认为该问题是由API脚本引起的,而是使用返回的数据来完成所需的会话数据,而这些数据我仍可以生成.
I do not believe the issue arises from the API script but using the returned data to complete the session data required, which I have yet been able to generate.
<?php
error_reporting(E_ALL);
ini_set('display_errors',1);
require_once('./shield_secureaccess.php');
$url = "http://{site_location}/service/v4_1/rest.php";
session_start();
$username = $_SESSION['SHIELD_user'];
session_write_close();
if(isset($username)){
$password = shield_secureaccess($username);}
else{require 'shield_session.php';}
//function to make cURL request
function call($method, $parameters, $url)
{
ob_start();
$curl_request = curl_init();
curl_setopt($curl_request, CURLOPT_URL, $url);
curl_setopt($curl_request, CURLOPT_POST, 1);
curl_setopt($curl_request, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
curl_setopt($curl_request, CURLOPT_HEADER, 1);
curl_setopt($curl_request, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($curl_request, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl_request, CURLOPT_FOLLOWLOCATION, 0);
$jsonEncodedData = json_encode($parameters);
$post = array(
"method" => $method,
"input_type" => "JSON",
"response_type" => "JSON",
"rest_data" => $jsonEncodedData
);
curl_setopt($curl_request, CURLOPT_POSTFIELDS, $post);
$result = curl_exec($curl_request);
curl_close($curl_request);
$result = explode("\r\n\r\n", $result, 2);
$response = json_decode($result[1]);
ob_end_flush();
return $response;
}
//login ------------------------------
$login_parameters = array(
"user_auth" => array(
"user_name" => $username,
"password" => md5($password),
"version" => "1"
),
"application_name" => "RestTest",
"name_value_list" => array(),
);
$login_result = call("login", $login_parameters, $url);
echo "<pre>";
// print_r($_SESSION);
print_r($login_result);
// print_r($current_user);
print_r($_SESSION);
echo "</pre>";
//get session id
$session_id = $login_result->id;
// header("Location: http://{site_location}/index.php?module=Home&action=inde");
// header("Location: http://{site_location}/index.php?MSID=$session_id");
?>
推荐答案
您快到了.无法立即使用会话ID进行登录,您必须首先调用seamless_login
.
You're almost there. The session id can't be used straight away to login, you first must call seamless_login
.
所以流程是:
- 按照上面的步骤登录API.
- 调用Seamless_login将返回0或1
- 将用户导航到
http://{site_location}/index.php?MSID=$session_id
,其中$session_id
是来自原始API登录调用的会话ID.
- Do API login as above.
- Call seamless_login this will return 0 or 1
- Navigate the user to
http://{site_location}/index.php?MSID=$session_id
where$session_id
is the session id from the original API login call.
这篇关于SuiteCRM API完全身份验证和登录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!