add XSRF Token logon to vrtnu

This commit is contained in:
pgaig 2021-07-22 09:58:39 +02:00
parent a803582717
commit 17dca698cf

View File

@ -17,6 +17,7 @@ from ..utils import (
str_or_none, str_or_none,
strip_or_none, strip_or_none,
url_or_none, url_or_none,
urlencode_postdata
) )
@ -259,7 +260,7 @@ class VrtNUIE(GigyaBaseIE):
'expected_warnings': ['Unable to download asset JSON', 'is not a supported codec', 'Unknown MIME type'], 'expected_warnings': ['Unable to download asset JSON', 'is not a supported codec', 'Unknown MIME type'],
}] }]
_NETRC_MACHINE = 'vrtnu' _NETRC_MACHINE = 'vrtnu'
_APIKEY = '3_0Z2HujMtiWq_pkAjgnS2Md2E11a1AwZjYiBETtwNE-EoEHDINgtnvcAOpNgmrVGy' _APIKEY = '3_qhEcPa5JGFROVwu5SWKqJ4mVOIkwlFNMSKwzPDAh8QZOtHqu6L4nD5Q7lk0eXOOG'
_CONTEXT_ID = 'R3595707040' _CONTEXT_ID = 'R3595707040'
def _real_initialize(self): def _real_initialize(self):
@ -270,35 +271,49 @@ class VrtNUIE(GigyaBaseIE):
if username is None: if username is None:
return return
auth_data = { # 1. Get Login Data
'APIKey': self._APIKEY, try:
'targetEnv': 'jssdk', auth_info = self._download_json(
'loginID': username, 'https://accounts.vrt.be/accounts.login', None,
'password': password, note='Login data', errnote='Could not get Login data',
'authMode': 'cookie', headers={}, data=urlencode_postdata({
} 'loginID':username,
'password':password,
auth_info = self._gigya_login(auth_data) 'sessionExpiration':'-2',
'APIKey':self._APIKEY,
'targetEnv':'jssdk',
}))
except ExtractorError as e:
self.report_warning("Cookie request HTTP code: %s" % e.cause.code)
raise e
# Sometimes authentication fails for no good reason, retry # Sometimes authentication fails for no good reason, retry
login_attempt = 1 login_attempt = 1
while login_attempt <= 3: while login_attempt <= 3:
try: try:
# When requesting a token, no actual token is returned, but the # get XSRF Token
# necessary cookies are set. xsrf_req = self._request_webpage('https://token.vrt.be/vrtnuinitlogin',
self._request_webpage( None, note='Requesting XSRF Token', errnote='Could not get XSRF Token',
'https://token.vrt.be', query={'provider':'site', 'destination':'https://www.vrt.be/vrtnu/'})
post_data = {
'UID': auth_info['UID'],
'UIDSignature': auth_info['UIDSignature'],
'signatureTimestamp': auth_info['signatureTimestamp'],
'client_id': 'vrtnu-site',
}
for cookie in self._downloader.cookiejar:
if cookie.name == 'OIDCXSRF':
post_data['_csrf'] = cookie.value
break
# do login
vrt_token = self._request_webpage(
'https://login.vrt.be/perform_login',
None, note='Requesting a token', errnote='Could not get a token', None, note='Requesting a token', errnote='Could not get a token',
headers={ headers={}, data=urlencode_postdata(post_data)
'Content-Type': 'application/json', )
'Referer': 'https://www.vrt.be/vrtnu/',
},
data=json.dumps({
'uid': auth_info['UID'],
'uidsig': auth_info['UIDSignature'],
'ts': auth_info['signatureTimestamp'],
'email': auth_info['profile']['email'],
}).encode('utf-8'))
except ExtractorError as e: except ExtractorError as e:
if isinstance(e.cause, compat_HTTPError) and e.cause.code == 401: if isinstance(e.cause, compat_HTTPError) and e.cause.code == 401:
login_attempt += 1 login_attempt += 1