mirror of
https://github.com/openhab/openhab-addons.git
synced 2025-01-10 15:11:59 +01:00
bugfix x-user-agent (#12841)
Signed-off-by: Bernd Weymann <bernd.weymann@gmail.com>
This commit is contained in:
parent
12b88a5c8b
commit
a0c3e7a88a
@ -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));
|
||||
|
@ -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";
|
||||
|
@ -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(),
|
||||
|
Loading…
Reference in New Issue
Block a user