diff --git a/pom.xml b/pom.xml index 83a6615f3..6a5b89879 100644 --- a/pom.xml +++ b/pom.xml @@ -735,7 +735,7 @@ - ${project.build.directory}/site/docs + ${project.build.directory}/site/docs ${java.home}/bin/javadoc public UTF-8 @@ -1075,13 +1075,6 @@ 0.22.1 - - - com.mashape.unirest - unirest-java - 1.4.9 - - org.jetbrains diff --git a/src/main/java/io/mapsmessaging/network/auth/Auth0TokenGenerator.java b/src/main/java/io/mapsmessaging/network/auth/Auth0TokenGenerator.java index 1a2c973c3..ecb0f79db 100644 --- a/src/main/java/io/mapsmessaging/network/auth/Auth0TokenGenerator.java +++ b/src/main/java/io/mapsmessaging/network/auth/Auth0TokenGenerator.java @@ -20,11 +20,11 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectWriter; -import com.mashape.unirest.http.HttpResponse; -import com.mashape.unirest.http.JsonNode; -import com.mashape.unirest.http.Unirest; -import com.mashape.unirest.http.exceptions.UnirestException; import java.io.IOException; +import java.net.URI; +import java.net.http.HttpClient; +import java.net.http.HttpRequest; +import java.net.http.HttpResponse; import java.util.Map; import lombok.Getter; @@ -54,38 +54,47 @@ public String generate() throws IOException { try { ObjectWriter ow = new ObjectMapper().writer().withDefaultPrettyPrinter(); String json = ow.writeValueAsString(body); - HttpResponse response = Unirest.post("https://" + domain + "/oauth/token") - .header("content-type", "application/json") - .body(json) - .asJson(); - return response.getBody().getObject().getString("access_token"); - } catch (UnirestException e) { - throw new IOException(e); + + HttpClient client = HttpClient.newHttpClient(); + HttpRequest request = HttpRequest.newBuilder() + .uri(URI.create("https://" + domain + "/oauth/token")) + .header("Content-Type", "application/json") + .POST(HttpRequest.BodyPublishers.ofString(json)) + .build(); + + HttpResponse response = client.send(request, HttpResponse.BodyHandlers.ofString()); + + if (response.statusCode() != 200) { + throw new IOException("Failed to fetch token: " + response.body()); + } + + ObjectMapper objectMapper = new ObjectMapper(); + return objectMapper.readTree(response.body()).get("access_token").asText(); + + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + throw new IOException("Request interrupted", e); } } - private Auth0TokenGenerator(Map properties) { - domain = ((String)properties.get("domain")).trim(); + private Auth0TokenGenerator(Map properties) { + domain = ((String) properties.get("domain")).trim(); body = new Auth0TokenBody(properties); } + @Getter private static final class Auth0TokenBody { - @Getter private final String clientId; - @Getter private final String clientSecret; - @Getter private final String audience; - @Getter private final String grantType; - public Auth0TokenBody(Map properties) { - clientId = ((String)properties.get("client_id")).trim(); - clientSecret = ((String)properties.get("client_secret")).trim(); - audience = "https://" + ((String)properties.get("domain")).trim() + "/api/v2/"; - grantType = ((String)properties.get("grant_type")).trim(); + public Auth0TokenBody(Map properties) { + clientId = ((String) properties.get("client_id")).trim(); + clientSecret = ((String) properties.get("client_secret")).trim(); + audience = "https://" + ((String) properties.get("domain")).trim() + "/api/v2/"; + grantType = ((String) properties.get("grant_type")).trim(); } } - }