use of org.openhab.core.auth.client.oauth2.OAuthClientService in project openhab-addons by openhab.
the class OAuthAuthorizationHandlerImplTest method getClientService.
private OAuthClientService getClientService() {
final OAuthClientService clientService = this.clientService;
assertNotNull(clientService);
return Objects.requireNonNull(clientService);
}
use of org.openhab.core.auth.client.oauth2.OAuthClientService in project openhab-addons by openhab.
the class OpenHabOAuthTokenRefresher method unsetRefreshListener.
@Override
public void unsetRefreshListener(String serviceHandle) {
final AccessTokenRefreshListener refreshListener = listenerByServiceHandle.get(serviceHandle);
if (refreshListener != null) {
try {
OAuthClientService clientService = getOAuthClientService(serviceHandle);
clientService.removeAccessTokenRefreshListener(refreshListener);
} catch (OAuthException e) {
logger.warn("Failed to remove refresh listener: OAuth client service is unavailable. Cause: {}", e.getMessage());
}
}
listenerByServiceHandle.remove(serviceHandle);
}
use of org.openhab.core.auth.client.oauth2.OAuthClientService in project openhab-addons by openhab.
the class OpenHabOAuthTokenRefresher method refreshToken.
@Override
public void refreshToken(String serviceHandle) {
if (listenerByServiceHandle.get(serviceHandle) == null) {
logger.warn("Token refreshing was requested but there is no token refresh listener registered!");
return;
}
OAuthClientService clientService = getOAuthClientService(serviceHandle);
refreshAccessToken(clientService);
}
use of org.openhab.core.auth.client.oauth2.OAuthClientService in project openhab-addons by openhab.
the class OAuthAuthorizationHandlerImpl method completeAuthorization.
@Override
public synchronized void completeAuthorization(String redirectUrlWithParameters) {
abortTimer();
final OAuthClientService oauthClientService = this.oauthClientService;
if (oauthClientService == null) {
throw new NoOngoingAuthorizationException("There is no ongoing authorization.");
}
try {
String authorizationCode = oauthClientService.extractAuthCodeFromAuthResponse(redirectUrlWithParameters);
// Although this method is called "get" it actually fetches and stores the token response as a side effect.
oauthClientService.getAccessTokenResponseByAuthorizationCode(authorizationCode, redirectUri);
} catch (IOException e) {
throw new OAuthException("Network error while retrieving token response: " + e.getMessage(), e);
} catch (OAuthResponseException e) {
throw new OAuthException("Failed to retrieve token response: " + e.getMessage(), e);
} catch (org.openhab.core.auth.client.oauth2.OAuthException e) {
throw new OAuthException("Error while processing Miele service response: " + e.getMessage(), e);
} finally {
this.oauthClientService = null;
this.bridgeUid = null;
this.email = null;
this.redirectUri = null;
}
}
use of org.openhab.core.auth.client.oauth2.OAuthClientService in project openhab-addons by openhab.
the class MieleHandlerFactoryTest method setUp.
@BeforeEach
public void setUp() throws Exception {
registerVolatileStorageService();
thingRegistry = getService(ThingRegistry.class, ThingRegistry.class);
assertNotNull(thingRegistry, "Thing registry is missing");
// Ensure the MieleWebservice is not initialized.
MieleHandlerFactory factory = getService(ThingHandlerFactory.class, MieleHandlerFactory.class);
assertNotNull(factory);
// Assume an access token has already been stored
AccessTokenResponse accessTokenResponse = new AccessTokenResponse();
accessTokenResponse.setAccessToken(ACCESS_TOKEN);
OAuthClientService oAuthClientService = mock(OAuthClientService.class);
when(oAuthClientService.getAccessTokenResponse()).thenReturn(accessTokenResponse);
OAuthFactory oAuthFactory = mock(OAuthFactory.class);
when(oAuthFactory.getOAuthClientService(MieleCloudBindingIntegrationTestConstants.EMAIL)).thenReturn(oAuthClientService);
OpenHabOAuthTokenRefresher tokenRefresher = getService(OAuthTokenRefresher.class, OpenHabOAuthTokenRefresher.class);
assertNotNull(tokenRefresher);
setPrivate(Objects.requireNonNull(tokenRefresher), "oauthFactory", oAuthFactory);
}
Aggregations