mirror of
https://github.com/openhab/openhab-addons.git
synced 2025-01-10 15:11:59 +01:00
[homeconnect] Fix login for simulator environment (#13653)
* Add redirect URI to oAuth request Signed-off-by: Jonas Brüstel <jonas@bruestel.net>
This commit is contained in:
parent
c114714a7b
commit
5654b9f97a
@ -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<HomeConnectBridgeHandler> 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);
|
||||
|
||||
|
@ -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);
|
||||
|
@ -71,12 +71,13 @@
|
||||
<dd class="col-sm-8">
|
||||
<form method="post" style="display: inline-block">
|
||||
<input type="hidden" name="bridgeId" th:value="${uid}"/>
|
||||
<input type="hidden" name="action" value="clearCredentials">
|
||||
<input type="hidden" name="action" value="clearCredentials" />
|
||||
<button type="submit" class="btn btn-secondary btn-sm">Clear stored credentials</button>
|
||||
</form>
|
||||
<form method="post" style="display: inline-block">
|
||||
<input type="hidden" name="bridgeId" th:value="${uid}" />
|
||||
<input type="hidden" name="action" value="authorize">
|
||||
<input type="hidden" name="action" value="authorize" />
|
||||
<input type="hidden" name="redirectUri" value="" class="redirectUriInput" />
|
||||
<button type="submit" class="btn btn-primary btn-sm">Authorize bridge</button>
|
||||
</form>
|
||||
</dd>
|
||||
|
Loading…
Reference in New Issue
Block a user