# Authentication

All ARENA360 products use credential-based authentication. This page covers the authentication methods used across the platform.

***

## Credential Types

### Account Credentials

Provided by your Customer Success Manager (CSM):

| Credential            | Format        | Used For                       |
| --------------------- | ------------- | ------------------------------ |
| **Username**          | Email address | API authentication, RabbitMQ   |
| **Password**          | String        | API authentication, RabbitMQ   |
| **Package ID**        | Numeric       | TRADE subscription identifier  |
| **CustomerPackageId** | Numeric       | ENGAGE subscription identifier |

### API Keys

Generated from the platform backoffice:

| Key Type           | Format       | Used For                     |
| ------------------ | ------------ | ---------------------------- |
| **JWT Token**      | Bearer token | REST API authentication      |
| **Widget API Key** | String       | ENGAGE widget initialization |

***

## Authentication by Product

### TRADE

**RabbitMQ Connection:**

```csharp
ConnectionFactory factory = new ConnectionFactory
{
    HostName = "inplay-rmq.lsports.eu",
    Port = 5672,
    UserName = "YOUR_USERNAME",
    Password = "YOUR_PASSWORD",
    VirtualHost = "Customers"
};
```

**REST API (Distribution):**

```json
POST https://stm-api.lsports.eu/Distribution/Start
{
    "PackageId": "YOUR_PACKAGE_ID",
    "UserName": "YOUR_USERNAME",
    "Password": "YOUR_PASSWORD"
}
```

### DEFEND

**REST API:**

```http
POST /api/endpoint
Authorization: Bearer <jwt_token>
Content-Type: application/json
```

See [DEFEND Authentication](https://docs.lsports.eu/u/defend/integration-guide/authentication) for JWT token generation.

### ENGAGE

**Tips Feed (RabbitMQ):**

```python
connection_params = pika.ConnectionParameters(
    host='your-rabbitmq-host',
    port=5671,
    virtual_host='tips',
    credentials=pika.PlainCredentials('USERNAME', 'PASSWORD'),
    ssl_options=pika.SSLOptions(ssl_context)
)
```

**Widget Integration:**

```javascript
LSports.Livescore.init({
    containerId: 'widget-container',
    apiKey: 'YOUR_API_KEY'
});
```

***

## Getting API Keys

### From the Backoffice

1. Log in to the LSports platform
2. Navigate to **Widgets** (for ENGAGE) or **Settings**
3. Locate your widget or API configuration
4. Click the three dots menu
5. Select **Copy API Key**

### From Your CSM

Contact your Customer Success Manager for:

* Initial account credentials
* Package IDs
* Sandbox/testing credentials
* Production credentials

***

## Security Best Practices

### Credential Storage

* **Never** hardcode credentials in source code
* Use environment variables or secrets management
* Rotate credentials periodically
* Use different credentials for sandbox vs production

### Connection Security

| Product         | Protocol | Port | TLS      |
| --------------- | -------- | ---- | -------- |
| TRADE RabbitMQ  | AMQP     | 5672 | Optional |
| ENGAGE RabbitMQ | AMQPS    | 5671 | Required |
| REST APIs       | HTTPS    | 443  | Required |

### Rate Limits

API endpoints may enforce rate limits. See product-specific documentation for limits:

* [TRADE API Notes](https://docs.lsports.eu/u/trade/integration/apis/notes-and-troubleshooting)
* [DEFEND API](https://docs.lsports.eu/u/defend/api)

***

## Troubleshooting

### "Access Refused" Error

* Verify credentials are correct
* Ensure package is enabled (call Distribution/Start)
* Check VirtualHost is correct (`Customers` for TRADE)

### "Connection Failed" Error

* Verify hostname and port
* Check network/firewall allows connection
* Confirm TLS settings match requirements

### Token Expired

* JWT tokens have expiration times
* Implement token refresh logic
* Re-authenticate to get new tokens

***

## Support

Need help with credentials?

* **New credentials:** Contact your CSM
* **Reset password:** Contact <support@lsports.eu>
* **Technical issues:** [Open a ticket](https://support.lsports.eu/support/tickets/new)
