Search in sources :

Example 1 with AuthenticationPayload

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

Example 2 with AuthenticationPayload

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();
                }
            });
        }
    });
}
Also used : AuthenticationPayload(com.okta.oidc.AuthenticationPayload) Result(com.okta.oidc.results.Result) AnyThread(androidx.annotation.AnyThread)

Example 3 with AuthenticationPayload

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());
}
Also used : AuthenticationPayload(com.okta.oidc.AuthenticationPayload) Result(com.okta.oidc.results.Result) Tokens(com.okta.oidc.Tokens) Test(org.junit.Test)

Aggregations

AuthenticationPayload (com.okta.oidc.AuthenticationPayload)3 Result (com.okta.oidc.results.Result)3 Test (org.junit.Test)2 AnyThread (androidx.annotation.AnyThread)1 Tokens (com.okta.oidc.Tokens)1 AuthorizationException (com.okta.oidc.util.AuthorizationException)1 MockRequestCallback (com.okta.oidc.util.MockRequestCallback)1 CountDownLatch (java.util.concurrent.CountDownLatch)1