mirror of
https://github.com/friendica/friendica
synced 2024-11-20 17:43:41 +00:00
api: call hook 'authenticate' from api_login()
This commit is contained in:
parent
d597fb6b5a
commit
b45a4b398b
1 changed files with 36 additions and 11 deletions
|
@ -96,13 +96,36 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
$user = $_SERVER['PHP_AUTH_USER'];
|
$user = $_SERVER['PHP_AUTH_USER'];
|
||||||
$encrypted = hash('whirlpool',trim($_SERVER['PHP_AUTH_PW']));
|
$password = $_SERVER['PHP_AUTH_PW'];
|
||||||
|
$encrypted = hash('whirlpool',trim($password));
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* next code from mod/auth.php. needs better solution
|
* next code from mod/auth.php. needs better solution
|
||||||
*/
|
*/
|
||||||
|
$record = null;
|
||||||
|
|
||||||
|
$addon_auth = array(
|
||||||
|
'username' => trim($user),
|
||||||
|
'password' => trim($password),
|
||||||
|
'authenticated' => 0,
|
||||||
|
'user_record' => null
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* A plugin indicates successful login by setting 'authenticated' to non-zero value and returning a user record
|
||||||
|
* Plugins should never set 'authenticated' except to indicate success - as hooks may be chained
|
||||||
|
* and later plugins should not interfere with an earlier one that succeeded.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
call_hooks('authenticate', $addon_auth);
|
||||||
|
|
||||||
|
if(($addon_auth['authenticated']) && (count($addon_auth['user_record']))) {
|
||||||
|
$record = $addon_auth['user_record'];
|
||||||
|
}
|
||||||
|
else {
|
||||||
// process normal login request
|
// process normal login request
|
||||||
|
|
||||||
$r = q("SELECT * FROM `user` WHERE ( `email` = '%s' OR `nickname` = '%s' )
|
$r = q("SELECT * FROM `user` WHERE ( `email` = '%s' OR `nickname` = '%s' )
|
||||||
|
@ -111,9 +134,11 @@
|
||||||
dbesc(trim($user)),
|
dbesc(trim($user)),
|
||||||
dbesc($encrypted)
|
dbesc($encrypted)
|
||||||
);
|
);
|
||||||
if(count($r)){
|
if(count($r))
|
||||||
$record = $r[0];
|
$record = $r[0];
|
||||||
} else {
|
}
|
||||||
|
|
||||||
|
if((! $record) || (! count($record))) {
|
||||||
logger('API_login failure: ' . print_r($_SERVER,true), LOGGER_DEBUG);
|
logger('API_login failure: ' . print_r($_SERVER,true), LOGGER_DEBUG);
|
||||||
header('WWW-Authenticate: Basic realm="Friendica"');
|
header('WWW-Authenticate: Basic realm="Friendica"');
|
||||||
header('HTTP/1.0 401 Unauthorized');
|
header('HTTP/1.0 401 Unauthorized');
|
||||||
|
|
Loading…
Reference in a new issue