setState ( [ $user_id, $auth_time, $op_browser_state ] ); return $principal; } /** * @param IPrincipal $principal * @return void */ public function save(IPrincipal $principal) { Log::debug("PrincipalService::save"); $this->register ( $principal->getUserId(), $principal->getAuthTime() ); } /** * @return string */ private function calculateBrowserState(): string { return hash('sha256', Session::getId()); } /** * @param int $user_id * @param int $auth_time * @return mixed */ public function register($user_id, $auth_time) { Log::debug(sprintf("PrincipalService::register user_id %s auth_time %s", $user_id, $auth_time)); Session::put(self::UserIdParam, $user_id); Session::put(self::AuthTimeParam, $auth_time); // Maintain a `op_browser_state` cookie along with the `sessionid` cookie that // represents the End-User's login state at the OP. If the user is not logged $op_browser_state = $this->calculateBrowserState(); Cookie::queue ( IPrincipalService::OP_BROWSER_STATE_COOKIE_NAME, $op_browser_state, Config::get("session.lifetime", 120), $path = Config::get("session.path"), $domain = Config::get("session.domain"), $secure = true, $httpOnly = false, $raw = false, $sameSite = 'none' ); Log::debug(sprintf("PrincipalService::register op_browser_state %s", $op_browser_state)); Session::put(self::OPBrowserState, $op_browser_state); Session::save(); } /** * @return $this */ public function clear() { Log::debug("PrincipalService::clear"); Session::remove(self::UserIdParam); Session::remove(self::AuthTimeParam); Session::remove(self::OPBrowserState); Session::save(); Cookie::queue ( IPrincipalService::OP_BROWSER_STATE_COOKIE_NAME, null, $minutes = -2628000, $path = Config::get("session.path"), $domain = Config::get("session.domain"), $secure = true, $httpOnly = false, $raw = false, $sameSite = 'none' ); } }