KaiRo bug 392 - Create an interstitial page to confirm the user to log in
[authserver.git] / authsystem.inc.php
index 62c6a80fd965c0f7369507cba2824b3ccaff3f28..5354cd9528b4d4a80a2abb5c713c5efd2dd77cdc 100644 (file)
@@ -3,14 +3,21 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
+/*
+  Some resources for how to store passwords:
+  - https://blog.mozilla.org/webdev/2012/06/08/lets-talk-about-password-storage/
+  - https://wiki.mozilla.org/WebAppSec/Secure_Coding_Guidelines
+  oauth-server-php: https://bshaffer.github.io/oauth2-server-php-docs/cookbook
+*/
+
 // error reporting (for testing)
 ini_set('display_errors', 1); error_reporting(E_ALL);
 
 // Read DB settings
 $dbdata = json_decode(file_get_contents('/etc/kairo/auth_db.json'), true);
 if (!is_array($dbdata)) { trigger_error('DB configuration not found', E_USER_ERROR); }
-
-$pwd_options = array('cost' => 10);
+$settings = json_decode(file_get_contents('/etc/kairo/auth_settings.json'), true);
+if (!is_array($settings)) { trigger_error('Auth settings not found', E_USER_ERROR); }
 
 // Extended DOM document class
 require_once('../kairo/include/cbsm/util/document.php-class');
@@ -24,6 +31,8 @@ bind_textdomain_codeset('kairo_auth', 'utf-8');
 
 // Connect to our MySQL DB
 $db = new PDO($dbdata['dsn'], $dbdata['username'], $dbdata['password']);
+// Instantiate auth utils.
+$utils = new AuthUtils($settings, $db);
 
 /* Creating the DB tables:
 CREATE TABLE `auth_sessions` (
@@ -33,6 +42,7 @@ CREATE TABLE `auth_sessions` (
  `logged_in` BOOLEAN NOT NULL DEFAULT FALSE ,
  `time_created` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ,
  `time_expire` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ,
+ `saved_redirect` VARCHAR(255) NOT NULL DEFAULT '' ,
  PRIMARY KEY (`id`),
  INDEX (`sesskey`),
  INDEX (`time_expire`)
@@ -46,6 +56,15 @@ CREATE TABLE `auth_users` (
  PRIMARY KEY (`id`),
  UNIQUE (`email`)
 );
+CREATE TABLE `auth_log` (
+ `id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT ,
+ `code` VARCHAR(100) NOT NULL ,
+ `info` TEXT NULL DEFAULT NULL ,
+ `ip_addr` VARCHAR(50) NULL DEFAULT NULL ,
+ `time_logged` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ,
+ PRIMARY KEY (`id`),
+ INDEX (`time_logged`)
+);
 */
 
 // include our OAuth2 Server object