Expand my Community achievements bar.

Generate JWT Token for AEM Cloud Manager API | AEM Community Blog Seeding

Avatar

Administrator

BlogImage.jpg

Generate JWT Token for AEM Cloud Manager API by Himanshu Singhal

Abstract

Most of you who're in project migration phase or already migrated to AEM as cloud service might had this challenge where you'd want to deploy to CM directly from your end instead of going to cloud web and triggering it from there.
For development environments, it's alright to set it to deploy on 'GIT CHNAGE' but that's mostly not the case with Stage, Prod environments.
Obviously, the available web look provided by Adobe is amazing to perform actions but sometimes based on your organisation requirement, you'd want to automate tasks and if you'd want to go with API, you definitely need to have a valid access token.
Generation of access token is available via Adobe developer console (https://developer.adobe.com/) by going to project and generating token however, it valid only for 24 hours. And, it's tedious to update token manually every time when it expires so here's the python script that would help you to generate JWT that further is used to generate access token.
import request
import json
import time
import jwt


current_sec_time = int(round(time.time()))
expiry_time = current_sec_time + (60*60*24)


adobeOrdId = ""
techAcctId = ""
api_key = ""
client_secret = ""
ims_server = "ims-na1.adobelogin.com"
keyfile = r''


# create payload
payload = {
"exp" : expiry_time,
"iss" : adobeOrdId,
"sub" : techAcctId,
"aud" : "https://" + ims_server + "/c/" + api_key,
"https://" + ims_server + "/s/ent_cloudmgr_sdk": True
}


# read private key from file
priv_key_file = open(keyfile)
priv_key = priv_key_file.read()
priv_key_file.close()


# create JSON Web Token
jwt_token = jwt.encode(payload, priv_key, algorithm="RS256")


print(jwt_token)

Read Full Blog

Generate JWT Token for AEM Cloud Manager API

Q&A

Please use this thread to ask the related questions.



Kautuk Sahni
0 Replies