Rudimentary implementation of authentication processflow
This commit is contained in:
@ -5,6 +5,16 @@ if (!file_exists($configurationFile)) {
|
||||
throw new Exception(sprintf('Missing config file. Please rename \'%1$s.example\' to \'%1$s\' and edit it to reflect your setup.', explode('../', $configurationFile)[1]));
|
||||
}
|
||||
$settings = include_once($configurationFile);
|
||||
try {
|
||||
# switch ($settings->Database['Driver']) {
|
||||
# case 'sqlite':
|
||||
# $database = new PDO('sqlite:' . $settings->Database['Path']);
|
||||
$pdoDB = new PDO('sqlite:' . $settings->Sqlite['Path']);
|
||||
# }
|
||||
}
|
||||
catch (Exception $e) {
|
||||
throw new Exception(sprintf('Unable to connect to database \'%1$s\'', $settings->Sqlite['Path']));
|
||||
}
|
||||
|
||||
function authenticateLDAP (string $username, string $password) {
|
||||
global $settings;
|
||||
@ -45,21 +55,45 @@ function authenticateLDAP (string $username, string $password) {
|
||||
function storeToken (string $username, string $password, object $cookie) {
|
||||
global $settings;
|
||||
|
||||
|
||||
}
|
||||
|
||||
function retrieveToken (string $username, string $foo) {
|
||||
function retrieveTokenFromDB (string $username, string $foo) {
|
||||
global $settings;
|
||||
|
||||
}
|
||||
|
||||
function validateCookie (int $expiration, string $username, string $securetoken) {
|
||||
# $_COOKIE['Exp'], $_COOKIE['Sub'], $_COOKIE['JWT']
|
||||
function validateToken (array $cookieData) {
|
||||
global $settings;
|
||||
|
||||
If ($expiration > time()) {
|
||||
#moo
|
||||
try {
|
||||
$jwtPayload = JWT::decode($cookieData['token'], base64_decode($settings->JWT['PrivateKey_base64']), $settings->JWT['Algorithm']);
|
||||
} catch (Exception $e) {
|
||||
// Invalid token, inform client (client should handle discarding invalid token)
|
||||
return ['status' => 'Fail', 'reason' => '3'];
|
||||
}
|
||||
|
||||
$pdoQuery = $pdoDB->prepare('
|
||||
SELECT SecureToken.Payload
|
||||
FROM SecureToken
|
||||
LEFT JOIN User
|
||||
ON (User.Id=SecureToken.UserId)
|
||||
WHERE User.Username = :username
|
||||
');
|
||||
$pdoQuery->execute([
|
||||
'username' => ($_COOKIE['Sub'] ?? "Danny")
|
||||
]);
|
||||
foreach($pdoQuery->fetchAll(PDO::FETCH_ASSOC) as $row) {
|
||||
$tokens[] = $row['Payload'];
|
||||
}
|
||||
print_r($tokens);
|
||||
# if ($pdoResult['Username'])
|
||||
|
||||
|
||||
If ($cookieData['Exp'] < time()) {
|
||||
// Expired cookie (shouldn't the browser disregard it?)
|
||||
return ['status' => 'Fail', 'reason' => '3'];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
Reference in New Issue
Block a user