use of com.okta.oidc.util.AuthorizationException in project okta-oidc-android by okta.
the class RevokeTokenRequest method executeRequest.
@Override
public Boolean executeRequest(OktaHttpClient client) throws AuthorizationException {
AuthorizationException exception = null;
HttpResponse response = null;
try {
response = openConnection(client);
if (response.getStatusCode() == HttpURLConnection.HTTP_UNAUTHORIZED) {
exception = AuthorizationException.TokenRequestErrors.INVALID_CLIENT;
} else if (response.getStatusCode() == HttpURLConnection.HTTP_OK) {
return true;
}
} catch (IOException ex) {
exception = new AuthorizationException(ex.getMessage(), ex);
} catch (Exception e) {
exception = AuthorizationException.fromTemplate(AuthorizationException.GeneralErrors.NETWORK_ERROR, e);
} finally {
if (response != null) {
response.disconnect();
}
if (exception != null) {
throw exception;
}
}
return false;
}
use of com.okta.oidc.util.AuthorizationException in project okta-oidc-android by okta.
the class ConfigurationRequest method executeRequest.
@WorkerThread
@Override
public ProviderConfiguration executeRequest(OktaHttpClient client) throws AuthorizationException {
AuthorizationException exception = null;
HttpResponse response = null;
try {
response = openConnection(client);
JSONObject json = response.asJson();
ProviderConfiguration configuration = new Gson().fromJson(json.toString(), ProviderConfiguration.class);
configuration.validate(mIsOAuth2);
return configuration;
} catch (IOException ex) {
exception = new AuthorizationException(ex.getMessage(), ex);
} catch (JSONException ex) {
exception = AuthorizationException.fromTemplate(AuthorizationException.GeneralErrors.JSON_DESERIALIZATION_ERROR, ex);
} catch (IllegalArgumentException ex) {
exception = AuthorizationException.fromTemplate(AuthorizationException.GeneralErrors.INVALID_DISCOVERY_DOCUMENT, ex);
} catch (Exception e) {
exception = new AuthorizationException(e.getMessage(), e);
} finally {
if (response != null) {
response.disconnect();
}
if (exception != null) {
throw exception;
}
}
return null;
}
use of com.okta.oidc.util.AuthorizationException in project okta-oidc-android by okta.
the class BaseRequestTest method setUp.
@Before
public void setUp() throws Exception {
mEndPoint = new MockEndPoint();
mRequest = new BaseRequest<String, AuthorizationException>() {
@Override
public String executeRequest(OktaHttpClient client) throws AuthorizationException {
return null;
}
};
mClientFactory = new HttpClientFactory();
mClientFactory.setClientType(mClientType);
mHttpClient = mClientFactory.build();
}
use of com.okta.oidc.util.AuthorizationException in project okta-oidc-android by okta.
the class HttpClientImplTest method cancel.
@Test
public void cancel() throws AuthorizationException {
mEndPoint.enqueueUserInfoSuccess(5);
final CountDownLatch latch = new CountDownLatch(1);
final JSONObject[] result = new JSONObject[1];
final AuthorizationException[] exception = new AuthorizationException[1];
Thread t = new Thread(() -> {
try {
result[0] = mRequest.executeRequest(mHttpClient);
} catch (AuthorizationException e) {
exception[0] = e;
}
});
t.start();
mHttpClient.cancel();
if (exception[0] != null) {
// The exception can be canceled or stream is closed.
String errorMessage = exception[0].getMessage();
assertTrue("Canceled".equals(errorMessage) || "stream is closed".equals(errorMessage));
} else {
assertNull(result[0]);
}
}
Aggregations