Used the Local Development Access Token
- Download the temporary Local Development Access Token from AEM Developer Console
- The Local Development Access Token expires every 24 hours, so developers need to do download new access tokens daily
- An External Application is being developed that programmatically interacts with AEM as a Cloud Service
- The External Application reads in the Local Development Access Token
- The External Application constructs HTTP requests to AEM as a Cloud Service, adding the Local Development Access Token as a Bearer token to the HTTP requests’ Authorization header
- AEM as a Cloud Service receives the HTTP request, authenticates the request, and performs the work requested by the HTTP request, and returns an HTTP response back to the External Application
The Sample External Application
We’ll create a simple external JavaScript application to illustrate how to programmatically access AEM as a Cloud Service over HTTPS using the local developer access token. This illustrates how any application or system running outside of AEM, regardless of framework or language, can use the access token to programmatically authenticate to, and access, AEM as a Cloud Service. In the next section, we’ll update this application code to support the approach for generating a token for production use.
This sample application is run from the command line, and updates AEM asset metadata using AEM Assets HTTP APIs, using the following flow:
- Reads in parameters from the command line (
getCommandLineParams()
) - Obtains the access token used to authenticate to AEM as a Cloud Service (
getAccessToken(...)
) - Lists all assets in a AEM asset folder specified in a command-line parameters (
listAssetsByFolder(...)
) - Update listed assets’ metadata with values specified in command-line parameters (
updateMetadata(...)
)
The key element in programmatically authenticating to AEM using the access token is adding an Authorization HTTP request header to all HTTP requests made to AEM, in the following format:
Authorization: Bearer ACCESS_TOKEN