use of org.openhab.core.auth.client.oauth2.OAuthException 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;
}
use of org.openhab.core.auth.client.oauth2.OAuthException in project openhab-core by openhab.
the class AbstractTestAgent method testGetCachedAccessToken.
@Override
public AccessTokenResponse testGetCachedAccessToken() throws OAuthException, IOException, OAuthResponseException {
logger.debug("test getCachedAccessToken");
AccessTokenResponse oldRefreshedToken = oauthClientService.getAccessTokenResponse();
return oldRefreshedToken;
}
use of org.openhab.core.auth.client.oauth2.OAuthException in project smarthome by eclipse.
the class OAuthClientServiceImpl method extractAuthCodeFromAuthResponse.
@Override
public String extractAuthCodeFromAuthResponse(@NonNull String redirectURLwithParams) throws OAuthException {
// parse the redirectURL
try {
URL redirectURLObject = new URL(redirectURLwithParams);
UrlEncoded urlEncoded = new UrlEncoded(redirectURLObject.getQuery());
// may contain multiple...
String stateFromRedirectURL = urlEncoded.getValue(STATE, 0);
if (stateFromRedirectURL == null) {
if (persistedParams.state == null) {
// This should not happen as the state is usually set
return urlEncoded.getValue(CODE, 0);
}
// else
throw new OAuthException(String.format("state from redirectURL is incorrect. Expected: %s Found: %s", persistedParams.state, stateFromRedirectURL));
} else {
if (stateFromRedirectURL.equals(persistedParams.state)) {
return urlEncoded.getValue(CODE, 0);
}
// else
throw new OAuthException(String.format("state from redirectURL is incorrect. Expected: %s Found: %s", persistedParams.state, stateFromRedirectURL));
}
} catch (MalformedURLException e) {
throw new OAuthException("Redirect URL is malformed", e);
}
}
use of org.openhab.core.auth.client.oauth2.OAuthException in project smarthome by eclipse.
the class OAuthFactoryImpl method deleteServiceAndAccessToken.
@Override
public void deleteServiceAndAccessToken(String handle) {
OAuthClientService clientImpl = oauthClientServiceCache.get(handle);
if (clientImpl != null) {
try {
clientImpl.remove();
} catch (OAuthException e) {
// client was already closed, does not matter
}
oauthClientServiceCache.remove(handle);
}
oAuthStoreHandler.remove(handle);
}
use of org.openhab.core.auth.client.oauth2.OAuthException in project openhab-core by openhab.
the class OAuthClientServiceImpl method extractAuthCodeFromAuthResponse.
@Override
public String extractAuthCodeFromAuthResponse(String redirectURLwithParams) throws OAuthException {
// parse the redirectURL
try {
URL redirectURLObject = new URL(redirectURLwithParams);
UrlEncoded urlEncoded = new UrlEncoded(redirectURLObject.getQuery());
// may contain multiple...
String stateFromRedirectURL = urlEncoded.getValue(STATE, 0);
if (stateFromRedirectURL == null) {
if (persistedParams.state == null) {
// This should not happen as the state is usually set
return urlEncoded.getValue(CODE, 0);
}
// else
throw new OAuthException(String.format("state from redirectURL is incorrect. Expected: %s Found: %s", persistedParams.state, stateFromRedirectURL));
} else {
if (stateFromRedirectURL.equals(persistedParams.state)) {
return urlEncoded.getValue(CODE, 0);
}
// else
throw new OAuthException(String.format("state from redirectURL is incorrect. Expected: %s Found: %s", persistedParams.state, stateFromRedirectURL));
}
} catch (MalformedURLException e) {
throw new OAuthException("Redirect URL is malformed", e);
}
}
Aggregations