--- /dev/null
+<?php
+// 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); }
+
+// Extended DOM document class
+require_once('../kairo/include/cbsm/util/document.php-class');
+
+bindtextdomain('kairo_auth', 'en'); // XXX: Should negotiate locale.
+bind_textdomain_codeset('kairo_auth', 'utf-8');
+
+// include our OAuth2 Server object
+require_once(__DIR__.'/server.inc.php');
+?>
--- /dev/null
+<?php
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * 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/. */
+
+// Include the common auth system files (including the OAuth2 Server object).
+require_once(__DIR__.'/authsystem.inc.php');
+
+// Start HTML document as a DOM object.
+extract(ExtendedDocument::initHTML5()); // sets $document, $html, $head, $title, $body
+$document->formatOutput = true; // we want a nice output
+
+$style = $head->appendElement('link');
+$style->setAttribute('rel', 'stylesheet');
+$style->setAttribute('href', 'authsystem.css');
+
+$title->appendText('KaiRo.at Authentication Server');
+$h1 = $body->appendElement('h1', 'KaiRo.at Authentication Server');
+
+$logged_in = false;
+$user_id = 0;
+$user_email = '';
+
+if ($logged_in) {
+ $div = $body->appendElement('div', $user_email);
+ $div->setAttribute('class', 'loginheader');
+ $div = $body->appendElement('div');
+ $div->setAttribute('class', 'loginlinks');
+ $link = $div->appendLink('?logout', _('Log out'));
+ $link->setAttribute('title', _('Log out user of the system'));
+}
+else { // not logged in
+ $form = $body->appendForm('#', 'POST', 'loginform');
+ $form->setAttribute('class', 'loginarea');
+ $label = $form->appendLabel('login_email', _('Email').':');
+ $label->setAttribute('id', 'emailprompt');
+ $label->setAttribute('class', 'loginprompt');
+ $inptxt = $form->appendInputText('form[email]', 30, 20, 'login_email', (intval($user_id)?$user_email:''));
+ $inptxt->setAttribute('class', 'login');
+ $form->appendElement('br');
+ $label = $form->appendLabel('login_pwd', _('Password').':');
+ $label->setAttribute('id', 'pwdprompt');
+ $label->setAttribute('class', 'loginprompt');
+ $inptxt = $form->appendInputPassword('form[pwd]', 20, 20, 'login_pwd', '');
+ $inptxt->setAttribute('class', 'login');
+ $form->appendElement('br');
+ $cbox = $form->appendInputCheckbox('form[remember]', 'login_remember', 'true', false);
+ $cbox->setAttribute('class', 'logincheck');
+ $label = $form->appendLabel('login_remember', _('Remember me'));
+ $label->setAttribute('id', 'rememprompt');
+ $label->setAttribute('class', 'loginprompt');
+ $form->appendElement('br');
+ $submit = $form->appendInputSubmit(_('Log in'));
+ $submit->setAttribute('class', 'loginbutton');
+}
+
+// Send HTML to client.
+print($document->saveHTML());
+?>
// Simple server based on https://bshaffer.github.io/oauth2-server-php-docs/cookbook
-$dsn = 'mysql:dbname=kairo_at_auth;host=localhost';
-$username = 'kairo_at_auth';
-$password = '6z0KIuUsHJhgD5rB';
-
-// error reporting (this is a demo, after all!)
-ini_set('display_errors',1);error_reporting(E_ALL);
+// $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"
-$storage = new OAuth2\Storage\Pdo(array('dsn' => $dsn, 'username' => $username, 'password' => $password));
+$storage = new OAuth2\Storage\Pdo($dbdata);
// Pass a storage object or array of storage objects to the OAuth2 server class
$server = new OAuth2\Server($storage);