AEM Cloud Servlet exchange token | Community
Skip to main content
Prince_Shivhare
Community Advisor
Community Advisor
February 19, 2024
Question

AEM Cloud Servlet exchange token

  • February 19, 2024
  • 1 reply
  • 1069 views

Hi Team,

 

I got an error while trying to connect to the exchange token URL internally via servlet.

"Server returned HTTP response code: 400 for URL: https://ims-na1.adobelogin.com/ims/exchange/jwt"
 

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.


https://techrevel.blog/2023/09/06/access-restricted-resources-on-aemaacs-with-java-and-service-accou...

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

1 reply

SureshDhulipudi
Community Advisor
Community Advisor
February 19, 2024

Working in Localhost and Not working DEV instance - did you check the Network tab about the error details?

Might be a Firewall or Dispatcher configuration required to pass/allow the outside domain request.

Firewall or Network Restrictions: If it's working on your local machine but not on your DEV environment, it could be due to network restrictions. Check if your DEV environment has access to the Adobe IMS URL (https://ims-na1.adobelogin.com). You might need to work with your network team to allow access.

 

400 error - Generally with invalid syntax - ensure the String formatted correctly (one way to try with Hardcoded string first and then change it)

Prince_Shivhare
Community Advisor
Community Advisor
February 19, 2024

@sureshdhulipudi 

 

I think there should not be any syntax-related error because it's working in localhost. also, I am not passing any parameter from Postman which can create an issue.

Regarding the Dispatcher, I am getting the same issue in the author's environment as well.

so it's looking like AEM Cloud is blocking the domain 'https://ims-na1.adobelogin.com.

SureshDhulipudi
Community Advisor
Community Advisor
February 20, 2024

you might need to work with Adobe Support to allow access for this domain.