From 2f74619552fd8ab55eeac95fb89955326ccf04ac Mon Sep 17 00:00:00 2001 From: juan-cortizas-ponte Date: Fri, 31 Jul 2020 12:09:17 +0200 Subject: [PATCH] sso with HMAC token validation --- main/auth/hmac/login.php | 107 ++++++++++++++++++++++++++++++ main/auth/hmac/settings.dist..php | 7 ++ 2 files changed, 114 insertions(+) create mode 100644 main/auth/hmac/login.php create mode 100644 main/auth/hmac/settings.dist..php diff --git a/main/auth/hmac/login.php b/main/auth/hmac/login.php new file mode 100644 index 0000000000..31a0610f8e --- /dev/null +++ b/main/auth/hmac/login.php @@ -0,0 +1,107 @@ + 0) { + $tokenTime = strtotime($time); + $diff = abs($tokenTime - time()) / 60; + if ($diff > $settingsInfo['expiration_time']) { + Display::addFlash(Display::return_message('Token expired', 'error')); + header('Location: '.api_get_path(WEB_PATH)); + exit; + } + } + + // Get the user info + $userInfo = api_get_user_info_from_email($email); + + // Log-in user if exists or a show error message + if (!empty($userInfo)) { + Session::write('_user', $userInfo); + Session::write('is_platformAdmin', false); + Session::write('is_allowedCreateCourse', false); + + Event::eventLogin($userId); + + Session::write('flash_messages', ''); + } else { + Display::addFlash(Display::return_message('User not found', 'error')); + header('Location: '.api_get_path(WEB_PATH)); + exit; + } + + header('Location: '.api_get_path(WEB_PATH).'user_portal.php'); +} else { + Display::addFlash(Display::return_message('Invalid request', 'error')); + header('Location: '.api_get_path(WEB_PATH)); + exit; +} \ No newline at end of file diff --git a/main/auth/hmac/settings.dist..php b/main/auth/hmac/settings.dist..php new file mode 100644 index 0000000000..f46e7ebf6e --- /dev/null +++ b/main/auth/hmac/settings.dist..php @@ -0,0 +1,7 @@ + '', + 'system' => '', + 'expiration_time' => 0, +]; \ No newline at end of file