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());
}
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());
}
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);
}
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);
}
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);
}
Aggregations