async def authenticate(self, stored_credentials=None): self._http_client.create_session(stored_credentials) if not stored_credentials: return NextStep("web_session", AUTH_PARAMS) try: log.info("INFO: The credentials were successfully obtained.") cookies = pickle.loads(bytes.fromhex(stored_credentials['session_object'])).cookies log.debug("ROCKSTAR_COOKIES_FROM_HEX: " + str(cookies)) for cookie in cookies: cookie_object = { "name": cookie.name, "value": cookie.value, "domain": cookie.domain, "path": cookie.path } self._http_client.update_cookie(cookie_object) self._http_client.set_current_auth_token(stored_credentials['current_auth_token']) log.info("INFO: The stored credentials were successfully parsed. Beginning authentication...") user = await self._http_client.authenticate() return Authentication(user_id=user['rockstar_id'], user_name=user['display_name']) except Exception as e: log.warning("ROCKSTAR_AUTH_WARNING: The exception " + repr(e) + " was thrown, presumably because of " "outdated credentials. Attempting to get new credentials...") self._http_client.set_auth_lost_callback(self.lost_authentication) try: user = await self._http_client.authenticate() return Authentication(user_id=user['rockstar_id'], user_name=user['display_name']) except Exception as e: log.error("ROCKSTAR_AUTH_FAILURE: Something went terribly wrong with the re-authentication. " + repr(e)) log.exception("ROCKSTAR_STACK_TRACE") raise InvalidCredentials()
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 authenticate(self, stored_credentials=None): if not stored_credentials: return NextStep( "web_session", AUTH_PARAMS, cookies=[Cookie("passedICO", "true", ".bethesda.net")], js=JS) try: log.info("Got stored credentials") cookies = pickle.loads( bytes.fromhex(stored_credentials['cookie_jar'])) cookies_parsed = [] for cookie in cookies: if cookie.key in cookies_parsed and cookie.domain: self._http_client.update_cookies( {cookie.key: cookie.value}) elif cookie.key not in cookies_parsed: self._http_client.update_cookies( {cookie.key: cookie.value}) cookies_parsed.append(cookie.key) log.info("Finished parsing stored credentials, authenticating") user = await self._http_client.authenticate() self._http_client.set_auth_lost_callback(self.lost_authentication) return Authentication(user_id=user['user_id'], user_name=user['display_name']) except (AccessDenied, Banned, UnknownError) as e: log.error( f"Couldn't authenticate with stored credentials {repr(e)}") raise InvalidCredentials()
async def _do_auth(self, morsels): cookies = [(morsel.key, morsel) for morsel in morsels] self._http_client.update_cookies(cookies) self._http_client.set_cookies_updated_callback(self._store_cookies) self._force_utc() try: profile_url = await self._client.get_profile() except UnknownBackendResponse: raise InvalidCredentials() try: self._steam_id, self._miniprofile_id, login = await self._client.get_profile_data( profile_url) self.create_task(self._steam_client.run(), "Run WebSocketClient") except AccessDenied: raise InvalidCredentials() self._http_client.set_auth_lost_callback(self.lost_authentication) if "steamRememberLogin" in (cookie[0] for cookie in cookies): logger.debug("Remember login cookie present") else: logger.debug("Remember login cookie not present") return Authentication(self._steam_id, login)
async def authenticate(self, stored_credentials=None): creds = {} creds["user"] = "******" self.store_credentials(creds) return Authentication("RAUser", "Retroarch")
async def authenticate(self, stored_credentials=None): logging.debug("authenticate") if not (stored_credentials.get("access_token") if stored_credentials else None): return NextStep( "web_session", { "window_title": "Log in to Itch.io", "window_width": 536, "window_height": 675, "start_uri": r"https://itch.io/user/oauth?client_id=3821cecdd58ae1a920be15f6aa479f7e&scope=profile&response_type=token&redirect_uri=http%3A%2F%2F127.0.0.1%3A7157%2Fgogg2itchintegration", "end_uri_regex": r"^http://127\.0\.0\.1:7157/gogg2itchintegration#access_token=.+", }) else: try: user = await self.get_user_data( stored_credentials["access_token"]) return Authentication(user["id"], user["username"]) except AccessDenied: raise InvalidCredentials()
async def authenticate(self, stored_credentials=None): if not stored_credentials: logging.info('No stored credentials') AUTH_PARAMS = { "window_title": "Login to Wargaming", "window_width": 640, "window_height": 460, "start_uri": self._wgc.auth_server_uri(), "end_uri_regex": '.*finished' } if not self._wgc.auth_server_start(): raise BackendError() return NextStep("web_session", AUTH_PARAMS) else: auth_passed = self._wgc.login_info_set(stored_credentials) if not auth_passed: logging.warning('Stored credentials are invalid') raise InvalidCredentials() return Authentication( self._wgc.account_id(), '%s_%s' % (self._wgc.account_realm(), self._wgc.account_nickname()))
async def test_no_stored_credentials(backend_client, plugin, cookies, auth_info, stored_credentials, mocker): steam_fake_cookie = Cookie(name="n", value="v") mocker.patch.object(plugin, "_create_two_factor_fake_cookie", return_value=steam_fake_cookie) assert NextStep( "web_session", AUTH_PARAMS, [steam_fake_cookie], {re.escape(LOGIN_URI): [JS_PERSISTENT_LOGIN]}, ) == await plugin.authenticate() backend_client.get_profile.return_value = PROFILE_URL backend_client.get_profile_data.return_value = auth_info[0], auth_info[ 1], auth_info[2] store_credentials = mocker.patch.object(plugin, "store_credentials") assert Authentication( auth_info[0], auth_info[2]) == await plugin.pass_login_credentials( "random step name", { "end_uri": "https://steamcommunity.com/id/{}/goto".format(auth_info[0]) }, cookies) store_credentials.assert_called_with(stored_credentials) backend_client.get_profile.assert_called_once_with() backend_client.get_profile_data.assert_called_once_with(PROFILE_URL)
async def authenticate(self, stored_credentials=None): authserver = self._wgc.get_auth_server() wgni = self._wgc.get_wgni_client() if not stored_credentials: self._logger.info('plugin/authenticate: no stored credentials') AUTH_PARAMS = { "window_title": "Login to Wargaming", "window_width": 640, "window_height": 460, "start_uri": authserver.get_uri(), "end_uri_regex": '.*finished' } if not await authserver.start(): raise BackendError() return NextStep("web_session", AUTH_PARAMS) else: auth_passed = await wgni.login_info_set(stored_credentials) if not auth_passed: self._logger.warning( 'plugin/authenticate: stored credentials are invalid') raise InvalidCredentials() return Authentication( wgni.get_account_id(), '%s_%s' % (wgni.get_account_realm(), wgni.get_account_nickname()))
def __do_auth__(self): user_data = {} user_data['username'] = '******' user_data['ID'] = "GDPS_User_ID" self.store_credentials(user_data) return Authentication(user_data['ID'], user_data["username"])
async def authenticate(self, stored_credentials=None): #check stored credentials if stored_credentials: auth_result = await self._gw2_api.do_auth_apikey(stored_credentials['api_key']) if auth_result != gw2.gw2_api.GW2AuthorizationResult.FINISHED: self.__logger.warning('authenticate: stored credentials are invalid') raise InvalidCredentials() return Authentication(self._gw2_api.get_account_id(), self._gw2_api.get_account_name()) #new auth self.__authserver = gw2.gw2_authserver.Gw2AuthServer(self._gw2_api) self.__logger.info('authenticate: no stored credentials') AUTH_PARAMS = { "window_title": "Login to Guild Wars 2", "window_width": 640, "window_height": 460, "start_uri": self.__authserver.get_uri(), "end_uri_regex": '.*finished' } if not await self.__authserver.start(): self.__logger.error('authenticate: failed to start auth server', exc_info=True) raise BackendError() return NextStep("web_session", AUTH_PARAMS)
def parse_user_details(self): log.info(f"oauth/userinfo: {self.user_details}") if 'id' and 'battletag' in self.user_details: return Authentication(self.user_details["id"], self.user_details["battletag"]) else: raise Aborted()
def finish_login(self): some_dict = dict() some_dict["roms_path"] = roms_path self.store_credentials(some_dict) self.parse_games() return Authentication(user_id="a_high_quality_dosbox_user", user_name=roms_path)
async def authenticate( self, stored_credentials: Optional[Dict] = None ) -> Union[NextStep, Authentication]: if not self._launcher_client.is_installed: webbrowser.open_new_tab("https://www.twitch.tv/downloads") raise InvalidCredentials def get_auth_info() -> Optional[Tuple[str, str]]: user_info = self._get_user_info() if not user_info: logging.warning("No user info") return None user_id = user_info.get("id") user_name = user_info.get("displayName") if not user_id or not user_name: logging.warning("No user id/name") return None return user_id, user_name auth_info = get_auth_info() if not auth_info: await self._launcher_client.start_launcher() raise InvalidCredentials self.store_credentials( {"external-credentials": "force-reconnect-on-startup"}) return Authentication(user_id=auth_info[0], user_name=auth_info[1])
async def pass_login_credentials(self, step, credentials, cookies): logging.debug(json.dumps(cookies, indent=2)) auth_cookie = next(filter(lambda c: c['name'] == '_simpleauth_sess', cookies)) user_id, user_name = await self._api.authenticate(auth_cookie) self.store_credentials(auth_cookie) return Authentication(user_id, user_name)
async def _do_auth(self): user_info = await self._epic_client.get_users_info([self._http_client.account_id]) display_name = self._epic_client.get_display_name(user_info) self._http_client.set_auth_lost_callback(self.lost_authentication) return Authentication(self._http_client.account_id, display_name)
async def authenticate(self, stored_credentials=None): logging.debug("authenticate") confirmation_uri = 'https://itch.io/user/oauth?client_id=3821cecdd58ae1a920be15f6aa479f7e&scope=profile&response_type=token&redirect_uri=http%3A%2F%2F127.0.0.1%3A7157%2Fgogg2itchintegration' if not stored_credentials: return NextStep("web_session", { "window_title": "Log in to Itch.io", "window_width": 536, "window_height": 675, "start_uri": confirmation_uri, "end_uri_regex": r"^(http://127\.0\.0\.1:7157/gogg2itchintegration#access_token=.+)", }, js={ r'^https://itch\.io/my-feed.*': [f'window.location = "{confirmation_uri}"'] }) else: self.http_client.update_cookies(stored_credentials) try: user = await self.get_user_data() return Authentication(str(user.get("id")), str(user.get("username"))) except AccessDenied: raise InvalidCredentials()
async def authenticate(self, stored_credentials=None): usercred = {} username = config.username usercred["username"] = config.username self.store_credentials(usercred) return Authentication("PSVuserId", usercred["username"])
async def authenticate(self, stored_credentials=None): show_news = self.__is_after_minor_update() self._save_cache('last_version', __version__) if not stored_credentials: return NextStep( "web_session", { "window_title": "Login to HumbleBundle", "window_width": 560, "window_height": 610, "start_uri": "https://www.humblebundle.com/login?goto=/home/library", "end_uri_regex": "^" + re.escape("https://www.humblebundle.com/home/library") }) logging.info('Stored credentials found') user_id = await self._api.authenticate(stored_credentials) user_email = await self._fetch_marketing_data() if show_news: self._open_config(OPTIONS_MODE.NEWS) return Authentication(user_id, user_email or user_id)
async def pass_login_credentials(self, step, credentials, cookies): auth_cookie = next( filter(lambda c: c['name'] == '_simpleauth_sess', cookies)) user_id = await self._api.authenticate(auth_cookie) self.store_credentials(auth_cookie) self._open_config(OPTIONS_MODE.WELCOME) return Authentication(user_id, user_id)
async def authenticate(self, stored_credentials=None): if not stored_credentials: logging.info('No stored credentials') AUTH_PARAMS = { "window_title": "Login to Guild Wars 2", "window_width": 640, "window_height": 460, "start_uri": self._gw2_api.auth_server_uri(), "end_uri_regex": '.*finished' } if not self._gw2_api.auth_server_start(): raise BackendError() return NextStep("web_session", AUTH_PARAMS) else: auth_passed = self._gw2_api.do_auth_apikey( stored_credentials['api_key']) if not auth_passed: logging.warning( 'plugin/authenticate: stored credentials are invalid') raise InvalidCredentials() return Authentication(self._gw2_api.get_account_id(), self._gw2_api.get_account_name())
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)
def test_updated_cookies(plugin, http_client, backend_client): loop = asyncio.get_event_loop() user_id = "13" persona_id = "19" user_name = "Jan" cookies = {"cookie": "value"} credentials = {"cookies": cookies} new_cookies = {"new_cookie": "new_value"} morsel = Morsel() morsel.set("new_cookie", "new_value", "new_value") new_credentials = {"cookies": new_cookies} http_client.authenticate.return_value = None def get_identity(): callback = http_client.set_cookies_updated_callback.call_args[0][0] callback([morsel]) return user_id, persona_id, user_name backend_client.get_identity.side_effect = get_identity with patch.object(plugin, "store_credentials") as store_credentials: result = loop.run_until_complete(plugin.authenticate(credentials)) assert result == Authentication(user_id, user_name) store_credentials.assert_called_with(new_credentials) http_client.authenticate.assert_called_with(cookies) backend_client.get_identity.assert_called_with()
def test_no_stored_credentials(plugin, http_client, backend_client): loop = asyncio.get_event_loop() cookies = {"cookie": "value"} user_id = "13" persona_id = "19" user_name = "Jan" http_client.authenticate.return_value = None backend_client.get_identity.return_value = user_id, persona_id, user_name with patch.object(plugin, "store_credentials") as store_credentials: result = loop.run_until_complete(plugin.authenticate()) assert result == NextStep("web_session", AUTH_PARAMS, js=JS) credentials = { "cookies": cookies, } result = loop.run_until_complete( plugin.pass_login_credentials("whatever step", "whatever credentials", [{ "name": key, "value": value } for key, value in cookies.items()])) assert result == Authentication(user_id, user_name) store_credentials.assert_called_with(credentials) http_client.authenticate.assert_called_with(cookies) backend_client.get_identity.assert_called_with()
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: return NextStep("web_session", AUTH_PARAMS) logging.info('Stored credentials found') user_id, user_name = await self._api.authenticate(stored_credentials) return Authentication(user_id, user_name)
def parse_auth_after_setting_battletag(self): self.creds["user_details_cache"] = self.user_details try: battletag = self.user_details["battletag"] except KeyError: raise InvalidCredentials() self._plugin.store_credentials(self.creds) return Authentication(self.user_details["id"], battletag)
async def _do_auth(self, npsso): if not npsso: raise InvalidCredentials() await self._http_client.authenticate(npsso) user_id, user_name = await self._psn_client.async_get_own_user_info() return Authentication(user_id=user_id, user_name=user_name)
async def authenticate(self, stored_credentials=None ) -> Union[NextStep, Authentication]: if not self.config_data['dolphin_path'] or not self.config_data[ 'games_path']: return NextStep('web_session', utils.SETUP_WEB_PARAMS) return Authentication( "Dolphin-ID", "Dolphin") # don't care about authentication values
async def do_auth(self, username): logging.debug("Auth request started") user_data = {} logging.debug(username) user_data['username'] = username self.store_credentials(user_data) self.backend.my_authenticated = True return Authentication('importer_user', user_data['username'])