# Oauth2 for LXM usage

Unique offers the possibility to use oauth2 as authentication for LXM calls. Means supporting the configuration of an `clientId`, an `clientSecret`, an `endpoint` and optionally a `scope` value to first call this endpoint in order to receive a valid token for the request to the LXM.

This token endpoint needs to provide an `access_token` and an `expires_in` (seconds) attribute as response. Based on this `expires_in` and the `clientId` Unique caches this token in the application memory to not request a new token for the same `clientId` again for every LXM request. 30 seconds before the token expires or when its already expired Unique will request a new token.

**Configuration for LXM calls from node-chat application:**

|     |     |
| --- | --- |
| Environment variable | `CHAT_LLM_OAUTH_CONFIGURATION` |
| Description | Its an JSON array of objects, which contain the following string attributes: <br>- `clientId`<br>  <br>- `clientSecret`<br>  <br>- `authEndpoint`<br>  <br>- `scope` (optional)<br>  <br>- `llmEndpoint`<br>  <br>The `llmEndpoint` needs to match with the endpoint corresponding to the provided LLM configuration environment variable. |

Example:

json

```
CHAT_LLM_OAUTH_CONFIGURATION='[{\
   "llmEndpoint": "{SAME_ENDPOINT_AS_IN_ENDPOINTS_JSON}",\
   "clientId": "myClientId",\
   "clientSecret": "myClientSecret",\
   "authEndpoint": "https://www.oauth.testing/token",\
   "scope": "custom-scope"\
}]'
```

Also External / Custom LXMs can use the oauth2 authentication. Please check the following [documentation](https://docs.unique.ai/it-operators/custom-models-and-embeddings/connect-custom-lxm-llm-with-unique-ai).

**Configuration for embedding calls from node-ingestion:**

|     |     |
| --- | --- |
| Environment variable | `INGESTION_EMBEDDING_OAUTH_CLIENT_ID`<br>`INGESTION_EMBEDDING_OAUTH_CLIENT_SECRET`<br>`INGESTION_EMBEDDING_OAUTH_ENDPOINT`<br>`INGESTION_EMBEDDING_OAUTH_SCOPE` (optional) |

Example:

json

```
INGESTION_EMBEDDING_OAUTH_CLIENT_ID="My ClientId"
INGESTION_EMBEDDING_OAUTH_CLIENT_SECRET="My ClientSecret"
INGESTION_EMBEDDING_OAUTH_ENDPOINT="https://www.oauth.testing/token"
INGESTION_EMBEDDING_OAUTH_SCOPE="custom-scope"
```

**Configuration for MS Document Intelligence calls from node-ingestion-worker**

|     |     |
| --- | --- |
| Environment variable | `INGESTION_WORKER_MS_DI_OAUTH_CLIENT_ID`<br>`INGESTION_WORKER_MS_DI_OAUTH_CLIENT_SECRET`<br>`INGESTION_WORKER_MS_DI_OAUTH_ENDPOINT`<br>`INGESTION_WORKER_MS_DI_OAUTH_SCOPE` (optional) |

Example:

json

```
INGESTION_WORKER_MS_DI_OAUTH_CLIENT_ID="My ClientId"
INGESTION_WORKER_MS_DI_OAUTH_CLIENT_SECRET="My ClientSecret"
INGESTION_WORKER_MS_DI_OAUTH_ENDPOINT="https://www.oauth.testing/token"
INGESTION_WORKER_MS_DI_OAUTH_SCOPE="custom-scope"
```
