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

# Authentication

> Authentication guarantees privacy of API Services by authenticating users. Authentication requires users to log in before accessing iklim.co API Services. This guide covers setup for each available handshake method.

<Danger>
  🚨 All authorized endpoints require the `Authorization: Bearer <ACCESS_TOKEN>` header in every request.<br />
  Without it, the API responds with `401 - Unauthorized` and blocks the call.
</Danger>

Example header:

```ini theme={null}
Authorization: Bearer eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJtdXJhdG96ZGVtaXJAdGFybGEuaW8iLCJ1c2VySWQiOiJjOGI1OTQwZS01M2QyLTQwZGYtYTg4Yi0xMTBjODYxNTVjZmEiLCJyb2xlcyI6WyJBUElfVVNFUiIsIkFETUlOIl0sImxvY2FsZSI6InRyX1RSIiwidGltZVpvbmUiOiJFdXJvcGUvSXN0YW5idWwiLCJpYXQiOjE3NTMyMTA2MzQsImV4cCI6MTc1MzIxNDIzNH0.hfF1bjcNDhVthtpaZ_HkysA-zJH3VN1a6Sr59aRZbk0
```

# 1. Login Operation

> 🔐 Login operations always use a username and password pair.<br />
> API Endpoint: `/v1/auth/login`

Example Request Payload:

```json theme={null}
{
  "username": "name@domain.com",
  "password": "password"
}
```

Example Success Response:

```json theme={null}
{
    "username": "name@domain.com",
    "type": "Bearer",
    "accessToken": "eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJtdXJhdG96ZGVtaXJAdGFybGEuaW8iLCJ1c2VySWQiOiJjOGI1OTQwZS01M2QyLTQwZGYtYTg4Yi0xMTBjODYxNTVjZmEiLCJyb2xlcyI6WyJBUElfVVNFUiIsIkFETUlOIl0sImxvY2FsZSI6InRyX1RSIiwidGltZVpvbmUiOiJFdXJvcGUvSXN0YW5idWwiLCJpYXQiOjE3NTMyMDc1OTAsImV4cCI6MTc1MzIxMTE5MH0.fTCunl7i7yQ8nAuughBpvpRfdH8VFK8uhZWeTrDOPAc",
    "refreshToken": "eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJtdXJhdG96ZGVtaXJAdGFybGEuaW8iLCJ1c2VySWQiOiJjOGI1OTQwZS01M2QyLTQwZGYtYTg4Yi0xMTBjODYxNTVjZmEiLCJsb2NhbGUiOiJ0cl9UUiIsInRpbWVab25lIjoiRXVyb3BlL0lzdGFuYnVsIiwiaWF0IjoxNzUzMjA3NTkwLCJleHAiOjE3NTMyOTM5OTB9.ozFiZzNPSUtzwvu3wuocA8q8t6MlqbyT6On2i0vSENQ"
}
```

<Tip>
  ⏳ Access tokens stay valid for 1 hour, while refresh tokens live for 1 full day.
</Tip>

Possible Error Responses:

```json theme={null}
{
  "timestamp": "2025-04-14T16:58:22.22308754",
  "status": 401,
  "error": "Unauthorized",
  "message": "Bad credentials",
  "path": "/auth/login"
}
```

```json theme={null}
{
"timestamp": "2025-04-21T16:35:54.095818",
"status": 401,
"error": "Unauthorized",
"message": "User is disabled",
"path": "/auth/login"
}
```

# 2. Authentication Token Refresh Operation

> 🔁 When the access token expires, renew it with the refresh token.<br />
> API Endpoint: `/v1/auth/refresh`

Example Request Payload:

```json theme={null}
{
  "refreshToken": "eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJtdXJhdG96ZGVtaXJAdGFybGEuaW8iLCJ1c2VySWQiOiJjOGI1OTQwZS01M2QyLTQwZGYtYTg4Yi0xMTBjODYxNTVjZmEiLCJsb2NhbGUiOiJ0cl9UUiIsInRpbWVab25lIjoiRXVyb3BlL0lzdGFuYnVsIiwiaWF0IjoxNzUzMjA3NTkwLCJleHAiOjE3NTMyOTM5OTB9.ozFiZzNPSUtzwvu3wuocA8q8t6MlqbyT6On2i0vSENQ"
}
```

✅ Responses mirror the payload returned by the `Login Operation`.

<Warning>
  ⚠️ If you receive a `401 - Unauthorized` response, refresh your access token and retry.<br />
  🔁 Should refresh attempts also fail with `401`, perform a fresh login before proceeding.
</Warning>
