Expand my Community achievements bar.

July 31st AEM Gems Webinar: Elevate your AEM development to master the integration of private GitHub repositories within AEM Cloud Manager.

AEM Cloud Servlet exchange token

Avatar

Community Advisor

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...

Topics

Topics help categorize Community content and increase your ability to discover relevant content.

4 Replies

Avatar

Community Advisor

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)

Avatar

Community Advisor

@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.

Avatar

Community Advisor

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

Avatar

Community Advisor

It's very weird actually, it works sometimes but sometime it gives an error.