Access token exchange

To establish a secure session, you create a JWT that encapsulates your identity information and exchange it for an access token. Every call to the Target API endpoints must be authorized with this access token in the Authorization header, along with the API key you created when you set up your API client in the Developer Portal.

The access token is valid for 24 hours after it is created in response to the exchange request. You can request multiple access tokens. Previous tokens are not invalidated when a new one is issued. You can authorize requests with any valid access token.

Access request syntax

Exchange your JWT for an API access token by making a POST request to the Adobe identity service.

Endpoint

https://ims-na1.adobelogin.com/ims/exchange/jwt

Request parameters

Pass URL-encoded parameters in the body of your POST request:

client_id

The API key assigned to your API client account.

client_secret

The client secret assigned to your API client account.

jwt_token

The base-64 encoded JSON token that encapsulates your identity information, signed with the private key for any certificate that you have associated with your API key.

Constructing an access request

To obtain an access token for the Target APIs, this part of the script constructs a request that contains the JSON Web Token (JWT), and receives the access token in the response. First, we set variables for request URL and headers.

Copy
• # method parameters • url = "https://" + ims_host + ims_endpoint_jwt • headers = { • "Content-Type" : "application/x-www-form-urlencoded", • "Cache-Control" : "no-cache" • }

The credentials are placed in the body of the POST request. Notice that the "client_id" value is your API key.

Copy
• body_credentials = { • "client_id" : api_key, • "client_secret" : client_secret, • "jwt_token" : jwt_token • } • body = urlencode(body_credentials)

Finally, we connect to the server, send the request, and receive the response.

Copy
• # send http request • res = requests.post(url, headers=headers, data=body)

If the request is successful, we extract the access token from the body of the response. For this demonstration, we print the result.

Copy
• # evaluate response • if res.status_code == 200: • • # extract token • access_token = json.loads(res.text)["access_token"] • • # print access token • print("Your access token is:") • print(access_token) • • else: • • # print response • print(res.status_code) • print(res.headers) • print(res.text)