Search in sources :

Example 16 with OAuthClientService

use of org.openhab.core.auth.client.oauth2.OAuthClientService in project openhab-addons by openhab.

the class MieleBridgeHandlerTest method getOAuthClientServiceMock.

private OAuthClientService getOAuthClientServiceMock() {
    OAuthClientService oauthClientServiceMock = this.oauthClientServiceMock;
    assertNotNull(oauthClientServiceMock);
    return Objects.requireNonNull(oauthClientServiceMock);
}
Also used : OAuthClientService(org.openhab.core.auth.client.oauth2.OAuthClientService)

Example 17 with OAuthClientService

use of org.openhab.core.auth.client.oauth2.OAuthClientService in project openhab-core by openhab.

the class OAuthFactoryImpl method getOAuthClientService.

@Override
@Nullable
public OAuthClientService getOAuthClientService(String handle) {
    OAuthClientService clientImpl = oauthClientServiceCache.get(handle);
    if (clientImpl == null || clientImpl.isClosed()) {
        // This happens after reboot, or client was closed without factory knowing; create a new client
        // the store has the handle/config data
        clientImpl = OAuthClientServiceImpl.getInstance(handle, oAuthStoreHandler, tokenExpiresInBuffer, httpClientFactory);
        if (clientImpl == null) {
            return null;
        }
        oauthClientServiceCache.put(handle, clientImpl);
    }
    return clientImpl;
}
Also used : OAuthClientService(org.openhab.core.auth.client.oauth2.OAuthClientService) Nullable(org.eclipse.jdt.annotation.Nullable)

Example 18 with OAuthClientService

use of org.openhab.core.auth.client.oauth2.OAuthClientService in project openhab-core by openhab.

the class OAuthFactoryImpl method ungetOAuthService.

@SuppressWarnings("null")
@Override
public void ungetOAuthService(String handle) {
    OAuthClientService clientImpl = oauthClientServiceCache.get(handle);
    if (clientImpl == null) {
        logger.debug("{} handle not found. Cannot unregisterOAuthServie", handle);
        return;
    }
    clientImpl.close();
    oauthClientServiceCache.remove(handle);
}
Also used : OAuthClientService(org.openhab.core.auth.client.oauth2.OAuthClientService)

Example 19 with OAuthClientService

use of org.openhab.core.auth.client.oauth2.OAuthClientService in project openhab-core by openhab.

the class AbstractTestAgent method testGetAccessTokenByResourceOwnerPasswordCredentials.

@Override
public AccessTokenResponse testGetAccessTokenByResourceOwnerPasswordCredentials() throws OAuthException, IOException, OAuthResponseException {
    logger.debug("test getOAuthTokenByResourceOwnerPasswordCredentials");
    if (handle == null) {
        logger.debug("Creating new oauth service");
        oauthClientService = testCreateClient();
    } else {
        logger.debug("getting oauth client by handle: {}", handle);
        oauthClientService = oauthFactory.getOAuthClientService(handle);
    }
    AccessTokenResponse accessTokenResponse = oauthClientService.getAccessTokenByResourceOwnerPasswordCredentials(username, password, scope);
    logger.debug("Token: {}", accessTokenResponse);
    return accessTokenResponse;
}
Also used : AccessTokenResponse(org.openhab.core.auth.client.oauth2.AccessTokenResponse)

Example 20 with OAuthClientService

use of org.openhab.core.auth.client.oauth2.OAuthClientService in project smarthome by eclipse.

the class OAuthFactoryImpl method getOAuthClientService.

@Override
@Nullable
public OAuthClientService getOAuthClientService(String handle) {
    OAuthClientService clientImpl = oauthClientServiceCache.get(handle);
    if (clientImpl == null || clientImpl.isClosed()) {
        // This happens after reboot, or client was closed without factory knowing; create a new client
        // the store has the handle/config data
        clientImpl = OAuthClientServiceImpl.getInstance(handle, oAuthStoreHandler, tokenExpiresInBuffer, httpClientFactory);
        if (clientImpl == null) {
            return null;
        }
        oauthClientServiceCache.put(handle, clientImpl);
    }
    return clientImpl;
}
Also used : OAuthClientService(org.eclipse.smarthome.core.auth.client.oauth2.OAuthClientService) Nullable(org.eclipse.jdt.annotation.Nullable)

Aggregations

OAuthClientService (org.openhab.core.auth.client.oauth2.OAuthClientService)36 OAuthFactory (org.openhab.core.auth.client.oauth2.OAuthFactory)15 AccessTokenResponse (org.openhab.core.auth.client.oauth2.AccessTokenResponse)12 IOException (java.io.IOException)10 Test (org.junit.jupiter.api.Test)10 OAuthResponseException (org.openhab.core.auth.client.oauth2.OAuthResponseException)10 Nullable (org.eclipse.jdt.annotation.Nullable)8 OAuthException (org.openhab.core.auth.client.oauth2.OAuthException)7 OAuthClientService (org.eclipse.smarthome.core.auth.client.oauth2.OAuthClientService)6 AuthorizationException (org.openhab.binding.homeconnect.internal.client.exception.AuthorizationException)4 CommunicationException (org.openhab.binding.homeconnect.internal.client.exception.CommunicationException)4 List (java.util.List)3 Map (java.util.Map)3 NonNullByDefault (org.eclipse.jdt.annotation.NonNullByDefault)3 BeforeEach (org.junit.jupiter.api.BeforeEach)3 ZonedDateTime (java.time.ZonedDateTime)2 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 HashMap (java.util.HashMap)2 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)2