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>
  • Loading branch information
digitaldan authored and Nemer_Daud committed Jan 28, 2022
1 parent 20b50a3 commit ca1e395
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 ca1e395

Please sign in to comment.