use of com.okta.oidc.AuthenticationPayload 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.AuthenticationPayload in project okta-oidc-android by okta.
the class WebAuthClientImpl method signIn.
@Override
@AnyThread
public void signIn(@NonNull final Activity activity, AuthenticationPayload payload) {
registerActivityLifeCycle(activity);
cancelFuture();
// add the login hint if it exists.
if (payload == null && mLoginHint != null) {
payload = new AuthenticationPayload.Builder().setLoginHint(mLoginHint).build();
} else if (mLoginHint != null) {
payload = new AuthenticationPayload.Builder().copyPayload(payload).setLoginHint(mLoginHint).build();
}
final AuthenticationPayload finalPayload = payload;
mFutureTask = mDispatcher.submit(() -> {
Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
try {
Result result = mSyncAuthClient.signIn(activity, finalPayload);
processSignInResult(result);
} catch (InterruptedException e) {
mDispatcher.submitResults(() -> {
if (mResultCb != null) {
mResultCb.onCancel();
}
});
}
});
}
use of com.okta.oidc.AuthenticationPayload in project okta-oidc-android by okta.
the class SyncAuthClientTest method signInNative.
@Test
public void signInNative() throws AuthorizationException, OktaRepository.EncryptionException {
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);
mEndPoint.enqueueTokenSuccess(jws);
Result result = mSyncNativeAuth.signIn(SESSION_TOKEN, payload);
assertNotNull(result);
Tokens tokens = new Tokens(mOktaState.getTokenResponse());
assertNotNull(tokens);
assertNotNull(tokens.getAccessToken());
assertNotNull(tokens.getRefreshToken());
assertNotNull(tokens.getIdToken());
}
Aggregations