Now using Zutil Oauth code properly
This commit is contained in:
parent
03ae4329bc
commit
ccc99033cd
4 changed files with 23 additions and 14 deletions
|
|
@ -12,4 +12,4 @@ se.hal.level = ALL
|
||||||
|
|
||||||
zutil.level = ALL
|
zutil.level = ALL
|
||||||
zutil.db.bean.level = INFO
|
zutil.db.bean.level = INFO
|
||||||
zutil.net.http.page.level = INFO
|
zutil.net.http.page.HttpFilePage.level = INFO
|
||||||
|
|
@ -33,7 +33,6 @@ import zutil.net.http.page.oauth.OAuth2AuthorizationPage;
|
||||||
import zutil.net.http.page.oauth.OAuth2Registry;
|
import zutil.net.http.page.oauth.OAuth2Registry;
|
||||||
import zutil.net.http.page.oauth.OAuth2TokenPage;
|
import zutil.net.http.page.oauth.OAuth2TokenPage;
|
||||||
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.concurrent.ScheduledExecutorService;
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
|
@ -41,8 +40,9 @@ import java.util.logging.Logger;
|
||||||
public class SmartHomeDaemon implements HalDaemon {
|
public class SmartHomeDaemon implements HalDaemon {
|
||||||
private static final Logger logger = LogUtil.getLogger();
|
private static final Logger logger = LogUtil.getLogger();
|
||||||
|
|
||||||
public static final String ENDPOINT_AUTH = "api/assistant/google/auth/token";
|
public static final String ENDPOINT_AUTH = "api/assistant/google/auth/authorize";
|
||||||
public static final String ENDPOINT_TOKEN = "api/assistant/google/auth/authorize";
|
public static final String ENDPOINT_TOKEN = "api/assistant/google/auth/token";
|
||||||
|
public static final String ENDPOINT_SMARTHOME = "api/assistant/google/smarthome";
|
||||||
|
|
||||||
private static final String PARAM_PORT = "assistant.google.port";
|
private static final String PARAM_PORT = "assistant.google.port";
|
||||||
private static final String PARAM_CLIENT_ID = "assistant.google.client_id";
|
private static final String PARAM_CLIENT_ID = "assistant.google.client_id";
|
||||||
|
|
@ -60,15 +60,16 @@ public class SmartHomeDaemon implements HalDaemon {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
smartHome = new SmartHomeImpl("token", new Date(System.currentTimeMillis() + 24*60*60*1000));
|
smartHome = new SmartHomeImpl();
|
||||||
|
|
||||||
oAuth2Registry = new OAuth2Registry();
|
oAuth2Registry = new OAuth2Registry();
|
||||||
oAuth2Registry.addWhitelist(HalContext.getStringProperty(PARAM_CLIENT_ID));
|
oAuth2Registry.addWhitelist(HalContext.getStringProperty(PARAM_CLIENT_ID));
|
||||||
|
oAuth2Registry.setTokenListener(smartHome);
|
||||||
|
|
||||||
httpServer = new HttpServer(HalContext.getIntegerProperty(PARAM_PORT));
|
httpServer = new HttpServer(HalContext.getIntegerProperty(PARAM_PORT));
|
||||||
httpServer.setPage(ENDPOINT_AUTH, new OAuth2AuthorizationPage(oAuth2Registry));
|
httpServer.setPage(ENDPOINT_AUTH, new OAuth2AuthorizationPage(oAuth2Registry));
|
||||||
httpServer.setPage(ENDPOINT_TOKEN, new OAuth2TokenPage(oAuth2Registry));
|
httpServer.setPage(ENDPOINT_TOKEN, new OAuth2TokenPage(oAuth2Registry));
|
||||||
httpServer.setPage(SmartHomePage.ENDPOINT_URL, new SmartHomePage(smartHome));
|
httpServer.setPage(ENDPOINT_SMARTHOME, new SmartHomePage(smartHome));
|
||||||
httpServer.start();
|
httpServer.start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,26 +17,35 @@
|
||||||
package se.hal.plugin.assistant.google;
|
package se.hal.plugin.assistant.google;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import com.google.actions.api.smarthome.*;
|
import com.google.actions.api.smarthome.*;
|
||||||
import com.google.auth.oauth2.AccessToken;
|
import com.google.auth.oauth2.AccessToken;
|
||||||
import com.google.auth.oauth2.GoogleCredentials;
|
import com.google.auth.oauth2.GoogleCredentials;
|
||||||
import zutil.log.LogUtil;
|
import zutil.log.LogUtil;
|
||||||
|
import zutil.net.http.page.oauth.OAuth2Registry.TokenRegistrationListener;
|
||||||
|
|
||||||
|
|
||||||
public class SmartHomeImpl extends SmartHomeApp {
|
public class SmartHomeImpl extends SmartHomeApp implements TokenRegistrationListener {
|
||||||
private static final Logger logger = LogUtil.getLogger();
|
private static final Logger logger = LogUtil.getLogger();
|
||||||
|
|
||||||
|
|
||||||
public SmartHomeImpl(String accessToken, Date accessExpirationTime) {
|
public SmartHomeImpl() { }
|
||||||
/* try {
|
|
||||||
GoogleCredentials credentials = GoogleCredentials.create(new AccessToken(accessToken, accessExpirationTime));
|
|
||||||
|
@Override
|
||||||
|
public void onTokenRegistration(String clientId, String token, long timeoutMillis) {
|
||||||
|
try {
|
||||||
|
GoogleCredentials credentials = GoogleCredentials.create(new AccessToken(
|
||||||
|
token,
|
||||||
|
new Date(System.currentTimeMillis() + timeoutMillis)
|
||||||
|
));
|
||||||
this.setCredentials(credentials);
|
this.setCredentials(credentials);
|
||||||
|
logger.fine("New OAuth2 token registered.");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.severe("Could not load google credentials");
|
logger.log(Level.SEVERE, "Could not load google credentials", e);
|
||||||
throw new RuntimeException(e);
|
}
|
||||||
}*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -61,7 +61,6 @@ import zutil.net.http.HttpPrintStream;
|
||||||
*/
|
*/
|
||||||
public class SmartHomePage implements HttpPage {
|
public class SmartHomePage implements HttpPage {
|
||||||
private static final Logger logger = LogUtil.getLogger();
|
private static final Logger logger = LogUtil.getLogger();
|
||||||
public static final String ENDPOINT_URL = "api/assistant/google/smarthome";
|
|
||||||
|
|
||||||
private SmartHomeImpl smartHome;
|
private SmartHomeImpl smartHome;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue