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

# Authentication

> Setting up Artemis authentication access

<Info>
  **Prerequisite**: In order to run the collection below,
  a **Authentication\_URL** is required which will be provided by Cynopsis, which can then be set as a global variable
  or in the enviroment created for Artemis in the Introduction section.
</Info>

[Artemis3 Postman Collection Link](https://www.getpostman.com/collections/74daad63426fa5c7b3c6)

## Authentication URLs

Use the appropriate authentication URL depending on your environment.

| Environment | Authentication URL             |
| ----------- | ------------------------------ |
| **UAT**     | `https://crm-demo.cynopsis.co` |
| **PROD**    | `https://crm.cynopsis.co`      |

***

## Generate Token for a Guest

To generate a token, please make a `POST` API call to the following endpoint:

```bash theme={null}
POST {{authentication_url}}/oauth/token
```

### Requirements

The request must use the `application/x-www-form-urlencoded` format.

#### Headers

```http theme={null}
Content-Type: application/x-www-form-urlencoded
```

#### Body (form data)

```
grant_type=client_credentials
client_id=YOUR_CLIENT_ID
client_secret=YOUR_CLIENT_SECRET
```

Replace `YOUR_CLIENT_ID` and `YOUR_CLIENT_SECRET` with the credentials provided by Cynopsis.

### Sample HTTP Request

```bash theme={null}
curl -X POST {{authentication_url}}/oauth/token \
  -H "Content-Type: application/x-www-form-urlencoded" \
  -d "grant_type=client_credentials&client_id=YOUR_CLIENT_ID&client_secret=YOUR_CLIENT_SECRET"
```

### Sample HTTP Response

```json theme={null}
{
  "access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6...",
  "token_type": "Bearer",
  "expires_in": 3600
}
```

## Get Access Token/Refresh Token Using Username and Password

```bash theme={null}
POST {{authentication_url}}/oauth/token
```

### Requirements

Use the `application/x-www-form-urlencoded` content type.

#### Headers

```http theme={null}
Content-Type: application/x-www-form-urlencoded
```

#### Body (form data)

```
grant_type=password
client_id=YOUR_CLIENT_ID
client_secret=YOUR_CLIENT_SECRET
username=USER_EMAIL
password=USER_PASSWORD
```

Replace the values accordingly. These credentials are required for authenticating the user.

***

### Sample Request

Use `application/x-www-form-urlencoded` and URL-encode all values.

```bash theme={null}
# Get access + refresh tokens with username/password
curl --location '{{authentication_url}}/oauth/token' \
  --header 'Content-Type: application/x-www-form-urlencoded' \
  --data-urlencode 'grant_type=password' \
  --data-urlencode 'client_id=YOUR_CLIENT_ID' \
  --data-urlencode 'client_secret=YOUR_CLIENT_SECRET' \
  --data-urlencode 'username=USER_EMAIL' \
  --data-urlencode 'password=USER_PASSWORD'
```

***

### Sample Response

```json theme={null}
{
  "access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6...",
  "refresh_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6...",
  "token_type": "Bearer",
  "expires_in": 3600
}
```

***

## Using Refresh Token for User

To obtain a new access token using a valid refresh token (from above), make the following request:

```bash theme={null}
POST {{authentication_url}}/oauth/token
```

#### Headers

```http theme={null}
Content-Type: application/x-www-form-urlencoded
```

#### Body (form data)

```
grant_type=refresh_token
refresh_token=USER_REFRESH_TOKEN
client_id=YOUR_CLIENT_ID
client_secret=YOUR_CLIENT_SECRET
```

***

### Sample Request (Refresh)

```bash theme={null}
# Refresh access token using a refresh token
curl --location '{{authentication_url}}/oauth/token' \
  --header 'Content-Type: application/x-www-form-urlencoded' \
  --data-urlencode 'grant_type=refresh_token' \
  --data-urlencode 'refresh_token=YOUR_REFRESH_TOKEN' \
  --data-urlencode 'client_id=YOUR_CLIENT_ID' \
  --data-urlencode 'client_secret=YOUR_CLIENT_SECRET'
```

***

### Sample Response

```json theme={null}
{
  "access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6...",
  "refresh_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6...",
  "token_type": "Bearer",
  "expires_in": 3600
}
```
