Search in sources :

Example 21 with AuthorizationException

use of com.okta.oidc.util.AuthorizationException in project okta-oidc-android by okta.

the class SessionClientImpl method revokeToken.

public void revokeToken(String token, final RequestCallback<Boolean, AuthorizationException> cb) {
    CallbackWrapper<Boolean, AuthorizationException> wrapper = new CallbackWrapper<>(cb);
    executeSerial(wrapper, () -> {
        Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
        try {
            Boolean isRevoke = mSyncSessionClient.revokeToken(token);
            mDispatcher.submitResults(() -> wrapper.onSuccess(isRevoke));
        } catch (AuthorizationException ae) {
            mDispatcher.submitResults(() -> wrapper.onError(ae.error, ae));
        } catch (Exception ex) {
            mDispatcher.submitResults(() -> wrapper.onError(ex.getMessage(), new AuthorizationException(ex.getMessage(), ex)));
        }
    });
}
Also used : AuthorizationException(com.okta.oidc.util.AuthorizationException) AuthorizationException(com.okta.oidc.util.AuthorizationException)

Example 22 with AuthorizationException

use of com.okta.oidc.util.AuthorizationException in project okta-oidc-android by okta.

the class SessionClientImpl method authorizedRequest.

@Override
public void authorizedRequest(@NonNull Uri uri, @Nullable Map<String, String> properties, @Nullable Map<String, String> postParameters, @NonNull ConnectionParameters.RequestMethod method, final RequestCallback<JSONObject, AuthorizationException> cb) {
    CallbackWrapper<JSONObject, AuthorizationException> wrapper = new CallbackWrapper<>(cb);
    executeSerial(wrapper, () -> {
        Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
        try {
            JSONObject result = mSyncSessionClient.authorizedRequest(uri, properties, postParameters, method);
            mDispatcher.submitResults(() -> wrapper.onSuccess(result));
        } catch (AuthorizationException ae) {
            mDispatcher.submitResults(() -> wrapper.onError(ae.error, ae));
        } catch (Exception ex) {
            mDispatcher.submitResults(() -> wrapper.onError(ex.getMessage(), new AuthorizationException(ex.getMessage(), ex)));
        }
    });
}
Also used : JSONObject(org.json.JSONObject) AuthorizationException(com.okta.oidc.util.AuthorizationException) AuthorizationException(com.okta.oidc.util.AuthorizationException)

Example 23 with AuthorizationException

use of com.okta.oidc.util.AuthorizationException in project okta-oidc-android by okta.

the class SessionClientImplTest method introspectToken.

@Test
public void introspectToken() throws InterruptedException {
    mEndPoint.enqueueIntrospectSuccess();
    final CountDownLatch latch = new CountDownLatch(1);
    MockRequestCallback<IntrospectInfo, AuthorizationException> cb = new MockRequestCallback<>(latch);
    mSessionClient.introspectToken(ACCESS_TOKEN, TokenTypeHint.ACCESS_TOKEN, cb);
    latch.await();
    assertNotNull(cb.getResult());
    assertTrue(cb.getResult().isActive());
}
Also used : MockRequestCallback(com.okta.oidc.util.MockRequestCallback) AuthorizationException(com.okta.oidc.util.AuthorizationException) CountDownLatch(java.util.concurrent.CountDownLatch) IntrospectInfo(com.okta.oidc.net.response.IntrospectInfo) Test(org.junit.Test)

Example 24 with AuthorizationException

use of com.okta.oidc.util.AuthorizationException in project okta-oidc-android by okta.

the class SessionClientImplTest method refreshTokenInParallel.

@Test
public void refreshTokenInParallel() throws InterruptedException {
    final CountDownLatch latch = new CountDownLatch(2);
    String nonce = CodeVerifierUtil.generateRandomState();
    String jws = TestValues.getJwt(mEndPoint.getUrl(), nonce, mConfig.getClientId());
    mEndPoint.enqueueTokenSuccess(jws);
    MockRequestCallback<Tokens, AuthorizationException> cb = new MockRequestCallback<>(latch);
    MockRequestCallback<Tokens, AuthorizationException> cb2 = new MockRequestCallback<>(latch);
    new Thread(() -> mSessionClient.refreshToken(cb)).start();
    new Thread(() -> mSessionClient.refreshToken(cb2)).start();
    latch.await();
    Tokens result = cb.getResult();
    Tokens result2 = cb2.getResult();
    TokenResponse original = mGson.fromJson(String.format(TOKEN_SUCCESS, jws), TokenResponse.class);
    assertEquals(original.getIdToken(), result.getIdToken());
    assertEquals(original.getRefreshToken(), result.getRefreshToken());
    assertEquals(original.getIdToken(), result.getIdToken());
    assertEquals(result, result2);
}
Also used : MockRequestCallback(com.okta.oidc.util.MockRequestCallback) TokenResponse(com.okta.oidc.net.response.TokenResponse) AuthorizationException(com.okta.oidc.util.AuthorizationException) CountDownLatch(java.util.concurrent.CountDownLatch) Tokens(com.okta.oidc.Tokens) Test(org.junit.Test)

Example 25 with AuthorizationException

use of com.okta.oidc.util.AuthorizationException in project okta-oidc-android by okta.

the class SessionClientImplTest method refreshTokenFailure.

@Test
public void refreshTokenFailure() throws InterruptedException {
    final CountDownLatch latch = new CountDownLatch(1);
    mEndPoint.enqueueReturnInvalidClient();
    MockRequestCallback<Tokens, AuthorizationException> cb = new MockRequestCallback<>(latch);
    mSessionClient.refreshToken(cb);
    latch.await();
    assertNull(cb.getResult());
    assertNotNull(cb.getException());
    assertEquals(cb.getException().getMessage(), "No client credentials found.");
    assertEquals(cb.getException().type, TYPE_OAUTH_TOKEN_ERROR);
}
Also used : MockRequestCallback(com.okta.oidc.util.MockRequestCallback) AuthorizationException(com.okta.oidc.util.AuthorizationException) CountDownLatch(java.util.concurrent.CountDownLatch) Tokens(com.okta.oidc.Tokens) Test(org.junit.Test)

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