Expand my Community achievements bar.

SOLVED

Generating JWT for Target API

Avatar

Level 3

Hi,

I've followed the steps to generate JWT token from Adobe I/O and then exchange it with Access Token.

It's working as expected but the expiration of the token is set for 24 hours.

After 24 hours I need to generate a new JWT token and Access token.

Since I need to generate it every day is there a way to do it programmatically or ser a process to refresh it?

Thanks,

Sagi

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi Sagil - here is Python code to generate JWT token:

# expiry time as 24 hours

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

ims_host = 'ims-na1.adobelogin.com'

ims_endpoint_jwt = '/ims/exchange/jwt/'

# create payload

payload = {

    'exp' : expiry_time,

    'iss' : <YOUR-ADOBE-ORG-ID>,

    'sub' : <YOUR-TEST-ACCOUNT-ID>,

    'https://ims-na1.adobelogin.com/s/ent_marketing_sdk': True,   

    'aud' : "https://" + ims_host + "/c/" + <API-KEY-OF-ADOBE-IO-INTEGRATION>

}

# Read the private key we will use to sign the JWT.

priv_key_file = open(<PRIVATE-KEY-PATH>)

priv_key = priv_key_file.read()

priv_key_file.close()

# create JSON Web Token, signing it with the private key.

jwt_token = jwt.encode(payload, priv_key, algorithm='RS256')

# decode bytes into string

jwt_token = jwt_token.decode("utf-8")

Hope this helps,

Rajneesh

View solution in original post

6 Replies

Avatar

Employee Advisor

sagil23995776​,

Unfortunately for security purposes it needs to be re-generated every 24hrs.

Mihnea Docea | Technical Support Consultant | Customer Experience | Adobe | (:: 1 (800) 497-0335

Avatar

Correct answer by
Community Advisor

Hi Sagil - here is Python code to generate JWT token:

# expiry time as 24 hours

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

ims_host = 'ims-na1.adobelogin.com'

ims_endpoint_jwt = '/ims/exchange/jwt/'

# create payload

payload = {

    'exp' : expiry_time,

    'iss' : <YOUR-ADOBE-ORG-ID>,

    'sub' : <YOUR-TEST-ACCOUNT-ID>,

    'https://ims-na1.adobelogin.com/s/ent_marketing_sdk': True,   

    'aud' : "https://" + ims_host + "/c/" + <API-KEY-OF-ADOBE-IO-INTEGRATION>

}

# Read the private key we will use to sign the JWT.

priv_key_file = open(<PRIVATE-KEY-PATH>)

priv_key = priv_key_file.read()

priv_key_file.close()

# create JSON Web Token, signing it with the private key.

jwt_token = jwt.encode(payload, priv_key, algorithm='RS256')

# decode bytes into string

jwt_token = jwt_token.decode("utf-8")

Hope this helps,

Rajneesh

Avatar

Level 9
@Deleted Account, can you please help. The above code will generate a access token?

Avatar

Level 3
Is there an example of the above Python code for C#? thank you

Avatar

Level 1

I'm trying to do this exact same thing but in C# .NET. You wouldn't happen to have an example for that as well?

Avatar

Level 2

Hi All,

I'm facing the same issue currently, I'm trying to generate token programmatically and followed the steps per the doc here: https://experienceleague.adobe.com/docs/experience-platform/tags/api/getting-started.html?lang=en#:~...
but I'm getting a 503: Service Unavailable response!
Is it not available anymore or what?