use of org.openhab.core.auth.client.oauth2.OAuthClientService in project smarthome by eclipse.
the class OAuthFactoryImpl method createOAuthClientService.
@Override
public OAuthClientService createOAuthClientService(String handle, String tokenUrl, @Nullable String authorizationUrl, String clientId, @Nullable String clientSecret, @Nullable String scope, @Nullable Boolean supportsBasicAuth) {
PersistedParams params = oAuthStoreHandler.loadPersistedParams(handle);
PersistedParams newParams = new PersistedParams(handle, tokenUrl, authorizationUrl, clientId, clientSecret, scope, supportsBasicAuth, tokenExpiresInBuffer);
OAuthClientService clientImpl = null;
// If parameters in storage and parameters are the same as arguments passed get the client from storage
if (params != null && params.equals(newParams)) {
clientImpl = getOAuthClientService(handle);
}
// client in storage.
if (clientImpl == null) {
clientImpl = OAuthClientServiceImpl.createInstance(handle, oAuthStoreHandler, httpClientFactory, newParams);
oauthClientServiceCache.put(handle, clientImpl);
}
return clientImpl;
}
use of org.openhab.core.auth.client.oauth2.OAuthClientService in project smarthome by eclipse.
the class AbstractTestAgent method testCreateClient.
@Override
public OAuthClientService testCreateClient() {
logger.debug("test createClient");
handle = UUID.randomUUID().toString();
OAuthClientService service = oauthFactory.createOAuthClientService(handle, tokenUrl, authUrl, clientId, clientSecret, scope, false);
logger.info("new client handle: {}", handle);
return service;
}
use of org.openhab.core.auth.client.oauth2.OAuthClientService in project smarthome by eclipse.
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()));
}
}
use of org.openhab.core.auth.client.oauth2.OAuthClientService in project openhab-addons by openhab.
the class InnogyBridgeHandlerTest method before.
@BeforeEach
public void before() throws Exception {
bridgeMock = mock(Bridge.class);
when(bridgeMock.getUID()).thenReturn(new ThingUID("innogysmarthome", "bridge"));
webSocketMock = mock(InnogyWebSocket.class);
OAuthClientService oAuthService = mock(OAuthClientService.class);
OAuthFactory oAuthFactoryMock = mock(OAuthFactory.class);
when(oAuthFactoryMock.createOAuthClientService(any(), any(), any(), any(), any(), any(), any())).thenReturn(oAuthService);
HttpClient httpClientMock = mock(HttpClient.class);
bridgeHandler = new InnogyBridgeHandlerAccessible(bridgeMock, oAuthFactoryMock, httpClientMock);
}
use of org.openhab.core.auth.client.oauth2.OAuthClientService in project openhab-addons by openhab.
the class HomeConnectBridgeHandler method handleConfigurationUpdate.
@Override
public void handleConfigurationUpdate(Map<String, Object> configurationParameters) {
if (isModifyingCurrentConfig(configurationParameters)) {
List<String> parameters = configurationParameters.entrySet().stream().map((entry) -> {
if (CLIENT_ID.equals(entry.getKey()) || CLIENT_SECRET.equals(entry.getKey())) {
return entry.getKey() + ": ***";
}
return entry.getKey() + ": " + entry.getValue();
}).collect(Collectors.toList());
logger.debug("Update bridge configuration. bridge={}, parameters={}", getThing().getLabel(), parameters);
validateConfigurationParameters(configurationParameters);
Configuration configuration = editConfiguration();
for (Entry<String, Object> configurationParameter : configurationParameters.entrySet()) {
configuration.put(configurationParameter.getKey(), configurationParameter.getValue());
}
// invalidate oAuth credentials
try {
logger.debug("Clear oAuth credential store. bridge={}", getThing().getLabel());
var oAuthClientService = this.oAuthClientService;
if (oAuthClientService != null) {
oAuthClientService.remove();
}
} catch (OAuthException e) {
logger.error("Could not clear oAuth credentials. bridge={}", getThing().getLabel(), e);
}
if (isInitialized()) {
// persist new configuration and reinitialize handler
dispose();
updateConfiguration(configuration);
initialize();
} else {
// persist new configuration and notify Thing Manager
updateConfiguration(configuration);
@Nullable ThingHandlerCallback callback = getCallback();
if (callback != null) {
callback.configurationUpdated(this.getThing());
} else {
logger.warn("Handler {} tried updating its configuration although the handler was already disposed.", this.getClass().getSimpleName());
}
}
}
}
Aggregations