use of org.eclipse.smarthome.core.auth.client.oauth2.OAuthException in project openhab-core by openhab.
the class ConsoleOAuthCommandExtension method execute.
@Override
public void execute(String[] args, Console console) {
this.console = console;
if (args.length < 2) {
console.println("Argument expected. Please check usage.");
return;
}
AbstractTestAgent agent = getTestAgent(args[0]);
if (agent == null) {
console.println("Unexpected test agent:" + args[0]);
return;
}
AccessTokenResponse response;
try {
switch(args[1]) {
case "create":
OAuthClientService newService = agent.testCreateClient();
console.println("handle: " + agent.handle + ", service: " + newService);
break;
case "getAccessTokenByResourceOwnerPassword":
response = agent.testGetAccessTokenByResourceOwnerPasswordCredentials();
consolePrintAccessToken(response);
break;
case "getClient":
OAuthClientService service = agent.testGetClient(args[2]);
console.println("OAuthClientService: " + service);
break;
case "refresh":
response = agent.testRefreshToken();
consolePrintAccessToken(response);
break;
case "getAccessTokenByCode":
console.println("using authorization code: " + args[2]);
response = agent.testGetAccessTokenByAuthorizationCode(args[2]);
consolePrintAccessToken(response);
break;
case "getAuthorizationUrl":
String authURL;
if (args.length >= 3) {
authURL = agent.testGetAuthorizationUrl(args[2]);
console.println("Authorization URL: " + authURL + " state: " + args[2]);
} else {
authURL = agent.testGetAuthorizationUrl(null);
console.println("Authorization URL: " + authURL + " state: null");
}
break;
case "getCachedAccessToken":
response = agent.testGetCachedAccessToken();
consolePrintAccessToken(response);
break;
case "close":
console.println("Closing test agent client service...");
agent.close();
break;
case "delete":
console.println("Delete by handle: " + args[2]);
agent.delete(args[2]);
break;
default:
console.println("Commands are case-sensitive. Unknown command: " + args[1]);
break;
}
} catch (OAuthException | IOException | OAuthResponseException e) {
console.print(String.format("%s %s, cause %s", e.getClass(), e.getMessage(), e.getCause()));
}
}
Aggregations