use of com.okta.idx.sdk.api.request.ChallengeRequest in project okta-idx-java by okta.
the class IDXAuthenticationWrapper method selectPasswordAuthenticatorIfNeeded.
// If app sign-on policy is set to "any 1 factor", the next remediation after identify is
// select-authenticator-authenticate
// Check if that's the case, and proceed to select password authenticator
private AuthenticationTransaction selectPasswordAuthenticatorIfNeeded(AuthenticationTransaction authenticationTransaction) throws ProcessingException {
// If remediation contains challenge-authenticator for passcode, we don't need to check SELECT_AUTHENTICATOR_AUTHENTICATE
Optional<RemediationOption> challengeRemediationOptionOptional = authenticationTransaction.getOptionalRemediationOption(RemediationType.CHALLENGE_AUTHENTICATOR);
if (challengeRemediationOptionOptional.isPresent()) {
// proceed with password challenge
return authenticationTransaction;
}
Optional<RemediationOption> remediationOptionOptional = authenticationTransaction.getOptionalRemediationOption(RemediationType.SELECT_AUTHENTICATOR_AUTHENTICATE);
if (!remediationOptionOptional.isPresent()) {
// We don't need to.
return authenticationTransaction;
}
Map<String, String> authenticatorOptions = remediationOptionOptional.get().getAuthenticatorOptions();
Authenticator authenticator = new Authenticator();
authenticator.setId(authenticatorOptions.get("password"));
ChallengeRequest selectAuthenticatorRequest = ChallengeRequestBuilder.builder().withStateHandle(authenticationTransaction.getStateHandle()).withAuthenticator(authenticator).build();
return authenticationTransaction.proceed(() -> remediationOptionOptional.get().proceed(client, selectAuthenticatorRequest));
}
use of com.okta.idx.sdk.api.request.ChallengeRequest in project okta-idx-java by okta.
the class BaseIDXClient method challenge.
@Override
public IDXResponse challenge(ChallengeRequest challengeRequest, String href) throws ProcessingException {
IDXResponse idxResponse;
try {
Request request = new DefaultRequest(HttpMethod.POST, href, null, getHttpHeaders(false), new ByteArrayInputStream(objectMapper.writeValueAsBytes(challengeRequest)), -1L);
Response response = requestExecutor.executeRequest(request);
if (response.getHttpStatus() != 200) {
handleErrorResponse(request, response);
}
JsonNode responseJsonNode = objectMapper.readTree(response.getBody());
idxResponse = objectMapper.convertValue(responseJsonNode, IDXResponse.class);
} catch (IOException | HttpException e) {
throw new ProcessingException(e);
}
return idxResponse;
}
Aggregations