com.afrozaar.wordpress.wpapi.v2.util.AuthUtil Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of wp-api-v2-client-java Show documentation
Show all versions of wp-api-v2-client-java Show documentation
A Java client implementation to the WordPress WP-API v2 plugin.
package com.afrozaar.wordpress.wpapi.v2.util;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import java.util.Base64;
public class AuthUtil {
public static HttpHeaders createHeaders(String username, String password) {
HttpHeaders httpHeaders = new HttpHeaders();
final Tuple2 authHeader = authTuple(username, password);
httpHeaders.set(authHeader.a, authHeader.b);
httpHeaders.setContentType(MediaType.APPLICATION_JSON);
return httpHeaders;
}
public static Tuple2 authTuple(String username, String password) {
final byte[] encodedAuth = Base64.getEncoder().encode((username + ":" + password).getBytes());
return Tuple2.of("Authorization", "Basic " + new String(encodedAuth));
}
public static HttpEntity basicAuth(String username, String password) {
return new HttpEntity<>(createHeaders(username, password));
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy