这是indexloc提供的服务,不要输入任何密码
Skip to content
This repository was archived by the owner on May 17, 2021. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,8 @@ public void updated(Dictionary<String, ?> config) throws ConfigurationException
properlyConfigured = false;
break;
}
// Knowing this OAuthCredentials object is complete, load its tokens from persistent storage.
oauthCredentials.load();
}

setProperlyConfigured(properlyConfigured);
Expand Down Expand Up @@ -832,6 +834,7 @@ private Selection createSelection(OAuthCredentials oauthCredentials) {
*/
static class OAuthCredentials {

private static final String APP_KEY = "appKey";
private static final String AUTH_TOKEN = "authToken";
private static final String REFRESH_TOKEN = "refreshToken";
private static final String ACCESS_TOKEN = "accessToken";
Expand Down Expand Up @@ -884,13 +887,7 @@ static class OAuthCredentials {
private Map<String, Revision> lastRevisionMap = new HashMap<String, Revision>();

public OAuthCredentials(String userid) {

try {
this.userid = userid;
load();
} catch (Exception e) {
throw new EcobeeException("Cannot create OAuthCredentials.", e);
}
this.userid = userid;
}

public Map<String, Revision> getLastRevisionMap() {
Expand All @@ -907,13 +904,23 @@ private Preferences getPrefsNode() {

private void load() {
Preferences prefs = getPrefsNode();
this.authToken = prefs.get(AUTH_TOKEN, null);
this.refreshToken = prefs.get(REFRESH_TOKEN, null);
this.accessToken = prefs.get(ACCESS_TOKEN, null);
/*
* Only load the tokens if they were not saved with the app key used to create them (backwards
* compatibility), or if the saved app key matches the current app key specified in openhab.cfg. This
* properly ignores saved tokens when the app key has been changed.
*/
final String savedAppKey = prefs.get(APP_KEY, null);
if (savedAppKey == null || savedAppKey.equals(this.appKey)) {
this.authToken = prefs.get(AUTH_TOKEN, null);
this.refreshToken = prefs.get(REFRESH_TOKEN, null);
this.accessToken = prefs.get(ACCESS_TOKEN, null);
}
}

private void save() {
Preferences prefs = getPrefsNode();
prefs.put(APP_KEY, this.appKey);

if (this.authToken != null) {
prefs.put(AUTH_TOKEN, this.authToken);
} else {
Expand Down Expand Up @@ -993,6 +1000,14 @@ public boolean refreshTokens() {

if (response.isError()) {
logger.error("Error retrieving tokens: {}", response.getError());
if ("authorization_expired".equals(response.getError())) {
this.refreshToken = null;
this.accessToken = null;
if (request instanceof TokenRequest) {
this.authToken = null;
}
save();
}
return false;
} else {
this.refreshToken = response.getRefreshToken();
Expand Down