mirror of
https://github.com/FH-Complete/FHC-Core.git
synced 2026-07-24 02:12:17 +00:00
HTTP basic authentication
Set this as default authentication, providing codeception test case
This commit is contained in:
@@ -110,7 +110,7 @@ $config['rest_realm'] = 'FHC REST API';
|
||||
| authorization key
|
||||
|
|
||||
*/
|
||||
$config['rest_auth'] = 'digest';
|
||||
$config['rest_auth'] = 'basic';
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
@@ -119,7 +119,8 @@ $config['rest_auth'] = 'digest';
|
||||
|
|
||||
| Is login required and if so, the user store to use
|
||||
|
|
||||
| '' Use config based users or wildcard testing
|
||||
| '' Use config based users or wildcard testing, only for testing purpose
|
||||
| it would be very unsecure to let unset in a production environment
|
||||
| 'ldap' Use LDAP authentication
|
||||
| 'library' Use a authentication library
|
||||
|
|
||||
@@ -145,10 +146,10 @@ $config['auth_source'] = 'library';
|
||||
$config['auth_library_class'] = 'FHC_Auth';
|
||||
|
||||
// rest_auth is basic
|
||||
//$config['auth_library_function'] = 'auth';
|
||||
$config['auth_library_function'] = 'basicAuthentication';
|
||||
|
||||
// rest_auth is digest
|
||||
$config['auth_library_function'] = 'digestAuthentication';
|
||||
//$config['auth_library_function'] = 'digestAuthentication';
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
@@ -515,4 +516,4 @@ $config['rest_ajax_only'] = FALSE;
|
||||
| Language file to load from the language directory
|
||||
|
|
||||
*/
|
||||
$config['rest_language'] = 'en-US';
|
||||
$config['rest_language'] = 'en-US';
|
||||
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
defined('BASEPATH') || exit('No direct script access allowed');
|
||||
|
||||
require_once APPPATH . '/libraries/REST_Controller.php';
|
||||
|
||||
/**
|
||||
* Testing class for REST calls and authentication
|
||||
*/
|
||||
class Test extends REST_Controller
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test HTTP GET method
|
||||
* It responses whith the HTTP status 200 and prints this JSON string
|
||||
* {"success":true,"message":"API HTTP GET call test succeed"}
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function test_get()
|
||||
{
|
||||
$payload = [
|
||||
'success' => TRUE,
|
||||
'message' => 'API HTTP GET call test succeed'
|
||||
];
|
||||
$httpstatus = REST_Controller::HTTP_OK;
|
||||
$this->response($payload, $httpstatus);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test HTTP POST method
|
||||
* * It responses whith the HTTP status 200 and prints this JSON string
|
||||
* {"success":true,"message":"API HTTP POST call test succeed"}
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function test_post()
|
||||
{
|
||||
$payload = [
|
||||
'success' => TRUE,
|
||||
'message' => 'API HTTP POST call test succeed'
|
||||
];
|
||||
$httpstatus = REST_Controller::HTTP_OK;
|
||||
$this->response($payload, $httpstatus);
|
||||
}
|
||||
}
|
||||
@@ -33,19 +33,17 @@ class FHC_Auth
|
||||
*
|
||||
* @param string $username
|
||||
* @param string $password
|
||||
* @return bool
|
||||
* @return bool
|
||||
*/
|
||||
function auth($username, $password)
|
||||
function basicAuthentication($username, $password)
|
||||
{
|
||||
$auth = new authentication();
|
||||
if ($auth->checkpassword($username, $password))
|
||||
if($auth->checkpassword($username, $password))
|
||||
{
|
||||
//echo 'Auth-Method-True';
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
//echo 'Auth-Method-False';
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,51 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* FH-Complete
|
||||
*
|
||||
* @package FHC-Helper
|
||||
* @author FHC-Team
|
||||
* @copyright Copyright (c) 2016 fhcomplete.org
|
||||
* @license GPLv3
|
||||
* @link https://fhcomplete.org
|
||||
* @since Version 1.0.0
|
||||
* @filesource
|
||||
*/
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
require_once FCPATH.'include/authentication.class.php';
|
||||
|
||||
/**
|
||||
* FHC-Auth Helpers
|
||||
*
|
||||
* @package FH-Complete
|
||||
* @subpackage Helpers
|
||||
* @category Helpers
|
||||
* @author FHC-Team
|
||||
* @link http://fhcomplete.org/user_guide/helpers/fhcauth_helper.html
|
||||
*/
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
class Fhcauth
|
||||
{
|
||||
/**
|
||||
* Auth Username, Password over FH-Complete
|
||||
*
|
||||
* @param string $username
|
||||
* @param string $password
|
||||
* @return bool
|
||||
*/
|
||||
function auth($username, $password)
|
||||
{
|
||||
$auth = new authentication();
|
||||
if ($auth->checkpassword($username, $password))
|
||||
{
|
||||
//echo 'Auth-Method-True';
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
//echo 'Auth-Method-False';
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user