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

# Authentication

> API authentication methods

## API Key

```bash theme={null}
curl -H "Authorization: Bearer dg_live_..." \
  https://api.getdatagate.com/v1/datasets/discover
```

### Generate API Key

```bash theme={null}
curl -X POST -H "Authorization: Bearer <jwt>" \
  https://api.getdatagate.com/v1/auth/api-keys
```

Response (key shown once):

```json theme={null}
{"api_key": "dg_live_abc123..."}
```

### Revoke API Key

```bash theme={null}
curl -X DELETE -H "Authorization: Bearer <jwt>" \
  https://api.getdatagate.com/v1/auth/api-keys
```

## JWT Login Flow

### 1. Login

```bash theme={null}
curl -X POST https://api.getdatagate.com/v1/auth/login \
  -H "Content-Type: application/json" \
  -d '{"email": "user@example.com", "password": "..."}'
```

Response:

```json theme={null}
{"token": "<temporary_token>", "message": "verification code sent"}
```

### 2. Verify 2FA

```bash theme={null}
curl -X POST https://api.getdatagate.com/v1/auth/login/verify \
  -H "Content-Type: application/json" \
  -d '{"token": "<temporary_token>", "code": "123456"}'
```

Response:

```json theme={null}
{"access_token": "eyJ..."}
```

Also sets an HttpOnly `refresh_token` cookie.

### 3. Refresh

```bash theme={null}
curl -X POST https://api.getdatagate.com/v1/auth/refresh \
  --cookie "refresh_token=..."
```

Access tokens expire after 15 minutes.
