From d3b7a0a98d6c42a960c308329861f84f54ab3e21 Mon Sep 17 00:00:00 2001 From: lolodomo Date: Fri, 5 May 2023 23:22:20 +0200 Subject: [PATCH] [myq] Remove the access token when the thing is removed (#14938) * [myq] Remove the access token when the thing is removed * oAuthService.removeAccessTokenRefreshListener added Related to #14818 Signed-off-by: Laurent Garnier --- .../myq/internal/handler/MyQAccountHandler.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/bundles/org.openhab.binding.myq/src/main/java/org/openhab/binding/myq/internal/handler/MyQAccountHandler.java b/bundles/org.openhab.binding.myq/src/main/java/org/openhab/binding/myq/internal/handler/MyQAccountHandler.java index d70721b0b..a533321fa 100644 --- a/bundles/org.openhab.binding.myq/src/main/java/org/openhab/binding/myq/internal/handler/MyQAccountHandler.java +++ b/bundles/org.openhab.binding.myq/src/main/java/org/openhab/binding/myq/internal/handler/MyQAccountHandler.java @@ -162,10 +162,21 @@ public class MyQAccountHandler extends BaseBridgeHandler implements AccessTokenR stopPolls(); OAuthClientService oAuthService = this.oAuthService; if (oAuthService != null) { - oAuthService.close(); + oAuthService.removeAccessTokenRefreshListener(this); + oAuthFactory.ungetOAuthService(getThing().toString()); + this.oAuthService = null; } } + @Override + public void handleRemoval() { + OAuthClientService oAuthService = this.oAuthService; + if (oAuthService != null) { + oAuthFactory.deleteServiceAndAccessToken(getThing().toString()); + } + super.handleRemoval(); + } + @Override public Collection> getServices() { return Collections.singleton(MyQDiscoveryService.class);