Retrieving Access Token using JAVA code (AEMaaCS)

Kinjal P Darji
2 min readApr 26, 2023

In this blog I will explain to create a JWT token and use the same to retrieve access token from AEMaaCS environment. There is a very good documentation available on the same here and here. However, there are bits and pieces those need to be put together to get this working correctly using JAVA code.

The sample code to retrieve the JWT token and access token can be found at github.

Steps to use the same code are mentioned below.

Step 1 — Retrieve token from developer console. For this, you’ll need to access developer console that will look something like this

Here, it is required that a technical account is created and a certificate is added.

Step 2 — Download the public key and private key by clicking on meatballs menu of valid/active certificate and clicking on view. Note there are other details in the json retrieved and those will be useful in the next steps.

Step 3 — Format the private key. Copy and paste the private key in a tool like notepad++ and replace \r\n with enter key.

Step4 — Convert this key in DER format. For that use below command. Please note that this command is incorrect in github documentation.

openssl pkcs8 -topk8 -inform PEM -outform DER -in secret.pem -out secret.der -nocrypt

Step 5 — Download adobe-jwt-java code from github.

Step 6 — Use the secret.der instead of secret.key in the adobe-jwt-java project.

Step 7 — Change config.properties with values in the json that was retrieved while downloading the public and private keys.

Step 8 — Change pom.xml for appropriate dependencies.

Step 9 — Run the java class — IMSClient.

--

--

Kinjal P Darji

Hi, I am an AEM architect and a certified AWS Developer — Associate.