AEM Cloud Servlet exchange token
Hi Team,
I got an error while trying to connect to the exchange token URL internally via servlet.
So basically I am first generating the JWT token using the privatekey.pem file and then hitting the exchange URL internally via servlet to generate the access token so that I can access the AEM author environment to access the resource.
String body = "client_id=" + URLEncoder.encode(clientId, "UTF-8") + "&" + "client_secret="
+ URLEncoder.encode(clientSecret, "UTF-8") + "&" + "jwt_token=" + URLEncoder.encode(jwtToken, "UTF-8");
try (DataOutputStream outputStream = new DataOutputStream(connection.getOutputStream())) {
outputStream.writeBytes(body);
}
try (BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()))) {
String inputLine;
StringBuffer stringBuffer = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
stringBuffer.append(inputLine);
}
response.getWriter().print(stringBuffer);
}
I followed the below URL but not sure what is casuing the issue. do I have to allow my cloud instance to access EXCHANGE TOKEN url?
It's working well in localhost and breaking in DEV in second try statement.
