mediamtx/internal/core/externalauth.go
ShiBen e3f63a43c9 External authentication support send url raw query
Do some dynamic authentication, such as token
2022-01-23 23:04:36 +01:00

46 lines
807 B
Go

package core
import (
"bytes"
"encoding/json"
"fmt"
"net/http"
)
func externalAuth(
ur string,
ip string,
user string,
password string,
path string,
action string,
query string,
) error {
enc, _ := json.Marshal(struct {
IP string `json:"ip"`
User string `json:"user"`
Password string `json:"password"`
Path string `json:"path"`
Action string `json:"action"`
Query string `json:"query"`
}{
IP: ip,
User: user,
Password: password,
Path: path,
Action: action,
Query: query,
})
res, err := http.Post(ur, "application/json", bytes.NewReader(enc))
if err != nil {
return err
}
defer res.Body.Close()
if res.StatusCode < 200 || res.StatusCode > 299 {
return fmt.Errorf("bad status code: %d", res.StatusCode)
}
return nil
}