SuiteCRM API 完全认证和登录 [英] SuiteCRM API full authentication and login

查看:41
本文介绍了SuiteCRM API 完全认证和登录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以通过后台 API 登录获得对 SuiteCRM 的完全访问权限?

例如,我们在一个单独的站点上使用 LDAP,我想在后台将经过身份验证的用户传递给suitecrm,然后让suitcrm 授予该用户访问权限,而无需他们再次登录.

我已经能够让 API 工作并登录"用户并返回 session_id,但是它仍然将我定向到登录页面.如果我尝试强制重定向,我会收到 err_to_many_redirects.

我不认为问题出自 API 脚本,而是使用返回的数据来完成所需的会话数据,而我尚未能够生成这些数据.

以下代码来自 http://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_6.5/Application_Framework/Web_Services/Examples/REST/PHP/Logging_In/

$方法,输入类型" =>"JSON",响应类型" =>"JSON",rest_data" =>$jsonEncodedData);curl_setopt($curl_request, CURLOPT_POSTFIELDS, $post);$result = curl_exec($curl_request);curl_close($curl_request);$result = expand("\r\n\r\n", $result, 2);$response = json_decode($result[1]);ob_end_flush();返回 $response;}//登录  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -$login_parameters = 数组(user_auth" =>大批(用户名"=>$用户名,密码" =>md5($密码),版本" =>1"),应用程序名称"=>"休息测试",name_value_list"=>大批(),);$login_result = call("登录", $login_parameters, $url);echo "

";//print_r($_SESSION);print_r($login_result);//print_r($current_user);打印_r($_SESSION);echo "</pre>";//获取会话ID$session_id = $login_result->id;//header("位置:http://{site_location}/index.php?module=Home&action=inde");//header("位置:http://{site_location}/index.php?MSID=$session_id");?>

解决方案

大功告成.会话 ID 不能立即用于登录,您首先必须调用 seamless_login.

所以流程是:

  1. 如上进行 API 登录.
  2. 调用 seamless_login 这将返回 0 或 1
  3. 将用户导航到 http://{site_location}/index.php?MSID=$session_id,其中 $session_id 是原始 API 登录调用的会话 ID.

Is there a away to gain full access to SuiteCRM through background API login?

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.

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.

EDIT:

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.

Code below acquired from http://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_6.5/Application_Framework/Web_Services/Examples/REST/PHP/Logging_In/

<?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");
?>

解决方案

You're almost there. The session id can't be used straight away to login, you first must call seamless_login.

So the flow is:

  1. Do API login as above.
  2. Call seamless_login this will return 0 or 1
  3. 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