use of com.okta.idx.sdk.api.request.EnrollRequest 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.request.EnrollRequest 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);
}
}
use of com.okta.idx.sdk.api.request.EnrollRequest in project okta-idx-java by okta.
the class IDXAuthenticationWrapper method fetchSignUpFormValues.
/**
* Populate UI form values for signing up a new user.
*
* @param proceedContext the proceedContext
* @return the authentication response
*/
public AuthenticationResponse fetchSignUpFormValues(ProceedContext proceedContext) {
AuthenticationResponse newUserRegistrationResponse = new AuthenticationResponse();
try {
Assert.notNull(proceedContext.getSelectProfileEnrollHref(), "Org policy is not configured to register new users.");
// enroll new user
AuthenticationTransaction enrollTransaction = AuthenticationTransaction.proceed(client, proceedContext, () -> {
EnrollRequest enrollRequest = EnrollRequestBuilder.builder().withStateHandle(proceedContext.getStateHandle()).build();
return client.enroll(enrollRequest, proceedContext.getSelectProfileEnrollHref());
});
RemediationOption enrollProfileRemediationOption = enrollTransaction.getRemediationOption(RemediationType.ENROLL_PROFILE);
List<FormValue> enrollProfileFormValues = Arrays.stream(enrollProfileRemediationOption.form()).filter(x -> "userProfile".equals(x.getName())).collect(Collectors.toList());
newUserRegistrationResponse.setFormValues(enrollProfileFormValues);
newUserRegistrationResponse.setProceedContext(enrollTransaction.createProceedContext());
return newUserRegistrationResponse;
} catch (ProcessingException e) {
return handleProcessingException(e);
} catch (IllegalArgumentException e) {
return handleIllegalArgumentException(e);
}
}
use of com.okta.idx.sdk.api.request.EnrollRequest in project okta-idx-java by okta.
the class BaseIDXClient method enroll.
@Override
public IDXResponse enroll(EnrollRequest enrollRequest, String href) throws ProcessingException {
IDXResponse idxResponse;
try {
Request request = new DefaultRequest(HttpMethod.POST, href, null, getHttpHeaders(false), new ByteArrayInputStream(objectMapper.writeValueAsBytes(enrollRequest)), -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