--- /dev/null
+package com.jacobcasper.fflogs;
+
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.http.HttpClient;
+import java.net.http.HttpRequest;
+import java.net.http.HttpResponse;
+import java.util.Base64;
+
+public class ApiAuthClient {
+ private static final String TOKEN_URL = "https://www.fflogs.com/oauth/token";
+
+ private final String clientId;
+ private final String clientSecret;
+ private final HttpClient client;
+
+ public ApiAuthClient(final String clientId, final String clientSecret) {
+ this.clientId = clientId;
+ this.clientSecret = clientSecret;
+ this.client = HttpClient.newHttpClient();
+ }
+
+ public String getToken() throws URISyntaxException, IOException, InterruptedException {
+ final var req = HttpRequest.newBuilder()
+ .POST(HttpRequest.BodyPublishers.ofString("grant_type=client_credentials"))
+ .header("Content-Type", "application/x-www-form-urlencoded")
+ .header("Authorization", getBasicAuthenticationHeader(clientId, clientSecret))
+ .uri(new URI(TOKEN_URL))
+ .build();
+
+ return client.send(req, HttpResponse.BodyHandlers.ofString()).body();
+ }
+
+ private static String getBasicAuthenticationHeader(String username, String password) {
+ String valueToEncode = username + ":" + password;
+ return "Basic " + Base64.getEncoder().encodeToString(valueToEncode.getBytes());
+ }
+}
--- /dev/null
+package com.jacobcasper.fflogs;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.PropertyNamingStrategies;
+
+import java.io.IOException;
+import java.net.URISyntaxException;
+
+public class Main {
+ public static void main(String... args) throws IOException, URISyntaxException, InterruptedException {
+ final var om = new ObjectMapper();
+ om.setPropertyNamingStrategy(PropertyNamingStrategies.SNAKE_CASE);
+ final var creds = om.readValue(Main.class.getClassLoader().getResource("client_secret.json"), ClientCredentials.class);
+ final var token = om.readValue(new ApiAuthClient(creds.clientId(), creds.clientSecret()).getToken(), BearerToken.class);
+ System.out.println(token);
+ }
+}
<artifactId>graphql-java-common-runtime</artifactId>
<version>${graphqlMavenPluginVersion}</version>
</dependency>
+ <dependency>
+ <groupId>com.fasterxml.jackson.core</groupId>
+ <artifactId>jackson-databind</artifactId>
+ <version>2.17.1</version>
+ </dependency>
</dependencies>
<build>