mirror of
https://github.com/openhab/openhab-addons.git
synced 2025-01-10 15:11:59 +01:00
adapt to core StringUtils (#15784)
Signed-off-by: Leo Siepel <leosiepel@gmail.com>
This commit is contained in:
parent
ab5ebbc41b
commit
e761240bf0
@ -52,6 +52,7 @@ import org.openhab.binding.mybmw.internal.utils.Converter;
|
||||
import org.openhab.binding.mybmw.internal.utils.HTTPConstants;
|
||||
import org.openhab.binding.mybmw.internal.utils.ImageProperties;
|
||||
import org.openhab.core.io.net.http.HttpClientFactory;
|
||||
import org.openhab.core.util.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@ -323,12 +324,12 @@ public class MyBMWProxy {
|
||||
/*
|
||||
* Step 2) Calculate values for base parameters
|
||||
*/
|
||||
String verfifierBytes = Converter.getRandomString(64);
|
||||
String verfifierBytes = StringUtils.getRandomAlphabetic(64).toLowerCase();
|
||||
String codeVerifier = Base64.getUrlEncoder().withoutPadding().encodeToString(verfifierBytes.getBytes());
|
||||
MessageDigest digest = MessageDigest.getInstance("SHA-256");
|
||||
byte[] hash = digest.digest(codeVerifier.getBytes(StandardCharsets.UTF_8));
|
||||
String codeChallange = Base64.getUrlEncoder().withoutPadding().encodeToString(hash);
|
||||
String stateBytes = Converter.getRandomString(16);
|
||||
String stateBytes = StringUtils.getRandomAlphabetic(16).toLowerCase();
|
||||
String state = Base64.getUrlEncoder().withoutPadding().encodeToString(stateBytes.getBytes());
|
||||
|
||||
MultiMap<String> baseParams = new MultiMap<String>();
|
||||
|
@ -13,7 +13,6 @@
|
||||
package org.openhab.binding.mybmw.internal.utils;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.security.SecureRandom;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.LocalTime;
|
||||
import java.time.ZoneId;
|
||||
@ -24,7 +23,6 @@ import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Random;
|
||||
import java.util.TimeZone;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
@ -249,15 +247,6 @@ public class Converter {
|
||||
return v;
|
||||
}
|
||||
|
||||
public static String getRandomString(int size) {
|
||||
int leftLimit = 97; // letter 'a'
|
||||
int rightLimit = 122; // letter 'z'
|
||||
Random random = new SecureRandom();
|
||||
|
||||
return random.ints(leftLimit, rightLimit + 1).limit(size)
|
||||
.collect(StringBuilder::new, StringBuilder::appendCodePoint, StringBuilder::append).toString();
|
||||
}
|
||||
|
||||
public static State getLockState(boolean lock) {
|
||||
if (lock) {
|
||||
return StringType.valueOf(Constants.LOCKED);
|
||||
|
@ -46,6 +46,7 @@ import org.openhab.binding.mybmw.internal.utils.BimmerConstants;
|
||||
import org.openhab.binding.mybmw.internal.utils.Constants;
|
||||
import org.openhab.binding.mybmw.internal.utils.Converter;
|
||||
import org.openhab.core.io.net.http.HttpClientFactory;
|
||||
import org.openhab.core.util.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@ -78,16 +79,14 @@ class AuthTest {
|
||||
AuthQueryResponse aqr = Converter.getGson().fromJson(firstResponse.getContentAsString(),
|
||||
AuthQueryResponse.class);
|
||||
|
||||
// String verifier_bytes = RandomStringUtils.randomAlphanumeric(64);
|
||||
String verifierBytes = Converter.getRandomString(64);
|
||||
String verifierBytes = StringUtils.getRandomAlphabetic(64).toLowerCase();
|
||||
String codeVerifier = Base64.getUrlEncoder().withoutPadding().encodeToString(verifierBytes.getBytes());
|
||||
|
||||
MessageDigest digest = MessageDigest.getInstance("SHA-256");
|
||||
byte[] hash = digest.digest(codeVerifier.getBytes(StandardCharsets.UTF_8));
|
||||
String codeChallenge = Base64.getUrlEncoder().withoutPadding().encodeToString(hash);
|
||||
|
||||
// String state_bytes = RandomStringUtils.randomAlphanumeric(16);
|
||||
String stateBytes = Converter.getRandomString(16);
|
||||
String stateBytes = StringUtils.getRandomAlphabetic(16).toLowerCase();
|
||||
String state = Base64.getUrlEncoder().withoutPadding().encodeToString(stateBytes.getBytes());
|
||||
|
||||
String authUrl = aqr.gcdmBaseUrl + BimmerConstants.OAUTH_ENDPOINT;
|
||||
|
Loading…
Reference in New Issue
Block a user