# eduzz-miau-client

Python client for the Eduzz Miau authentication service.

## Installation

```bash
pip install eduzz-miau-client
```

## Usage

```python
from eduzz_miau_client import MiauClient

client = MiauClient(
    api_url="https://your-miau-api-url",
    app_secret="your-app-secret",
)

token = client.get_token()
```

Or using a context manager:

```python
with MiauClient(api_url="https://your-miau-api-url", app_secret="your-app-secret") as client:
    token = client.get_token()
```

## Example

```python
import httpx
import json
import os
from eduzz_miau_client import MiauClient

MIAU_API_URL = os.environ.get('MIAU_API_URL')
MIAU_APP_SECRET = os.environ.get('MIAU_APP_SECRET', '')
YOUR_API_URL = os.environ.get('YOUR_API_URL', 'https://your-api.example.com')

client = MiauClient(api_url=MIAU_API_URL, app_secret=MIAU_APP_SECRET)
token = client.get_token()

http = httpx.Client()
response = http.get(YOUR_API_URL+'/your/endpoint', headers={'Authorization': f'Bearer {token}'})
print(json.dumps(response.json(), indent=2, ensure_ascii=False))
```

## API

### `MiauClient(api_url, app_secret)`

Creates a new client instance.

| Parameter    | Type  | Description                  |
|-------------|-------|------------------------------|
| `api_url`   | `str` | Miau API base URL            |
| `app_secret`| `str` | Application secret from Miau |

### `client.get_token() -> str`

Returns a valid JWT access token. Tokens are cached in memory and automatically refreshed when they are within 60 seconds of expiration.

### `client.close()`

Closes the underlying HTTP client. Called automatically when using the context manager.

## Requirements

- Python >= 3.10
