Skip to content

Commit

Permalink
[myq] Fixes a serious issue that could wipe out cookies across an ent…
Browse files Browse the repository at this point in the history
…ire OH instance for bindings using the shared Jetty client (openhab#11343)

Signed-off-by: Dan Cunningham <dan@digitaldan.com>
Signed-off-by: Dave J Schoepel <dave@theschoepels.com>
  • Loading branch information
digitaldan authored and dschoepel committed Nov 9, 2021
1 parent 6c56afb commit bfaf2f0
Showing 1 changed file with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.CookieStore;
import java.net.HttpCookie;
import java.net.URI;
import java.net.URISyntaxException;
Expand Down Expand Up @@ -291,10 +292,14 @@ private synchronized void fetchData() {
*/
private AccessTokenResponse login()
throws InterruptedException, MyQCommunicationException, MyQAuthenticationException {
// make sure we have a fresh session
httpClient.getCookieStore().removeAll();

try {
// make sure we have a fresh session
URI authUri = new URI(LOGIN_BASE_URL);
CookieStore store = httpClient.getCookieStore();
store.get(authUri).forEach(cookie -> {
store.remove(authUri, cookie);
});

String codeVerifier = generateCodeVerifier();

ContentResponse loginPageResponse = getLoginPage(codeVerifier);
Expand Down Expand Up @@ -328,7 +333,7 @@ private AccessTokenResponse login()
}
getOAuthService().importAccessTokenResponse(accessTokenResponse);
return accessTokenResponse;
} catch (IOException | ExecutionException | TimeoutException | OAuthException e) {
} catch (IOException | ExecutionException | TimeoutException | OAuthException | URISyntaxException e) {
throw new MyQCommunicationException(e.getMessage());
}
}
Expand Down

0 comments on commit bfaf2f0

Please sign in to comment.