dao = $dao; $this->basePath = $basePath; $this->callbacks = $callbacks; } /** * If a callback URL is not in the configured list we should return null. */ public function filterCallbackURL($callbackURL) { foreach ($this->callbacks as $callback) { if ($callback['url'] === $callbackURL) { return $callbackURL; } } return null; } /** * Each callback has a title and a logo in order to avoid confusion in users * and show in which application they are logging in using RAP. * @param type $callbackURL * @return type the callback title or null if the callback URL is not listed * in configuration file or it doesn't have a title. */ public function getCallbackTitle($callbackURL) { foreach ($this->callbacks as $callback) { if ($callback['url'] === $callbackURL) { return $callback['title']; } } return null; } /** * Each callback has a title and a logo in order to avoid confusion in users * and show in which application they are logging in using RAP. * @param type $callbackURL * @return type the callback logo or null if the callback URL is not listed * in configuration file or it doesn't have a logo. */ public function getCallbackLogo($callbackURL) { foreach ($this->callbacks as $callback) { if ($callback['url'] === $callbackURL) { if (array_key_exists('logo', $callback)) { return $callback['logo']; } else { return null; } } } return null; } public function manageLoginRedirect($user, SessionData $session) { if ($session->getCallbackURL() === null) { http_response_code(401); die("Unauthorized callback URL"); } if ($session->getCallbackURL() === $this->basePath . '/') { // Login in session $session->user = $user; $session->save(); // Return to index header('Location: ' . $this->basePath); die(); } else { // External login using token header('Location: ' . $this->getLoginWithTokenURL($user->id, $session->getCallbackURL())); die(); } } public function getLoginWithTokenURL($userId, $callbackURL) { $token = Util::createNewToken(); $this->dao->createLoginToken($token, $userId); return $callbackURL . '?token=' . $token; } }