Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions packages/modules/vehicles/vwid/README.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
Die python library libvwid.py dient als Basis und wird hier gepflegt:
Die python library libvwid.py diente ursprünglich als Basis und wurde hier gepflegt:
https://github.com/skagmo/ha_vwid/blob/main/custom_components/vwid/libvwid.py
Der Autor der libvwid.py wird diese nicht mehr weiterpflegen.
Daher wird die libvwid.py im Rahmen des vwid SoC-Moduls weitergepflegt.

Als weitere Quelle dient https://github.com/TA2k/ioBroker.vw-connect

Folgende python Komponenten werden zusätzlich benötigt, diese werden in requirements.txt eingetragen:
lxml, aiohttp, pyjwt

The script prepare_libvwid.py downloads libvwid.py from github and applies fixes for flake8 issues,
resulting in a flake8-clean version of libvwid.py
42 changes: 39 additions & 3 deletions packages/modules/vehicles/vwid/libvwid.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
import secrets
import logging
import json
import uuid
import base64
import hashlib

from helpermodules.utils.error_handling import ImportErrorContext
with ImportErrorContext():
Expand All @@ -16,6 +19,20 @@
LOGIN_BASE = "https://emea.bff.cariad.digital/user-login/v1"
LOGIN_HANDLER_BASE = "https://identity.vwgroup.io"
API_BASE = "https://emea.bff.cariad.digital/vehicle/v1"
CLIENT_ID = "a24fba63-34b3-4d43-b181-942111e6bda8@apps_vw-dilab_com"
SCOPE = "openid profile badge cars dealers birthdate vin"
REDIRECT_URI = "weconnect://authenticated"
RESPONSE_TYPE = "code id_token token"
CODE_CHALLENGE_METHOD = 'S256'
REGION = "emea"

# XREQUEST = "com.volkswagen.weconnect"
# XCLIENT_ID = ""
# TYPE = "VW"
# COUNTRY = "DE"
# XAPPVERSION = ""
# XAPPNAME = ""
# XBRAND = "volkswagen"


class vwid:
Expand Down Expand Up @@ -83,15 +100,34 @@ def set_credentials(self, username, password):
def set_jobs(self, jobs):
self.jobs_string = ','.join(jobs)

def get_code_challenge(self):
code_verifier = secrets.token_urlsafe(64).replace('+', '-').replace('/', '_').replace('=', '')
code_challenge = base64.b64encode(hashlib.sha256(code_verifier.encode('utf-8')).digest())
code_challenge = code_challenge.decode('utf-8').replace('+', '-').replace('/', '_').replace('=', '')
return (code_verifier, code_challenge)

async def connect(self, username, password):
self.set_credentials(username, password)
return (await self.reconnect())

async def reconnect(self):
# Get code challenge and verifier
code_verifier, code_challenge = self.get_code_challenge()

# Get authorize page
# payload = {
# 'nonce': secrets.token_urlsafe(12),
# 'redirect_uri': 'weconnect://authenticated'
# }
payload = {
'client_id': CLIENT_ID,
'scope': SCOPE,
'response_type': RESPONSE_TYPE,
'nonce': secrets.token_urlsafe(12),
'redirect_uri': 'weconnect://authenticated'
'redirect_uri': REDIRECT_URI,
'state': str(uuid.uuid4()),
'code_challenge': code_challenge,
'code_challenge_method': CODE_CHALLENGE_METHOD
}

response = await self.session.get(LOGIN_BASE + '/authorize', params=payload)
Expand Down Expand Up @@ -156,8 +192,8 @@ async def reconnect(self):
payload = {
'state': query['state'],
'id_token': query['id_token'],
'redirect_uri': "weconnect://authenticated",
'region': "emea",
'redirect_uri': REDIRECT_URI,
'region': REGION,
'access_token': query["access_token"],
'authorizationCode': query["code"]
}
Expand Down
43 changes: 0 additions & 43 deletions packages/modules/vehicles/vwid/prepare_libvwid.sh

This file was deleted.