Search in sources :

Example 31 with AuthorizationException

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"));
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockRequestCallback(com.okta.oidc.util.MockRequestCallback) AuthorizationException(com.okta.oidc.util.AuthorizationException) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 32 with AuthorizationException

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"));
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockRequestCallback(com.okta.oidc.util.MockRequestCallback) AuthorizationException(com.okta.oidc.util.AuthorizationException) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 33 with AuthorizationException

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();
}
Also used : MockRequestCallback(com.okta.oidc.util.MockRequestCallback) MockRequestCallback(com.okta.oidc.util.MockRequestCallback) RequestCallback(com.okta.oidc.RequestCallback) AuthorizationException(com.okta.oidc.util.AuthorizationException) NonNull(androidx.annotation.NonNull) CountDownLatch(java.util.concurrent.CountDownLatch) Tokens(com.okta.oidc.Tokens) Test(org.junit.Test)

Example 34 with AuthorizationException

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);
}
Also used : AuthorizationException(com.okta.oidc.util.AuthorizationException) Bundle(android.os.Bundle) Test(org.junit.Test)

Example 35 with AuthorizationException

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;
}
Also used : JSONObject(org.json.JSONObject) AuthorizationException(com.okta.oidc.util.AuthorizationException) HttpResponse(com.okta.oidc.net.HttpResponse) Gson(com.google.gson.Gson) JSONException(org.json.JSONException) IOException(java.io.IOException) JSONException(org.json.JSONException) IOException(java.io.IOException) AuthorizationException(com.okta.oidc.util.AuthorizationException)

Aggregations

AuthorizationException (com.okta.oidc.util.AuthorizationException)39 Test (org.junit.Test)19 CountDownLatch (java.util.concurrent.CountDownLatch)16 MockRequestCallback (com.okta.oidc.util.MockRequestCallback)15 IOException (java.io.IOException)9 Tokens (com.okta.oidc.Tokens)8 JSONObject (org.json.JSONObject)8 HttpResponse (com.okta.oidc.net.HttpResponse)6 TokenResponse (com.okta.oidc.net.response.TokenResponse)6 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)6 IntrospectInfo (com.okta.oidc.net.response.IntrospectInfo)5 UserInfo (com.okta.oidc.net.response.UserInfo)5 Uri (android.net.Uri)4 JSONException (org.json.JSONException)4 NonNull (androidx.annotation.NonNull)3 WorkerThread (androidx.annotation.WorkerThread)3 Gson (com.google.gson.Gson)3 RequestCallback (com.okta.oidc.RequestCallback)3 ProviderConfiguration (com.okta.oidc.net.request.ProviderConfiguration)3 TokenRequest (com.okta.oidc.net.request.TokenRequest)3