Skip to content

Commit a24288c

Browse files
TatevikGrtatevikg1
andauthored
update SSO login logic
* ISSUE-339: oidc login * ISSUE-338: settings --------- Co-authored-by: Tatevik <[email protected]>
1 parent a458c3f commit a24288c

File tree

4 files changed

+48
-16
lines changed

4 files changed

+48
-16
lines changed

public_html/lists/admin/index.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ function mb_strtolower($string)
375375
//$msg = 'Not logged in';
376376
$logged = false;
377377
foreach ($GLOBALS['plugins'] as $pluginname => $plugin) {
378-
if ($pluginname == 'simplesaml' && !isset($_GET['sso'])) {
378+
if ($pluginname == 'simplesaml' && !isset($_GET[$GLOBALS['plugins'][$pluginname]->autUrl])) {
379379
continue;
380380
}
381381
if ($plugin->login()) {

public_html/lists/admin/init.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -647,7 +647,11 @@
647647
if (!isset($allowed_referrers) || !is_array($allowed_referrers)) {
648648
$allowed_referrers = array();
649649
}
650-
if (isset($_SERVER['HTTP_ORIGIN']) && defined('ACCESS_CONTROL_ALLOW_ORIGINS') && in_array($_SERVER['HTTP_ORIGIN'], ACCESS_CONTROL_ALLOW_ORIGINS)) {
650+
if (
651+
isset($_SERVER['HTTP_ORIGIN'])
652+
&& defined('ACCESS_CONTROL_ALLOW_ORIGINS')
653+
&& in_array($_SERVER['HTTP_ORIGIN'], ACCESS_CONTROL_ALLOW_ORIGINS)
654+
) {
651655
define('ACCESS_CONTROL_ALLOW_ORIGIN', $_SERVER['HTTP_ORIGIN']);
652656
} elseif (!defined('ACCESS_CONTROL_ALLOW_ORIGIN')) {
653657
define('ACCESS_CONTROL_ALLOW_ORIGIN', $GLOBALS['scheme'].'://'.$_SERVER['HTTP_HOST']);

public_html/lists/admin/login.php

Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,31 @@ function footer()
4343
echo $GLOBALS['I18N']->get('Enter your email address').': </p><input type="text" name="forgotpassword" value="" size="30" />';
4444
echo ' <input class="submit" type="submit" name="process" value="'.$GLOBALS['I18N']->get('Send password').'" />';
4545
echo ' <div class="clear"></div>';
46-
if (isset($GLOBALS['plugins']['simplesaml'])) {
47-
echo '<a href="?sso" style="display: inline-block; padding: 5px 10px; background-color: #2c2c2c; color: #fff; text-decoration: none; border-radius: 5px; font-size: 16px; text-align: center;"">SSO login</a>';
48-
}
4946
echo '</div></form>';
5047
}
5148

49+
function renderSSO()
50+
{
51+
if (!empty($GLOBALS['ssoplugin'])) {
52+
echo '<form method="post" id="forgotpassword-form" action="">';
53+
echo '<div style="display: flex; justify-content: space-around; align-items: center;">';
54+
55+
foreach ($GLOBALS['ssoplugin'] as $plugin) {
56+
$ssoUrl = $GLOBALS['plugins'][$plugin]->autUrl;
57+
$buttonText = 'Login with ' . $GLOBALS['plugins'][$plugin]->settings['display_name']['value'];
58+
59+
echo '<a href="?' . $ssoUrl . '"
60+
style="display: inline-block; padding: 8px 15px; background-color: #3c3c3c; color: #fff;
61+
text-decoration: none; border-radius: 5px; font-size: 16px; text-align: center;
62+
min-width: 120px;">
63+
' . $buttonText . '
64+
</a>';
65+
}
66+
67+
echo '</div>';
68+
echo '</form>';
69+
}
70+
}
5271
//Delete from the DB every token older than certain elapsed time.
5372
function deleteOldTokens()
5473
{
@@ -119,16 +138,20 @@ function deleteOldTokens()
119138
exit;
120139
}
121140
} else {
122-
echo "<form method=\"post\" id=\"login-form\" action=\"\">\n";
123-
echo " <input type=\"hidden\" name=\"page\" value=\"$page\" />\n";
124-
echo " <table class=\"loginPassUpdate\" width=\"100%\" border=\"0\" cellpadding=\"2\" cellspacing=\"0\">\n";
125-
echo ' <tr><td><span class="general">'.$GLOBALS['I18N']->get('Name').":</span></td></tr>\n";
126-
echo ' <tr><td><input type="text" name="login" value="" size="30" autofocus="autofocus" /></td></tr>';
127-
echo ' <tr><td><span class="general">'.$GLOBALS['I18N']->get('Password').':</span></td></tr>';
128-
echo ' <tr><td><input type="password" name="password" value="" size="30" /></td></tr>';
129-
echo ' <tr><td><input class="submit" type="submit" name="process" value="'.$GLOBALS['I18N']->get('Continue').'" /></td></tr>';
130-
echo ' </table>';
131-
echo '</form>';
132-
footer();
141+
$showDefaultLogin = !isset($GLOBALS['ssoplugin']) || !getConfig('hide_default_login');
142+
if ($showDefaultLogin) {
143+
echo "<form method=\"post\" id=\"login-form\" action=\"\">\n";
144+
echo " <input type=\"hidden\" name=\"page\" value=\"$page\" />\n";
145+
echo " <table class=\"loginPassUpdate\" width=\"100%\" border=\"0\" cellpadding=\"2\" cellspacing=\"0\">\n";
146+
echo ' <tr><td><span class="general">'.$GLOBALS['I18N']->get('Name').":</span></td></tr>\n";
147+
echo ' <tr><td><input type="text" name="login" value="" size="30" autofocus="autofocus" /></td></tr>';
148+
echo ' <tr><td><span class="general">'.$GLOBALS['I18N']->get('Password').':</span></td></tr>';
149+
echo ' <tr><td><input type="password" name="password" value="" size="30" /></td></tr>';
150+
echo ' <tr><td><input class="submit" type="submit" name="process" value="'.$GLOBALS['I18N']->get('Continue').'" /></td></tr>';
151+
echo ' </table>';
152+
echo '</form>';
153+
footer();
154+
}
155+
renderSSO();
133156
}
134157
?>

public_html/lists/admin/pluginlib.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
$GLOBALS['emailsenderplugin'] = false;
1313
$GLOBALS['analyticsqueryplugin'] = false;
1414
$GLOBALS['updaterplugin'] = false;
15+
$GLOBALS['ssoplugin'] = [];
1516

1617
$pluginRootDirs = array();
1718
if (PLUGIN_ROOTDIRS != '') {
@@ -111,6 +112,10 @@
111112
) {
112113
$GLOBALS['editorplugin'] = $className;
113114
}
115+
if (method_exists($pluginInstance, 'login') && isset($pluginInstance->ssoProvider))
116+
{
117+
$GLOBALS['ssoplugin'][] = $className;
118+
}
114119
if (!$GLOBALS['authenticationplugin'] && $pluginInstance->authProvider && method_exists($pluginInstance,
115120
'validateLogin')
116121
) {

0 commit comments

Comments
 (0)