use of com.okta.idx.sdk.api.model.Authenticator 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.model.Authenticator in project okta-idx-java by okta.
the class IDXAuthenticationWrapper method submitPhoneAuthenticator.
/**
* Submit phone authenticator enrollment with the provided phone number.
*
* @param proceedContext the ProceedContext
* @param phone the phone number
* @param factor factor
* @return the Authentication response
*/
public AuthenticationResponse submitPhoneAuthenticator(ProceedContext proceedContext, String phone, com.okta.idx.sdk.api.client.Authenticator.Factor factor) {
try {
Assert.notNull(proceedContext, "proceed context cannot be null");
Authenticator phoneAuthenticator = new Authenticator();
phoneAuthenticator.setId(factor.getId());
phoneAuthenticator.setMethodType(factor.getMethod());
phoneAuthenticator.setPhoneNumber(phone);
EnrollRequest enrollRequest = EnrollRequestBuilder.builder().withAuthenticator(phoneAuthenticator).withStateHandle(proceedContext.getStateHandle()).build();
return AuthenticationTransaction.proceed(client, proceedContext, () -> client.enroll(enrollRequest, proceedContext.getHref())).asAuthenticationResponse();
} catch (ProcessingException e) {
return handleProcessingException(e);
} catch (IllegalArgumentException e) {
return handleIllegalArgumentException(e);
}
}
use of com.okta.idx.sdk.api.model.Authenticator in project okta-idx-java by okta.
the class IDXAuthenticationWrapper method enrollAuthenticator.
public AuthenticationResponse enrollAuthenticator(ProceedContext proceedContext, String authenticatorId) {
try {
AuthenticationResponse authenticationResponse = AuthenticationTransaction.proceed(client, proceedContext, () -> {
Authenticator authenticator = new Authenticator();
authenticator.setId(authenticatorId);
EnrollRequest enrollRequest = EnrollRequestBuilder.builder().withAuthenticator(authenticator).withStateHandle(proceedContext.getStateHandle()).build();
return client.enroll(enrollRequest, proceedContext.getHref());
}).asAuthenticationResponse();
if (authenticationResponse.getWebAuthnParams() != null) {
AuthenticatorEnrollments authenticatorEnrollments = authenticationResponse.getAuthenticatorEnrollments();
Optional<AuthenticatorEnrollment> authenticatorEnrollmentOptional = authenticatorEnrollments.stream().filter(x -> "security_key".equals(x.getType())).findAny();
authenticatorEnrollmentOptional.ifPresent(authenticatorEnrollment -> authenticationResponse.getWebAuthnParams().setWebauthnCredentialId(authenticatorEnrollment.getCredentialId()));
}
return authenticationResponse;
} catch (ProcessingException e) {
return handleProcessingException(e);
} catch (IllegalArgumentException e) {
return handleIllegalArgumentException(e);
}
}
Aggregations