@@ -16,7 +16,7 @@ import { URLSearchParams } from 'url';
1616
1717import { CookieJar } from 'tough-cookie' ;
1818import { VehicleRegisterOptions } from '../interfaces/common.interfaces' ;
19- import { asyncMap , manageBluelinkyError , Stringifiable , uuidV4 } from '../tools/common.tools' ;
19+ import { asyncMap , manageBluelinkyError , Stringifiable } from '../tools/common.tools' ;
2020import { AuthStrategy , Code } from './authStrategies/authStrategy' ;
2121import { EuropeanBrandAuthStrategy } from './authStrategies/european.brandAuth.strategy' ;
2222import { EuropeanLegacyAuthStrategy } from './authStrategies/european.legacyAuth.strategy' ;
@@ -53,7 +53,8 @@ export class EuropeanController extends SessionController<EuropeBlueLinkyConfig>
5353 ) } are.`
5454 ) ;
5555 }
56- this . session . deviceId = uuidV4 ( ) ;
56+ // this.session.deviceId = uuidV4();
57+ this . session . deviceId = 'c629f223-3c53-4128-8a83-36bea6b74207' ;
5758 this . _environment = getBrandEnvironment ( userConfig ) ;
5859 this . authStrategies = {
5960 main : new EuropeanBrandAuthStrategy ( this . _environment , this . userConfig . language ) ,
@@ -70,7 +71,8 @@ export class EuropeanController extends SessionController<EuropeBlueLinkyConfig>
7071 accessToken : undefined ,
7172 refreshToken : undefined ,
7273 controlToken : undefined ,
73- deviceId : uuidV4 ( ) ,
74+ // deviceId: uuidV4(),
75+ deviceId : 'c629f223-3c53-4128-8a83-36bea6b74207' ,
7476 tokenExpiresAt : 0 ,
7577 controlTokenExpiresAt : 0 ,
7678 } ;
@@ -155,6 +157,41 @@ export class EuropeanController extends SessionController<EuropeBlueLinkyConfig>
155157 }
156158 }
157159
160+ public async register ( ) : Promise < string > {
161+ /*
162+ const genRanHex = size =>
163+ [...Array(size)].map(() => Math.floor(Math.random() * 16).toString(16)).join('');
164+ const notificationReponse = await got(
165+ `${this.environment.baseUrl}/api/v1/spa/notifications/register`,
166+ {
167+ method: 'POST',
168+ headers: {
169+ 'ccsp-service-id': this.environment.clientId,
170+ 'Content-Type': 'application/json;charset=UTF-8',
171+ 'Host': this.environment.host,
172+ 'Connection': 'Keep-Alive',
173+ 'Accept-Encoding': 'gzip',
174+ 'User-Agent': 'okhttp/3.10.0',
175+ 'ccsp-application-id': this.environment.appId,
176+ 'Stamp': await this.environment.stamp(),
177+ },
178+ body: {
179+ pushRegId: genRanHex(64),
180+ pushType: 'APNS',
181+ uuid: this.session.deviceId,
182+ },
183+ json: true,
184+ }
185+ );
186+
187+ if (notificationReponse) {
188+ this.session.deviceId = notificationReponse.body.resMsg.deviceId;
189+ }
190+ logger.debug('@EuropeController.login: Device registered');
191+ */
192+ return 'Registered again' ;
193+ }
194+
158195 public async login ( ) : Promise < string > {
159196 try {
160197 if ( ! this . userConfig . password || ! this . userConfig . username ) {
@@ -202,7 +239,7 @@ export class EuropeanController extends SessionController<EuropeBlueLinkyConfig>
202239 } ,
203240 body : {
204241 pushRegId : genRanHex ( 64 ) ,
205- pushType : 'APNS ' ,
242+ pushType : 'GCM ' ,
206243 uuid : this . session . deviceId ,
207244 } ,
208245 json : true ,
@@ -213,24 +250,25 @@ export class EuropeanController extends SessionController<EuropeBlueLinkyConfig>
213250 this . session . deviceId = notificationReponse . body . resMsg . deviceId ;
214251 }
215252 logger . debug ( '@EuropeController.login: Device registered' ) ;
216-
217253 const formData = new URLSearchParams ( ) ;
218254 formData . append ( 'grant_type' , 'authorization_code' ) ;
219- formData . append ( 'redirect_uri' , this . environment . endpoints . redirectUri ) ;
255+ formData . append ( 'redirect_uri' , this . environment . endpoints . redirectUri ) ; //`${this.environment.baseUrl}/api/v1/user/oauth2/redirect` );
220256 formData . append ( 'code' , authResult . code ) ;
257+ formData . append ( 'client_id' , this . environment . clientId ) ;
258+ formData . append ( 'client_secret' , 'secret' ) ;
221259
222- const response = await got ( this . environment . endpoints . token , {
260+ const response = await got ( ` ${ this . environment . idpUrl } /auth/api/v2/user/oauth2/ token` , {
223261 method : 'POST' ,
224262 headers : {
225- 'Authorization' : this . environment . basicToken ,
263+ // 'Authorization': this.environment.basicToken,
226264 'Content-Type' : 'application/x-www-form-urlencoded' ,
227- 'Host' : this . environment . host ,
228- 'Connection' : 'Keep-Alive' ,
265+ // 'Host': this.environment.host,
266+ // 'Connection': 'Keep-Alive',
229267 'Accept-Encoding' : 'gzip' ,
230268 'User-Agent' : 'okhttp/3.10.0' ,
231- 'grant_type' : 'authorization_code' ,
232- 'ccsp-application-id' : this . environment . appId ,
233- 'Stamp' : await this . environment . stamp ( ) ,
269+ // 'grant_type': 'authorization_code',
270+ // 'ccsp-application-id': this.environment.appId,
271+ 'Stamp' : false , // await this.environment.stamp(),
234272 } ,
235273 body : formData . toString ( ) ,
236274 cookieJar : authResult . cookies ,
@@ -321,14 +359,18 @@ export class EuropeanController extends SessionController<EuropeBlueLinkyConfig>
321359 }
322360 }
323361
324- public async getVehicleHttpService ( ) : Promise < GotInstance < GotJSONFn > > {
362+ public async getVehicleHttpService ( vehicle ?: EuropeanVehicle ) : Promise < GotInstance < GotJSONFn > > {
325363 await this . checkControlToken ( ) ;
364+ const ccuccs2 = Number ( vehicle ? vehicle . vehicleConfig . ccuCCS2ProtocolSupport : false ) ;
365+
326366 return got . extend ( {
327367 baseUrl : this . environment . baseUrl ,
328368 headers : {
329369 ...this . defaultHeaders ,
330370 'Authorization' : this . session . controlToken ,
371+ 'AuthorizationCCSP' : this . session . controlToken ,
331372 'Stamp' : await this . environment . stamp ( ) ,
373+ 'Ccuccs2protocolsupport' : ccuccs2 ,
332374 } ,
333375 json : true ,
334376 } ) ;
0 commit comments