Commit ee4612fe authored by Damien's avatar Damien
Browse files

FEAT Basic auth for Rest + basic auth for curl calls

parent fa311c43
<?xml version="1.0" encoding="utf-8"?>
<ROOT>
<user>super</user>
<password>maaarch</password>
<call>
<id>sendFile</id>
<url></url>
<url>http://127.0.0.1/maarch_trunk/rest/user/profile</url>
<method>POST</method>
</call>
<call>
......
......@@ -22,6 +22,7 @@ class CurlModel
ValidatorModel::notEmpty($aArgs, ['curlCallId']);
ValidatorModel::stringType($aArgs, ['curlCallId']);
ValidatorModel::arrayType($aArgs, ['bodyData']);
ValidatorModel::boolType($aArgs, ['noAuth']);
$curlConfig = CurlModel::getConfigByCallId(['curlCallId' => $aArgs['curlCallId']]);
if (empty($curlConfig)) {
......@@ -36,6 +37,9 @@ class CurlModel
],
CURLOPT_RETURNTRANSFER => true,
];
if (empty($aArgs['noAuth'])) {
$opts[CURLOPT_HTTPHEADER][] = 'Authorization: Basic ' . base64_encode($curlConfig['user']. ':' .$curlConfig['password']);
}
if ($curlConfig['method'] == 'POST' || $curlConfig['method'] == 'PUT') {
if (!empty($curlConfig['data'])) {
......@@ -76,6 +80,9 @@ class CurlModel
$curlConfig = [];
if (file_exists($path)) {
$loadedXml = simplexml_load_file($path);
$curlConfig['user'] = (string)$loadedXml->user;
$curlConfig['password'] = (string)$loadedXml->password;
foreach ($loadedXml->call as $call) {
if ((string)$call->id == $aArgs['curlCallId']) {
$curlConfig['url'] = (string)$call->url;
......
......@@ -70,13 +70,25 @@ if (empty($_SESSION['user'])) {
//login management
if (empty($_SESSION['user'])) {
require_once('apps/maarch_entreprise/class/class_login.php');
$loginObj = new login();
$loginMethods = $loginObj->build_login_method();
require_once('core/services/Session.php');
$oSessionService = new \Core_Session_Service();
$loginObj->execute_login_script($loginMethods, true);
if (!empty($_SERVER['PHP_AUTH_USER']) && !empty($_SERVER['PHP_AUTH_PW'])) {
$_SESSION['error'] = '';
$security = new security();
$pass = $security->getPasswordHash($_SERVER['PHP_AUTH_PW']);
$res = $security->login($_SERVER['PHP_AUTH_USER'], $pass);
$_SESSION['user'] = $res['user'];
if (!empty($res['error'])) {
$_SESSION['error'] = $res['error'];
}
} else {
require_once('apps/maarch_entreprise/class/class_login.php');
$loginObj = new login();
$loginMethods = $loginObj->build_login_method();
require_once('core/services/Session.php');
$oSessionService = new \Core_Session_Service();
$loginObj->execute_login_script($loginMethods, true);
}
}
if ($_SESSION['error']) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment