コード例 #1
0
def create_next_step(start, end):
    params = {**_AUTH_PARAMS}

    params['start_uri'] = start
    params['end_uri_regex'] = end

    return NextStep('web_session', params)
コード例 #2
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)
コード例 #3
0
    async def authenticate(self, stored_credentials=None):
        show_news = self.__is_after_minor_update()
        just_after_broken_sub_version = self.__is_after_broken_subscriptions_version(
        )  # remove after ~04.2021
        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')
        auth: Authentication = await self._do_auth(stored_credentials)

        # To be removed around 04.2021
        # After fixing bug with offline plugin for subscribers (#151),
        # reconnection is need to make Galaxy recognize `get_subscriptions` feature again.
        if just_after_broken_sub_version and await self._api.had_subscription(
        ):
            show_news = True

        if show_news:
            self._open_config(OPTIONS_MODE.NEWS)
        return auth
コード例 #4
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())
コード例 #5
0
    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)
コード例 #6
0
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()
コード例 #7
0
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)
コード例 #8
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()
コード例 #9
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()
コード例 #10
0
    async def authenticate(self, stored_credentials=None):
        stored_npsso ="DqjxBT163jkksHrOJLUZIoLnutuTnlgWpu6mgo06sOwTZRx3L4AAl1Pk1IhKeU3x"
        if not stored_npsso:
            return NextStep("web_session", AUTH_PARAMS)

        auth_info = await self._do_auth(stored_npsso)
        return auth_info
コード例 #11
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()
コード例 #12
0
    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)
コード例 #13
0
    async def authenticate(self, stored_credentials: dict = None) -> Union[Authentication, NextStep]:
        poesessid: Optional[PoeSessionId] = None
        profile_name: Optional[ProfileName] = None

        if stored_credentials:
            poesessid = stored_credentials.get(self._AUTH_SESSION_ID)
            profile_name = stored_credentials.get(self._AUTH_PROFILE_NAME)

        if poesessid and profile_name:
            return await self._do_auth(poesessid, profile_name, store_poesessid=False)

        return NextStep(
            "web_session"
            , {
                "window_title": "Still sane, exile?"
                , "window_width": 800
                , "window_height": 600
                , "start_uri": "https://www.pathofexile.com/login"
                , "end_uri_regex": re.escape(self._AUTH_REDIRECT) + ".*"
            }
            , js={
                "https://www.pathofexile.com/my-account": [
                    r'''
                        profileName = document.getElementsByClassName("name")[0].textContent;
                        window.location.replace("''' + self._AUTH_REDIRECT + r'''" + profileName);
                    '''
                ]
            }
        )
コード例 #14
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()
コード例 #15
0
    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()))
コード例 #16
0
    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()))
コード例 #17
0
 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
コード例 #18
0
    async def authenticate(self, stored_credentials=None):
        stored_npsso = stored_credentials.get(
            "npsso") if stored_credentials else None
        if not stored_npsso:
            return NextStep("web_session", AUTH_PARAMS)

        auth_info = await self._do_auth(stored_npsso)
        return auth_info
コード例 #19
0
    async def authenticate(self, stored_credentials=None):
        stored_cookies = stored_credentials.get(
            "cookies") if stored_credentials else None

        if not stored_cookies:
            return NextStep("web_session", AUTH_PARAMS)

        return await self._do_authenticate(stored_cookies)
コード例 #20
0
    async def authenticate(self, stored_credentials=None):
        if not stored_credentials:
            return NextStep("web_session", AUTH_PARAMS,
                            [self._create_two_factor_fake_cookie()],
                            {re.escape(LOGIN_URI): [JS_PERSISTENT_LOGIN]})

        cookies = stored_credentials.get("cookies", [])
        morsels = parse_stored_cookies(cookies)
        return await self._do_auth(morsels)
コード例 #21
0
 def authenticate_using_login(self):
     _URI = f'{self.blizzard_oauth_url}/authorize?response_type=code&client_id={CLIENT_ID}&redirect_uri={REDIRECT_URI}&scope=wow.profile+sc2.profile'
     auth_params = {
         "window_title": "Login to Battle.net",
         "window_width": 540,
         "window_height": 700,
         "start_uri": _URI,
         "end_uri_regex": r"(.*logout&app=oauth.*)|(^http://friendsofgalaxy\.com.*)"
     }
     return NextStep("web_session", auth_params)
