async def _handle_login_finished(self, credentials): parsed_url = parse.urlsplit(credentials['end_uri']) params = parse.parse_qs(parsed_url.query) if 'username' not in params or 'password' not in params: return next_step_response(START_URI.LOGIN_FAILED, END_URI.LOGIN_FINISHED) username = params['username'][0] password = params['password'][0] self._user_info_cache.account_username = username self._auth_data = [username, password] await self._steam_client.communication_queues['websocket'].put( {'password': password}) result = await self._get_websocket_auth_step() if result == UserActionRequired.NoActionRequired: self._auth_data = None self.store_credentials(self._user_info_cache.to_dict()) return Authentication(self._user_info_cache.steam_id, self._user_info_cache.persona_name) if result == UserActionRequired.EmailTwoFactorInputRequired: return next_step_response(START_URI.TWO_FACTOR_MAIL, END_URI.TWO_FACTOR_MAIL_FINISHED) if result == UserActionRequired.PhoneTwoFactorInputRequired: return next_step_response(START_URI.TWO_FACTOR_MOBILE, END_URI.TWO_FACTOR_MOBILE_FINISHED) else: return next_step_response(START_URI.LOGIN_FAILED, END_URI.LOGIN_FINISHED)
async def _handle_two_step(self, params, fail, finish): if 'code' not in params: return next_step_response(fail, finish) two_factor = params['code'][0] await self._steam_client.communication_queues['websocket'].put( {'password': self._auth_data[1], 'two_factor': two_factor}) result = await self._get_websocket_auth_step() logger.info(f'2fa result {result}') if result != UserActionRequired.NoActionRequired: return next_step_response(fail, finish) else: self._auth_data = None self.store_credentials(self._user_info_cache.to_dict()) return Authentication(self._user_info_cache.steam_id, self._user_info_cache.persona_name)
async def authenticate(self, stored_credentials=None): if not stored_credentials: self.create_task(self._steam_client.run(), "Run WebSocketClient") return next_step_response(START_URI.LOGIN, END_URI.LOGIN_FINISHED) # TODO remove at some point, old refresh flow cookies = stored_credentials.get("cookies", []) if cookies: morsels = parse_stored_cookies(cookies) return await self._do_steamcommunity_auth(morsels) self._user_info_cache.from_dict(stored_credentials) if 'games' in self.persistent_cache: self._games_cache.loads(self.persistent_cache['games']) self.create_task(self._steam_client.run(), "Run WebSocketClient") try: await asyncio.wait_for(self._user_info_cache.initialized.wait(), 60) except asyncio.TimeoutError: self.check_for_websocket_errors() raise BackendTimeout() self.store_credentials(self._user_info_cache.to_dict()) return Authentication(self._user_info_cache.steam_id, self._user_info_cache.persona_name)
async def authenticate(self, stored_credentials=None): if not stored_credentials: self.create_task(self._steam_client.run(), "Run WebSocketClient") return next_step_response(START_URI.LOGIN, END_URI.LOGIN_FINISHED) # TODO remove at some point, old refresh flow cookies = stored_credentials.get("cookies", []) if cookies: morsels = parse_stored_cookies(cookies) return await self._do_steamcommunity_auth(morsels) self._user_info_cache.from_dict(stored_credentials) if 'games' in self.persistent_cache: self._games_cache.loads(self.persistent_cache['games']) steam_run_task = self.create_task(self._steam_client.run(), "Run WebSocketClient") connection_timeout = 30 try: await asyncio.wait_for(self._user_info_cache.initialized.wait(), connection_timeout) except asyncio.TimeoutError: try: self.raise_websocket_errors() except BackendError as e: logging.info(f"Unable to keep connection with steam backend {repr(e)}") except Exception as e: logging.info(f"Internal websocket exception caught during auth {repr(e)}") await self.cancel_task(steam_run_task) raise logging.info(f"Failed to initialize connection with steam client within {connection_timeout} seconds") await self.cancel_task(steam_run_task) raise BackendTimeout() self.store_credentials(self._user_info_cache.to_dict()) return Authentication(self._user_info_cache.steam_id, self._user_info_cache.persona_name)
async def _handle_two_step_email_finished(self, credentials): parsed_url = parse.urlsplit(credentials['end_uri']) params = parse.parse_qs(parsed_url.query) if 'resend' in params: await self._steam_client.communication_queues['websocket'].put({'password': self._auth_data[1]}) await self._get_websocket_auth_step() # Clear the queue return next_step_response(START_URI.TWO_FACTOR_MAIL, END_URI.TWO_FACTOR_MAIL_FINISHED) return await self._handle_two_step(params, START_URI.TWO_FACTOR_MAIL_FAILED, END_URI.TWO_FACTOR_MAIL_FINISHED)
async def authenticate(self, stored_credentials=None): if not stored_credentials: self.create_task(self._steam_client.run(), "Run WebSocketClient") return next_step_response(START_URI.LOGIN, END_URI.LOGIN_FINISHED) if stored_credentials.get("cookies", []): logger.error( 'Old http login flow is not unsupported. Please reconnect the plugin' ) raise AccessDenied() self._user_info_cache.from_dict(stored_credentials) if 'games' in self.persistent_cache: self._games_cache.loads(self.persistent_cache['games']) steam_run_task = self.create_task(self._steam_client.run(), "Run WebSocketClient") connection_timeout = 30 try: await asyncio.wait_for(self._user_info_cache.initialized.wait(), connection_timeout) except asyncio.TimeoutError: try: self.raise_websocket_errors() except BackendError as e: logging.info( f"Unable to keep connection with steam backend {repr(e)}") raise except InvalidCredentials: logging.info("Invalid credentials during authentication") raise except Exception as e: logging.info( f"Internal websocket exception caught during auth {repr(e)}" ) raise else: logging.info( f"Failed to initialize connection with steam client within {connection_timeout} seconds" ) raise BackendTimeout() finally: await self.cancel_task(steam_run_task) self.store_credentials(self._user_info_cache.to_dict()) return Authentication(self._user_info_cache.steam_id, self._user_info_cache.persona_name)