Skip to content

Instantly share code, notes, and snippets.

@ricardojlrufino
Created September 1, 2017 04:48
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ricardojlrufino/0bfddc33e172c8fc1f127f8b439ced18 to your computer and use it in GitHub Desktop.
Save ricardojlrufino/0bfddc33e172c8fc1f127f8b439ced18 to your computer and use it in GitHub Desktop.
phpMyAdmin SSO Login Example
<?php
$sso_server = "http://chat.local:8080/api/clients/validateDb";
/* Need to have cookie visible from parent directory */
session_set_cookie_params(0, '/', '', true, true);
/* Create signon session */
$session_name = 'SignonSession';
session_name($session_name);
// Uncomment and change the following line to match your $cfg['SessionSavePath']
// session_save_path('');
@session_start();
/* Was data posted? */
if (isset($_GET['remote_token']) || isset($_COOKIE['remote_token'])) {
$token = ( isset($_GET['remote_token']) ? $_GET['remote_token'] : $_COOKIE['remote_token']);
// Request credentials from remote server
$response = file_get_contents($sso_server . "/?token=" . $token);
$response = json_decode($response);
/* Store there credentials */
$_SESSION['PMA_single_signon_user'] = $response->{'user'};
$_SESSION['PMA_single_signon_password'] = $response->{'pass'};
/* Update another field of server configuration */
$_SESSION['PMA_single_signon_cfgupdate'] = array('verbose' => 'Signon test');
$id = session_id();
/* Close that session */
@session_write_close();
setcookie($session_name, $id , 0, "/");
/* Redirect to phpMyAdmin (should use absolute URL here!) */
header('Location: ../phpmyadmin/index.php');
// echo 'DONE';
} else {
/* Show simple form */
header('Content-Type: text/html; charset=utf-8');
echo '<?xml version="1.0" encoding="utf-8"?>' , "\n";
?>
<!DOCTYPE HTML>
<html lang="en" dir="ltr">
<head>
<link rel="icon" href="../favicon.ico" type="image/x-icon" />
<link rel="shortcut icon" href="../favicon.ico" type="image/x-icon" />
<meta charset="utf-8" />
<title>phpMyAdmin single signon</title>
</head>
<body>
<?php
if (isset($_SESSION['PMA_single_signon_error_message'])) {
echo '<p class="error">';
echo $_SESSION['PMA_single_signon_error_message'];
echo '</p>';
}
?>
<h1>Autenticação deve ser realizada pelo portal do Edu3</h1>
Token: <?php echo $_GET['remote_token'] ?>
</body>
</html>
<?php
}
?>
@ricardojlrufino
Copy link
Author

ricardojlrufino commented Sep 1, 2017

Put this script in
/usr/share/phpmyadmin

Configuration [/etc/phpmyadmin/config.inc.php]:

$cfg['Servers'][$i]['auth_type'] = 'signon';
$cfg['Servers'][$i]['SignonSession'] = 'SignonSession';
$cfg['Servers'][$i]['SignonURL'] = 'sso.php';

@martinslavov
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment