mirror of
https://github.com/bluenviron/mediamtx
synced 2024-12-12 09:44:59 +00:00
9c6ba7e2c7
This is a new authentication system that covers all the features exposed by the server, including playback, API, metrics and PPROF, improves internal authentication by adding permissions, improves HTTP-based authentication by adding the ability to exclude certain actions from being authenticated, adds an additional method (JWT-based authentication).
53 lines
1.1 KiB
Go
53 lines
1.1 KiB
Go
package conf
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
)
|
|
|
|
// AuthAction is an authentication action.
|
|
type AuthAction string
|
|
|
|
// auth actions
|
|
const (
|
|
AuthActionPublish AuthAction = "publish"
|
|
AuthActionRead AuthAction = "read"
|
|
AuthActionPlayback AuthAction = "playback"
|
|
AuthActionAPI AuthAction = "api"
|
|
AuthActionMetrics AuthAction = "metrics"
|
|
AuthActionPprof AuthAction = "pprof"
|
|
)
|
|
|
|
// MarshalJSON implements json.Marshaler.
|
|
func (d AuthAction) MarshalJSON() ([]byte, error) {
|
|
return json.Marshal(string(d))
|
|
}
|
|
|
|
// UnmarshalJSON implements json.Unmarshaler.
|
|
func (d *AuthAction) UnmarshalJSON(b []byte) error {
|
|
var in string
|
|
if err := json.Unmarshal(b, &in); err != nil {
|
|
return err
|
|
}
|
|
|
|
switch in {
|
|
case string(AuthActionPublish),
|
|
string(AuthActionRead),
|
|
string(AuthActionPlayback),
|
|
string(AuthActionAPI),
|
|
string(AuthActionMetrics),
|
|
string(AuthActionPprof):
|
|
*d = AuthAction(in)
|
|
|
|
default:
|
|
return fmt.Errorf("invalid auth action: '%s'", in)
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// UnmarshalEnv implements env.Unmarshaler.
|
|
func (d *AuthAction) UnmarshalEnv(_ string, v string) error {
|
|
return d.UnmarshalJSON([]byte(`"` + v + `"`))
|
|
}
|