Exchange JWT for Access Token
Last update: March 23, 2025
- Applies to:
- Experience Manager as a Cloud Service
- Topics:
- Output Service
CREATED FOR:
- Beginner
- Intermediate
- Developer
The JWT created in the previous step is exchanged with Adobe IMS APIs for an Access Token, which can then be used to access AEM as a Cloud Service. To request an Access Token send a POST request containing the JWT, client_id, client_secret to the IMS authentication service.
The following code was used to generate exchange JWT for Access Token
public String getAccessToken() {
String jwtToken = getJWTToken();
GetServiceCredentials getCredentials = new GetServiceCredentials();
System.out.println("Getting Access Token");
try {
HttpClient httpClient = HttpClientBuilder.create().build();
HttpHost authServer = new HttpHost(getCredentials.getIMS_ENDPOINT(), 443, "https");
HttpPost authPostRequest = new HttpPost("/ims/exchange/jwt");
List < NameValuePair > nameValuePairs = new ArrayList < NameValuePair > ();
nameValuePairs.add(new BasicNameValuePair("jwt_token", jwtToken));
nameValuePairs.add(new BasicNameValuePair("client_id", getCredentials.getCLIENT_ID()));
nameValuePairs.add(new BasicNameValuePair("client_secret", getCredentials.getCLIENT_SECRET()));
authPostRequest.setEntity(new UrlEncodedFormEntity(nameValuePairs, Consts.UTF_8));
HttpResponse response;
response = httpClient.execute(authServer, authPostRequest);
StatusLine statusLine = response.getStatusLine();
System.out.println("The status code is " + statusLine.getStatusCode());
HttpEntity result = response.getEntity();
String jsonResponseStr = EntityUtils.toString(result);
System.out.println(jsonResponseStr);
JsonReader jsonReader = new JsonReader(new StringReader(jsonResponseStr));
JsonObject jsonObject = JsonParser.parseReader(jsonReader).getAsJsonObject();
System.out.println("Returning access_token " + jsonObject.get("access_token").getAsString());
return jsonObject.get("access_token").getAsString();
} catch (Exception e) {
System.out.print("Error: " + e.getMessage());
}
return "null";
}
Previous pageCreate JWT Token
Next pageMerge Data with Template
Experience Manager
- Overview
- Playlists
- Introduction to AEM as a Cloud Service
- Experience Cloud integrations
- Underlying Technology
- Edge Delivery Services
- Cloud Manager
- Local Development Environment Setup
- Developing
- Debugging AEM
- AEM APIs
- Content Delivery
- Caching
- Accessing AEM
- Authentication
- Advanced Networking
- Security
- AEM Eventing
- Migration
- Content Transfer Tool
- Bulk Import of assets
- Moving to AEM as a Cloud Service
- Cloud Acceleration Manager
- Content Fragments
- Forms
- Developing for Forms as a Cloud Service
- 1 - Getting started
- 2 - Install IntelliJ
- 3 - Setup Git
- 4 - Sync IntelliJ with AEM
- 5 - Build a form
- 6 - Custom Submit Handler
- 7 - Registering servlet using resource type
- 8 - Enable Forms Portal Components
- 9 - Include Cloud Services and FDM
- 10 - Context aware cloud configuration
- 11 - Push to Cloud Manager
- 12 - Deploy to development environment
- 13 - Updating maven archetype
- Create Adaptive Form
- Custom submit service with headless form
- Create address block component
- Create clickable image component
- AEM Forms and Analytics
- Creating Countries Dropdown Component
- Creating Button Variations
- Using vertical tabs
- Using output and forms service
- Document Generation in AEM Forms CS
- Using Forms Document Services API
- Document Generation using Batch API
- PDF Manipulation in Forms CS
- Integrate with Marketo
- Store Form Submissions with Blob Index Tags
- Prefill core component based form
- Azure Portal Storage
- Save and Resume form filling
- Create Review Workflow
- Acrobat Sign with AEM Forms
- Integrate with Microsoft Power Automate
- Integrate with Microsoft Dynamics
- Integrate with Salesforce
- Store form submissions in one drive and sharepoint
- Developing for Forms as a Cloud Service
- Asset Compute Extensibility
- Multi-step Tutorials
- Expert Resources