userProvider = $userProvider; $this->authProvider = $authProvider; $this->host = $host; $this->apiRoot = $apiRoot; } public function token(): void { echo $this->authProvider->generateToken(); } public function get(string $token): void { $userData = $this->authProvider->getUser($token); Flight::json([ 'token' => $token, 'steamid' => $userData['steamid'], 'name' => $userData['name'], 'key' => $userData['key'], ]); } public function login(string $token): void { $_SESSION['return'] = $this->query('return', 'https://' . $this->host); $steam = new SteamLogin(); $url = $steam->url($this->apiRoot . '/auth/handle/' . urlencode($token), $this->apiRoot); Flight::redirect(str_replace('&', '&', $url)); // headers make no sense } public function logout(string $token): void { $this->authProvider->logout($token); Flight::json([ 'token' => $token, 'steamid' => null, 'name' => null, 'key' => null, ]); } public function handle(string $token): void { $return = $_SESSION['return'] ?? 'https://' . $this->host; unset($_SESSION['return']); $steam = new SteamLogin(); $steamId = $steam->validate(); if ($steamId) { $steamIdObject = new SteamId($steamId); $steamIdObject->fetch(); $key = $this->userProvider->store($steamIdObject, $steamIdObject->getNickname()); $this->authProvider->setUser($token, $steamIdObject, $key); } Flight::redirect($return); } }