use of com.okta.idx.sdk.api.response.InteractResponse in project okta-idx-java by okta.
the class BaseIDXClient method interact.
@Override
public IDXClientContext interact(String token, EmailTokenType tokenType) throws ProcessingException {
InteractResponse interactResponse;
String codeVerifier, codeChallenge, state;
try {
codeVerifier = PkceUtil.generateCodeVerifier();
codeChallenge = PkceUtil.generateCodeChallenge(codeVerifier);
state = UUID.randomUUID().toString();
StringBuilder urlParameters = new StringBuilder().append("client_id=").append(clientConfiguration.getClientId()).append("&client_secret=").append(clientConfiguration.getClientSecret()).append("&scope=").append(clientConfiguration.getScopes().stream().map(Object::toString).collect(Collectors.joining(" "))).append("&code_challenge=").append(codeChallenge).append("&code_challenge_method=").append(PkceUtil.CODE_CHALLENGE_METHOD).append("&redirect_uri=").append(clientConfiguration.getRedirectUri()).append("&state=").append(state);
if (Strings.hasText(token) && !Strings.isEmpty(tokenType)) {
if (tokenType == EmailTokenType.ACTIVATION_TOKEN) {
urlParameters.append("&activation_token=").append(token);
} else if (tokenType == EmailTokenType.RECOVERY_TOKEN) {
urlParameters.append("&recovery_token=").append(token);
}
}
HttpHeaders httpHeaders = getHttpHeaders(true);
if (clientConfiguration.getDeviceContext() != null) {
httpHeaders.setAll(clientConfiguration.getDeviceContext().getAll());
}
Request request = new DefaultRequest(HttpMethod.POST, normalizedIssuerUri(clientConfiguration.getIssuer(), "/v1/interact"), null, httpHeaders, new ByteArrayInputStream(urlParameters.toString().getBytes(StandardCharsets.UTF_8)), -1L);
Response response = requestExecutor.executeRequest(request);
if (response.getHttpStatus() != 200) {
handleErrorResponse(request, response);
}
JsonNode responseJsonNode = objectMapper.readTree(response.getBody());
interactResponse = objectMapper.convertValue(responseJsonNode, InteractResponse.class);
Assert.notNull(interactResponse, "interact response cannot be null");
Assert.notNull(interactResponse.getInteractionHandle(), "interactionHandle cannot be null");
} catch (IOException | IllegalArgumentException | HttpException | NoSuchAlgorithmException e) {
throw new ProcessingException(e);
}
return new IDXClientContext(codeVerifier, codeChallenge, interactResponse.getInteractionHandle(), state);
}
Aggregations