binbat / live777

A very simple, high performance, edge WebRTC SFU
https://live777.pages.dev
Mozilla Public License 2.0
205 stars 22 forks source link

feat(liveman): add admin auth #215

Closed a-wing closed 2 months ago

a-wing commented 2 months ago

How to enabled auth: at conf liveman.toml

[auth]
# JSON WEB TOKEN secret
secret = "<jwt_secret>"
# static JWT token, superadmin, debuggger can use this token
tokens = ["live777"]

# Admin Dashboard Accounts
[[auth.accounts]]
username = "live777"
password = "live777"

Use conf start

cargo run --package=liveman --features=liveion -- -c conf/liveman.toml

Get Json Web Token

curl -X POST -H 'Content-Type: application/json' \
http://localhost:8888/login \
-d '{"username": "live777", "password": "live777"}'
# {"access_token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6IioiLCJleHAiOjE3MjU1NDk4MzMsIm1vZGUiOjd9.LmEIyTpnn3nhIAOJ4BwZo9OndR9kq7j3Bs-hC4xQWpY","token_type":"Bearer"}

Use Json Web Token:

curl -H 'Content-Type: application/json' \
-H 'Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6IioiLCJleHAiOjE3MjU1NDk4MzMsIm1vZGUiOjd9.LmEIyTpnn3nhIAOJ4BwZo9OndR9kq7j3Bs-hC4xQWpY' \
http://localhost:8888/api/streams/
a-wing commented 2 months ago

We need a login page in liveman webui @rocka

a-wing commented 2 months ago

When you login, you can create a token for single stream.

About create a token:

id: stream id, use * match any stream id duration: Validity duration (second)

Permission:

curl -X POST -H 'Content-Type: application/json' \
-H 'Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6IioiLCJleHAiOjE3MjU2OTg0MjYsIm1vZGUiOjd9.sKmH2AbLCER46eDwJm9MFLPoqavvXAzcNkCcXA1qTXs' \
http://localhost:8888/token \
-d '{"id":"233","duration":3600,"subscribe":true,"publish":true,"admin":true}'