use of com.okta.oidc.util.AuthorizationException in project okta-oidc-android by okta.
the class SessionClientImplTest method revokeToken.
@Test
public void revokeToken() throws InterruptedException {
mEndPoint.enqueueReturnSuccessEmptyBody();
final CountDownLatch latch = new CountDownLatch(1);
MockRequestCallback<Boolean, AuthorizationException> cb = new MockRequestCallback<>(latch);
mSessionClient.revokeToken("access_token", cb);
RecordedRequest recordedRequest = mEndPoint.takeRequest();
latch.await();
assertNotNull(cb.getResult());
assertTrue(cb.getResult());
assertThat(recordedRequest.getPath(), equalTo("/revoke?client_id=CLIENT_ID&token=access_token"));
}
use of com.okta.oidc.util.AuthorizationException in project okta-oidc-android by okta.
the class SessionClientImplTest method revokeTokenFailure.
@Test
public void revokeTokenFailure() throws InterruptedException {
mEndPoint.enqueueReturnInvalidClient();
final CountDownLatch latch = new CountDownLatch(1);
MockRequestCallback<Boolean, AuthorizationException> cb = new MockRequestCallback<>(latch);
mSessionClient.revokeToken("access_token", cb);
RecordedRequest recordedRequest = mEndPoint.takeRequest();
latch.await();
assertNull(cb.getResult());
assertNotNull(cb.getException());
assertEquals(TYPE_OAUTH_TOKEN_ERROR, cb.getException().type);
assertThat(recordedRequest.getPath(), equalTo("/revoke?client_id=CLIENT_ID&token=access_token"));
}
use of com.okta.oidc.util.AuthorizationException in project okta-oidc-android by okta.
the class SessionClientImplTest method refreshTokenFailureInParallelCallbackCycle.
@Test
public void refreshTokenFailureInParallelCallbackCycle() throws InterruptedException {
final CountDownLatch latch = new CountDownLatch(1);
String nonce = CodeVerifierUtil.generateRandomState();
String jws = TestValues.getJwt(mEndPoint.getUrl(), nonce, mConfig.getClientId());
mEndPoint.enqueueTokenSuccess(jws);
MockRequestCallback<Tokens, AuthorizationException> errorCb = new MockRequestCallback<>(latch);
RequestCallback<Tokens, AuthorizationException> cb = new RequestCallback<Tokens, AuthorizationException>() {
@Override
public void onSuccess(@NonNull Tokens result) {
try {
mSessionClient.refreshToken(errorCb);
} catch (RuntimeException runtimeException) {
assertEquals(runtimeException.getMessage(), "refreshToken can't be called from callback.");
latch.countDown();
}
}
@Override
public void onError(String error, AuthorizationException exception) {
fail();
}
};
mSessionClient.refreshToken(cb);
latch.await();
}
use of com.okta.oidc.util.AuthorizationException in project okta-oidc-android by okta.
the class OktaAuthClientActivityTest method testWithException.
@Test
public void testWithException() throws JSONException {
instantiateActivity(mAuthorizeWithException);
mActivityController.create();
Bundle bundle = mActivityController.get().getIntent().getExtras();
assertNotNull(bundle);
String exception = bundle.getString(EXTRA_EXCEPTION);
assertNotNull(exception);
AuthorizationException ex = AuthorizationException.fromJson(exception);
assertNotNull(ex);
assertEquals(ex, AuthorizationException.GeneralErrors.NETWORK_ERROR);
assertThat(mShadowActivity.getResultCode()).isEqualTo(RESULT_CANCELED);
}
use of com.okta.oidc.util.AuthorizationException in project okta-oidc-android by okta.
the class IntrospectRequest method executeRequest.
@Override
public IntrospectInfo executeRequest(OktaHttpClient client) throws AuthorizationException {
AuthorizationException exception = null;
HttpResponse response = null;
try {
response = openConnection(client);
JSONObject json = response.asJson();
return new Gson().fromJson(json.toString(), IntrospectInfo.class);
} catch (IOException ex) {
exception = new AuthorizationException(ex.getMessage(), ex);
} catch (JSONException e) {
exception = AuthorizationException.fromTemplate(AuthorizationException.GeneralErrors.JSON_DESERIALIZATION_ERROR, e);
} catch (Exception e) {
exception = AuthorizationException.fromTemplate(AuthorizationException.GeneralErrors.NETWORK_ERROR, e);
} finally {
if (response != null) {
response.disconnect();
}
if (exception != null) {
throw exception;
}
}
return null;
}
Aggregations