@@ -1485,7 +1485,7 @@ class VwWeconnect extends utils.Adapter {
14851485
14861486 this . refreshTokenInterval = setInterval ( ( ) => {
14871487 this . refreshIDToken ( ) . catch ( ( ) => { } ) ;
1488- } , 0.89 * 60 * 60 * 1000 ) ; // 0.9hours
1488+ } , 0.89 * 60 * 60 * 1000 ) ; // 0.89 hours
14891489 this . log . info ( "ID login successfull" ) ;
14901490
14911491 resolve ( ) ;
@@ -4568,64 +4568,68 @@ class VwWeconnect extends utils.Adapter {
45684568 } ) ;
45694569 }
45704570
4571- refreshIDToken ( ) {
4572- return new Promise ( ( resolve , reject ) => {
4573- this . log . debug ( "Token Refresh started" ) ;
4571+ async refreshIDToken ( ) {
4572+ this . log . debug ( "Token Refresh started" ) ;
4573+
4574+ try {
45744575 const refreshHeaders = {
4575- accept : "*/*" ,
4576- "content-type" : "application/json" ,
4577- "content-version" : "1" ,
4578- "x-newrelic-id" : "VgAEWV9QDRAEXFlRAAYPUA==" ,
4579- "user-agent" : this . userAgent ,
4580- "accept-language" : "de-de" ,
4581- authorization : "Bearer " + this . config . rtoken ,
4576+ "Accept-Encoding" : "gzip, deflate, br" ,
4577+ "Connection" : "keep-alive" ,
4578+ "Content-Type" : "application/x-www-form-urlencoded" ,
4579+ "User-Agent" : this . userAgent ,
4580+ "Accept-Language" : "de-de" ,
45824581 } ;
45834582
45844583 if ( this . config . type === "id" && this . androidPackageName ) {
45854584 refreshHeaders [ "x-android-package-name" ] = this . androidPackageName ;
45864585 }
45874586
4588- request . get (
4589- {
4590- url : "https://emea.bff.cariad.digital/user-login/refresh/v1" ,
4591- headers : refreshHeaders ,
4592- followAllRedirects : true ,
4593- gzip : true ,
4594- json : true ,
4595- } ,
4596- ( err , resp , body ) => {
4597- if ( err || ( resp && resp . statusCode >= 400 ) ) {
4598- err && this . log . error ( err ) ;
4599- resp && this . log . error ( resp . statusCode . toString ( ) ) ;
4600- body && this . log . error ( JSON . stringify ( body ) ) ;
4601- this . log . error ( "Failed refresh token. Relogin" ) ;
4602- //reset login parameters because of wecharge
4603- this . type = "Id" ;
4604- this . clientId = "a24fba63-34b3-4d43-b181-942111e6bda8@apps_vw-dilab_com" ;
4605- this . scope = "openid profile badge cars dealers birthdate vin" ;
4606- this . redirect = "weconnect://authenticated" ;
4607- this . xrequest = "com.volkswagen.weconnect" ;
4608- this . responseType = "code id_token token" ;
4609- setTimeout ( ( ) => {
4610- this . log . error ( "restart adapter in 10min" ) ;
4611- this . restart ( ) ;
4612- } , 10 * 60 * 1000 ) ;
4613- reject ( ) ;
4614- return ;
4615- }
4616- try {
4617- this . log . debug ( "Token Refresh successful" ) ;
4618- this . config . atoken = body . accessToken ;
4619- this . config . rtoken = body . refreshToken ;
4587+ const refreshBody = {
4588+ grant_type : "refresh_token" ,
4589+ refresh_token : this . config . rtoken ,
4590+ client_id : this . clientId ,
4591+ } ;
46204592
4621- resolve ( ) ;
4622- } catch ( err ) {
4623- this . log . error ( err ) ;
4624- reject ( ) ;
4625- }
4626- } ,
4627- ) ;
4628- } ) ;
4593+ // Use BFF token endpoint for refresh (same as Python)
4594+ const response = await axios ( {
4595+ method : "post" ,
4596+ url : "https://emea.bff.cariad.digital/login/v1/idk/token" ,
4597+ headers : refreshHeaders ,
4598+ data : new URLSearchParams ( refreshBody ) . toString ( ) ,
4599+ } ) ;
4600+
4601+ this . log . debug ( "Token Refresh successful" ) ;
4602+ const tokens = response . data ;
4603+
4604+ // Store refreshed tokens (handle both camelCase and snake_case)
4605+ this . config . atoken = tokens . access_token || tokens . accessToken ;
4606+ this . config . rtoken = tokens . refresh_token || tokens . refreshToken ;
4607+
4608+ return Promise . resolve ( ) ;
4609+ } catch ( error ) {
4610+ if ( error . response ) {
4611+ this . log . error ( "Status: " + error . response . status ) ;
4612+ this . log . error ( "Response: " + JSON . stringify ( error . response . data ) ) ;
4613+ } else {
4614+ this . log . error ( error . message ) ;
4615+ }
4616+ this . log . error ( "Failed refresh token. Relogin" ) ;
4617+
4618+ // Reset login parameters because of wecharge
4619+ this . type = "Id" ;
4620+ this . clientId = "a24fba63-34b3-4d43-b181-942111e6bda8@apps_vw-dilab_com" ;
4621+ this . scope = "openid profile badge cars dealers birthdate vin" ;
4622+ this . redirect = "weconnect://authenticated" ;
4623+ this . xrequest = "com.volkswagen.weconnect" ;
4624+ this . responseType = "code id_token token" ;
4625+
4626+ setTimeout ( ( ) => {
4627+ this . log . error ( "restart adapter in 10min" ) ;
4628+ this . restart ( ) ;
4629+ } , 10 * 60 * 1000 ) ;
4630+
4631+ return Promise . reject ( error ) ;
4632+ }
46294633 }
46304634
46314635 async refreshSkodaEToken ( ) {
0 commit comments