use of com.okta.oidc.results.Result in project okta-oidc-android by okta.
the class SyncWebAuthClientTest method signInEmailAuthenticated.
@Test
public void signInEmailAuthenticated() throws AuthorizationException {
AuthorizeResponse response = AuthorizeResponse.fromUri(Uri.parse(String.format(TestValues.EMAIL_AUTHENTICATED, mEndPoint.getUrl())));
Assert.assertTrue(mSyncWebAuth.isVerificationFlow(response));
Result result = mSyncWebAuth.processEmailVerification(response);
assertEquals(AuthorizationStatus.EMAIL_VERIFICATION_AUTHENTICATED, result.getStatus());
assertNull(result.getLoginHint());
}
use of com.okta.oidc.results.Result in project okta-oidc-android by okta.
the class SyncWebAuthClientTest method signInEmailUnauthenticated.
@Test
public void signInEmailUnauthenticated() throws AuthorizationException {
AuthorizeResponse response = AuthorizeResponse.fromUri(Uri.parse(String.format(TestValues.EMAIL_UNAUTHENTICATED, mEndPoint.getUrl())));
Assert.assertTrue(mSyncWebAuth.isVerificationFlow(response));
Result result = mSyncWebAuth.processEmailVerification(response);
assertEquals(AuthorizationStatus.EMAIL_VERIFICATION_UNAUTHENTICATED, result.getStatus());
assertEquals(TestValues.LOGIN_HINT, result.getLoginHint());
}
use of com.okta.oidc.results.Result in project okta-oidc-android by okta.
the class SyncWebAuthClientTest method signOutWithNoData.
@Test
public void signOutWithNoData() {
mSyncWebAuth.getSessionClient().clear();
Result result = mSyncWebAuth.signOutOfOkta(Robolectric.setupActivity(FragmentActivity.class));
assertNotNull(result.getError());
Assert.assertTrue(result.getError().getCause() instanceof NullPointerException);
}
use of com.okta.oidc.results.Result in project okta-oidc-android by okta.
the class SyncAuthClientTest method signInNativeCancel.
@Test
public void signInNativeCancel() throws AuthorizationException, InterruptedException {
String nonce = CodeVerifierUtil.generateRandomState();
String state = CodeVerifierUtil.generateRandomState();
String jws = TestValues.getJwt(mEndPoint.getUrl(), nonce, mConfig.getClientId());
AuthenticationPayload payload = new AuthenticationPayload.Builder().addParameter("nonce", nonce).setState(state).build();
mEndPoint.enqueueNativeRequestSuccess(state, 5);
mEndPoint.enqueueTokenSuccess(jws);
CountDownLatch latch = new CountDownLatch(1);
MockRequestCallback<Result, AuthorizationException> mockCallback = new MockRequestCallback<>(latch);
mAuthClient.signIn(SESSION_TOKEN, payload, mockCallback);
// wait for request to be created
Thread.sleep(200);
mAuthClient.cancel();
latch.await();
assertNull(mockCallback.getResult());
assertNotNull(mockCallback.getException());
String errorMessage = mockCallback.getException().getMessage();
// Socket closed or canceled or stream is closed or network error.
if (errorMessage == null) {
assertTrue(mockCallback.getException().getCause() instanceof InterruptedException);
} else {
assertTrue("Socket closed".equals(errorMessage) || "Canceled".equals(errorMessage) || "stream is closed".equals(errorMessage) || "Network error".equals(errorMessage) || "interrupted".equals(errorMessage));
}
}
use of com.okta.oidc.results.Result in project okta-oidc-android by okta.
the class SyncWebAuthClientImpl method registerCallbackIfInterrupt.
@Override
public void registerCallbackIfInterrupt(Activity activity, ResultListener resultListener, ExecutorService executorService) {
AuthResultListener authResultListener = (result, type) -> {
if (!executorService.isShutdown()) {
executorService.execute(() -> {
switch(type) {
case SIGN_IN:
Result authorizationResult = processSignInResult(result);
resetCurrentState();
if (resultListener != null) {
resultListener.postResult(authorizationResult, type);
}
break;
case SIGN_OUT:
Result signOutResult = processSignOutResult(result);
resetCurrentState();
if (resultListener != null) {
resultListener.postResult(signOutResult, type);
}
break;
default:
break;
}
});
}
};
mHandler.setAuthenticationListener(authResultListener);
}
Aggregations