Skip to content

Commit 7ea24f9

Browse files
Merge pull request #223 from rklomp/master
Simple addition to allow login via any library
2 parents 796d48f + ea862c8 commit 7ea24f9

File tree

2 files changed

+55
-1
lines changed

2 files changed

+55
-1
lines changed

application/config/rest.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,25 @@
6868
|
6969
| Is login required and if so, which user store do we use?
7070
|
71-
| '' = use config based users, 'ldap' = use LDAP authencation
71+
| '' = use config based users, 'ldap' = use LDAP authencation, 'library' = use a authentication library
7272
|
7373
*/
7474
$config['auth_source'] = 'ldap';
7575

76+
/*
77+
|--------------------------------------------------------------------------
78+
| REST Login
79+
|--------------------------------------------------------------------------
80+
|
81+
| If library authentication is used define the class and function name here
82+
|
83+
| The function should accept two parameters: class->function($username, $password)
84+
| In other cases override the function _perform_library_auth in your controller
85+
|
86+
*/
87+
$config['auth_library_class'] = '';
88+
$config['auth_library_function'] = '';
89+
7690
/*
7791
|--------------------------------------------------------------------------
7892
| Override auth types for specific class/method

application/libraries/REST_Controller.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1242,6 +1242,40 @@ protected function _perform_ldap_auth($username = '', $password = NULL)
12421242
return true;
12431243
}
12441244

1245+
/**
1246+
* Perform Library Authentication - Override this function to change the way the library is called
1247+
*
1248+
* @param string $username The username to validate
1249+
* @param string $password The password to validate
1250+
* @return boolean
1251+
*/
1252+
protected function _perform_library_auth($username = '', $password = NULL)
1253+
{
1254+
if (empty($username))
1255+
{
1256+
log_message('debug', 'Library Auth: failure, empty username');
1257+
return false;
1258+
}
1259+
1260+
$auth_library_class = strtolower($this->config->item('auth_library_class'));
1261+
$auth_library_function = strtolower($this->config->item('auth_library_function'));
1262+
1263+
if (empty($auth_library_class))
1264+
{
1265+
log_message('debug', 'Library Auth: failure, empty auth_library_class');
1266+
return false;
1267+
}
1268+
1269+
if (empty($auth_library_function))
1270+
{
1271+
log_message('debug', 'Library Auth: failure, empty auth_library_function');
1272+
return false;
1273+
}
1274+
1275+
$this->load->library($auth_library_class);
1276+
return $this->$auth_library_class->$auth_library_function($username, $password);
1277+
}
1278+
12451279
/**
12461280
* Check if the user is logged in.
12471281
*
@@ -1264,6 +1298,12 @@ protected function _check_login($username = '', $password = NULL)
12641298
return $this->_perform_ldap_auth($username, $password);
12651299
}
12661300

1301+
if ($auth_source == 'library')
1302+
{
1303+
log_message('debug', 'performing Library authentication for $username');
1304+
return $this->_perform_library_auth($username, $password);
1305+
}
1306+
12671307
$valid_logins = $this->config->item('rest_valid_logins');
12681308

12691309
if ( ! array_key_exists($username, $valid_logins))

0 commit comments

Comments
 (0)