From 2b9aa8f3c5aeb5d3fa414a985ad14b351a12cfcd Mon Sep 17 00:00:00 2001 From: Robert Kaiser Date: Thu, 15 Dec 2016 14:57:44 +0100 Subject: [PATCH] KaiRo bug 412 - Use composer to load oauth2-server-php and doctrine DBAL --- .gitignore | 3 ++- app/authsystem.inc.php | 20 +++++++++++++------- app/authutils.php-class | 3 +++ app/server.inc.php | 4 ---- composer.json | 6 ++++++ 5 files changed, 24 insertions(+), 12 deletions(-) create mode 100644 composer.json diff --git a/.gitignore b/.gitignore index a79011c..1533c81 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ *~ -/oauth2-server-php +composer.lock +/vendor /php-utility-classes diff --git a/app/authsystem.inc.php b/app/authsystem.inc.php index d098af0..45d0e0f 100644 --- a/app/authsystem.inc.php +++ b/app/authsystem.inc.php @@ -20,16 +20,22 @@ $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('../php-utility-classes/classes/document.php-class'); +require_once(__DIR__.'/../php-utility-classes/classes/document.php-class'); // Class for sending emails -require_once('../php-utility-classes/classes/email.php-class'); -// Class for sending emails -require_once(__DIR__.'/authutils.php-class'); - +require_once(__DIR__.'/../php-utility-classes/classes/email.php-class'); +// Composer-provided libraries (oauth2-server-php, doctrine DBAL) +require_once(__DIR__.'/../vendor/autoload.php'); // Connect to our MySQL DB $db = new PDO($dbdata['dsn'], $dbdata['username'], $dbdata['password']); -// Instantiate auth utils. -$utils = new AuthUtils($settings, $db); +// Authentication utilities +require_once(__DIR__.'/authutils.php-class'); +// Instantiate server utils. +try { + $utils = new AuthUtils($settings, $db); +} +catch (Exception $e) { + $utils = null; +} // This is an array of locale tags in browser style mapping to unix system locale codes to use with gettext. $supported_locales = array( diff --git a/app/authutils.php-class b/app/authutils.php-class index db5dd89..42f5859 100755 --- a/app/authutils.php-class +++ b/app/authutils.php-class @@ -34,6 +34,9 @@ class AuthUtils { // function checkForSecureConnection() // Check is the connection is secure and return an array of error messages (empty if it's secure). // + // function sendSecurityHeaders() + // Rend HTTP headers for improving security. + // // function initSession() // Initialize a session. Returns an associative array of all the DB fields of the session. // diff --git a/app/server.inc.php b/app/server.inc.php index 87b6535..53e55b4 100644 --- a/app/server.inc.php +++ b/app/server.inc.php @@ -7,10 +7,6 @@ // $dbata needs to be set and be an associative array with the members 'dsn', 'username', and 'password'. -// Autoloading (composer is preferred, but for this example let's just do this) -require_once('../oauth2-server-php/src/OAuth2/Autoloader.php'); -OAuth2\Autoloader::register(); - // $dsn is the Data Source Name for your database, for exmaple "mysql:dbname=my_oauth2_db;host=localhost" $oauth2_storage = new OAuth2\Storage\Pdo($dbdata); diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..a448d97 --- /dev/null +++ b/composer.json @@ -0,0 +1,6 @@ +{ +"require": { + "doctrine/dbal": "v2.5.5", + "bshaffer/oauth2-server-php": "~1.8" +} +} \ No newline at end of file -- 2.35.3