Search in sources :

Example 1 with WebRequest

use of com.okta.oidc.net.request.web.WebRequest in project okta-oidc-android by okta.

the class OktaStateTest method getAuthorizeRequest.

@Test
public void getAuthorizeRequest() throws OktaRepository.EncryptionException, AuthorizationException {
    WebRequest authorizedRequest = TestValues.getAuthorizeRequest(TestValues.getConfigWithUrl(CUSTOM_URL), null);
    mOktaState.save(authorizedRequest);
    AuthorizeRequest expected = (AuthorizeRequest) mOktaState.getAuthorizeRequest();
    assertNotNull(expected);
    assertEquals(authorizedRequest.persist(), expected.persist());
}
Also used : WebRequest(com.okta.oidc.net.request.web.WebRequest) AuthorizeRequest(com.okta.oidc.net.request.web.AuthorizeRequest) Test(org.junit.Test)

Example 2 with WebRequest

use of com.okta.oidc.net.request.web.WebRequest in project okta-oidc-android by okta.

the class SyncWebAuthClientImpl method processSignInResult.

@NonNull
private Result processSignInResult(StateResult result) {
    if (result == null) {
        return Result.error(new AuthorizationException("Result is empty", new NullPointerException()));
    }
    switch(result.getStatus()) {
        case CANCELED:
            return Result.cancel();
        case ERROR:
            return Result.error(result.getException());
        case AUTHORIZED:
            mOktaState.setCurrentState(State.TOKEN_EXCHANGE);
            TokenResponse response;
            try {
                WebRequest authorizedRequest = mOktaState.getAuthorizeRequest();
                ProviderConfiguration providerConfiguration = mOktaState.getProviderConfiguration();
                AuthorizeResponse authResponse = (AuthorizeResponse) result.getAuthorizationResponse();
                if (isVerificationFlow((authResponse))) {
                    return processEmailVerification(authResponse);
                }
                validateResult(result.getAuthorizationResponse(), authorizedRequest);
                TokenRequest request = tokenExchange((AuthorizeResponse) result.getAuthorizationResponse(), providerConfiguration, (AuthorizeRequest) authorizedRequest);
                mCurrentRequest.set(new WeakReference<>(request));
                response = request.executeRequest(mHttpClient);
                mOktaState.save(response);
            } catch (OktaRepository.EncryptionException e) {
                return Result.error(EncryptionErrors.byEncryptionException(e));
            } catch (AuthorizationException e) {
                return Result.error(e);
            }
            return Result.success();
        default:
            return Result.error(new AuthorizationException("StateResult with invalid status: " + result.getStatus().name(), new IllegalStateException()));
    }
}
Also used : AuthorizeResponse(com.okta.oidc.net.response.web.AuthorizeResponse) TokenResponse(com.okta.oidc.net.response.TokenResponse) WebRequest(com.okta.oidc.net.request.web.WebRequest) AuthorizationException(com.okta.oidc.util.AuthorizationException) OktaRepository(com.okta.oidc.storage.OktaRepository) TokenRequest(com.okta.oidc.net.request.TokenRequest) ProviderConfiguration(com.okta.oidc.net.request.ProviderConfiguration) NonNull(androidx.annotation.NonNull)

Example 3 with WebRequest

use of com.okta.oidc.net.request.web.WebRequest in project okta-oidc-android by okta.

the class SyncSessionClientImpl method migrateTo.

@Override
public void migrateTo(EncryptionManager manager) throws AuthorizationException {
    try {
        final ProviderConfiguration providerConfiguration = mOktaState.getProviderConfiguration();
        final TokenResponse tokenResponse = mOktaState.getTokenResponse();
        final WebRequest authorizedRequest = mOktaState.getAuthorizeRequest();
        clear();
        mOktaState.setEncryptionManager(manager);
        mOktaState.save(providerConfiguration);
        mOktaState.save(tokenResponse);
        mOktaState.save(authorizedRequest);
    } catch (OktaRepository.EncryptionException e) {
        throw AuthorizationException.EncryptionErrors.byEncryptionException(e);
    }
}
Also used : TokenResponse(com.okta.oidc.net.response.TokenResponse) WebRequest(com.okta.oidc.net.request.web.WebRequest) OktaRepository(com.okta.oidc.storage.OktaRepository) ProviderConfiguration(com.okta.oidc.net.request.ProviderConfiguration)

Example 4 with WebRequest

