HTTP basic authentication

Set this as default authentication, providing codeception test case
This commit is contained in:
paolo
2016-04-15 15:41:38 +02:00
parent aec2e7b5ac
commit 9aef5dcc30
12 changed files with 4329 additions and 75 deletions
+6 -5
View File
@@ -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';
+50
View File
@@ -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);
}
}
+3 -5
View File
@@ -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;
}
}
-51
View File
@@ -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;
}
}
}