Search in sources :

Example 1 with NativeAuthorizeRequest

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

the class SyncAuthClientTest method nativeSignInRequestSuccess.

@Test
public void nativeSignInRequestSuccess() throws AuthorizationException {
    mEndPoint.enqueueNativeRequestSuccess(CUSTOM_STATE);
    NativeAuthorizeRequest request = mSyncNativeAuth.nativeAuthorizeRequest(SESSION_TOKEN, mProviderConfig, null);
    AuthorizeResponse response = request.executeRequest(mHttpClient);
    assertNotNull(response);
    assertEquals(response.getCode(), EXCHANGE_CODE);
    assertEquals(response.getState(), CUSTOM_STATE);
}
Also used : AuthorizeResponse(com.okta.oidc.net.response.web.AuthorizeResponse) NativeAuthorizeRequest(com.okta.oidc.net.request.NativeAuthorizeRequest) Test(org.junit.Test)

Example 2 with NativeAuthorizeRequest

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

the class SyncAuthClientImpl method signIn.

@WorkerThread
@Override
public Result signIn(String sessionToken, @Nullable AuthenticationPayload payload) {
    try {
        mCancel.set(false);
        ProviderConfiguration providerConfiguration = obtainNewConfiguration();
        checkIfCanceled();
        mOktaState.setCurrentState(State.SIGN_IN_REQUEST);
        NativeAuthorizeRequest request = nativeAuthorizeRequest(sessionToken, providerConfiguration, payload);
        mCurrentRequest.set(new WeakReference<>(request));
        // Save the nativeAuth request in a AuthRequest because it is needed to verify results.
        AuthorizeRequest authRequest = new AuthorizeRequest(request.getParameters());
        mOktaState.save(authRequest);
        AuthorizeResponse authResponse = request.executeRequest(mHttpClient);
        checkIfCanceled();
        // This flow should never happen but if it does throw a exception.
        if (isVerificationFlow(authResponse)) {
            return Result.error(new AuthorizationException("Email verification required. Session: " + authResponse.getSessionHint(), null));
        }
        validateResult(authResponse, authRequest);
        mOktaState.setCurrentState(State.TOKEN_EXCHANGE);
        TokenRequest requestToken = tokenExchange(authResponse, providerConfiguration, authRequest);
        mCurrentRequest.set(new WeakReference<>(requestToken));
        TokenResponse tokenResponse = requestToken.executeRequest(mHttpClient);
        mOktaState.save(tokenResponse);
        return Result.success();
    } catch (AuthorizationException e) {
        return Result.error(e);
    } catch (IOException e) {
        return Result.cancel();
    } catch (Exception e) {
        return Result.error(new AuthorizationException(OTHER.code, e.getMessage(), e));
    } finally {
        resetCurrentState();
    }
}
Also used : AuthorizeResponse(com.okta.oidc.net.response.web.AuthorizeResponse) TokenResponse(com.okta.oidc.net.response.TokenResponse) AuthorizeRequest(com.okta.oidc.net.request.web.AuthorizeRequest) NativeAuthorizeRequest(com.okta.oidc.net.request.NativeAuthorizeRequest) AuthorizationException(com.okta.oidc.util.AuthorizationException) TokenRequest(com.okta.oidc.net.request.TokenRequest) IOException(java.io.IOException) NativeAuthorizeRequest(com.okta.oidc.net.request.NativeAuthorizeRequest) IOException(java.io.IOException) AuthorizationException(com.okta.oidc.util.AuthorizationException) ProviderConfiguration(com.okta.oidc.net.request.ProviderConfiguration) WorkerThread(androidx.annotation.WorkerThread)

Example 3 with NativeAuthorizeRequest

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

the class SyncAuthClientTest method nativeSignInRequestFailure.

@Test
public void nativeSignInRequestFailure() throws AuthorizationException {
    mExpectedEx.expect(AuthorizationException.class);
    mEndPoint.enqueueReturnUnauthorizedRevoked();
    NativeAuthorizeRequest request = mSyncNativeAuth.nativeAuthorizeRequest(SESSION_TOKEN, mProviderConfig, null);
    AuthorizeResponse response = request.executeRequest(mHttpClient);
    assertNull(response);
}
Also used : AuthorizeResponse(com.okta.oidc.net.response.web.AuthorizeResponse) NativeAuthorizeRequest(com.okta.oidc.net.request.NativeAuthorizeRequest) Test(org.junit.Test)

Aggregations

NativeAuthorizeRequest (com.okta.oidc.net.request.NativeAuthorizeRequest)3 AuthorizeResponse (com.okta.oidc.net.response.web.AuthorizeResponse)3 Test (org.junit.Test)2 WorkerThread (androidx.annotation.WorkerThread)1 ProviderConfiguration (com.okta.oidc.net.request.ProviderConfiguration)1 TokenRequest (com.okta.oidc.net.request.TokenRequest)1 AuthorizeRequest (com.okta.oidc.net.request.web.AuthorizeRequest)1 TokenResponse (com.okta.oidc.net.response.TokenResponse)1 AuthorizationException (com.okta.oidc.util.AuthorizationException)1 IOException (java.io.IOException)1