示例#1
0
    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)
示例#2
0
    async def pass_login_credentials(self, step, credentials, cookies):
        if "logout&app=oauth" in credentials['end_uri']:
            # 2fa expired, repeat authentication
            return self.authentication_client.authenticate_using_login()

        if self.authentication_client.attempted_to_set_battle_tag:
            self.authentication_client.user_details = await self.backend_client.get_user_info()
            return self.authentication_client.parse_auth_after_setting_battletag()

        cookie_jar = self.authentication_client.parse_cookies(cookies)
        auth_data = await self.authentication_client.get_auth_data_login(cookie_jar, credentials)

        try:
            await self.authentication_client.create_session()
            await self.backend_client.refresh_cookies()
        except (BackendNotAvailable, BackendError, NetworkError, UnknownError, BackendTimeout) as e:
            raise e
        except Exception:
            raise InvalidCredentials()

        auth_status = await self.backend_client.validate_access_token(auth_data.access_token)
        if not ("authorities" in auth_status and "IS_AUTHENTICATED_FULLY" in auth_status["authorities"]):
            raise InvalidCredentials()

        self.authentication_client.user_details = await self.backend_client.get_user_info()

        self.authentication_client.set_credentials()

        return self.authentication_client.parse_battletag()
示例#3
0
    async def _do_auth(self, npsso):
        if not npsso:
            raise InvalidCredentials()

        try:
            await self._http_client.authenticate(npsso)
            user_id, user_name = await self._psn_client.async_get_own_user_info()
        except Exception:
            raise InvalidCredentials()

        return Authentication(user_id=user_id, user_name=user_name)
示例#4
0
 def validate_auth_status(self, auth_status):
     if 'error' in auth_status:
         if not self.user_details:
             raise InvalidCredentials()
         else:
             return False
     elif not self.user_details:
         raise InvalidCredentials()
     else:
         if not ("authorities" in auth_status and "IS_AUTHENTICATED_FULLY" in auth_status["authorities"]):
             raise InvalidCredentials()
         return True
示例#5
0
    async def _do_auth(
        self, poesessid: PoeSessionId, profile_name: ProfileName, store_poesessid: bool = True
    ) -> Authentication:
        if not poesessid:
            raise InvalidCredentials(self._AUTH_SESSION_ID)
        if not profile_name:
            raise InvalidCredentials(self._AUTH_PROFILE_NAME)

        self._http_client = PoeHttpClient(poesessid, profile_name, self._on_auth_lost)

        if store_poesessid:
            self.store_credentials({self._AUTH_SESSION_ID: poesessid, self._AUTH_PROFILE_NAME: profile_name})

        return Authentication(user_id=profile_name, user_name=profile_name)
示例#6
0
    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()
示例#7
0
 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()
示例#8
0
    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)
示例#9
0
    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()
示例#10
0
 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:
            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 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()))
    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)
        if user_id is None:
            raise InvalidCredentials()
        if show_news:
            self._open_config(OPTIONS_MODE.NEWS)
        return Authentication(user_id, user_id)
 async def get_access_token(self,
                            refresh_token=None,
                            url=OAUTH_TOKEN_URL,
                            cookies=None):
     response = None
     if cookies is None:
         cookies = {"npsso": refresh_token}
     try:
         response = await super().request("GET",
                                          url=url,
                                          cookies=cookies,
                                          allow_redirects=False)
         location_params = urlsplit(response.headers["Location"])
         self._validate_auth_response(location_params)
         fragment = dict(parse_qsl(location_params.fragment))
         if 'access_token' not in fragment:
             return await self.get_access_token(
                 url=response.headers['Location'], cookies=response.cookies)
         self._store_new_npsso(cookies)
         return fragment["access_token"]
     except AuthenticationRequired as e:
         raise InvalidCredentials(e.data)
     except (KeyError, IndexError):
         raise UnknownBackendResponse(str(response.headers))
     finally:
         if response:
             response.close()
示例#15
0
    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())
示例#16
0
 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)
示例#17
0
 async def set_profile_data(profile_url):
     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")
         return login
     except AccessDenied:
         raise InvalidCredentials()
示例#18
0
    async def pass_login_credentials(self, step, credentials, cookies):
        try:
            await self._http_client.authenticate_with_exchage_code(
                credentials["end_uri"].split(AUTH_REDIRECT_URL, 1)[1]
            )
        except Exception:
            # TODO: distinguish between login-related and all other (networking, server, e.t.c.) errors
            raise InvalidCredentials()

        return await self._do_auth()
示例#19
0
 async def authenticate(self, stored_credentials=None):
     if not stored_credentials:
         log.debug("DISCORD_RESTART: Restarting Discord...")
         await prepare_and_discover_discord()
         await get_ws_url()
         try:
             await self.scrape_discord()
         except Exception:
             log.exception(
                 "DISCORD_AUTH_FAILURE: A critical exception was thrown when scraping the Discord client."
             )
             raise InvalidCredentials()
         if self.user_email:
             self.store_credentials({"user_email": self.user_email})
         else:
             raise InvalidCredentials()
     else:
         self.user_email = stored_credentials["user_email"]
     return Authentication(self.user_email, self.user_email)
    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, login = await self._client.get_profile_data(profile_url)
        except AccessDenied:
            raise InvalidCredentials()

        self._http_client.set_auth_lost_callback(self.lost_authentication)

        return Authentication(self._steam_id, login)