use of com.okta.oidc.net.request.web.WebRequest in project okta-oidc-android by okta.

the class SyncWebAuthClientImpl method signOutOfOkta.

@Override
@AnyThread
public Result signOutOfOkta(@NonNull final Activity activity) {
    try {
        mOktaState.setCurrentState(State.SIGN_OUT_REQUEST);
        WebRequest request;
        request = new LogoutRequest.Builder().provideConfiguration(mOktaState.getProviderConfiguration()).config(mOidcConfig).tokenResponse(mOktaState.getTokenResponse()).state(CodeVerifierUtil.generateRandomState()).create();
        mOktaState.save(request);
        StateResult logoutResult = startSignOut(activity, request);
        return processSignOutResult(logoutResult);
    } catch (InterruptedException e) {
        return Result.cancel();
    } catch (OktaRepository.EncryptionException e) {
        return Result.error(EncryptionErrors.byEncryptionException(e));
    } catch (AuthorizationException e) {
        return Result.error(e);
    } catch (NullPointerException e) {
        return Result.error(new AuthorizationException(e.getMessage(), e));
    } finally {
        resetCurrentState();
    }
}
Also used : WebRequest(com.okta.oidc.net.request.web.WebRequest) StateResult(com.okta.oidc.AuthenticationResultHandler.StateResult) AuthorizationException(com.okta.oidc.util.AuthorizationException) OktaRepository(com.okta.oidc.storage.OktaRepository) AnyThread(androidx.annotation.AnyThread)

Example 5 with WebRequest

use of com.okta.oidc.net.request.web.WebRequest in project okta-oidc-android by okta.

the class SyncWebAuthClientImpl method signIn.

@Override
@WorkerThread
public Result signIn(@NonNull final Activity activity, @Nullable AuthenticationPayload payload) {
    mCancel.set(false);
    try {
        if (!isRedirectUrisRegistered(mOidcConfig.getRedirectUri(), activity)) {
            String errorDescription = "No uri registered to handle redirect " + "or multiple applications registered";
            Log.e(TAG, errorDescription);
            throw new AuthorizationException(TYPE_OAUTH_REGISTRATION_ERROR, INVALID_REDIRECT_URI.code, INVALID_REDIRECT_URI.error, errorDescription, null, null);
        }
        ProviderConfiguration configuration = obtainNewConfiguration();
        checkIfCanceled();
        WebRequest request = new AuthorizeRequest.Builder().config(mOidcConfig).providerConfiguration(configuration).authenticationPayload(payload).create();
        mOktaState.save(request);
        mOktaState.setCurrentState(State.SIGN_IN_REQUEST);
        StateResult authResult = startSignIn(activity, request);
        return processSignInResult(authResult);
    } catch (AuthorizationException e) {
        return Result.error(e);
    } catch (IOException | InterruptedException e) {
        return Result.cancel();
    } catch (OktaRepository.EncryptionException e) {
        return Result.error(EncryptionErrors.byEncryptionException(e));
    } finally {
        resetCurrentState();
    }
}
Also used : WebRequest(com.okta.oidc.net.request.web.WebRequest) AuthorizationException(com.okta.oidc.util.AuthorizationException) StateResult(com.okta.oidc.AuthenticationResultHandler.StateResult) OktaRepository(com.okta.oidc.storage.OktaRepository) IOException(java.io.IOException) ProviderConfiguration(com.okta.oidc.net.request.ProviderConfiguration) WorkerThread(androidx.annotation.WorkerThread)

Aggregations

WebRequest (com.okta.oidc.net.request.web.WebRequest)5 OktaRepository (com.okta.oidc.storage.OktaRepository)4 ProviderConfiguration (com.okta.oidc.net.request.ProviderConfiguration)3 AuthorizationException (com.okta.oidc.util.AuthorizationException)3 StateResult (com.okta.oidc.AuthenticationResultHandler.StateResult)2 TokenResponse (com.okta.oidc.net.response.TokenResponse)2 AnyThread (androidx.annotation.AnyThread)1 NonNull (androidx.annotation.NonNull)1 WorkerThread (androidx.annotation.WorkerThread)1 TokenRequest (com.okta.oidc.net.request.TokenRequest)1 AuthorizeRequest (com.okta.oidc.net.request.web.AuthorizeRequest)1 AuthorizeResponse (com.okta.oidc.net.response.web.AuthorizeResponse)1 IOException (java.io.IOException)1 Test (org.junit.Test)1