Files
rtsp-simple-server/internal/protocols/httpp/credentials.go
Alessandro Ros f97213ae6e support passing JWTs through the password field (#4516)
This is safer than passing JWTs through query parameters, unfortunately support is limited.
2025-05-10 22:54:24 +02:00

27 lines
604 B
Go

package httpp
import (
"net/http"
"strings"
"github.com/bluenviron/mediamtx/internal/auth"
)
// Credentials extracts credentials from a HTTP request.
func Credentials(h *http.Request) *auth.Credentials {
c := &auth.Credentials{}
c.User, c.Pass, _ = h.BasicAuth()
if auth := h.Header.Get("Authorization"); strings.HasPrefix(auth, "Bearer ") {
if parts := strings.Split(auth[len("Bearer "):], ":"); len(parts) == 2 { // user:pass in Authorization Bearer
c.User = parts[0]
c.Pass = parts[1]
} else { // JWT in Authorization Bearer
c.Token = auth[len("Bearer "):]
}
}
return c
}