示例#21
0
    async def pass_login_credentials(self, step, credentials, cookies):
        self._gw2_api.auth_server_stop()

        api_key = self._gw2_api.get_api_key()
        if not api_key:
            logging.error('plugin/pass_login_credentials: api_key is None!')
            raise InvalidCredentials()

        self.store_credentials({'api_key': api_key})
        return Authentication(self._gw2_api.get_account_id(),
                              self._gw2_api.get_account_name())
示例#22
0
 async def set_profile_data():
     try:
         await self._client.get_authentication_data()
         steam_id, login = await self._client.get_profile_data(profile_url)
         self._user_info_cache.account_username = login
         self._user_info_cache.old_flow = True
         self._user_info_cache.steam_id = steam_id
         self.create_task(self._steam_client.run(), "Run WebSocketClient")
         return steam_id, login
     except AccessDenied:
         raise InvalidCredentials()
示例#23
0
    async def _do_authenticate(self, cookies):
        try:
            await self._http_client.authenticate(cookies)

            self._user_id, self._persona_id, user_name = await self._backend_client.get_identity(
            )
            return Authentication(self._user_id, user_name)

        except (AccessDenied, InvalidCredentials, AuthenticationRequired) as e:
            logging.exception("Failed to authenticate %s", repr(e))
            raise InvalidCredentials()
示例#24
0
    async def authenticate(self, stored_credentials=None):
        if not stored_credentials:
            return NextStep("web_session", AUTH_PARAMS, js=AUTH_JS)

        refresh_token = stored_credentials["refresh_token"]
        try:
            await self._http_client.authenticate_with_refresh_token(refresh_token)
        except Exception:
            # TODO: distinguish between login-related and all other (networking, server, e.t.c.) errors
            raise InvalidCredentials()

        return await self._do_auth()
    async def pass_login_credentials(self, step, credentials, cookies):
        self._wgc.auth_server_stop()

        login_info = self._wgc.login_info_get()
        if not login_info:
            logging.error('Login info is None!')
            raise InvalidCredentials()

        self.store_credentials(login_info)
        return Authentication(
            self._wgc.account_id(), '%s_%s' %
            (self._wgc.account_realm(), self._wgc.account_nickname()))
示例#26
0
async def start(rec_tries=0):
    if rec_tries > 100:
        log.debug(
            "DISCORD_SCRAPE_FAILED: The maximum number of retries has been reached."
        )
        raise InvalidCredentials()
    global returned_from_trio_run
    # await trio.sleep(10)
    ws = websocket.WebSocket()
    ws.connect(ws_url)
    returned_from_trio_run = (await get_games(ws), await get_friends(ws), await
                              get_user_email(ws))
示例#27
0
    async def pass_login_credentials(self, step, credentials, cookies):
        if self.__authserver is not None:
            await self.__authserver.shutdown()

        api_key = self._gw2_api.get_api_key()
        account_id = self._gw2_api.get_account_id()
        account_name = self._gw2_api.get_account_name()
        if (api_key is None) or (account_id is None) or (account_name is None):
            self.__logger.error('pass_login_credentials: invalid credentials')
            raise InvalidCredentials()

        self.store_credentials({'api_key': api_key})
        return Authentication(account_id, account_name)
    async def authenticate(self, stored_credentials=None):
        if not stored_credentials:
            return NextStep("web_session", AUTH_PARAMS)

        refresh_token = stored_credentials["refresh_token"]
        try:
            await self._http_client.authenticate_with_refresh_token(refresh_token)
        except (BackendNotAvailable, BackendError, BackendTimeout, NetworkError, UnknownError) as e:
            raise e
        except Exception:
            raise InvalidCredentials()

        return await self._do_auth()
示例#29
0
    async def _do_authenticate(self, cookies):
        try:
            await self._http_client.authenticate(cookies)

            self._pid, self._persona_id, user_name = await self._backend_client.get_identity(
            )
            return Authentication(self._pid, user_name)

        except (BackendNotAvailable, BackendTimeout, BackendError):
            raise
        except Exception:
            # TODO: more precise error reason
            logging.exception("Authentication failed")
            raise InvalidCredentials()
 async def do_request(self, method, *args, **kwargs):
     try:
         return await self.request(method, *args, **kwargs)
     except Exception as e:
         log.warning(
             f"Request failed with {repr(e)}, attempting to refresh credentials"
         )
     try:
         await self.refresh_credentials()
         return await self.request(method, *args, **kwargs)
     except Exception as e:
         log.error(f"Refresh workflow failed with {repr(e)}")
         self._auth_lost_callback()
         raise InvalidCredentials()