Skip to content

Commit

Permalink
Merge pull request #169 from Hacksore/develop
Browse files Browse the repository at this point in the history
  • Loading branch information
Hacksore authored Oct 26, 2021
2 parents 561b845 + 88cb93b commit 5d39f11
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/npmpublish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: npm

on:
release:

types: [created]

jobs:
publish:
Expand Down
3 changes: 2 additions & 1 deletion debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,8 @@ async function performCommand(command) {
break;
case 'drvInfo':
const info = await vehicle.driveHistory();
console.log('drvInfo : ', info);
console.log('drvInfo : ');
console.dir(info,{ depth: null });
break;
case 'tripInfo':
const currentYear = new Date().getFullYear();
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bluelinky",
"version": "7.5.0",
"version": "7.6.0",
"description": "An unofficial nodejs API wrapper for Hyundai bluelink",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
10 changes: 5 additions & 5 deletions src/constants/europe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ const getHyundaiEnvironment = (stampsTimeout?: number): EuropeanBrandEnvironment
const host = 'prd.eu-ccapi.hyundai.com:8080';
const baseUrl = `https://${host}`;
const clientId = '6d477c38-3ca4-4cf3-9557-2a1929a94654';
const appId = '99cfff84-f4e2-4be8-a5ed-e5b755eb6581';
const appId = '014d2225-8495-4735-812d-2616334fd15d';
return {
brand: 'hyundai',
host,
Expand All @@ -81,8 +81,8 @@ const getHyundaiEnvironment = (stampsTimeout?: number): EuropeanBrandEnvironment
appId,
endpoints: Object.freeze(getEndpoints(baseUrl, clientId)),
basicToken: 'Basic NmQ0NzdjMzgtM2NhNC00Y2YzLTk1NTctMmExOTI5YTk0NjU0OktVeTQ5WHhQekxwTHVvSzB4aEJDNzdXNlZYaG10UVI5aVFobUlGampvWTRJcHhzVg==',
GCMSenderID: '199360397125',
stamp: getStamp('hyundai', stampsTimeout),
GCMSenderID: '414998006775',
stamp: getStamp(`hyundai-${appId}`, stampsTimeout),
brandAuthUrl({ language, serviceId, userId }) {
const newAuthClientId = '97516a3c-2060-48b4-98cd-8e7dcd3c47b2';
return `https://eu-account.hyundai.com/auth/realms/euhyundaiidm/protocol/openid-connect/auth?client_id=${newAuthClientId}&scope=openid%20profile%20email%20phone&response_type=code&hkid_session_reset=true&redirect_uri=${baseUrl}/api/v1/user/integration/redirect/login&ui_locales=${language}&state=${serviceId}:${userId}`;
Expand All @@ -103,10 +103,10 @@ const getKiaEnvironment = (stampsTimeout?: number): EuropeanBrandEnvironment =>
appId,
endpoints: Object.freeze(getEndpoints(baseUrl, clientId)),
basicToken: 'Basic ZmRjODVjMDAtMGEyZi00YzY0LWJjYjQtMmNmYjE1MDA3MzBhOnNlY3JldA==',
GCMSenderID: '199360397125',
GCMSenderID: '345127537656',
stamp: getStamp(`kia-${appId}`, stampsTimeout),
brandAuthUrl({ language, serviceId, userId }) {
const newAuthClientId = 'f4d531c7-1043-444d-b09a-ad24bd913dd4';
const newAuthClientId = '572e0304-5f8d-4b4c-9dd5-41aa84eed160';
return `https://eu-account.kia.com/auth/realms/eukiaidm/protocol/openid-connect/auth?client_id=${newAuthClientId}&scope=openid%20profile%20email%20phone&response_type=code&hkid_session_reset=true&redirect_uri=${baseUrl}/api/v1/user/integration/redirect/login&ui_locales=${language}&state=${serviceId}:${userId}`;
}
};
Expand Down
43 changes: 41 additions & 2 deletions src/controllers/authStrategies/european.brandAuth.strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@ export class EuropeanBrandAuthStrategy implements AuthStrategy {
json: true,
headers: stdHeaders
});
const brandAuthUrl = this.environment.brandAuthUrl({ language: this.language, userId, serviceId });
const parsedBrandUrl = Url.parse(brandAuthUrl, true);
const { body: authForm } = await got(
this.environment.brandAuthUrl({ language: this.language, userId, serviceId }), {
brandAuthUrl, {
cookieJar,
headers: stdHeaders
});
Expand Down Expand Up @@ -61,13 +63,50 @@ export class EuropeanBrandAuthStrategy implements AuthStrategy {
}
throw new Error('@EuropeanBrandAuthStrategy.login: Authentication failed, cannot retrieve error message');
}
const { url, body: htmlPage } = await got(redirectTo, {
const authResult = await got(redirectTo, {
cookieJar,
headers: stdHeaders
});
let url = authResult.url;
let htmlPage = authResult.body;
if(!url) {
throw new Error(`@EuropeanBrandAuthStrategy.login: after login redirection got stuck : ${htmlPage}`);
}
if(url.includes('login-actions/required-action')) {
const loginActionUrl = /action="([a-z0-9:/\-.?_=&;]*)"/gi.exec(htmlPage);
const loginActionCode = /name="code" value="(.*)"/gi.exec(htmlPage);
if (!loginActionUrl) {
throw new Error('@EuropeanBrandAuthStrategy.login: Cannot find login-actions url.');
}
if (!loginActionCode) {
throw new Error('@EuropeanBrandAuthStrategy.login: Cannot find login-actions code.');
}
const actionUrl = (loginActionUrl[1].startsWith('/')) ? `${parsedBrandUrl.protocol}//${parsedBrandUrl.host}${loginActionUrl[1]}` : loginActionUrl[1];
const loginActionForm = new URLSearchParams();
loginActionForm.append('code', loginActionCode[1]);
loginActionForm.append('accept', '');
const { headers: { location: loginActionRedirect }, body: AfterLoginActionAuthForm } = await manageGot302(got.post(actionUrl, {
cookieJar,
body: loginActionForm.toString(),
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
...stdHeaders
},
}));
if(!loginActionRedirect) {
const errorMessage = /<span class="kc-feedback-text">(.+)<\/span>/gm.exec(AfterLoginActionAuthForm);
if (errorMessage) {
throw new Error(`@EuropeanBrandAuthStrategy.login: Authentication action failed with message : ${errorMessage[1]}`);
}
throw new Error('@EuropeanBrandAuthStrategy.login: Authentication action failed, cannot retrieve error message');
}
const authResult = await got(loginActionRedirect, {
cookieJar,
headers: stdHeaders
});
url = authResult.url;
htmlPage = authResult.body;
}
const { intUserId: appUser } = Url.parse(url, true).query;
if (!appUser) {
throw new Error(`@EuropeanBrandAuthStrategy.login: Cannot find the argument userId in ${url}.`);
Expand Down
2 changes: 1 addition & 1 deletion src/util.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { REGION } from "./constants";
import { REGION } from './constants';

const dec2hexString = (dec: number) => '0x' + dec.toString(16).substr(-4).toUpperCase();

Expand Down

0 comments on commit 5d39f11

Please sign in to comment.