diff --git a/bundles/org.openhab.binding.mybmw/src/main/java/org/openhab/binding/mybmw/internal/handler/MyBMWProxy.java b/bundles/org.openhab.binding.mybmw/src/main/java/org/openhab/binding/mybmw/internal/handler/MyBMWProxy.java index 20a4f4c5d..6c848d83e 100644 --- a/bundles/org.openhab.binding.mybmw/src/main/java/org/openhab/binding/mybmw/internal/handler/MyBMWProxy.java +++ b/bundles/org.openhab.binding.mybmw/src/main/java/org/openhab/binding/mybmw/internal/handler/MyBMWProxy.java @@ -113,8 +113,7 @@ public class MyBMWProxy { } // return in case of unknown brand - String userAgent = BimmerConstants.BRAND_USER_AGENTS_MAP.get(brand.toLowerCase()); - if (userAgent == null) { + if (!BimmerConstants.ALL_BRANDS.contains(brand.toLowerCase())) { logger.warn("Unknown Brand {}", brand); return; } @@ -138,7 +137,8 @@ public class MyBMWProxy { req = httpClient.newRequest(completeUrl); } req.header(HttpHeader.AUTHORIZATION, getToken().getBearerToken()); - req.header(HTTPConstants.X_USER_AGENT, userAgent); + req.header(HTTPConstants.X_USER_AGENT, + String.format(BimmerConstants.X_USER_AGENT, brand, configuration.region)); req.header(HttpHeader.ACCEPT_LANGUAGE, configuration.language); if (callback instanceof ByteResponseCallback) { req.header(HttpHeader.ACCEPT, "image/png"); @@ -306,7 +306,9 @@ public class MyBMWProxy { + BimmerConstants.API_OAUTH_CONFIG; Request authValuesRequest = httpClient.newRequest(authValuesUrl); authValuesRequest.header(ACP_SUBSCRIPTION_KEY, BimmerConstants.OCP_APIM_KEYS.get(configuration.region)); - authValuesRequest.header(X_USER_AGENT, BimmerConstants.USER_AGENT_BMW); + authValuesRequest.header(X_USER_AGENT, + String.format(BimmerConstants.X_USER_AGENT, BimmerConstants.BRAND_BMW, configuration.region)); + ContentResponse authValuesResponse = authValuesRequest.send(); if (authValuesResponse.getStatus() != 200) { throw new HttpResponseException("URL: " + authValuesRequest.getURI() + ", Error: " @@ -442,7 +444,9 @@ public class MyBMWProxy { String publicKeyUrl = "https://" + BimmerConstants.EADRAX_SERVER_MAP.get(BimmerConstants.REGION_CHINA) + BimmerConstants.CHINA_PUBLIC_KEY; Request oauthQueryRequest = httpClient.newRequest(publicKeyUrl); - oauthQueryRequest.header(X_USER_AGENT, BimmerConstants.USER_AGENT_BMW); + oauthQueryRequest.header(HttpHeader.USER_AGENT, BimmerConstants.USER_AGENT); + oauthQueryRequest.header(X_USER_AGENT, + String.format(BimmerConstants.X_USER_AGENT, BimmerConstants.BRAND_BMW, configuration.region)); ContentResponse publicKeyResponse = oauthQueryRequest.send(); if (publicKeyResponse.getStatus() != 200) { throw new HttpResponseException("URL: " + oauthQueryRequest.getURI() + ", Error: " @@ -476,7 +480,8 @@ public class MyBMWProxy { String tokenUrl = "https://" + BimmerConstants.EADRAX_SERVER_MAP.get(BimmerConstants.REGION_CHINA) + BimmerConstants.CHINA_LOGIN; Request loginRequest = httpClient.POST(tokenUrl); - loginRequest.header(X_USER_AGENT, BimmerConstants.USER_AGENT_BMW); + loginRequest.header(X_USER_AGENT, + String.format(BimmerConstants.X_USER_AGENT, BimmerConstants.BRAND_BMW, configuration.region)); String jsonContent = "{ \"mobile\":\"" + configuration.userName + "\", \"password\":\"" + encodedPassword + "\"}"; loginRequest.content(new StringContentProvider(jsonContent)); diff --git a/bundles/org.openhab.binding.mybmw/src/main/java/org/openhab/binding/mybmw/internal/utils/BimmerConstants.java b/bundles/org.openhab.binding.mybmw/src/main/java/org/openhab/binding/mybmw/internal/utils/BimmerConstants.java index 5e19e8fef..76e094e99 100644 --- a/bundles/org.openhab.binding.mybmw/src/main/java/org/openhab/binding/mybmw/internal/utils/BimmerConstants.java +++ b/bundles/org.openhab.binding.mybmw/src/main/java/org/openhab/binding/mybmw/internal/utils/BimmerConstants.java @@ -54,10 +54,8 @@ public class BimmerConstants { public static final String CHINA_LOGIN = "/eadrax-coas/v1/login/pwd"; // Http variables - public static final String USER_AGENT_BMW = "android(v1.07_20200330);bmw;1.7.0(11152)"; - public static final String USER_AGENT_MINI = "android(v1.07_20200330);mini;1.7.0(11152)"; - public static final Map BRAND_USER_AGENTS_MAP = Map.of(BRAND_BMW, USER_AGENT_BMW, BRAND_MINI, - USER_AGENT_MINI); + public static final String USER_AGENT = "Dart/2.14 (dart:io)"; + public static final String X_USER_AGENT = "android(SP1A.210812.016.C1);%s;2.5.2(14945);%s"; public static final String LOGIN_NONCE = "login_nonce"; public static final String AUTHORIZATION_CODE = "authorization_code"; diff --git a/bundles/org.openhab.binding.mybmw/src/test/java/org/openhab/binding/mybmw/internal/handler/AuthTest.java b/bundles/org.openhab.binding.mybmw/src/test/java/org/openhab/binding/mybmw/internal/handler/AuthTest.java index b73556289..446376458 100644 --- a/bundles/org.openhab.binding.mybmw/src/test/java/org/openhab/binding/mybmw/internal/handler/AuthTest.java +++ b/bundles/org.openhab.binding.mybmw/src/test/java/org/openhab/binding/mybmw/internal/handler/AuthTest.java @@ -394,7 +394,8 @@ class AuthTest { String url = "https://" + BimmerConstants.EADRAX_SERVER_MAP.get(BimmerConstants.REGION_CHINA) + BimmerConstants.CHINA_PUBLIC_KEY; Request oauthQueryRequest = authHttpClient.newRequest(url); - oauthQueryRequest.header(X_USER_AGENT, BimmerConstants.USER_AGENT_BMW); + oauthQueryRequest.header(X_USER_AGENT, + String.format(BimmerConstants.BRAND_BMW, BimmerConstants.BRAND_BMW, BimmerConstants.REGION_ROW)); ContentResponse publicKeyResponse = oauthQueryRequest.send(); ChinaPublicKeyResponse pkr = Converter.getGson().fromJson(publicKeyResponse.getContentAsString(),