Skip to content

Commit

Permalink
simplify login
Browse files Browse the repository at this point in the history
  • Loading branch information
TA2k committed Dec 2, 2023
1 parent 1638c69 commit a8e7733
Showing 1 changed file with 26 additions and 72 deletions.
98 changes: 26 additions & 72 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,18 +102,12 @@ class Boschindego extends utils.Adapter {
if (this.session.access_token) {
await this.getDeviceList();
await this.updateDevices();
this.updateInterval = setInterval(
async () => {
await this.updateDevices();
},
this.config.interval * 60 * 1000,
);
this.refreshTokenInterval = setInterval(
async () => {
await this.refreshToken();
},
(this.session.expires_in || 3600) * 1000,
);
this.updateInterval = setInterval(async () => {
await this.updateDevices();
}, this.config.interval * 60 * 1000);
this.refreshTokenInterval = setInterval(async () => {
await this.refreshToken();
}, (this.session.expires_in - 100 || 3500) * 1000);
}
}

Expand All @@ -125,8 +119,7 @@ class Boschindego extends utils.Adapter {
nonce: 'b_x1uhAjiy3iKMcXX1TKbJnBph18-J_Hms4vvWeE7qw',
response_type: 'code',
code_challenge_method: 'S256',
scope:
'openid profile email https://prodindego.onmicrosoft.com/indego-mobile-api/Indego.Mower.User offline_access',
scope: 'openid profile email https://prodindego.onmicrosoft.com/indego-mobile-api/Indego.Mower.User offline_access',
code_challenge: '5C1HXuvfGjAo-6TVzy_95lQNmpAjorsngCwiD3w3VHs',
redirect_uri: 'msauth.com.bosch.indegoconnect.cloud://auth/',
client_id: '65bb8c9d-1070-4fb4-aa95-853618acc876',
Expand Down Expand Up @@ -177,69 +170,33 @@ class Boschindego extends utils.Adapter {
});

// const token = this.cookieJar.getCookiesSync('https://singlekey-id.com/auth/').find((cookie) => cookie.key === 'X-CSRF-FORM-TOKEN');
const userResponse = await this.requestClient({
await this.requestClient({
method: 'post',
maxBodyLength: Infinity,
url: 'https://singlekey-id.com/auth/de-de/login',
url: 'https://singlekey-id.com/auth/api/v1/authentication/login',
headers: {
'content-type': 'application/x-www-form-urlencoded',
accept: '*/*',
'hx-request': 'true',
'sec-fetch-site': 'same-origin',
'hx-boosted': 'true',
'accept-language': 'de-DE,de;q=0.9',
'sec-fetch-mode': 'cors',
origin: 'https://singlekey-id.com',
'user-agent':
'Mozilla/5.0 (iPhone; CPU iPhone OS 16_7_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.6 Mobile/15E148 Safari/604.1',
'sec-fetch-dest': 'empty',
},
params: loginParams,
data: {
'UserIdentifierInput.EmailInput.StringValue': this.config.username,
__RequestVerificationToken: formData['undefined'],
Accept: 'application/json, text/plain, */*',
'Content-Type': 'application/json',
RequestVerificationToken: formData['undefined'],
},

data: JSON.stringify({
username: this.config.username,
password: this.config.password,
keepMeSignedIn: true,
returnUrl: loginParams.returnUrl,
}),
})
.then((res) => {
this.log.debug(JSON.stringify(res.data));
return this.extractHidden(res.data);
return res.data;
})
.catch((error) => {
this.log.error('Please check username and password');
this.log.error(error);
error.response && this.log.error(JSON.stringify(error.response.data));
if (error.response) {
this.log.error(JSON.stringify(error.response.data));
}
});
if (!userResponse) {
this.log.error('Could not extract user data');
return;
}
await this.requestClient({
method: 'post',
maxBodyLength: Infinity,
url: 'https://singlekey-id.com/auth/de-de/login/password',
headers: {
'content-type': 'application/x-www-form-urlencoded',
accept: '*/*',
'hx-request': 'true',
'sec-fetch-site': 'same-origin',
'hx-boosted': 'true',
'accept-language': 'de-DE,de;q=0.9',
'sec-fetch-mode': 'cors',
origin: 'https://singlekey-id.com',
'user-agent':
'Mozilla/5.0 (iPhone; CPU iPhone OS 16_7_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.6 Mobile/15E148 Safari/604.1',
'sec-fetch-dest': 'empty',
},
params: loginParams,
data: {
Password: this.config.password,
RememberMe: 'true',
__RequestVerificationToken: userResponse['undefined'],
},
}).catch((error) => {
this.log.error(error);
error.response && this.log.error(JSON.stringify(error.response.data));
});

const htmlForm = await this.requestClient({
method: 'get',
url: 'https://singlekey-id.com' + loginParams.returnUrl,
Expand Down Expand Up @@ -521,10 +478,7 @@ class Boschindego extends utils.Adapter {
}

for (const id of this.deviceArray) {
if (
(this.config.getMap && this.lastState[id] == null) ||
(this.lastState[id] >= 500 && this.lastState[id] <= 799)
) {
if ((this.config.getMap && this.lastState[id] == null) || (this.lastState[id] >= 500 && this.lastState[id] <= 799)) {
statusArray.push({
path: 'map',
url: 'https://api.indego-cloud.iot.bosch-si.com/api/v1/alms/$id/map',
Expand Down Expand Up @@ -610,7 +564,7 @@ class Boschindego extends utils.Adapter {
//add location to map
map = map.replace(
'</svg>',
`<circle cx="${state.svg_xPos}" cy="${state.svg_yPos}" r="20" stroke="black" stroke-width="3" fill="yellow"/> </svg>`,
`<circle cx="${state.svg_xPos}" cy="${state.svg_yPos}" r="20" stroke="black" stroke-width="3" fill="yellow"/> </svg>`
);
//transparent background
map = map.replace('ry="0" fill="#FAFAFA"', 'ry="0" fill="#00000" fill-opacity="0.0"');
Expand Down

0 comments on commit a8e7733

Please sign in to comment.