Search in sources :

Example 1 with Result

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());
}
Also used : AuthorizeResponse(com.okta.oidc.net.response.web.AuthorizeResponse) Result(com.okta.oidc.results.Result) StateResult(com.okta.oidc.AuthenticationResultHandler.StateResult) Test(org.junit.Test)

Example 2 with Result

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());
}
Also used : AuthorizeResponse(com.okta.oidc.net.response.web.AuthorizeResponse) Result(com.okta.oidc.results.Result) StateResult(com.okta.oidc.AuthenticationResultHandler.StateResult) Test(org.junit.Test)

Example 3 with Result

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);
}
Also used : FragmentActivity(androidx.fragment.app.FragmentActivity) Result(com.okta.oidc.results.Result) StateResult(com.okta.oidc.AuthenticationResultHandler.StateResult) Test(org.junit.Test)

Example 4 with Result

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));
    }
}
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 5 with Result

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);
}
Also used : OktaResultFragment.addLogoutFragment(com.okta.oidc.OktaResultFragment.addLogoutFragment) PackageManager(android.content.pm.PackageManager) NonNull(androidx.annotation.NonNull) Uri(android.net.Uri) REQUEST_CODE_SIGN_IN(com.okta.oidc.OktaResultFragment.REQUEST_CODE_SIGN_IN) RestrictTo(androidx.annotation.RestrictTo) EncryptionManager(com.okta.oidc.storage.security.EncryptionManager) ActivityInfo(android.content.pm.ActivityInfo) WebRequest(com.okta.oidc.net.request.web.WebRequest) TYPE_OAUTH_REGISTRATION_ERROR(com.okta.oidc.util.AuthorizationException.TYPE_OAUTH_REGISTRATION_ERROR) Log(android.util.Log) INVALID_REDIRECT_URI(com.okta.oidc.util.AuthorizationException.RegistrationRequestErrors.INVALID_REDIRECT_URI) ProviderConfiguration(com.okta.oidc.net.request.ProviderConfiguration) CustomTabOptions(com.okta.oidc.CustomTabOptions) AuthorizationException(com.okta.oidc.util.AuthorizationException) Result(com.okta.oidc.results.Result) OktaResultFragment.addLoginFragment(com.okta.oidc.OktaResultFragment.addLoginFragment) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) Nullable(androidx.annotation.Nullable) State(com.okta.oidc.clients.State) REQUEST_CODE_SIGN_OUT(com.okta.oidc.OktaResultFragment.REQUEST_CODE_SIGN_OUT) OktaResultFragment.createAuthIntent(com.okta.oidc.OktaResultFragment.createAuthIntent) AuthenticationPayload(com.okta.oidc.AuthenticationPayload) Context(android.content.Context) AuthorizeRequest(com.okta.oidc.net.request.web.AuthorizeRequest) AuthResultListener(com.okta.oidc.AuthenticationResultHandler.AuthResultListener) LogoutRequest(com.okta.oidc.net.request.web.LogoutRequest) OIDCConfig(com.okta.oidc.OIDCConfig) WorkerThread(androidx.annotation.WorkerThread) Intent(android.content.Intent) AtomicReference(java.util.concurrent.atomic.AtomicReference) FragmentActivity(androidx.fragment.app.FragmentActivity) Lifecycle(androidx.lifecycle.Lifecycle) EncryptionErrors(com.okta.oidc.util.AuthorizationException.EncryptionErrors) SyncSessionClientFactoryImpl(com.okta.oidc.clients.sessions.SyncSessionClientFactoryImpl) TESTS(androidx.annotation.RestrictTo.Scope.TESTS) TokenRequest(com.okta.oidc.net.request.TokenRequest) OktaHttpClient(com.okta.oidc.net.OktaHttpClient) AuthorizeResponse(com.okta.oidc.net.response.web.AuthorizeResponse) OktaStorage(com.okta.oidc.storage.OktaStorage) WeakReference(java.lang.ref.WeakReference) ExecutorService(java.util.concurrent.ExecutorService) ResultType(com.okta.oidc.AuthenticationResultHandler.ResultType) TokenResponse(com.okta.oidc.net.response.TokenResponse) IDLE(com.okta.oidc.clients.State.IDLE) TextUtils(android.text.TextUtils) IOException(java.io.IOException) AnyThread(androidx.annotation.AnyThread) OktaRepository(com.okta.oidc.storage.OktaRepository) CodeVerifierUtil(com.okta.oidc.util.CodeVerifierUtil) ResolveInfo(android.content.pm.ResolveInfo) SyncSessionClient(com.okta.oidc.clients.sessions.SyncSessionClient) StateResult(com.okta.oidc.AuthenticationResultHandler.StateResult) OktaRedirectActivity(com.okta.oidc.OktaRedirectActivity) AuthenticationResultHandler(com.okta.oidc.AuthenticationResultHandler) Activity(android.app.Activity) VisibleForTesting(androidx.annotation.VisibleForTesting) AuthAPI(com.okta.oidc.clients.AuthAPI) AuthResultListener(com.okta.oidc.AuthenticationResultHandler.AuthResultListener) Result(com.okta.oidc.results.Result) StateResult(com.okta.oidc.AuthenticationResultHandler.StateResult)

Aggregations

Result (com.okta.oidc.results.Result)9 StateResult (com.okta.oidc.AuthenticationResultHandler.StateResult)5 Test (org.junit.Test)5 AuthenticationPayload (com.okta.oidc.AuthenticationPayload)4 AuthorizeResponse (com.okta.oidc.net.response.web.AuthorizeResponse)3 AuthorizationException (com.okta.oidc.util.AuthorizationException)3 AnyThread (androidx.annotation.AnyThread)2 NonNull (androidx.annotation.NonNull)2 FragmentActivity (androidx.fragment.app.FragmentActivity)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 Activity (android.app.Activity)1 Context (android.content.Context)1 Intent (android.content.Intent)1 ActivityInfo (android.content.pm.ActivityInfo)1 PackageManager (android.content.pm.PackageManager)1 ResolveInfo (android.content.pm.ResolveInfo)1 Uri (android.net.Uri)1 TextUtils (android.text.TextUtils)1 Log (android.util.Log)1 Nullable (androidx.annotation.Nullable)1