Skip to content

Commit

Permalink
v1.1.1 user-agent fix to fix authorisation failure
Browse files Browse the repository at this point in the history
  • Loading branch information
myTselection committed Jul 30, 2023
1 parent a2a3614 commit 263847e
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ cards:
timestamp_custom("%d-%m-%Y")}}
Wi-Free verbruik:
{{(state_attr('sensor.telenet_telemeter_internet_w123456','wifree_usage')/1024 )| int}}MB
{{(state_attr('sensor.telenet_telemeter_internet_w123456','wifree_usage')*1024 )| int}}MB
{{state_attr('sensor.telenet_telemeter_internet_w123456','product')}}: {{state_attr('sensor.telenet_telemeter_internet_w123456','download_speed')}}/{{state_attr('sensor.telenet_telemeter_internet_w123456','upload_speed')}} (Peak {{states('sensor.telenet_telemeter_peak_w123456')}}, {{state_attr('sensor.telenet_telemeter_peak_w123456','download_speed')}})
Expand Down
2 changes: 1 addition & 1 deletion custom_components/telenet_telemeter/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
"iot_class": "cloud_polling",
"issue_tracker": "https://github.com/myTselection/telenet_telemeter/issues",
"requirements": ["beautifulsoup4", "html5lib"],
"version": "1.1.0"
"version": "1.1.1"
}
6 changes: 4 additions & 2 deletions custom_components/telenet_telemeter/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ def check_settings(config, hass):
class TelenetSession(object):
def __init__(self):
self.s = requests.Session()
self.s.headers["User-Agent"] = "TelemeterPython/3"
self.s.headers["x-alt-referer"] = "https://www2.telenet.be/nl/klantenservice/#/pages=1/menu=selfservice"
self.s.headers["User-Agent"] = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36"
# self.s.headers["x-alt-referer"] = "https://www2.telenet.be/nl/klantenservice/#/pages=1/menu=selfservice"
self.s.headers["x-alt-referer"] = "https://www2.telenet.be/residential/nl/mijn-telenet"

def callTelenet(self, url, caller = "Not set", data = None, expectedStatusCode = "200", printResponse = False):
if data == None:
Expand All @@ -68,6 +69,7 @@ def login(self, username, password):
return
assert response.status_code == 401
# Fetch state & nonce
_LOGGER.debug(f"loging response to split state, nonce: {response.text}")
state, nonce = response.text.split(",", maxsplit=2)
# Log in
self.callTelenet(f'https://login.prd.telenet.be/openid/oauth/authorize?client_id=ocapi&response_type=code&claims={{"id_token":{{"http://telenet.be/claims/roles":null,"http://telenet.be/claims/licenses":null}}}}&lang=nl&state={state}&nonce={nonce}&prompt=login',"login", None, None)
Expand Down

0 comments on commit 263847e

Please sign in to comment.