Exemple #1
0
    def LogOn(self):
        tokenCookie = UriHandler.GetCookie("X-VRT-Token", ".vrt.be")
        if tokenCookie is not None:
            return True

        username = self._GetSetting("username")
        if not username:
            return None

        v = Vault()
        password = v.GetChannelSetting(self.guid, "password")
        if not password:
            Logger.Warning("Found empty password for VRT user")

        Logger.Debug("Using: %s / %s", username, "*" * len(password))
        url = "https://accounts.eu1.gigya.com/accounts.login"
        data = "loginID=%s" \
               "&password=%s" \
               "&targetEnv=jssdk" \
               "&APIKey=3_qhEcPa5JGFROVwu5SWKqJ4mVOIkwlFNMSKwzPDAh8QZOtHqu6L4nD5Q7lk0eXOOG" \
               "&includeSSOToken=true" \
               "&authMode=cookie" % \
               (HtmlEntityHelper.UrlEncode(username), HtmlEntityHelper.UrlEncode(password))

        logonData = UriHandler.Open(url, params=data, proxy=self.proxy, noCache=True)
        sig, uid, timestamp = self.__ExtractSessionData(logonData)
        if sig is None and uid is None and timestamp is None:
            return False

        url = "https://token.vrt.be/"
        tokenData = '{"uid": "%s", ' \
                    '"uidsig": "%s", ' \
                    '"ts": "%s", ' \
                    '"fn": "VRT", "ln": "NU", ' \
                    '"email": "%s"}' % (uid, sig, timestamp, username)

        headers = {"Content-Type": "application/json", "Referer": "https://www.vrt.be/vrtnu/"}
        UriHandler.Open(url, params=tokenData, proxy=self.proxy, additionalHeaders=headers)
        return True
    def LogOn(self):
        """ Makes sure that we are logged on. """

        username = self._GetSetting("username")
        if not username:
            Logger.Info("No user name for NPO, not logging in")
            return False

        # cookieValue = self._GetSetting("cookie")
        cookie = UriHandler.GetCookie("isAuthenticatedUser", "www.npo.nl")
        if cookie:
            expireDate = DateHelper.GetDateFromPosix(float(cookie.expires))
            Logger.Info("Found existing valid NPO token (valid until: %s)", expireDate)
            return True

        v = Vault()
        password = v.GetChannelSetting(self.guid, "password")

        # get a token (why?), cookies and an xsrf token
        token = UriHandler.Open("https://www.npo.nl/api/token", proxy=self.proxy, noCache=True,
                                additionalHeaders={"X-Requested-With": "XMLHttpRequest"})

        jsonToken = JsonHelper(token)
        token = jsonToken.GetValue("token")
        if not token:
            return False
        xsrfToken = UriHandler.GetCookie("XSRF-TOKEN", "www.npo.nl").value
        xsrfToken = HtmlEntityHelper.UrlDecode(xsrfToken)

        data = "username=%s&password=%s" % (HtmlEntityHelper.UrlEncode(username),
                                            HtmlEntityHelper.UrlEncode(password))
        UriHandler.Open("https://www.npo.nl/api/login", proxy=self.proxy, noCache=True,
                        additionalHeaders={
                            "X-Requested-With": "XMLHttpRequest",
                            "X-XSRF-TOKEN": xsrfToken
                        },
                        params=data)

        # token = Regexer.DoRegex('name="authenticity_token"[^>]+value="([^"]+)"', tokenData)[0]
        #
        # # login: https://mijn.npo.nl/sessions POST
        # # utf8=%E2%9C%93&authenticity_token=<token>&email=<username>&password=<password>&remember_me=1&commit=Inloggen
        # postData = {
        #     "token": HtmlEntityHelper.UrlEncode(token),
        #     "email": HtmlEntityHelper.UrlEncode(username),
        #     "password": HtmlEntityHelper.UrlEncode(password)
        # }
        # postData = "utf8=%%E2%%9C%%93&authenticity_token=%(token)s&email=%(email)s&" \
        #            "password=%(password)s&remember_me=1&commit=Inloggen" % postData
        # data = UriHandler.Open("https://mijn.npo.nl/sessions", noCache=True, proxy=self.proxy,
        #                        params=postData)
        # if not data:
        #     Logger.Error("Error logging in: no response data")
        #     return False
        #
        # # extract the cookie and store
        # authCookie = UriHandler.GetCookie("npo_portal_auth_token", ".mijn.npo.nl")
        # if not authCookie:
        #     Logger.Error("Error logging in: Cookie not found.")
        #     return False

        # The cookie should already be in the jar now
        return True