String runOauth2Msg = "Create ${HOME}/.appcfg_oauth2_tokens by running $appcfg.sh --oauth2 update YOUR-WAR-DIR";
String userDir = System.getProperty("user.home");
File tokenFile = new File(userDir, ".appcfg_oauth2_tokens_java");
if (!tokenFile.exists()) {
throw new ConfigurationException(runOauth2Msg);
}
boolean useCookies = true; // use ${HOME}/.appcfg_oauth2_tokens_java
String oauth2ClientId = null;
String oauth2ClientSecret = null;
String oauth2RefreshToken = null;
OAuth2Native client = new OAuth2Native(useCookies, oauth2ClientId,
oauth2ClientSecret, oauth2RefreshToken);
Credential credential = client.authorize();
if (credential == null || credential.getAccessToken() == null) {
String errMsg = "Tokens expired? " + runOauth2Msg;
throw new ConfigurationException(errMsg);
}
return credential.getAccessToken();
}