// 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');
-$head->appendJSFile('authsystem.js');
-$title->appendText('Authorization Request | KaiRo.at');
-$h1 = $body->appendElement('h1', 'KaiRo.at Authentication Server');
-
$errors = $utils->checkForSecureConnection();
$utils->sendSecurityHeaders();
-$para = $body->appendElement('p', _('This login system does not work without JavaScript. Please activate JavaScript for this site to log in.'));
-$para->setAttribute('id', 'jswarning');
-$para->setAttribute('class', 'warn');
+// Initialize the HTML document with our basic elements.
+extract($utils->initHTMLDocument(sprintf(_('Authorization Request | %s'), $utils->settings['operator_name']),
+ sprintf(_('%s Authentication Server'), $utils->settings['operator_name']))); // sets $document, $html, $head, $title, $body
if (!count($errors)) {
$session = $utils->initSession(); // Read session or create new session and set cookie.
$user = array('id' => 0, 'email' => '');
}
if (is_null($session)) {
- $errors[] = _('The session system is not working. Please <a href="https://www.kairo.at/contact">contact KaiRo.at</a> and tell the team about this.');
+ $errors[] = _('The session system is not working.').' '
+ .sprintf(_('Please <a href="%s">contact %s</a> and tell the team about this.'), $utils->settings['operator_contact_url'], $utils->settings['operator_name']);
}
elseif ($session['logged_in']) {
// We are logged in, process authorization request.
exit();
}
- if (empty($_POST) && (@$request->query['scope'] != 'email')) {
+ $is_authorized = !array_key_exists('authorized', $_POST) ? null : (@$_POST['authorized'] === 'yes');
+
+ if (is_null($is_authorized) && (@$request->query['scope'] != 'email')) {
// Display an authorization form (unless the scope is email, which we handle as a login request below).
$para = $body->appendElement('p', sprintf(_('Hi %s!'), $user['email']));
$para->setAttribute('class', 'userwelcome');
$domain_name = parse_url($request->query['redirect_uri'], PHP_URL_HOST);
if (!strlen($domain_name)) { $domain_name = $request->query['client_id']; }
$form->appendElement('p', sprintf(_('Do you authorize %s to access %s?'), $domain_name, $request->query['scope']));
- $submit = $form->appendInputSubmit(_('yes'));
- $submit->setAttribute('name', 'authorized');
+ $authinput = $form->appendInputHidden('authorized', 'yes');
+ $authinput->setAttribute('id', 'isauthorized');
+ $submit = $form->appendInputSubmit(_('Yes'));
$form->appendText(' ');
- $submit = $form->appendInputSubmit(_('no'));
- $submit->setAttribute('name', 'authorized');
+ $button = $form->appendButton(_('No'));
+ $button->setAttribute('id', 'cancelauth');
}
- elseif (empty($_POST) && (@$request->query['scope'] == 'email')) {
+ elseif (@$request->query['scope'] == 'email') {
// Display an interstitial page for a login when we have email scope (verified email for logging in).
$domain_name = parse_url($request->query['redirect_uri'], PHP_URL_HOST);
if (!strlen($domain_name)) { $domain_name = $request->query['client_id']; }
- $para = $body->appendElement('p', sprintf(_('Sign in to %s using…'), $domain_name));
- $para->setAttribute('class', 'signinwelcome');
- $form = $body->appendForm('', 'POST', 'loginauthform');
- $form->setAttribute('id', 'loginauthform');
- $form->setAttribute('class', 'loginarea');
- $ulist = $form->appendElement('ul');
- $ulist->setAttribute('class', 'flat emaillist');
- $emails = $utils->getGroupedEmails($user['group_id']);
- if (!count($emails)) { $emails = array($user['email']); }
- foreach ($emails as $email) {
- $litem = $ulist->appendElement('li');
- $litem->appendInputRadio('user_email', 'uemail_'.md5($email), $email, $email == $user['email']);
- $litem->appendLabel('uemail_'.md5($email), $email);
+ // If the referrer is from the auth system and we have a different domain to redirect to,
+ // we can safely assume we just logged in with that email and skip the interstitial page.
+ $refer_domain = parse_url($_SERVER['HTTP_REFERER'], PHP_URL_HOST);
+ if (is_null($is_authorized) && ($refer_domain == $_SERVER['SERVER_NAME']) && ($refer_domain != $domain_name) &&
+ (dirname($_SERVER['REQUEST_URI']) == dirname(parse_url($_SERVER['HTTP_REFERER'], PHP_URL_PATH)))) {
+ $is_authorized = true;
+ }
+ if (is_null($is_authorized)) {
+ $para = $body->appendElement('p', sprintf(_('Sign in to %s using…'), $domain_name));
+ $para->setAttribute('class', 'signinwelcome');
+ $form = $body->appendForm('', 'POST', 'authform');
+ $form->setAttribute('id', 'authform');
+ $form->setAttribute('class', 'loginarea');
+ $ulist = $form->appendElement('ul');
+ $ulist->setAttribute('class', 'flat emaillist');
+ $emails = $utils->getGroupedEmails($user['group_id']);
+ if (!count($emails)) { $emails = array($user['email']); }
+ foreach ($emails as $email) {
+ $litem = $ulist->appendElement('li');
+ $litem->appendInputRadio('user_email', 'uemail_'.md5($email), $email, $email == $user['email']);
+ $litem->appendLabel('uemail_'.md5($email), $email);
+ }
+ $para = $form->appendElement('p');
+ $para->setAttribute('class', 'small otheremaillinks');
+ $link = $para->appendLink('#', _('Add another email address'));
+ $link->setAttribute('id', 'addanotheremail'); // Makes the JS put the right functionality onto the link.
+ $para->appendText(' ');
+ $link = $para->appendLink('#', _('This is not me'));
+ $link->setAttribute('id', 'isnotme'); // Makes the JS put the right functionality onto the link.
+ $authinput = $form->appendInputHidden('authorized', 'yes');
+ $authinput->setAttribute('id', 'isauthorized');
+ $submit = $form->appendInputSubmit(_('Sign in'));
+ $para = $form->appendElement('p');
+ $para->setAttribute('class', 'small');
+ $link = $para->appendLink('#', _('Cancel'));
+ $link->setAttribute('id', 'cancelauth'); // Makes the JS put the right functionality onto the link.
+ $utils->setRedirect($session, $_SERVER['REQUEST_URI']);
}
- $para = $form->appendElement('p');
- $para->setAttribute('class', 'small otheremaillinks');
- $link = $para->appendLink('#', _('Add another email address'));
- $link->setAttribute('id', 'addanotheremail'); // Makes the JS put the right functionality onto the link.
- $para->appendText(' ');
- $link = $para->appendLink('#', _('This is not me'));
- $link->setAttribute('id', 'isnotme'); // Makes the JS put the right functionality onto the link.
- $authinput = $form->appendInputHidden('authorized', 'yes');
- $authinput->setAttribute('id', 'isauthorized');
- $submit = $form->appendInputSubmit(_('Sign in'));
- $para = $form->appendElement('p');
- $para->setAttribute('class', 'small');
- $link = $para->appendLink('#', _('Cancel'));
- $link->setAttribute('id', 'cancelauth'); // Makes the JS put the right functionality onto the link.
- $utils->setRedirect($session, $_SERVER['REQUEST_URI']);
}
- else {
+ if (!is_null($is_authorized)) {
// Switch to different user if we selected a different email within the group.
if (strlen(@$_POST['user_email']) && ($_POST['user_email'] != $user['email'])) {
$result = $db->prepare('SELECT `id`, `pwdhash`, `email`, `status`, `verify_hash`,`group_id` FROM `auth_users` WHERE `group_id` = :groupid AND `email` = :email;');
$session = $utils->getLoginSession($user['id'], $session);
}
}
+ if ($settings['piwik_enabled']) {
+ // If we do not send out an HTML file, we need to do the Piwik tracking ourselves.
+ require_once($settings['piwik_tracker_path'].'PiwikTracker.php');
+ PiwikTracker::$URL = ((strpos($settings['piwik_url'], '://') === false) ? 'http://localhost' : '' ).$settings['piwik_url'];
+ $piwikTracker = new PiwikTracker($idSite = $settings['piwik_site_id']);
+ $piwikTracker->doTrackPageView('Handle Authorize Request');
+ }
// Handle authorize request, forwarding code in GET parameters if the user has authorized your client.
- $is_authorized = (@$_POST['authorized'] === 'yes');
$server->handleAuthorizeRequest($request, $response, $is_authorized, $user['id']);
/* For testing only
if ($is_authorized) {