|
| 1 | +# Auth Proxy |
| 2 | + |
| 3 | +This service acts as a proxy for an authentication provider (Authentik), caching user data locally and exposing it through a simplified API for devices on the local network. |
| 4 | + |
| 5 | +It periodically fetches user information, including their card IDs and membership status, and provides endpoints to query this data. |
| 6 | + |
| 7 | +## Configuration |
| 8 | + |
| 9 | +Authentik token provided via `AUTHENTIK_TOKEN` or `AUTHENTIK_TOKEN_FILE` environment variable. |
| 10 | + |
| 11 | +## Background Sync |
| 12 | + |
| 13 | +The service automatically synchronizes user data from the Authentik service every 5 minutes. It fetches users with an active membership. |
| 14 | + |
| 15 | +## API Reference |
| 16 | + |
| 17 | +### Get User Stats |
| 18 | + |
| 19 | +Returns statistics about the user data synchronization process. |
| 20 | + |
| 21 | +**Endpoint:** `GET /users/-/stats` |
| 22 | + |
| 23 | +**Success Response (200 OK):** |
| 24 | + |
| 25 | +```json |
| 26 | +{ |
| 27 | + "last_success_run": "2025-10-08T12:00:00Z", |
| 28 | + "last_failed_run": null, |
| 29 | + "last_failed_reason": null, |
| 30 | + "users": { |
| 31 | + "count": 150 |
| 32 | + }, |
| 33 | + "cards": { |
| 34 | + "count": 350 |
| 35 | + } |
| 36 | +} |
| 37 | +``` |
| 38 | + |
| 39 | +### Get User by Card ID |
| 40 | + |
| 41 | +Retrieves a user by their associated card ID. The service handles multiple card ID formats automatically. |
| 42 | + |
| 43 | +**Endpoint:** `GET /users/-/by-card/{card_id}` |
| 44 | + |
| 45 | +**Path Parameters:** |
| 46 | + |
| 47 | +* `card_id` (string, required): The card ID to look up. |
| 48 | + |
| 49 | +**Success Response (200 OK):** |
| 50 | + |
| 51 | +```json |
| 52 | +{ |
| 53 | + "uid": "someuser", |
| 54 | + "mifare_card_ids": ["112233"], |
| 55 | + "unique_card_ids": ["aabbccdd"], |
| 56 | + "membership_expiration": 1765432109 |
| 57 | +} |
| 58 | +``` |
| 59 | + |
| 60 | +**Error Response (404 Not Found):** |
| 61 | + |
| 62 | +```json |
| 63 | +{ |
| 64 | + "detail": "Item not found" |
| 65 | +} |
| 66 | +``` |
| 67 | + |
| 68 | +### WebSocket API |
| 69 | + |
| 70 | +For real-time communication, a WebSocket endpoint is available. |
| 71 | + |
| 72 | +**Endpoint:** `WS /ws` |
| 73 | + |
| 74 | +**Description:** |
| 75 | + |
| 76 | +After establishing a connection, the client can send JSON messages to request user information. |
| 77 | + |
| 78 | +**Request Message:** |
| 79 | + |
| 80 | +Send a message with the following structure to look up a user by their card ID: |
| 81 | + |
| 82 | +```json |
| 83 | +{ |
| 84 | + "action": "get", |
| 85 | + "object": "user", |
| 86 | + "card_id": "aabbccdd" |
| 87 | +} |
| 88 | +``` |
| 89 | + |
| 90 | +**Success Response:** |
| 91 | + |
| 92 | +The server will respond with the user object if the card is found: |
| 93 | + |
| 94 | +```json |
| 95 | +{ |
| 96 | + "status": "ok", |
| 97 | + "object": { |
| 98 | + "uid": "someuser", |
| 99 | + "mifare_card_ids": ["112233"], |
| 100 | + "unique_card_ids": ["aabbccdd"], |
| 101 | + "membership_expiration": 1765432109 |
| 102 | + } |
| 103 | +} |
| 104 | +``` |
| 105 | + |
| 106 | +**Error Response:** |
| 107 | + |
| 108 | +If the user is not found, the server will respond with an error message: |
| 109 | + |
| 110 | +```json |
| 111 | +{ |
| 112 | + "status": "error", |
| 113 | + "error": "user not found" |
| 114 | +} |
| 115 | +``` |
0 commit comments