Metadata-Version: 2.4
Name: aa-desktop-bridge
Version: 0.2.0
Summary: Alliance Auth plugin that exposes the AA Desktop bridge API.
Requires-Python: >=3.10
Description-Content-Type: text/markdown
Requires-Dist: django<6,>=5.2
Requires-Dist: django-ninja<2,>=1.3
Requires-Dist: django-oauth-toolkit<4,>=3.2
Provides-Extra: dev
Requires-Dist: pytest>=8; extra == "dev"
Requires-Dist: pytest-django>=4.8; extra == "dev"

# aa-desktop-bridge

Alliance Auth plugin for [AA Desktop](../README.md). It mounts a django-ninja API at `/api/desktop/v1/`.

| Method | Path | Auth |
| --- | --- | --- |
| `GET` | `/api/desktop/v1/discovery` | none |
| `GET` | `/api/desktop/v1/me` | Bearer access token, scope `desktop.core` |
| `GET` | `/api/desktop/v1/modules` | Bearer access token, scope `desktop.core` |
| any | `/api/desktop/v1/modules/<id>/...` | Bearer access token, a scope of that module, and the module's Alliance Auth permissions |

Session cookies are not a credential. See the repository README for installing it on Alliance Auth 5.5 and for the OIDC client the desktop app expects.

## Module routes

Another Alliance Auth app can give the desktop client its own routes. It registers a `desktop_module_hook` that returns a `DesktopModule` (id, name, version, scopes, required permissions, and a django-ninja `Router`). The bridge mounts the router at `/api/desktop/v1/modules/<id>/`. The full example and rules are in [`aa_desktop_bridge/modules.py`](aa_desktop_bridge/modules.py). In short:

- Scopes are named `desktop.<id>` or `desktop.<id>.<name>`.
- At least one Alliance Auth permission is required.
- Every route uses `DesktopBearer([...], permissions=...)` with the module's own scopes and all of its required permissions, and nothing else.

A module that breaks a rule, or whose hook raises, is not mounted at all, and the reason is logged. The rest of the API keeps working.

The admin registers each module scope in `OAUTH2_PROVIDER["SCOPES"]`, the same way as `desktop.core`. Until then the scope cannot be granted, and the module's routes answer 403.

`discovery` lists mounted modules and their scopes. `/modules` lists the ones the signed-in user has the permissions for, and which of their scopes the token already holds. `/me` gives their ids in `modules_available`.

Check what is mounted:

```bash
python manage.py desktop_modules
```

It prints each mounted module and its scopes, each skipped module with the reason, and any module scope that is missing from `OAUTH2_PROVIDER["SCOPES"]`. It exits 1 if anything is wrong, so an image build can stop on it.

## Publishing

The package is published to PyPI from a `bridge-v<version>` tag. The workflow and the one-time Trusted Publisher settings are in [docs/pypi.md](../docs/pypi.md).