コード例 #22
0
 async def authenticate(self, stored_credentials=None):
     if stored_credentials:
         stored_cookies = pickle.loads(
             bytes.fromhex(stored_credentials['cookie_jar']))
         self._http_client.authenticate_with_cookies(stored_cookies)
         self._http_client.set_auth_lost_callback(self.lost_authentication)
         acc_id = await self.paradox_client.get_account_id()
         return Authentication(str(acc_id), 'Paradox')
     if not stored_credentials:
         return NextStep("web_session", AUTH_PARAMS)
コード例 #23
0
    async def authenticate(self, stored_credentials=None):
        if not stored_credentials:
            if await self._client.get_steamcommunity_response_status() != 200:
                logger.error("Steamcommunity website not accessible")
            return NextStep("web_session", AUTH_PARAMS,
                            [self._create_two_factor_fake_cookie()],
                            {re.escape(LOGIN_URI): [JS_PERSISTENT_LOGIN]})

        cookies = stored_credentials.get("cookies", [])
        morsels = parse_stored_cookies(cookies)
        return await self._do_auth(morsels)
コード例 #24
0
    async def authenticate(self, stored_credentials=None):
        if not stored_credentials:
            PARAMS = {
                "window_title": "Configure PS2 Integration",
                "window_width": 550,
                "window_height": 730,
                "start_uri": "http://localhost:" + str(self.auth_server.port),
                "end_uri_regex": ".*/end.*"
            }
            return NextStep("web_session", PARAMS)

        return self._do_auth()
コード例 #25
0
ファイル: plugin.py プロジェクト: dominik-ba/galaxy-epic
    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()
コード例 #26
0
    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()
コード例 #27
0
    async def authenticate(self, stored_credentials=None):
        global roms_path
        if len(roms_path) == 0 and stored_credentials is not None and "roms_path" in stored_credentials:
            roms_path = stored_credentials["roms_path"]

        if len(roms_path) == 0:
            PARAMS = {
                "window_title": "Configure Dosbox Plugin",
                "window_width": 400,
                "window_height": 300,
                "start_uri": "http://localhost:" + str(self.server.port),
                "end_uri_regex": ".*/end.*"
            }
            return NextStep("web_session", PARAMS)

        return self.finish_login()
コード例 #28
0
    def parse_battletag(self):
        try:
            battletag = self.user_details["battletag"]
        except KeyError:
            _URI = f'https://{self.region}.battle.net/login/en/flow/app.app?step=login&ST={requests.utils.dict_from_cookiejar(self.auth_data.cookie_jar)["BA-tassadar"]}&app=app&cr=true'
            auth_params = {
                "window_title": "Login to Battle.net",
                "window_width": 540,
                "window_height": 700,
                "start_uri": _URI,
                "end_uri_regex": r".*accountName.*"
            }
            self.attempted_to_set_battle_tag = True
            return NextStep("web_session", auth_params)

        self._plugin.store_credentials(self.creds)
        return Authentication(self.user_details["id"], battletag)
コード例 #29
0
async def test_no_stored_credentials(get_access_token, http_get, psn_plugin,
                                     access_token, stored_credentials, npsso,
                                     user_profile, auth_info, mocker):
    assert NextStep("web_session",
                    AUTH_PARAMS) == await psn_plugin.authenticate()

    get_access_token.return_value = access_token
    http_get.return_value = user_profile

    assert auth_info == await psn_plugin.pass_login_credentials(
        "whatever step", {}, [{
            "name": "npsso",
            "value": npsso
        }])

    get_access_token.assert_called_once_with(npsso)
    http_get.assert_called_once_with(OWN_USER_INFO_URL)
コード例 #30
0
 async def authenticate(self, stored_credentials=None):
     if not stored_credentials:
         return NextStep("web_session", AUTH_PARAMS, cookies=COOKIES)
     else:
         try:
             user_data = await self.client.authorise_with_stored_credentials(
                 stored_credentials)
         except AccessDenied:
             raise InvalidCredentials()
         except Exception as e:
             log.exception(repr(e))
             raise Aborted()  # for sure this should be raised?
         else:
             self.local_client.initialize(user_data['userId'])
             self.client.set_auth_lost_callback(self.auth_lost)
             return Authentication(user_data['userId'],
                                   user_data['username'])