Search in sources :

Example 1 with AuthorizeResponse

use of com.okta.oidc.net.response.web.AuthorizeResponse 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 AuthorizeResponse

use of com.okta.oidc.net.response.web.AuthorizeResponse 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 AuthorizeResponse

use of com.okta.oidc.net.response.web.AuthorizeResponse in project okta-oidc-android by okta.

the class SyncWebAuthClientTest method tokenExchangeSuccess.

@Test
public void tokenExchangeSuccess() throws InterruptedException, JSONException, AuthorizationException, OktaRepository.EncryptionException {
    String codeVerifier = CodeVerifierUtil.generateRandomCodeVerifier();
    String nonce = CodeVerifierUtil.generateRandomState();
    AuthorizeRequest request = new AuthorizeRequest.Builder().codeVerifier(codeVerifier).authorizeEndpoint(mProviderConfig.authorization_endpoint).redirectUri(mConfig.getRedirectUri().toString()).scope("openid", "email", "profile").nonce(nonce).create();
    mOktaState.save(request);
    AuthorizeResponse response = AuthorizeResponse.fromUri(Uri.parse("com.okta.test:/callback?code=CODE&state=CUSTOM_STATE"));
    String jws = TestValues.getJwt(mEndPoint.getUrl(), nonce, mConfig.getClientId());
    mEndPoint.enqueueTokenSuccess(jws);
    TokenRequest tokenRequest = mSyncWebAuth.tokenExchange(response, mOktaState.getProviderConfiguration(), (AuthorizeRequest) mOktaState.getAuthorizeRequest());
    TokenResponse tokenResponse = tokenRequest.executeRequest(mHttpClient);
    RecordedRequest recordedRequest = mEndPoint.takeRequest();
    assertThat(recordedRequest.getPath(), equalTo("/token"));
    assertNotNull(tokenResponse);
    assertEquals(tokenResponse.getIdToken(), jws);
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) AuthorizeResponse(com.okta.oidc.net.response.web.AuthorizeResponse) TokenResponse(com.okta.oidc.net.response.TokenResponse) AuthorizeRequest(com.okta.oidc.net.request.web.AuthorizeRequest) TokenRequest(com.okta.oidc.net.request.TokenRequest) RevokeTokenRequest(com.okta.oidc.net.request.RevokeTokenRequest) Test(org.junit.Test)

Example 4 with AuthorizeResponse

use of com.okta.oidc.net.response.web.AuthorizeResponse in project okta-oidc-android by okta.

the class SyncWebAuthClientTest method tokenExchangeFailure.

@Test
public void tokenExchangeFailure() throws InterruptedException, JSONException, AuthorizationException, OktaRepository.EncryptionException {
    mExpectedEx.expect(AuthorizationException.class);
    String codeVerifier = CodeVerifierUtil.generateRandomCodeVerifier();
    String nonce = CodeVerifierUtil.generateRandomState();
    AuthorizeRequest request = new AuthorizeRequest.Builder().codeVerifier(codeVerifier).authorizeEndpoint(mProviderConfig.authorization_endpoint).redirectUri(mConfig.getRedirectUri().toString()).scope(SCOPES).nonce(nonce).create();
    mOktaState.save(request);
    AuthorizeResponse response = AuthorizeResponse.fromUri(Uri.parse("com.okta.test:/callback?code=CODE&state=CUSTOM_STATE"));
    mEndPoint.enqueueReturnInvalidClient();
    TokenRequest tokenRequest = mSyncWebAuth.tokenExchange(response, mOktaState.getProviderConfiguration(), (AuthorizeRequest) mOktaState.getAuthorizeRequest());
    TokenResponse tokenResponse = tokenRequest.executeRequest(mHttpClient);
    RecordedRequest recordedRequest = mEndPoint.takeRequest();
    assertThat(recordedRequest.getPath(), equalTo("/token"));
    assertNull(tokenResponse);
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) AuthorizeResponse(com.okta.oidc.net.response.web.AuthorizeResponse) TokenResponse(com.okta.oidc.net.response.TokenResponse) AuthorizeRequest(com.okta.oidc.net.request.web.AuthorizeRequest) TokenRequest(com.okta.oidc.net.request.TokenRequest) RevokeTokenRequest(com.okta.oidc.net.request.RevokeTokenRequest) Test(org.junit.Test)

Example 5 with AuthorizeResponse

use of com.okta.oidc.net.response.web.AuthorizeResponse in project okta-oidc-android by okta.

the class SyncWebAuthClientTest method handleActivityResult.

@Test
public void handleActivityResult() throws InterruptedException {
    Intent intent = new Intent();
    intent.setData(Uri.parse("com.okta.test:/callback?code=" + CUSTOM_CODE + "&state=" + CUSTOM_STATE));
    CountDownLatch latch = new CountDownLatch(1);
    final StateResult[] stateResult = new StateResult[1];
    handler().setAuthenticationListener((result, type) -> {
        stateResult[0] = result;
        latch.countDown();
    });
    handler().onActivityResult(OktaResultFragment.REQUEST_CODE_SIGN_IN, RESULT_OK, intent);
    latch.await();
    assertNotNull(stateResult[0]);
    AuthorizeResponse response = (AuthorizeResponse) stateResult[0].getAuthorizationResponse();
    assertNotNull(response);
    assertEquals(stateResult[0].getStatus(), AuthenticationResultHandler.Status.AUTHORIZED);
    assertEquals(response.getState(), CUSTOM_STATE);
    assertEquals(response.getCode(), CUSTOM_CODE);
}
Also used : AuthorizeResponse(com.okta.oidc.net.response.web.AuthorizeResponse) StateResult(com.okta.oidc.AuthenticationResultHandler.StateResult) Intent(android.content.Intent) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Aggregations

AuthorizeResponse (com.okta.oidc.net.response.web.AuthorizeResponse)12 Test (org.junit.Test)10 StateResult (com.okta.oidc.AuthenticationResultHandler.StateResult)4 TokenRequest (com.okta.oidc.net.request.TokenRequest)4 TokenResponse (com.okta.oidc.net.response.TokenResponse)4 NativeAuthorizeRequest (com.okta.oidc.net.request.NativeAuthorizeRequest)3 AuthorizeRequest (com.okta.oidc.net.request.web.AuthorizeRequest)3 Intent (android.content.Intent)2 ProviderConfiguration (com.okta.oidc.net.request.ProviderConfiguration)2 RevokeTokenRequest (com.okta.oidc.net.request.RevokeTokenRequest)2 Result (com.okta.oidc.results.Result)2 AuthorizationException (com.okta.oidc.util.AuthorizationException)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)2 NonNull (androidx.annotation.NonNull)1 WorkerThread (androidx.annotation.WorkerThread)1 ResultType (com.okta.oidc.AuthenticationResultHandler.ResultType)1 WebRequest (com.okta.oidc.net.request.web.WebRequest)1 OktaRepository (com.okta.oidc.storage.OktaRepository)1 IOException (java.io.IOException)1