diff --git a/bundles/org.openhab.binding.homeconnect/src/main/java/org/openhab/binding/homeconnect/internal/servlet/HomeConnectServlet.java b/bundles/org.openhab.binding.homeconnect/src/main/java/org/openhab/binding/homeconnect/internal/servlet/HomeConnectServlet.java index 27229541a..4c288f111 100644 --- a/bundles/org.openhab.binding.homeconnect/src/main/java/org/openhab/binding/homeconnect/internal/servlet/HomeConnectServlet.java +++ b/bundles/org.openhab.binding.homeconnect/src/main/java/org/openhab/binding/homeconnect/internal/servlet/HomeConnectServlet.java @@ -95,6 +95,7 @@ public class HomeConnectServlet extends HttpServlet { private static final String PARAM_BRIDGE_ID = "bridgeId"; private static final String PARAM_THING_ID = "thingId"; private static final String PARAM_PATH = "path"; + private static final String PARAM_REDIRECT_URI = "redirectUri"; private static final String ACTION_AUTHORIZE = "authorize"; private static final String ACTION_CLEAR_CREDENTIALS = "clearCredentials"; private static final String ACTION_SHOW_DETAILS = "show-details"; @@ -392,8 +393,11 @@ public class HomeConnectServlet extends HttpServlet { HomeConnectBridgeHandler bridgeHandler = bridgeHandlerOptional.get(); if (ACTION_AUTHORIZE.equals(action)) { try { - String authorizationUrl = bridgeHandler.getOAuthClientService().getAuthorizationUrl(null, null, - bridgeHandler.getThing().getUID().getAsString()); + String redirectUri = bridgeHandler.getConfiguration().isSimulator() + ? request.getParameter(PARAM_REDIRECT_URI) + : null; + String authorizationUrl = bridgeHandler.getOAuthClientService().getAuthorizationUrl(redirectUri, + null, bridgeHandler.getThing().getUID().getAsString()); logger.debug("Generated authorization url: {}", authorizationUrl); response.sendRedirect(authorizationUrl); @@ -491,8 +495,11 @@ public class HomeConnectServlet extends HttpServlet { Optional bridgeHandler = getBridgeHandler(state); if (bridgeHandler.isPresent()) { try { + String redirectUri = bridgeHandler.get().getConfiguration().isSimulator() + ? request.getRequestURL().toString() + : null; AccessTokenResponse accessTokenResponse = bridgeHandler.get().getOAuthClientService() - .getAccessTokenResponseByAuthorizationCode(code, null); + .getAccessTokenResponseByAuthorizationCode(code, redirectUri); logger.debug("access token response: {}", accessTokenResponse); diff --git a/bundles/org.openhab.binding.homeconnect/src/main/resources/assets/js/homeconnect.js b/bundles/org.openhab.binding.homeconnect/src/main/resources/assets/js/homeconnect.js index 9f7fb05ef..4ffe25d5c 100644 --- a/bundles/org.openhab.binding.homeconnect/src/main/resources/assets/js/homeconnect.js +++ b/bundles/org.openhab.binding.homeconnect/src/main/resources/assets/js/homeconnect.js @@ -6,6 +6,7 @@ feather.replace(); $(".redirectUri").text(window.location.href.substring(0, window.location.href.lastIndexOf('/homeconnect') + 12)); + $(".redirectUriInput").val(window.location.href.substring(0, window.location.href.lastIndexOf('/homeconnect') + 12)); $('#apiDetailModal').on('show.bs.modal', function (event) { var button = $(event.relatedTarget); diff --git a/bundles/org.openhab.binding.homeconnect/src/main/resources/templates/bridges.html b/bundles/org.openhab.binding.homeconnect/src/main/resources/templates/bridges.html index b2bf3086a..091db72e4 100644 --- a/bundles/org.openhab.binding.homeconnect/src/main/resources/templates/bridges.html +++ b/bundles/org.openhab.binding.homeconnect/src/main/resources/templates/bridges.html @@ -71,12 +71,13 @@
- +
- - + + +