# Generate a secret

`POST /v3/auth`

Section: Authentication. Base URLs: Playground https://playground-api.briqpay.com, Production https://api.briqpay.com. Auth: HTTP Basic.

Optional: See the [Authentication guide](https://developer.briqpay.com/docs/authentication.md) for more information.

## Request body

- `lifetime` (object): Define how long this secret should be valid for.
  - `unit` (string, one of: `"second"`, `"minute"`, `"hour"`, `"day"`, default `"hour"`)
  - `count` (integer, default `24`)
- `scopes` (object)
  - `sessionId` (string): Optional: Scope this secret to only be valid for a specific session.
  - `tokenId` (string): Optional: Scope this secret to only be valid for a specific tokenized payment method.
  - `operations` (array of string): Optional: Define which operations this secret can be used for.

## Request examples

### Advanced

```bash
curl -X POST 'https://playground-api.briqpay.com/v3/auth' \
  -H 'Authorization: Basic <base64(merchantId:secret)>' \
  -H 'Content-Type: application/json' \
  -d '{
  "lifetime": {
    "unit": "hour",
    "count": 24
  },
  "scopes": {
    "sessionId": "c366f6fc-2757-43e2-bc50-2b65f57f60a1",
    "operations": [
      "read_session"
    ]
  }
}'
```

### Session

```bash
curl -X POST 'https://playground-api.briqpay.com/v3/auth' \
  -H 'Authorization: Basic <base64(merchantId:secret)>' \
  -H 'Content-Type: application/json' \
  -d '{
  "scopes": {
    "sessionId": "c366f6fc-2757-43e2-bc50-2b65f57f60a1"
  }
}'
```

### Operations

```bash
curl -X POST 'https://playground-api.briqpay.com/v3/auth' \
  -H 'Authorization: Basic <base64(merchantId:secret)>' \
  -H 'Content-Type: application/json' \
  -d '{
  "scopes": {
    "operations": [
      "read_session"
    ]
  }
}'
```

### Lifetime

```bash
curl -X POST 'https://playground-api.briqpay.com/v3/auth' \
  -H 'Authorization: Basic <base64(merchantId:secret)>' \
  -H 'Content-Type: application/json' \
  -d '{
  "lifetime": {
    "unit": "hour",
    "count": 24
  }
}'
```

## Responses

### 201

- `secret` (string)
- `expiresAt` (string)

### 400

- `error` (object)
  - `code` (string, one of: `"INVALID_DATA"`, `"UNKNOWN"`)
  - `message` (string)

### 403

- `error` (object)
  - `code` (string, one of: `"INVALID_CREDENTIALS"`, `"INVALID_API_KEY"`, `"AUTH_SECRET_EXPIRED"`)
  - `message` (string)

### 404

- `error` (object)
  - `code` (string, one of: `"SESSION_NOT_FOUND"`)
  - `message` (string)
