# authorize

This method is to generate a Cortex access token. Most of the methods of the Cortex API require this token as a parameter.

Application can specify the license key and the amount of sessions to be debited from the license and use them locally.

### Cortex token

The token is linked to your application. It cannot be used with another application. The token is also linked to the EmotivID of the current user. It cannot be used with another EmotivID. So if the user logs out in [EMOTIV Launcher](https://emotiv.gitbook.io/emotiv-launcher/), and then logs in with another EmotivID, your application must call this API again to get a new token.

Your application can save the Cortex token and reuse it later, within 2 days. Note that it is the responsibility of the application to secure the token.

{% hint style="danger" %}
The Cortex token must remain secret. Do NOT share it. It is your responsibility to keep it secure.
{% endhint %}

Once having Cortex token, the app can [work offline with Cortex](/cortex-api/overview-of-api-flow/offline-support.md).

### EULA not accepted warning

If the user has not accepted the EULA, then a warning message will be included in the response as well. The user must accept the EULA through EMOTIV Launcher.

{% hint style="info" %}
Before you call this method, the user must approve your application in [EMOTIV Launcher](https://emotiv.gitbook.io/emotiv-launcher/). See [requestAccess](/cortex-api/authentication/requestaccess.md) for details.
{% endhint %}

## Parameters

<table data-header-hidden><thead><tr><th width="141">Name</th><th width="142">Type</th><th width="146">Required</th><th>Description</th></tr></thead><tbody><tr><td>Name</td><td>Type</td><td>Required</td><td>Description</td></tr><tr><td>clientId</td><td><code>string</code></td><td>yes</td><td>The client id of your Cortex application.</td></tr><tr><td>clientSecret</td><td><code>string</code></td><td>yes</td><td>The client secret of your Cortex application.</td></tr><tr><td>license</td><td><code>string</code></td><td>no</td><td>A license id. In most cases, you don't need to specify the license id. Cortex will find the appropriate license based on the client id.</td></tr><tr><td>debit</td><td><code>number</code></td><td>no</td><td>Number of sessions to debit from the license, so that it can be spent locally without having to authorize again. You need to debit the license only if you want to <a href="/pages/-Lft-X0O-z3lAu1VkNsw#session-activation">activate a session</a>.<br>The default value is zero.</td></tr></tbody></table>

## Result

The result is an object containing a field **cortexToken**. It may also include a field **warning**, if the user didn't accept the EULA.

<table data-header-hidden><thead><tr><th width="144">Name</th><th width="154.33333333333331">Type</th><th>Description</th></tr></thead><tbody><tr><td>Name</td><td>Type</td><td>Description</td></tr><tr><td>cortexToken</td><td><code>string</code></td><td>The Cortex token of the user</td></tr><tr><td>warning</td><td><code>object</code></td><td>Contains a message and the URL to accept the EULA</td></tr></tbody></table>

## Examples

{% tabs %}
{% tab title="Request" %}

```javascript
{
    "id": 1,
    "jsonrpc": "2.0",
    "method": "authorize",
    "params": {
        "clientId": "xxx",
        "clientSecret": "xxx"
    }
}
```

{% endtab %}

{% tab title="Response" %}

```javascript
{
    "id": 1,
    "jsonrpc": "2.0",
    "result": {
        "cortexToken":"xxx",
        "warning": {
            "code": 6,
            "message": "...",
            "licenseUrl": "https://..."
        }
    }
}
```

{% endtab %}
{% endtabs %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://emotiv.gitbook.io/cortex-api/authentication/authorize.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
