> ## Documentation Index
> Fetch the complete documentation index at: https://developers.criteo.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Authorization Code Setup

# Setting up an authorization code application

## Step 1. Authorization Code Setup

### Creating an authorization code app

1. Once you have logged in to the Criteo Partners Portal, create a new App by clicking on ➕ button in the ***My apps*** section

<Frame>
  <img src="https://mintcdn.com/criteo-e1682996/o5kg7jsshijtmVtG/images/marketing-solutions/v2025.10/docs/285ba4d-52f9f11-app-card.PNG?fit=max&auto=format&n=o5kg7jsshijtmVtG&q=85&s=ff333e18b73326f4c4766bda810c2356" alt="52f9f11-app-card.PNG" width="1278" height="437" data-path="images/marketing-solutions/v2025.10/docs/285ba4d-52f9f11-app-card.PNG" />
</Frame>

This will open a modal where you can select the type of application.

### 1.1. Create app

1. **App details**
   1. Provide your app name and description. You can also provide an optional image to identify your application. On your App page, you will be able to define the scope of your application and the OAuth parameters. Please see this [page](/marketing-solutions/v2025.10/docs/onboarding-checklist#3-define-your-app-scope) to see more details on how to define your app scope.\\
      <Frame>
        <img src="https://mintcdn.com/criteo-e1682996/o5kg7jsshijtmVtG/images/marketing-solutions/v2025.10/docs/abc222c-portal-_step1_1.gif?s=78dd7add6e7f27538bff64bb720b8d7d" width="1896" height="750" data-path="images/marketing-solutions/v2025.10/docs/abc222c-portal-_step1_1.gif" />
      </Frame>
2. **Authentication method**
   1. Select your app authentication method. You will have the option to select Client Credentials or Authorization Code. To decide which option is best for your organization, review our [OAuth implementation](/marketing-solutions/v2025.10/docs/oauth-implementation) guide.\\
      <Frame>
        <img src="https://mintcdn.com/criteo-e1682996/o5kg7jsshijtmVtG/images/marketing-solutions/v2025.10/docs/190da94-auth_methods.png?fit=max&auto=format&n=o5kg7jsshijtmVtG&q=85&s=74b8d22bc02c1ec70ce41315ec5c97e2" width="1876" height="787" data-path="images/marketing-solutions/v2025.10/docs/190da94-auth_methods.png" />
      </Frame>

### 1.2. App activation

1. **Service**
   1. Select which Criteo service you want to use your API application with. Chose C-Growth for marketing solutions or C-Max for retail media\\
      <Frame>
        <img src="https://mintcdn.com/criteo-e1682996/o5kg7jsshijtmVtG/images/marketing-solutions/v2025.10/docs/4a14336-services.png?fit=max&auto=format&n=o5kg7jsshijtmVtG&q=85&s=fed6301ee1714766ffeefc08c72cb320" width="1847" height="501" data-path="images/marketing-solutions/v2025.10/docs/4a14336-services.png" />
      </Frame>

### 1.3. Authorizations

1. **Domains**
   1. Select the domains to choose which permission access your application will need\\
      <Frame>
        <img src="https://mintcdn.com/criteo-e1682996/KL9i4BnMuq4R7Zhu/images/marketing-solutions/v2025.10/docs/fb84380-portal-_step4final_1.gif?s=56120b013c8c407211a20a81049cc3ad" width="1896" height="750" data-path="images/marketing-solutions/v2025.10/docs/fb84380-portal-_step4final_1.gif" />
      </Frame>

Once all these steps have been done, click "Activate app" to activate the application

**Redirect URI**

Applications using Authorization code workflow will need to specify a **Redirect URI** as part of your app scope.

<Frame>
  <img src="https://mintcdn.com/criteo-e1682996/o5kg7jsshijtmVtG/images/marketing-solutions/v2025.10/docs/706af65-2023-06-30_14_57_56-My_First_App___Criteo_Developer_Portal.png?fit=max&auto=format&n=o5kg7jsshijtmVtG&q=85&s=94cb6b35f6f2ec1119561deb8a873995" width="1843" height="277" data-path="images/marketing-solutions/v2025.10/docs/706af65-2023-06-30_14_57_56-My_First_App___Criteo_Developer_Portal.png" />
</Frame>

***

## Step 2. Set Up Your OAuth Parameters

Once you have defined the scope of your application, you will be able to set what you need for the authorization code workflow

<table>
  <thead>
    <tr>
      <th>
        <p>
          Parameters
        </p>
      </th>

      <th>
        <p>
          Description
        </p>
      </th>
    </tr>
  </thead>

  <tbody>
    <tr>
      <td>
        <p>
          <code>
            client\_id
          </code>
        </p>
      </td>

      <td>
        <p>
          Your public key accessible in the app credentials section.
        </p>

        <p>
          You can add up to 5 pairs of credentials. Can be added and managed also once the App has been activated.
        </p>
      </td>
    </tr>

    <tr>
      <td>
        <p>
          <code>
            client\_secret
          </code>
        </p>
      </td>

      <td>
        <p>
          Your secret key, accessible only once when creating a pair of client\_id and client\_secret in the credentials section.
        </p>

        <p>
          You can add up to 5 pairs of credentials. Can be added and managed also once the App has been activated.
        </p>
      </td>
    </tr>

    <tr>
      <td>
        <p>
          <code>
            redirect\_uri
          </code>
        </p>
      </td>

      <td>
        <p>
          The URL to redirect the user to after consent delegation. HTTPs protocol required.
        </p>

        <p>
          You can add up to 30 redirect URIs. Can be added and managed also once the App has been activated.
        </p>
      </td>
    </tr>
  </tbody>
</table>

You can now publish the app, and start an authorization code workflow.

***

### 2.1. - Consent URL Creation

Once you have defined the parameters of your App you can start implementing your authorization code flow.

**Consent URL**

1. To request access to a user's data, you will create a Consent link (to be sent to the user or implemented through a button in your platform that will redirect the user to the link) with the following structure and parameters:

<Info>
  **Authorization Code v. Client Credentials Consent URLs**

  If you are familiar with the Client Credentials workflow, you will notice that in the partner portal you won't see the "***Generate Consent URL***" button. This is because with authorization code workflow you are required to provide the redirect URI which is unique to your organization. So these will need to be configured within your workflow.
</Info>

You will need to construct a consent URL similar to the example below while passing the required parameters for your application.

```http Consent URL Example theme={null}
https://consent.criteo.com/request?response_type=code&client_id={client_id}&redirect_uri={redirect_uri}&state={state}
```

<table>
  <thead>
    <tr>
      <th>
        <p>
          Parameters
        </p>
      </th>

      <th>
        <p>
          Required
        </p>
      </th>

      <th>
        <p>
          Description
        </p>
      </th>
    </tr>
  </thead>

  <tbody>
    <tr>
      <td>
        <p>
          <code>
            response\_type=code
          </code>
        </p>
      </td>

      <td>
        <p>
          Yes
        </p>
      </td>

      <td>
        <p>
          Indicates that an authorization code is expected as the outcome.
        </p>
      </td>
    </tr>

    <tr>
      <td>
        <p>
          <code>
            client\_id
          </code>
        </p>
      </td>

      <td>
        <p>
          Yes
        </p>
      </td>

      <td>
        <p>
          Your public key, accessible in the app credentials section.
        </p>
      </td>
    </tr>

    <tr>
      <td>
        <p>
          <code>
            redirect\_uri
          </code>
        </p>
      </td>

      <td>
        <p>
          Yes
        </p>
      </td>

      <td>
        <p>
          The URL to redirect the user to after consent delegation. HTTPS protocol required. Defined in the redirect URI section in the Developer Dashboard.
        </p>
      </td>
    </tr>

    <tr>
      <td>
        <p>
          <code>
            state
          </code>
        </p>
      </td>

      <td>
        <p>
          No
        </p>
      </td>

      <td>
        <p>
          A string that you can provide and that will be returned as-is in the final redirection (usually used to prevent Cross-Site Request Forgery attacks).
        </p>
      </td>
    </tr>
  </tbody>
</table>

2. The Consent link will direct your user to *Criteo Consent* page will look like this example:

<Frame>
  <img src="https://mintcdn.com/criteo-e1682996/o5kg7jsshijtmVtG/images/marketing-solutions/v2025.10/docs/0151441-consentgeneration3.png?fit=max&auto=format&n=o5kg7jsshijtmVtG&q=85&s=56d064350b89eaaebb1e11a8357749d0" width="1461" height="966" data-path="images/marketing-solutions/v2025.10/docs/0151441-consentgeneration3.png" />
</Frame>

2. The user will be able to choose what advertiser(s) from their portfolio they want to give access to.
3. The user will approve the request by clicking on "**Approve**"

<Note>
  **Notes**

  A consent request is displayed to a user in all cases except in the following:

  * The `client_id` does not match any published API app.
  * The `redirect_uri` is not authorized (*e.g not accessible from public network*)
  * An unexpected error occurred in our backend.

  In any of the cases above an error message will be displayed.
</Note>

### 2.2. - Redirection and Access Code

Once the user has completed the Consent Delegation flow, we redirect your user to the following URL:

```http Example of Redirect URL theme={null}
https://www.mywebsite.com/?code=58f4cd15-8087-48af-bab7-bba06d2df1da&state=4lr4e
```

This URL is forged with the authorized `redirect_uri` and the following query parameters:

<table>
  <thead>
    <tr>
      <th>
        <p>
          Parameter
        </p>
      </th>

      <th>
        <p>
          Description
        </p>
      </th>
    </tr>
  </thead>

  <tbody>
    <tr>
      <td>
        <p>
          <code>
            code
          </code>
        </p>
      </td>

      <td>
        <p>
          An authorization code valid for 30 seconds, usable only once.
        </p>
      </td>
    </tr>

    <tr>
      <td>
        <p>
          <code>
            state
          </code>
        </p>
      </td>

      <td>
        <p>
          The state parameter that you originally provided (returned as-is).
        </p>
      </td>
    </tr>
  </tbody>
</table>

If the consent request is denied, we redirect to the same `redirect-uri` but with an '***error***' query parameter instead of a '***code***'.

***

## Step 3. Exchanging Access Code For Access Token

Now that you have an authorization code, you can trade it for an access token by making the following **POST** call. Your call will need to be setup this way:

```http Access token request theme={null}
POST https://api.criteo.com/oauth2/token
 
grant_type=authorization_code
&code={code}
&redirect_uri={redirect_uri}
&client_id={client_id}
&client_secret={client_secret}
```

**Example of Token Request**

```sh curl theme={null}
curl -L 'https://api.criteo.com/oauth2/token?grant_type=authorization_code&client_id=<MY_CLIENT_ID>&client_secret=<MY_CLIENT_SECRET>&redirect_uri=<MY_URI>' \
-H 'Content-Type: application/x-www-form-urlencoded' \
-d 'client_id=<MY_CLIENT_ID>' \
-d 'client_secret=<MY_CLIENT_SECRET>' \
-d 'redirect_uri=<MY_URI>' \
-d 'code=<MY_CODE>' \
-d 'grant_type=authorization_code'
```

<table>
  <thead>
    <tr>
      <th>
        <p>
          Parameter
        </p>
      </th>

      <th>
        <p>
          Description
        </p>
      </th>
    </tr>
  </thead>

  <tbody>
    <tr>
      <td>
        <p>
          <code>
            grant\_type=authorization\_code
          </code>
        </p>
      </td>

      <td>
        <p>
          Indicates that you are providing an authorization code
        </p>
      </td>
    </tr>

    <tr>
      <td>
        <p>
          <code>
            code
          </code>
        </p>
      </td>

      <td>
        <p>
          Authorization code returned during redirection
        </p>
      </td>
    </tr>

    <tr>
      <td>
        <p>
          <code>
            redirect\_uri
          </code>
        </p>
      </td>

      <td>
        <p>
          Must match the

          <code>
            redirect\_uri
          </code>

          used for the authorization request
        </p>
      </td>
    </tr>

    <tr>
      <td>
        <p>
          <code>
            client\_id
          </code>
        </p>
      </td>

      <td>
        <p>
          Your public key accessible in app credentials section
        </p>
      </td>
    </tr>

    <tr>
      <td>
        <p>
          <code>
            client\_secret
          </code>
        </p>
      </td>

      <td>
        <p>
          Your secret key, accessible only once when creating a pair of

          <code>
            client\_id
          </code>

          and

          <code>
            client\_secret
          </code>

          in credentials section
        </p>
      </td>
    </tr>
  </tbody>
</table>

The response from Criteo API will be the following:

```json Access token response theme={null}
{
    "access_token": "eyJhbGciOi",
    "token_type": "Bearer",
    "refresh_token": "eyJhbGciO",
    "expires_in": 900
}
```

<table>
  <thead>
    <tr>
      <th>
        <p>
          Parameter
        </p>
      </th>

      <th>
        <p>
          Description
        </p>
      </th>
    </tr>
  </thead>

  <tbody>
    <tr>
      <td>
        <p>
          <code>
            access\_token
          </code>
        </p>
      </td>

      <td>
        <p>
          A short-lived (valid for 900 seconds) access token\*
        </p>
      </td>
    </tr>

    <tr>
      <td>
        <p>
          <code>
            refresh\_token
          </code>
        </p>
      </td>

      <td>
        <p>
          A long-lived refresh token (that expires after 6 months) that can be used to renew the access token (see next section).
        </p>
      </td>
    </tr>

    <tr>
      <td>
        <p>
          <code>
            token\_type=Bearer
          </code>
        </p>
      </td>

      <td>
        <p>
          Type of token.
        </p>
      </td>
    </tr>

    <tr>
      <td>
        <p>
          <code>
            expires\_in
          </code>
        </p>
      </td>

      <td>
        <p>
          Lifetime of the token in seconds.
        </p>
      </td>
    </tr>
  </tbody>
</table>

<Warning>
  **Token Lifetime**

  The refresh token will be revoked if the user that provided consent to an account changes the role or leaves the organization. Such an account needs to be re-authorized by launching the new consent flow and having the new administrator accept the consent.
</Warning>

### 3.1. - Using Refresh Token

When an access token is close to expiration, you can get a new one using a refresh token via the following request:

```http Refreshaccess token theme={null}
POST https://api.criteo.com/oauth2/token
 
grant_type=refresh_token
&refresh_token=eyJ.ela4a9e.afd
&client_id=6e75a
&client_secret=j7MfAp
```

<table>
  <thead>
    <tr>
      <th>
        <p>
          Parameter
        </p>
      </th>

      <th>
        <p>
          Description
        </p>
      </th>
    </tr>
  </thead>

  <tbody>
    <tr>
      <td>
        <p>
          <code>
            grant\_type=refresh\_token
          </code>
        </p>
      </td>

      <td>
        <p>
          Indicates that you are providing a refresh token.
        </p>
      </td>
    </tr>

    <tr>
      <td>
        <p>
          <code>
            refresh\_token
          </code>
        </p>
      </td>

      <td>
        <p>
          Refresh token shared when requesting an access token.
        </p>
      </td>
    </tr>

    <tr>
      <td>
        <p>
          <code>
            client\_id
          </code>
        </p>
      </td>

      <td>
        <p>
          Your public key, accessible in the app credentials section.
        </p>
      </td>
    </tr>

    <tr>
      <td>
        <p>
          <code>
            client\_secret
          </code>
        </p>
      </td>

      <td>
        <p>
          Your secret key, accessible only once when creating a pair of client\_id and client\_secret in the credentials section.
        </p>
      </td>
    </tr>
  </tbody>
</table>

The response will be the same as when issuing an access token

***

# Demo

Below you can find a code for a demo application in **NodeJS** that uses **Express JS** framework.

<CodeGroup>
  ```javascript index.js expandable theme={null}
  var express = require('express');
  var passport = require('passport');
  var OAuth2Strategy = require('passport-oauth2').Strategy;
  var app = express();
  var port = 3000;

  // Passport setup
  passport.use(new OAuth2Strategy({
      clientID: 'CLIENT_ID', // Enter your client_id here
      clientSecret: 'CLIENT_SECRET', // Enter your client_secret here
      authorizationURL: 'https://consent.criteo.com/request',
      callbackURL: `http://localhost:${port}/criteo-auth/callback`,
      tokenURL: 'https://api.criteo.com/oauth2/token',
      state: 'togorot'
    },
    function(accessToken, refreshToken, profile, cb) {
      cb(null, { accessToken, refreshToken });
    }
  ));
  app.use(passport.initialize());

  // Route declarations
  app.get('/', function(req, res) {
    res.send('<a href="/criteo-auth">Link my Criteo account!</a>');
  });

  app.get('/criteo-auth', passport.authenticate('oauth2'));

  app.get('/criteo-auth/callback',
    passport.authenticate('oauth2', { session: false }),
    function(req, res) {
      res.send(`<div>Authentication successful!</div><div>Access token:</div><textarea>${req.user.accessToken}</textarea><div>Refresh token:</div><textarea>${req.user.refreshToken}</textarea>`);
    }
  );

  console.log(`OAuth test app started on http://localhost:${port}`);
  app.listen(port);
  ```

  ```json markdown package.json theme={null}
  {
    "name": "oauth-node",
    "version": "1.0.0",
    "description": "",
    "main": "index.js",
    "scripts": {
      "start": "node index.js"
    },
    "author": "",
    "license": "ISC",
    "dependencies": {
      "ejs": "^3.1.6",
      "express": "^4.17.1",
      "passport": "^0.4.1",
      "passport-oauth2": "^1.6.0"
    }
  }
  ```
</CodeGroup>

## How to run the demo?

1. Run `npm install`
2. Connect to the developer portal and create an app according to the instructions above
3. Create an "Authorization code" app.
4. Generate app credentials and enter the client\_id and client\_secret in index.js.
5. Register "[http://localhost:3000/criteo-auth/callback](http://localhost:3000/criteo-auth/callback)" as the redirect URI.
6. Run `npm run start`
7. Open [http://localhost:3000](http://localhost:3000)

***

<Note>
  **FAQ**

  **What happens if my`client_id` and `client_secret` are compromised?**\
  You will need to delete the set of credentials in the App page and create a new one. You will need to request access again to your users.
</Note>
