Skip to content

Commit

Permalink
[amazonechocontrol] Bugfix for login in Australia (openhab#6034)
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Geramb <[email protected]>
Signed-off-by: Tim Roberts <[email protected]>
  • Loading branch information
Michael Geramb authored and tmrobert8 committed Jan 21, 2020
1 parent da5472d commit 4758e32
Showing 1 changed file with 13 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -720,15 +720,18 @@ public String registerConnectionAsApp(String oAutRedirectUrl)
if (StringUtils.isEmpty(this.refreshToken)) {
throw new ConnectionException("Error: No refresh token received");
}
String usersMeResponseJson = makeRequestAndReturnString("GET",
"https://alexa.amazon.com/api/users/me?platform=ios&version=2.2.223830.0", null, false, null);
JsonUsersMeResponse usersMeResponse = parseJson(usersMeResponseJson, JsonUsersMeResponse.class);

URI uri = new URI(usersMeResponse.marketPlaceDomainName);
String host = uri.getHost();
setAmazonSite(host);
try {
exhangeToken();
exchangeToken();
// Check which is the owner domain
String usersMeResponseJson = makeRequestAndReturnString("GET",
"https://alexa.amazon.com/api/users/me?platform=ios&version=2.2.223830.0", null, false, null);
JsonUsersMeResponse usersMeResponse = parseJson(usersMeResponseJson, JsonUsersMeResponse.class);
URI uri = new URI(usersMeResponse.marketPlaceDomainName);
String host = uri.getHost();

// Switch to owner domain
setAmazonSite(host);
exchangeToken();
tryGetBootstrap();
} catch (Exception e) {
logout();
Expand All @@ -749,7 +752,7 @@ public String registerConnectionAsApp(String oAutRedirectUrl)
return deviceName;
}

private void exhangeToken() throws IOException, URISyntaxException {
private void exchangeToken() throws IOException, URISyntaxException {

this.renewTime = 0;
String cookiesJson = "{\"cookies\":{\"." + getAmazonSite() + "\":[]}}";
Expand Down Expand Up @@ -808,7 +811,7 @@ public boolean checkRenewSession() throws UnknownHostException, URISyntaxExcepti
renewTokenPostData, false, null);
parseJson(renewTokenRepsonseJson, JsonRenewTokenResponse.class);

exhangeToken();
exchangeToken();
return true;
}
return false;
Expand Down

0 comments on commit 4758e32

Please sign in to comment.