]> git.basschouten.com Git - openhab-addons.git/commitdiff
bugfix x-user-agent (#12841)
authorBernd Weymann <bernd.weymann@gmail.com>
Sun, 29 May 2022 09:21:40 +0000 (11:21 +0200)
committerGitHub <noreply@github.com>
Sun, 29 May 2022 09:21:40 +0000 (11:21 +0200)
Signed-off-by: Bernd Weymann <bernd.weymann@gmail.com>
bundles/org.openhab.binding.mybmw/src/main/java/org/openhab/binding/mybmw/internal/handler/MyBMWProxy.java
bundles/org.openhab.binding.mybmw/src/main/java/org/openhab/binding/mybmw/internal/utils/BimmerConstants.java
bundles/org.openhab.binding.mybmw/src/test/java/org/openhab/binding/mybmw/internal/handler/AuthTest.java

index 20a4f4c5dc18614db862ad3de29f40b085fe7fca..6c848d83e598483367a692ea6291279476b05ba4 100644 (file)
@@ -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));
index 5e19e8fef7928ae74ce62133ef40ff4302fc0c5f..76e094e9962e94d73f77a2f86aa344c1e648993d 100644 (file)
@@ -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<String, String> 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";
index b735562890cbfa1e9e55cdc175695ba98e51480a..446376458dccd49323ef240e4bdb43dea2650923 100644 (file)
@@ -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(),