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)));
}
});
}
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)));
}
});
}
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());
}
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);
}
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);
}
Aggregations