Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX: Accept consent when login in #349

Merged
merged 1 commit into from
Dec 12, 2024
Merged
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
37 changes: 20 additions & 17 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -683,22 +683,24 @@ class VwWeconnect extends utils.Adapter {
//check for empty form object
if (Object.keys(form).length === 0 && form.constructor === Object) {
try {
const stringJson = body
.split("window._IDK = ")[1]
.split("</")[0]
.replace(/\n/g, "")
.replace(/:\/\//g, "")
.replace(/local:/g, "");
const json = stringJson
.replace(/(['"])?([a-z0-9A-Z_]+)(['"])?:/g, '"$2": ')
.replace(/'/g, '"')
.replace(/""/g, '"');
const parsedJson = JSON.parse(json);
form._csrf = parsedJson.csrf_token;
form.hmac = parsedJson.templateModel.hmac;
form.relayState = parsedJson.templateModel.relayState;
form.legalDocuments = parsedJson.templateModel.legalDocuments;
} catch (error) {
const stringJson = body
.split("window._IDK = ")[1]
.split("</")[0]

let json = stringJson.replace(/([{,]\s*)(\w+)\s*:/g, '$1"$2":') // Add quotes around property names
json = json.replace(/'/g, '"')
json = json.replace(/,\s*}/g, '}') // Remove trailing commas

const parsedJson = JSON.parse(json);

form._csrf = parsedJson.csrf_token;
form.hmac = parsedJson.templateModel.hmac;
form.relayState = parsedJson.templateModel.relayState;
form.legalDocuments = parsedJson.templateModel.legalDocuments;
form.countryOfResidence = 'DE';
form.countryOfJurisdiction = 'DE';

} catch (error) {
this.log.error(
"Error in consent form. Please accept the Data Privacy Statement in the app after relogin",
);
Expand Down Expand Up @@ -803,6 +805,7 @@ class VwWeconnect extends utils.Adapter {
);
this.log.info(getRequest.uri.href);
const form = this.extractHidden(body);

getRequest = request.post(
{
url: getRequest.uri.href,
Expand Down Expand Up @@ -6355,4 +6358,4 @@ if (module.parent) {
} else {
// otherwise start the instance directly
new VwWeconnect();
}
}
Loading