java
public static Token authorizeToken(String client_id, String client_secret, byte[] certificateBytes) {
Token token = null;
String basicAuth;
try {
System.out.println(certificateBytes.length);
basicAuth = Base64.getEncoder().encodeToString((client_id + ':' + client_secret).getBytes());
File tempFile = File.createTempFile("certificate", ".p12");
tempFile.deleteOnExit();
try (FileOutputStream fos = new FileOutputStream(tempFile)) {
fos.write(certificateBytes);
}
System.setProperty("javax.net.ssl.keyStoreType", "PKCS12");
System.setProperty("javax.net.ssl.keyStore", tempFile.getAbsolutePath());
SSLSocketFactory sslSocketFactory = (SSLSocketFactory) SSLSocketFactory.getDefault();
URL url = new URL("https://api-pix-h.gerencianet.com.br/oauth/token");
HttpsURLConnection conn = (HttpsURLConnection) url.openConnection();
conn.setDoOutput(true);
conn.setRequestMethod("POST");
conn.setRequestProperty("Content-Type", "application/json");
conn.setRequestProperty("Authorization", "Basic " + basicAuth);
conn.setSSLSocketFactory(sslSocketFactory);
String input = "{\"grant_type\": \"client_credentials\"}";
OutputStream os = conn.getOutputStream();
os.write(input.getBytes());
os.flush();
public static Token authorizeToken(String client_id, String client_secret, byte[] certificateBytes) {
Token token = null;
String basicAuth;
try {
System.out.println(certificateBytes.length);
basicAuth = Base64.getEncoder().encodeToString((client_id + ':' + client_secret).getBytes());
File tempFile = File.createTempFile("certificate", ".p12");
tempFile.deleteOnExit();
try (FileOutputStream fos = new FileOutputStream(tempFile)) {
fos.write(certificateBytes);
}
System.setProperty("javax.net.ssl.keyStoreType", "PKCS12");
System.setProperty("javax.net.ssl.keyStore", tempFile.getAbsolutePath());
SSLSocketFactory sslSocketFactory = (SSLSocketFactory) SSLSocketFactory.getDefault();
URL url = new URL("https://api-pix-h.gerencianet.com.br/oauth/token");
HttpsURLConnection conn = (HttpsURLConnection) url.openConnection();
conn.setDoOutput(true);
conn.setRequestMethod("POST");
conn.setRequestProperty("Content-Type", "application/json");
conn.setRequestProperty("Authorization", "Basic " + basicAuth);
conn.setSSLSocketFactory(sslSocketFactory);
String input = "{\"grant_type\": \"client_credentials\"}";
OutputStream os = conn.getOutputStream();
os.write(input.getBytes());
os.flush();