Magic Campus auth provider for MushroomAgent server auth.
Project description
mushroom-magic-campus-auth
Magic Campus authentication provider for MushroomAgent server auth.
It validates an incoming token by calling Magic Campus:
GET /api/v1/accounts/getUserInfo
Authorization: Bearer <AccessToken>
Expected response:
{
"code": 200,
"msg": "ok",
"data": {
"userId": 123,
"nickname": "Alice",
"avatarUrl": "https://example.test/avatar.png",
"phone": "13800000000",
"email": "alice@example.test"
}
}
Install For Local Development
From this directory:
pip install -e .
Or install it into the same Python environment that runs mushroom-agent.
After publishing to PyPI:
pip install mushroom-magic-campus-auth
MushroomAgent Config
Add this provider to ~/.mushroom_agent/config.yaml:
server:
auth:
providers:
- type: import
path: mushroom_magic_campus_auth:create_provider
config:
base_url: "https://magic-campus.example.com"
timeout_seconds: 3
# Optional fallback to existing MushroomAgent accesskeys.
- type: accesskey
If you do not include type: accesskey, only Magic Campus tokens will be accepted.
Token Sources
MushroomAgent extracts token candidates from:
Authorization: Bearer <token>- query parameters:
accesskey,token,auth_token - cookie:
mushroom_server_auth
This means the provider works for:
- HTTP API
- WebUI login
/ws/v1/chat/ws/v1/node
Config Options
config:
base_url: "https://magic-campus.example.com" # required
user_info_path: "/api/v1/accounts/getUserInfo" # optional
timeout_seconds: 3 # optional
expected_code: 200 # optional
issue_cookie: false # optional
headers: # optional extra headers
X-App-Id: "mushroom-agent"
issue_cookie: true asks MushroomAgent to set the accepted token as the auth cookie after WebUI login.
Try With curl
curl -X POST "http://127.0.0.1:7860/i/chat/api/messages" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer <MagicCampusAccessToken>" \
-d '{"text":"hello"}'
Development
pip install -e ".[dev]"
pytest
Build And Publish To PyPI
Install build tools:
pip install -e ".[dev]"
Build source and wheel distributions:
python -m build
Validate package metadata:
twine check dist/*
Upload to TestPyPI first:
twine upload --repository testpypi dist/*
Upload to PyPI:
twine upload dist/*
Use a PyPI API token when prompted for the password. The username is usually __token__.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mushroom_magic_campus_auth-0.1.0.tar.gz.
File metadata
- Download URL: mushroom_magic_campus_auth-0.1.0.tar.gz
- Upload date:
- Size: 4.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
732a866b3a7b31883c8ac2e2ba79ac3f07db7b9db8da626f1d58d25116485c37
|
|
| MD5 |
3927543e7a7276189f6f6833a4debe3b
|
|
| BLAKE2b-256 |
ff0dfdb2e50e0fd2ff8ad7f5e199f8da1c48d16f63be10bd56f3c9ca45d77947
|
File details
Details for the file mushroom_magic_campus_auth-0.1.0-py3-none-any.whl.
File metadata
- Download URL: mushroom_magic_campus_auth-0.1.0-py3-none-any.whl
- Upload date:
- Size: 5.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1a0e5d7f1eb017f0a2fed9b8656c8bd6747cab04ca7047c61945b450b16a9d37
|
|
| MD5 |
e7b5080c162cc41f03b4e9c3f5da9965
|
|
| BLAKE2b-256 |
7e7c0501b36e9e52f94e40905ea3dd2ea561cc360bf5e920a1f9cc0222b47b24
|