---
updatedAt: 2026-03-01T17:55:17.000Z
---

# Exchange an authorization code

```shell Shell
hostname="https://se-demos-gstemp.us-dev.janraincapture.com"

curl -L -X POST "$hostname/oauth/token" \
-H 'Authorization: Basic eTR4Zmc2ZjQ0bXNhYzN2ZXBqanZ4Z2d6dnQzZTNzazk6OTVjY3hrN2N6YnZ1eng2ZHB0ZTVrOXA2ZGo1Ynpla3U=' \
-H 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'grant_type=authorization_code' \
--data-urlencode 'code=36fczgm2uvks88' \
--data-urlencode 'redirect_uri=https://techdocs.akamai.com/callback'
```

```node Node
const hostname="https://se-demos-gstemp.us-dev.janraincapture.com"

var request = require('request');
var options = {
  'method': 'POST',
  'url': hostname.concat("/oauth/token"),
  'headers': {
    'Authorization': 'Basic eTR4Zmc2ZjQ0bXNhYzN2ZXBqanZ4Z2d6dnQzZTNzazk6OTVjY3hrN2N6YnZ1eng2ZHB0ZTVrOXA2ZGo1Ynpla3U=',
    'Content-Type': 'application/x-www-form-urlencoded'
  },
  form: {
    'grant_type': 'authorization_code',
    'code': '36fczgm2uvks88',
    'redirect_uri': 'https://techdocs.akamai.com/callback'
  }
};
request(options, function (error, response) {
  if (error) throw new Error(error);
  console.log(response.body);
});

```

```python Python
hostname="https://se-demos-gstemp.us-dev.janraincapture.com"

import requests

url = hostname + "/oauth/token"

payload='grant_type=authorization_code\
&code=36fczgm2uvks88\
&redirect_uri=https%3A%2F%2Ftechdocs.akamai.com%2Fcallback'
headers = {
  'Authorization': 'Basic eTR4Zmc2ZjQ0bXNhYzN2ZXBqanZ4Z2d6dnQzZTNzazk6OTVjY3hrN2N6YnZ1eng2ZHB0ZTVrOXA2ZGo1Ynpla3U=',
  'Content-Type': 'application/x-www-form-urlencoded'
}

response = requests.request("POST", url, headers=headers, data=payload)

print(response.text)

```

```json Response Example
{
  "access_token": "mnpqkxpujtcq5n8z",
  "expires_in": 3600,
  "refresh_token": "npyttuy6926s5wgew6vd",
  "stat": "ok"
}
```

# Get your Identity Cloud hostname

<!-- shell@1 -->
<!-- node@1 -->
<!-- python@1 -->

Your Identity Cloud hostname can be found on the **Manage Application** page in Console next to the label **Registration Domain(s)**.

# Get authorization

<!-- shell@4 -->
<!-- node@8 -->
<!-- python@11 -->

This operation requires Basic authentication. Use the client ID of an API client assigned the **owner** or the **direct_access** feature as your username and the client secret of that client as your password. See [Get started](https://techdocs.akamai.com/identity-cloud-auth/reference/get-started) for more information.

# Configure the content type

<!-- shell@5 -->
<!-- node@9 -->
<!-- python@12 -->

Set the **Content-Type** header to **application/x-www-form-urlencoded**. This causes request data to be sent as a single URL encoded string.

# Configure the grant type

<!-- shell@6 -->
<!-- node@12 -->
<!-- python@7 -->

Set the value to **authorization_code** to exchange an authorization code. To exchange a refresh token for a new access token set this value to **refresh_token**.

# Provide the authorization code

<!-- shell@7 -->
<!-- node@13 -->
<!-- python@8 -->

Enter the authorization code obtained by calling the [/access/getAuthorizationCode](https://techdocs.akamai.com/identity-cloud-auth/reference/post-authorization-code) operation. Authorization codes have a default lifetime of 30 seconds, which means that you should exchange the code shortly after receiving it.

# Configure the redirect URI

<!-- node@14 -->
<!-- python@9 -->

URL of your token exchange server. This must be the same redirect URI specified when obtaining the authorization code.

# Call the API

<!-- shell@3 -->
<!-- node@17-20 -->
<!-- python@15 -->

Use the POST method to exchange the authorization code.

# Review the response



If successful, the API response includes both an access token and a refresh token . Note that, by default, access codes expire after 1 hour. When that happens, use this operation to exchange your refresh token for a new access token and a new refresh token.