Search in sources :

Example 1 with AuthResultListener

use of com.okta.oidc.AuthenticationResultHandler.AuthResultListener 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)

Example 2 with AuthResultListener

use of com.okta.oidc.AuthenticationResultHandler.AuthResultListener in project okta-oidc-android by okta.

the class AuthenticationResultHandlerTest method setAuthenticationListener.

@Test
public void setAuthenticationListener() throws InterruptedException {
    AuthenticationResultHandler.handler().mCachedResult = StateResult.canceled();
    AuthenticationResultHandler.handler().mCachedResultType = ResultType.SIGN_IN;
    final StateResult[] resultFromListener = new StateResult[1];
    final ResultType[] typeFromListener = new ResultType[1];
    CountDownLatch latch = new CountDownLatch(1);
    AuthResultListener listener = (result, type) -> {
        resultFromListener[0] = result;
        typeFromListener[0] = type;
        latch.countDown();
    };
    AuthenticationResultHandler.handler().setAuthenticationListener(listener);
    latch.await();
    assertEquals(resultFromListener[0].getStatus(), CANCELED);
    assertEquals(typeFromListener[0], ResultType.SIGN_IN);
    assertNull(AuthenticationResultHandler.handler().mCachedResult);
    assertNull(AuthenticationResultHandler.handler().mCachedResultType);
}
Also used : JSON_DESERIALIZATION_ERROR(com.okta.oidc.util.AuthorizationException.GeneralErrors.JSON_DESERIALIZATION_ERROR) AuthResultListener(com.okta.oidc.AuthenticationResultHandler.AuthResultListener) RESULT_OK(android.app.Activity.RESULT_OK) LOGGED_OUT(com.okta.oidc.AuthenticationResultHandler.Status.LOGGED_OUT) Uri(android.net.Uri) RunWith(org.junit.runner.RunWith) Config(org.robolectric.annotation.Config) Intent(android.content.Intent) TestValues(com.okta.oidc.util.TestValues) REQUEST_CODE_SIGN_IN(com.okta.oidc.OktaResultFragment.REQUEST_CODE_SIGN_IN) LogoutResponse(com.okta.oidc.net.response.web.LogoutResponse) AuthorizeResponse(com.okta.oidc.net.response.web.AuthorizeResponse) CUSTOM_STATE(com.okta.oidc.util.TestValues.CUSTOM_STATE) AuthorizationRequestErrors(com.okta.oidc.util.AuthorizationException.AuthorizationRequestErrors) RESULT_CANCELED(android.app.Activity.RESULT_CANCELED) ResultType(com.okta.oidc.AuthenticationResultHandler.ResultType) CANCELED(com.okta.oidc.AuthenticationResultHandler.Status.CANCELED) Assert.assertNotNull(org.junit.Assert.assertNotNull) EXTRA_EXCEPTION(com.okta.oidc.OktaAuthenticationActivity.EXTRA_EXCEPTION) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) AuthorizationException(com.okta.oidc.util.AuthorizationException) Status(com.okta.oidc.AuthenticationResultHandler.Status) RobolectricTestRunner(org.robolectric.RobolectricTestRunner) CountDownLatch(java.util.concurrent.CountDownLatch) StateResult(com.okta.oidc.AuthenticationResultHandler.StateResult) Assert.assertNull(org.junit.Assert.assertNull) REQUEST_CODE_SIGN_OUT(com.okta.oidc.OktaResultFragment.REQUEST_CODE_SIGN_OUT) CUSTOM_CODE(com.okta.oidc.util.TestValues.CUSTOM_CODE) Assert.assertEquals(org.junit.Assert.assertEquals) StateResult(com.okta.oidc.AuthenticationResultHandler.StateResult) AuthResultListener(com.okta.oidc.AuthenticationResultHandler.AuthResultListener) ResultType(com.okta.oidc.AuthenticationResultHandler.ResultType) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Aggregations

Intent (android.content.Intent)2 Uri (android.net.Uri)2 AuthResultListener (com.okta.oidc.AuthenticationResultHandler.AuthResultListener)2 ResultType (com.okta.oidc.AuthenticationResultHandler.ResultType)2 StateResult (com.okta.oidc.AuthenticationResultHandler.StateResult)2 REQUEST_CODE_SIGN_IN (com.okta.oidc.OktaResultFragment.REQUEST_CODE_SIGN_IN)2 REQUEST_CODE_SIGN_OUT (com.okta.oidc.OktaResultFragment.REQUEST_CODE_SIGN_OUT)2 AuthorizeResponse (com.okta.oidc.net.response.web.AuthorizeResponse)2 AuthorizationException (com.okta.oidc.util.AuthorizationException)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 Activity (android.app.Activity)1 RESULT_CANCELED (android.app.Activity.RESULT_CANCELED)1 RESULT_OK (android.app.Activity.RESULT_OK)1 Context (android.content.Context)1 ActivityInfo (android.content.pm.ActivityInfo)1 PackageManager (android.content.pm.PackageManager)1 ResolveInfo (android.content.pm.ResolveInfo)1 TextUtils (android.text.TextUtils)1 Log (android.util.Log)1 AnyThread (androidx.annotation.AnyThread)1